private DependencySet saveTest(String file_path, String file_nonce, SystemProcedureExecutionContext context, String hostname) {
{
VoltTable result = constructNodeResultsTable();
// Choose the lowest site ID on this host to do the file scan
// All other sites should just return empty results tables.
Host catalog_host = context.getHost();
Site site = context.getSite();
CatalogMap<Partition> partition_map = site.getPartitions();
Integer lowest_partition_id = Integer.MAX_VALUE, p_id;
Integer lowest_site_id = Integer.MAX_VALUE, s_id;
for(Site st : CatalogUtil.getAllSites(catalog_host)){
s_id = st.getId();
lowest_site_id = Math.min(s_id, lowest_site_id);
}
for(Partition pt : partition_map){
p_id = pt.getId();
lowest_partition_id = Math.min(p_id, lowest_partition_id);
}
assert(lowest_partition_id != Integer.MAX_VALUE);
//LOG.trace("Partition id :" + context.getPartitionExecutor().getPartitionId());
//LOG.trace("Lowest Partition id :" + lowest_partition_id);
// Do it at partition with lowest partition id on site with lowest site id
// as we can have multiple partitions per site in HStore
if (context.getSite().getId() == lowest_site_id && context.getPartitionExecutor().getPartitionId() == lowest_partition_id) {
LOG.trace("Checking feasibility of save with path and nonce: " + file_path + ", " + file_nonce);
LOG.trace("ExecutionSitesCurrentlySnapshotting check : " + SnapshotSiteProcessor.ExecutionSitesCurrentlySnapshotting.get());
// CHANGE : Only 1 Site doing this
if (SnapshotSiteProcessor.ExecutionSitesCurrentlySnapshotting.get() != -1) {
result.addRow(Integer.parseInt(context.getSite().getHost().getTypeName().replaceAll("[\\D]", "")), hostname, "", "FAILURE", "SNAPSHOT IN PROGRESS");
return new DependencySet(DEP_saveTest, result);
}
for (Table table : SnapshotUtil.getTablesToSave(context.getDatabase())) {
File saveFilePath = SnapshotUtil.constructFileForTable(table, file_path, file_nonce,
String.valueOf(context.getHost().getId()),
String.valueOf(context.getHStoreSite().getSiteId()),
String.valueOf(context.getPartitionExecutor().getPartitionId())
);
LOG.trace("Host ID " + context.getSite().getHost().getTypeName() + " table: " + table.getTypeName() + " to path: " + saveFilePath);
String file_valid = "SUCCESS";
String err_msg = "";
if (saveFilePath.exists()) {
file_valid = "FAILURE";
err_msg = "SAVE FILE ALREADY EXISTS: " + saveFilePath;
} else if (!saveFilePath.getParentFile().canWrite()) {
file_valid = "FAILURE";
err_msg = "FILE LOCATION UNWRITABLE: " + saveFilePath;
} else {
try {
saveFilePath.createNewFile();
} catch (IOException ex) {
file_valid = "FAILURE";
err_msg = "FILE CREATION OF " + saveFilePath + "RESULTED IN IOException: " + ex.getMessage();
}
}
result.addRow(catalog_host.getId(), hostname, context.getHStoreSite().getSiteId(), context.getPartitionExecutor().getPartitionId(), table.getTypeName(), file_valid, err_msg);
}
}
//LOG.trace("Host ID " + context.getSite().getHost().getTypeName() + "\n" + new DependencySet(DEP_saveTest, result));
return new DependencySet(DEP_saveTest, result);
}