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);
}
}
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;
}
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;
}
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();
}
}
}
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;
}
Aggregations