m_fileNonce = (String) params.toArray()[1];
LOG.trace("Checking saved table state for restore of: " + m_filePath + ", " + m_fileNonce);
File[] savefiles = retrieveRelevantFiles(m_filePath, m_fileNonce);
for (File file : savefiles) {
LOG.trace("Retrieving File :" + file);
TableSaveFile savefile = null;
try {
savefile = getTableSaveFile(file, 1, null);
try {
if (!savefile.getCompleted()) {
continue;
}
String is_replicated = "FALSE";
if (savefile.isReplicated()) {
is_replicated = "TRUE";
}
int partitionIds[] = savefile.getPartitionIds();
for (int pid : partitionIds) {
result.addRow(m_hostId, hostname, savefile.getHostId(), savefile.getHostname(), savefile.getClusterName(), savefile.getDatabaseName(), savefile.getTableName(),
is_replicated, pid, savefile.getTotalPartitions());
}
} finally {
savefile.close();
}
} catch (FileNotFoundException e) {
// retrieveRelevantFiles should always generate a list
// of valid present files in m_filePath, so if we end up
// getting here, something has gone very weird.
e.printStackTrace();
} catch (IOException e) {
// For the time being I'm content to treat this as a
// missing file and let the coordinator complain if
// it discovers that it can't build a consistent
// database out of the files it sees available.
//
// Maybe just a log message? Later.
e.printStackTrace();
}
}
} else {
// Initialize on other sites
m_filePath = (String) params.toArray()[0];
m_fileNonce = (String) params.toArray()[1];
}
return new DependencySet(DEP_restoreScan, result);
} else if (fragmentId == SysProcFragmentId.PF_restoreScanResults) {
LOG.trace("Aggregating saved table state");
assert (dependencies.size() > 0);
List<VoltTable> dep = dependencies.get(DEP_restoreScan);
VoltTable result = ClusterSaveFileState.constructEmptySaveFileStateVoltTable();
for (VoltTable table : dep) {
while (table.advanceRow()) {
// the actually adds the active row... weird...
result.add(table);
}
}
return new DependencySet(DEP_restoreScanResults, result);
} else if (fragmentId == SysProcFragmentId.PF_restoreLoadReplicatedTable) {
assert (params.toArray()[0] != null);
assert (params.toArray()[1] != null);
assert (params.toArray()[2] != null);
String table_name = (String) params.toArray()[0];
int dependency_id = (Integer) params.toArray()[1];
int allowExport = (Integer) params.toArray()[2];
LOG.trace("restoreLoadReplicatedTable :: Partition id :" + context.getPartitionExecutor().getPartitionId());
//LOG.trace("Dependency_id :" + dependency_id + " - Loading replicated table: " + table_name);
String result_str = "SUCCESS";
String error_msg = "";
TableSaveFile savefile = null;
/**
* For replicated tables this will do the slow thing and read the
* file once for each ExecutionSite. This could use optimization
* like is done with the partitioned tables.
*/
try {
savefile = getTableSaveFile(getSaveFileForReplicatedTable(table_name), 3, null);
assert (savefile.getCompleted());
} catch (IOException e) {
VoltTable result = constructResultsTable();
result.addRow(m_hostId, hostname, m_siteId, table_name, -1, "FAILURE", "Unable to load table: " + table_name + " error: " + e.getMessage());
return new DependencySet(dependency_id, result);
}
try {
while (savefile.hasMoreChunks()) {
VoltTable table = null;
final org.voltdb.utils.DBBPool.BBContainer c = savefile.getNextChunk();
if (c == null) {
continue;// Should be equivalent to break
}
VoltTable old_table = PrivateVoltTableFactory.createVoltTableFromBuffer(c.b, true);
Table new_catalog_table = getCatalogTable(table_name);
table = SavedTableConverter.convertTable(old_table, new_catalog_table);
c.discard();
try {
LOG.trace("LoadTable " + table_name);
this.executor.loadTable(ts, context.getCluster().getTypeName(), context.getDatabase().getTypeName(), table_name, table, allowExport);
} catch (VoltAbortException e) {
result_str = "FAILURE";
error_msg = e.getMessage();
break;
}
}
} catch (IOException e) {
VoltTable result = constructResultsTable();
result.addRow(m_hostId, hostname, m_siteId, table_name, -1, "FAILURE", "Unable to load table: " + table_name + " error: " + e.getMessage());
return new DependencySet(dependency_id, result);
} catch (VoltTypeException e) {
VoltTable result = constructResultsTable();
result.addRow(m_hostId, hostname, m_siteId, table_name, -1, "FAILURE", "Unable to load table: " + table_name + " error: " + e.getMessage());
return new DependencySet(dependency_id, result);
}
VoltTable result = constructResultsTable();
result.addRow(m_hostId, hostname, m_siteId, table_name, -1, result_str, error_msg);
try {
savefile.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new DependencySet(dependency_id, result);