Search in sources :

Example 1 with VoltFile

use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.

the class InvocationDispatcher method getSnapshotCatalogFile.

private final File getSnapshotCatalogFile(JSONObject snapJo) throws JSONException {
    NodeSettings paths = m_catalogContext.get().getNodeSettings();
    String catFN = snapJo.getString(SnapshotUtil.JSON_NONCE) + ".jar";
    SnapshotPathType pathType = SnapshotPathType.valueOf(snapJo.optString(SnapshotUtil.JSON_PATH_TYPE, SnapshotPathType.SNAP_PATH.name()));
    switch(pathType) {
        case SNAP_AUTO:
            return new File(paths.resolve(paths.getSnapshoth()), catFN);
        case SNAP_CL:
            return new File(paths.resolve(paths.getCommandLogSnapshot()), catFN);
        default:
            File snapDH = new VoltFile(snapJo.getString(SnapshotUtil.JSON_PATH));
            return new File(snapDH, catFN);
    }
}
Also used : NodeSettings(org.voltdb.settings.NodeSettings) VoltFile(org.voltdb.utils.VoltFile) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) SnapshotPathType(org.voltdb.sysprocs.saverestore.SnapshotPathType)

Example 2 with VoltFile

use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.

the class SnapshotScanAgent method getDiskFreeResults.

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, total, free, used, "SUCCESS", "");
    } else {
        results.addRow(m_messenger.getHostId(), m_hostname, path, 0, 0, 0, "FAILURE", "Path is not a directory");
    }
    return results;
}
Also used : VoltFile(org.voltdb.utils.VoltFile) VoltFile(org.voltdb.utils.VoltFile) TableSaveFile(org.voltdb.sysprocs.saverestore.TableSaveFile) File(java.io.File)

Example 3 with VoltFile

use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.

the class SnapshotUtil method retrieveHashinatorConfig.

/**
     * Retrieve hashinator config for restore.
     * @param path snapshot base directory
     * @param nonce unique snapshot ID
     * @param hostId host ID
     * @return hashinator shapshot data
     * @throws Exception
     */
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);
                break;
            }
        }
    }
    if (hashData == null && TheHashinator.getConfiguredHashinatorType() == HashinatorType.ELASTIC) {
        throw new IOException("Missing hashinator data in snapshot");
    }
    return hashData;
}
Also used : VoltFile(org.voltdb.utils.VoltFile) IOException(java.io.IOException) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File)

Example 4 with VoltFile

use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.

the class SnapshotUtil method writeSnapshotDigest.

/**
     * Create a digest for a snapshot
     * @param txnId   transaction ID when snapshot was initiated
     * @param path    path to which snapshot files will be written
     * @param nonce   nonce used to distinguish this snapshot
     * @param tables   List of tables present in this snapshot
     * @param hostId   Host ID where this is happening
     * @param extraSnapshotData persisted export, DR, etc state
     * @throws IOException
     */
public static Runnable writeSnapshotDigest(long txnId, long catalogCRC, String path, String pathType, String nonce, List<Table> tables, int hostId, Map<Integer, Long> partitionTransactionIds, ExtensibleSnapshotDigestData extraSnapshotData, InstanceId instanceId, long timestamp, int newPartitionCount, int clusterId) 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.keySymbolValuePair("version", 1);
            stringer.keySymbolValuePair("clusterid", clusterId);
            stringer.keySymbolValuePair("txnId", txnId);
            stringer.keySymbolValuePair("timestamp", timestamp);
            stringer.keySymbolValuePair("timestampString", SnapshotUtil.formatHumanReadableDate(timestamp));
            stringer.keySymbolValuePair("newPartitionCount", newPartitionCount);
            stringer.key("tables").array();
            for (int ii = 0; ii < tables.size(); ii++) {
                stringer.value(tables.get(ii).getTypeName());
            }
            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.keySymbolValuePair("catalogCRC", catalogCRC);
            stringer.key("instanceId").value(instanceId.serializeToJSONObject());
            extraSnapshotData.writeToSnapshotDigest(stringer);
            stringer.endObject();
        } catch (JSONException e) {
            throw new IOException(e);
        }
        sw.append(stringer.toString());
        final byte[] tableListBytes = sw.getBuffer().toString().getBytes(StandardCharsets.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();
        }
    }
}
Also used : PureJavaCrc32(org.apache.hadoop_voltpatches.util.PureJavaCrc32) JSONException(org.json_voltpatches.JSONException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) StringWriter(java.io.StringWriter) VoltFile(org.voltdb.utils.VoltFile) FileOutputStream(java.io.FileOutputStream) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) JSONStringer(org.json_voltpatches.JSONStringer) Map(java.util.Map) CatalogMap(org.voltdb.catalog.CatalogMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 5 with VoltFile

use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.

the class SnapshotUtil method retrieveHashinatorConfigs.

/**
     * Read hashinator snapshots into byte buffers.
     * @param path base snapshot path
     * @param nonce unique snapshot name
     * @param maxConfigs max number of good configs to return (0 for all)
     * @param logger log writer
     * @return byte buffers for each host
     * @throws IOException
     */
public static List<ByteBuffer> retrieveHashinatorConfigs(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 {
                fis = new FileInputStream(file);
                dis = new DataInputStream(fis);
                dis.readFully(rawData);
                configs.add(ByteBuffer.wrap(rawData));
            } finally {
                if (dis != null) {
                    dis.close();
                }
                if (fis != null) {
                    fis.close();
                }
            }
        }
    }
    return configs;
}
Also used : VoltFile(org.voltdb.utils.VoltFile) ArrayList(java.util.ArrayList) DataInputStream(java.io.DataInputStream) ByteBuffer(java.nio.ByteBuffer) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

File (java.io.File)19 VoltFile (org.voltdb.utils.VoltFile)19 IOException (java.io.IOException)8 FileOutputStream (java.io.FileOutputStream)5 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 JSONException (org.json_voltpatches.JSONException)3 FileWriter (java.io.FileWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 SocketException (java.net.SocketException)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)2 JSONObject (org.json_voltpatches.JSONObject)2 CatalogMap (org.voltdb.catalog.CatalogMap)2 VoltCompiler (org.voltdb.compiler.VoltCompiler)2 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)2 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)1