Examples of VoltFile


Examples of org.voltdb.utils.VoltFile

    }

    private static Stuff getStream(final String name) throws IOException {
        Stuff s = m_files.get(name);
        if (s == null) {
            File f = new VoltFile(path, name);
            f.delete();
            RandomAccessFile ras = new RandomAccessFile(f, "rw");
            ras.seek(8);
            SnappyOutputStream sos = new SnappyOutputStream(new FileOutputStream(ras.getFD()));
            DataOutputStream dos = new DataOutputStream(sos);
            s = new Stuff();
View Full Code Here

Examples of org.voltdb.utils.VoltFile

        InstanceId instanceId,
        long timestamp,
        int newPartitionCount)
    throws IOException
    {
        final File f = new VoltFile(path, constructDigestFilenameForNonce(nonce, hostId));
        if (f.exists()) {
            if (!f.delete()) {
                throw new IOException("Unable to write table list file " + f);
            }
        }
        boolean success = false;
        try {
            final FileOutputStream fos = new FileOutputStream(f);
            StringWriter sw = new StringWriter();
            JSONStringer stringer = new JSONStringer();
            try {
                stringer.object();
                stringer.key("version").value(1);
                stringer.key("txnId").value(txnId);
                stringer.key("timestamp").value(timestamp);
                stringer.key("timestampString").value(SnapshotUtil.formatHumanReadableDate(timestamp));
                stringer.key("newPartitionCount").value(newPartitionCount);
                stringer.key("tables").array();
                for (int ii = 0; ii < tables.size(); ii++) {
                    stringer.value(tables.get(ii).getTypeName());
                }
                stringer.endArray();
                stringer.key("exportSequenceNumbers").array();
                for (Map.Entry<String, Map<Integer, Pair<Long, Long>>> entry : exportSequenceNumbers.entrySet()) {
                    stringer.object();

                    stringer.key("exportTableName").value(entry.getKey());

                    stringer.key("sequenceNumberPerPartition").array();
                    for (Map.Entry<Integer, Pair<Long,Long>> sequenceNumber : entry.getValue().entrySet()) {
                        stringer.object();
                        stringer.key("partition").value(sequenceNumber.getKey());
                        //First value is the ack offset which matters for pauseless rejoin, but not persistence
                        stringer.key("exportSequenceNumber").value(sequenceNumber.getValue().getSecond());
                        stringer.endObject();
                    }
                    stringer.endArray();

                    stringer.endObject();
                }
                stringer.endArray();

                stringer.key("partitionTransactionIds").object();
                for (Map.Entry<Integer, Long> entry : partitionTransactionIds.entrySet()) {
                    stringer.key(entry.getKey().toString()).value(entry.getValue());
                }
                stringer.endObject();

                stringer.key("catalogCRC").value(catalogCRC);
                stringer.key("instanceId").value(instanceId.serializeToJSONObject());
                stringer.endObject();
            } catch (JSONException e) {
                throw new IOException(e);
            }

            sw.append(stringer.toString());

            final byte tableListBytes[] = sw.getBuffer().toString().getBytes("UTF-8");
            final PureJavaCrc32 crc = new PureJavaCrc32();
            crc.update(tableListBytes);
            ByteBuffer fileBuffer = ByteBuffer.allocate(tableListBytes.length + 4);
            fileBuffer.putInt((int)crc.getValue());
            fileBuffer.put(tableListBytes);
            fileBuffer.flip();
            fos.getChannel().write(fileBuffer);
            success = true;
            return new Runnable() {
                @Override
                public void run() {
                    try {
                        fos.getChannel().force(true);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    } finally {
                        try {
                            fos.close();
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            };
        } finally {
            if (!success) {
                f.delete();
            }
        }
    }
View Full Code Here

Examples of org.voltdb.utils.VoltFile

        String nonce,
        int hostId,
        HashinatorSnapshotData hashData)
    throws IOException
    {
        final File file = new VoltFile(path, constructHashinatorConfigFilenameForNonce(nonce, hostId));
        if (file.exists()) {
            if (!file.delete()) {
                throw new IOException("Unable to replace existing hashinator config " + file);
            }
        }

        boolean success = false;
        try {
            final FileOutputStream fos = new FileOutputStream(file);
            ByteBuffer fileBuffer = hashData.saveToBuffer(instId);
            fos.getChannel().write(fileBuffer);
            success = true;
            return new Runnable()
            {
                @Override
                public void run()
                {
                    try {
                        fos.getChannel().force(true);
                    }
                    catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                    finally {
                        try {
                            fos.close();
                        }
                        catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            };
        }
        finally {
            if (!success) {
                file.delete();
            }
        }
    }
View Full Code Here

Examples of org.voltdb.utils.VoltFile

        throw new IllegalArgumentException("Bad snapshot filename: " + filename);
    }

    public static List<JSONObject> retrieveDigests(String path,
            String nonce, VoltLogger logger) throws Exception {
        VoltFile directoryWithDigest = new VoltFile(path);
        ArrayList<JSONObject> digests = new ArrayList<JSONObject>();
        if (directoryWithDigest.listFiles() == null) {
            return digests;
        }
        for (File f : directoryWithDigest.listFiles()) {
            if ( f.getName().equals(nonce + ".digest") || //old style digest name
                    (f.getName().startsWith(nonce + "-host_") && f.getName().endsWith(".digest"))) {//new style
                JSONObject retval = CRCCheck(f, logger);
                if (retval != null) {
                    digests.add(retval);
View Full Code Here

Examples of org.voltdb.utils.VoltFile

        String path,
        String nonce,
        int maxConfigs,
        VoltLogger logger) throws IOException
   {
        VoltFile directory = new VoltFile(path);
        ArrayList<ByteBuffer> configs = new ArrayList<ByteBuffer>();
        if (directory.listFiles() == null) {
            return configs;
        }
        for (File file : directory.listFiles()) {
            if (file.getName().startsWith(nonce + "-host_") && file.getName().endsWith(HASH_EXTENSION)) {
                byte[] rawData = new byte[(int) file.length()];
                FileInputStream fis = null;
                DataInputStream dis = null;
                try {
View Full Code Here

Examples of org.voltdb.utils.VoltFile

    /**
     * Write the .complete file for finished snapshot
     */
    public static Runnable writeSnapshotCompletion(String path, String nonce, int hostId, final VoltLogger logger) throws IOException {

        final File f = new VoltFile(path, constructCompletionFilenameForNonce(nonce, hostId));
        if (f.exists()) {
            if (!f.delete()) {
                throw new IOException("Failed to replace existing " + f.getName());
            }
        }
        return new Runnable() {
            @Override
            public void run() {
                try {
                    f.createNewFile();
                } catch (IOException e) {
                    throw new RuntimeException("Failed to create .complete file for " + f.getName(), e);
                }
            }
        };
    }
View Full Code Here

Examples of org.voltdb.utils.VoltFile

            String filePath,
            String fileNonce,
            SnapshotFormat format,
            int hostId)
    {
        return new VoltFile(filePath, SnapshotUtil.constructFilenameForTable(
            table, fileNonce, format, hostId));
    }
View Full Code Here

Examples of org.voltdb.utils.VoltFile

            {
                return file.startsWith(fileNonce) && file.endsWith(".vpt");
            }
        };

        File save_dir = new VoltFile(filePath);
        File[] save_files = save_dir.listFiles(has_nonce);
        return save_files;
    }
View Full Code Here

Examples of org.voltdb.utils.VoltFile

     */
    public static HashinatorSnapshotData retrieveHashinatorConfig(
            String path, String nonce, int hostId, VoltLogger logger) throws IOException {
        HashinatorSnapshotData hashData = null;
        String expectedFileName = constructHashinatorConfigFilenameForNonce(nonce, hostId);
        File[] files = new VoltFile(path).listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.getName().equals(expectedFileName)) {
                    hashData = new HashinatorSnapshotData();
                    hashData.restoreFromFile(file);
View Full Code Here

Examples of org.voltdb.utils.VoltFile

    }

    private VoltTable getDiskFreeResults(String path)
    {
        VoltTable results = constructDiskFreeResultsTable();
        File dir = new VoltFile(path);

        if (dir.isDirectory()) {
            final long free = dir.getUsableSpace();
            final long total = dir.getTotalSpace();
            final long used = total - free;
            results.addRow(
                    m_messenger.getHostId(),
                    m_hostname,
                    path,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.