use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class UpdateCore method executePlanFragment.
@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
if (fragmentId == SysProcFragmentId.PF_updateCatalogPrecheckAndSync) {
String[] tablesThatMustBeEmpty = (String[]) params.getParam(0);
String[] reasonsForEmptyTables = (String[]) params.getParam(1);
checkForNonEmptyTables(tablesThatMustBeEmpty, reasonsForEmptyTables, context);
// Send out fragments to do the initial round-trip to synchronize
// all the cluster sites on the start of catalog update, we'll do
// the actual work on the *next* round-trip below
// Don't actually care about the returned table, just need to send something
// back to the MPI scoreboard
DependencyPair success = new DependencyPair.TableDependencyPair(DEP_updateCatalogSync, new VoltTable(new ColumnInfo[] { new ColumnInfo("UNUSED", VoltType.BIGINT) }));
if (!context.isLowestSiteId()) {
// id on this host.
if (log.isInfoEnabled()) {
log.info("Site " + CoreUtils.hsIdToString(m_site.getCorrespondingSiteId()) + " completed data precheck.");
}
return success;
}
// We know the ZK bytes are okay because the run() method wrote them before sending
// out fragments
CatalogAndIds catalogStuff = null;
try {
catalogStuff = CatalogUtil.getCatalogFromZK(VoltDB.instance().getHostMessenger().getZK());
InMemoryJarfile testjar = new InMemoryJarfile(catalogStuff.catalogBytes);
JarLoader testjarloader = testjar.getLoader();
for (String classname : testjarloader.getClassNames()) {
try {
m_javaClass.forName(classname, true, testjarloader);
}// care about here.
catch (UnsupportedClassVersionError e) {
String msg = "Cannot load classes compiled with a higher version of Java than currently" + " in use. Class " + classname + " was compiled with ";
Integer major = 0;
try {
major = Integer.parseInt(e.getMessage().split("version")[1].trim().split("\\.")[0]);
} catch (Exception ex) {
log.debug("Unable to parse compile version number from UnsupportedClassVersionError.", ex);
}
if (m_versionMap.containsKey(major)) {
msg = msg.concat(m_versionMap.get(major) + ", current runtime version is " + System.getProperty("java.version") + ".");
} else {
msg = msg.concat("an incompatable Java version.");
}
log.error(msg);
throw new VoltAbortException(msg);
} catch (LinkageError | ClassNotFoundException e) {
String cause = e.getMessage();
if (cause == null && e.getCause() != null) {
cause = e.getCause().getMessage();
}
String msg = "Error loading class: " + classname + " from catalog: " + e.getClass().getCanonicalName() + ", " + cause;
log.warn(msg);
throw new VoltAbortException(e);
}
}
} catch (Exception e) {
Throwables.propagate(e);
}
if (log.isInfoEnabled()) {
log.info("Site " + CoreUtils.hsIdToString(m_site.getCorrespondingSiteId()) + " completed data and catalog precheck.");
}
return success;
} else if (fragmentId == SysProcFragmentId.PF_updateCatalogPrecheckAndSyncAggregate) {
// Don't actually care about the returned table, just need to send something
// back to the MPI scoreboard
log.info("Site " + CoreUtils.hsIdToString(m_site.getCorrespondingSiteId()) + " acknowledged data and catalog prechecks.");
return new DependencyPair.TableDependencyPair(DEP_updateCatalogSyncAggregate, new VoltTable(new ColumnInfo[] { new ColumnInfo("UNUSED", VoltType.BIGINT) }));
} else if (fragmentId == SysProcFragmentId.PF_updateCatalog) {
String catalogDiffCommands = (String) params.toArray()[0];
String commands = Encoder.decodeBase64AndDecompress(catalogDiffCommands);
int expectedCatalogVersion = (Integer) params.toArray()[1];
boolean requiresSnapshotIsolation = ((Byte) params.toArray()[2]) != 0;
boolean requireCatalogDiffCmdsApplyToEE = ((Byte) params.toArray()[3]) != 0;
boolean hasSchemaChange = ((Byte) params.toArray()[4]) != 0;
boolean requiresNewExportGeneration = ((Byte) params.toArray()[5]) != 0;
CatalogAndIds catalogStuff = null;
try {
catalogStuff = CatalogUtil.getCatalogFromZK(VoltDB.instance().getHostMessenger().getZK());
} catch (Exception e) {
Throwables.propagate(e);
}
String replayInfo = m_runner.getTxnState().isForReplay() ? " (FOR REPLAY)" : "";
// if this is a new catalog, do the work to update
if (context.getCatalogVersion() == expectedCatalogVersion) {
// update the global catalog if we get there first
@SuppressWarnings("deprecation") Pair<CatalogContext, CatalogSpecificPlanner> p = VoltDB.instance().catalogUpdate(commands, catalogStuff.catalogBytes, catalogStuff.getCatalogHash(), expectedCatalogVersion, DeprecatedProcedureAPIAccess.getVoltPrivateRealTransactionId(this), getUniqueId(), catalogStuff.deploymentBytes, catalogStuff.getDeploymentHash(), requireCatalogDiffCmdsApplyToEE, hasSchemaChange, requiresNewExportGeneration);
// The producer would have been turned off by the code above already.
if (VoltDB.instance().getReplicationRole() == ReplicationRole.NONE && !VoltDB.instance().getReplicationActive()) {
context.resetDrAppliedTracker();
}
// update the local catalog. Safe to do this thanks to the check to get into here.
long uniqueId = m_runner.getUniqueId();
long spHandle = m_runner.getTxnState().getNotice().getSpHandle();
context.updateCatalog(commands, p.getFirst(), p.getSecond(), requiresSnapshotIsolation, uniqueId, spHandle, requireCatalogDiffCmdsApplyToEE, requiresNewExportGeneration);
if (log.isDebugEnabled()) {
log.debug(String.format("Site %s completed catalog update with catalog hash %s, deployment hash %s%s.", CoreUtils.hsIdToString(m_site.getCorrespondingSiteId()), Encoder.hexEncode(catalogStuff.getCatalogHash()).substring(0, 10), Encoder.hexEncode(catalogStuff.getDeploymentHash()).substring(0, 10), replayInfo));
}
} else // if seen before by this code, then check to see if this is a restart
if (context.getCatalogVersion() == (expectedCatalogVersion + 1) && Arrays.equals(context.getCatalogHash(), catalogStuff.getCatalogHash()) && Arrays.equals(context.getDeploymentHash(), catalogStuff.getDeploymentHash())) {
log.info(String.format("Site %s will NOT apply an assumed restarted and identical catalog update with catalog hash %s and deployment hash %s.", CoreUtils.hsIdToString(m_site.getCorrespondingSiteId()), Encoder.hexEncode(catalogStuff.getCatalogHash()), Encoder.hexEncode(catalogStuff.getDeploymentHash())));
} else {
VoltDB.crashLocalVoltDB("Invalid catalog update. Expected version: " + expectedCatalogVersion + ", current version: " + context.getCatalogVersion(), false, null);
}
VoltTable result = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
result.addRow(VoltSystemProcedure.STATUS_OK);
return new DependencyPair.TableDependencyPair(DEP_updateCatalog, result);
} else if (fragmentId == SysProcFragmentId.PF_updateCatalogAggregate) {
VoltTable result = VoltTableUtil.unionTables(dependencies.get(DEP_updateCatalog));
return new DependencyPair.TableDependencyPair(DEP_updateCatalogAggregate, result);
} else {
VoltDB.crashLocalVoltDB("Received unrecognized plan fragment id " + fragmentId + " in UpdateApplicationCatalog", false, null);
}
throw new RuntimeException("Should not reach this code");
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class UpdateLogging method run.
/**
* Change the operational log configuration.
* @param ctx Internal parameter. Not user-accessible.
* @param xmlConfig New configuration XML document.
* @return Standard STATUS table.
*/
@SuppressWarnings("deprecation")
public VoltTable[] run(SystemProcedureExecutionContext ctx, String username, String remoteHost, String xmlConfig) {
long oldLevels = 0;
if (ctx.isLowestSiteId()) {
// Logger level is a global property, pick the site with lowest id to do it.
hostLog.info(String.format("%s from %s changed the log4j settings", username, remoteHost));
hostLog.info(xmlConfig);
oldLevels = hostLog.getLogLevels(loggers);
}
try {
// Mimic the multi-fragment semantics as scatter-gather pattern is an overkill for this simple task.
// There are chances that some sites being interrupted and update the logging before old logger level
// being read, but the reasons we don't care because 1) it is rare and 2) it only effects when HOST
// logger being changed from higher than INFO level to INFO or lower level.
barrier.await();
} catch (InterruptedException | BrokenBarrierException dontcare) {
}
VoltDB.instance().logUpdate(xmlConfig, DeprecatedProcedureAPIAccess.getVoltPrivateRealTransactionId(this), ctx.getPaths().getVoltDBRoot());
ctx.updateBackendLogLevels();
if (ctx.isLowestSiteId()) {
long newLevels = hostLog.getLogLevels(loggers);
if (newLevels != oldLevels) {
// If HOST logger wasn't able to log before and now it can, logs the setting change event.
int index = (int) ((oldLevels >> 3) & 7);
Level before = Level.values()[index];
index = (int) ((newLevels >> 3) & 7);
Level after = Level.values()[index];
if (before.ordinal() > Level.INFO.ordinal() && after.ordinal() <= Level.INFO.ordinal()) {
hostLog.info(String.format("%s from %s changed the log4j settings", username, remoteHost));
hostLog.info(xmlConfig);
}
}
barrier.reset();
}
VoltTable t = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
t.addRow(VoltSystemProcedure.STATUS_OK);
return (new VoltTable[] { t });
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class PrepareShutdown method executePlanFragment.
@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
if (fragmentId == PF_prepareShutdown) {
super.run(context);
VoltTable t = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
if (context.isLowestSiteId()) {
VoltDB.instance().setShuttingdown(true);
t.addRow(m_stat.getMzxid());
if (LOG.isDebugEnabled()) {
LOG.debug("@PrepareShutdown returning sigil " + ll(m_stat.getMzxid()));
}
}
return new DependencyPair.TableDependencyPair(DEP_prepareShutdown, t);
} else if (fragmentId == PF_prepareShutdownAggregate) {
NavigableSet<Long> uniqueTxnIds = new TreeSet<>();
for (VoltTable t : dependencies.get(DEP_prepareShutdown)) {
while (t.advanceRow()) {
uniqueTxnIds.add(t.getLong(0));
}
}
VoltTable t = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
for (long zktxnid : uniqueTxnIds) {
t.addRow(zktxnid);
}
return new DependencyPair.TableDependencyPair(DEP_prepareShutdonwAggregate, t);
} else {
VoltDB.crashLocalVoltDB("Received unrecognized plan fragment id " + fragmentId + " in PrepareShutdown", false, null);
}
throw new RuntimeException("Should not reach this code");
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class ProfCtl method run.
public VoltTable[] run(SystemProcedureExecutionContext ctx, String command) {
VoltTable table = new VoltTable(new ColumnInfo("Result", VoltType.STRING));
if (command.equalsIgnoreCase("SAMPLER_START")) {
VoltDB.instance().startSampler();
table.addRow(command);
} else if (command.equalsIgnoreCase("GPERF_ENABLE") || command.equalsIgnoreCase("GPERF_DISABLE")) {
// Choose the lowest site ID on this host to do the work.
table.addRow(command);
if (ctx.isLowestSiteId()) {
if (command.equalsIgnoreCase("GPERF_ENABLE")) {
ctx.getSiteProcedureConnection().toggleProfiler(1);
} else {
ctx.getSiteProcedureConnection().toggleProfiler(0);
}
}
} else {
table.addRow("Invalid command: " + command);
}
return (new VoltTable[] { table });
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class Quiesce method executePlanFragment.
@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
try {
if (fragmentId == SysProcFragmentId.PF_quiesce_sites) {
// tell each site to quiesce
context.getSiteProcedureConnection().quiesce();
VoltTable results = new VoltTable(new ColumnInfo("id", VoltType.BIGINT));
results.addRow(context.getSiteId());
return new DependencyPair.TableDependencyPair(DEP_SITES, results);
} else if (fragmentId == SysProcFragmentId.PF_quiesce_processed_sites) {
VoltTable dummy = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
dummy.addRow(VoltSystemProcedure.STATUS_OK);
return new DependencyPair.TableDependencyPair(DEP_PROCESSED_SITES, dummy);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
Aggregations