use of org.voltdb.VoltProcedure.VoltAbortException in project voltdb by VoltDB.
the class ProcedureRunnerNT method callAllNodeNTProcedure.
/**
* Send an invocation directly to each host's CI mailbox.
* This ONLY works for NT procedures.
* Track responses and complete the returned future when they're all accounted for.
*/
protected CompletableFuture<Map<Integer, ClientResponse>> callAllNodeNTProcedure(String procName, Object... params) {
// only one of these at a time
if (m_outstandingAllHostProc.get()) {
throw new VoltAbortException(new IllegalStateException("Only one AllNodeNTProcedure operation can be running at a time."));
}
m_outstandingAllHostProc.set(true);
StoredProcedureInvocation invocation = new StoredProcedureInvocation();
invocation.setProcName(procName);
invocation.setParams(params);
invocation.setClientHandle(m_id);
final Iv2InitiateTaskMessage workRequest = new Iv2InitiateTaskMessage(m_mailbox.getHSId(), m_mailbox.getHSId(), Iv2InitiateTaskMessage.UNUSED_TRUNC_HANDLE, m_id, m_id, true, false, invocation, m_id, ClientInterface.NT_REMOTE_PROC_CID, false);
m_allHostFut = new CompletableFuture<>();
m_allHostResponses = new HashMap<>();
Set<Integer> liveHostIds = null;
// also held when
synchronized (m_allHostCallbackLock) {
// collect the set of live client interface mailbox ids
liveHostIds = VoltDB.instance().getHostMessenger().getLiveHostIds();
m_outstandingAllHostProcedureHostIds = liveHostIds;
}
// convert host ids to hsids
long[] hsids = liveHostIds.stream().map(hostId -> CoreUtils.getHSIdFromHostAndSite(hostId, HostMessenger.CLIENT_INTERFACE_SITE_ID)).mapToLong(x -> x).toArray();
// you get a concurrent modification exception
for (long hsid : hsids) {
m_mailbox.send(hsid, workRequest);
}
return m_allHostFut;
}
use of org.voltdb.VoltProcedure.VoltAbortException in project voltdb by VoltDB.
the class ProcedureRunner method getCleanParams.
private final ParameterSet getCleanParams(SQLStmt stmt, boolean verifyTypeConv, Object... inArgs) {
final byte[] stmtParamTypes = stmt.statementParamTypes;
final int numParamTypes = stmtParamTypes.length;
final Object[] args = new Object[numParamTypes];
if (inArgs.length != numParamTypes) {
throw new VoltAbortException("Number of arguments provided was " + inArgs.length + " where " + numParamTypes + " was expected for statement " + stmt.getText());
}
for (int ii = 0; ii < numParamTypes; ii++) {
VoltType type = VoltType.get(stmtParamTypes[ii]);
// handle non-null values
if (inArgs[ii] != null) {
args[ii] = inArgs[ii];
assert (type != VoltType.INVALID);
if (verifyTypeConv && type != VoltType.INVALID) {
throwIfInfeasibleTypeConversion(stmt, args[ii].getClass(), ii, type);
}
continue;
}
// handle null values
switch(type) {
case TINYINT:
args[ii] = Byte.MIN_VALUE;
break;
case SMALLINT:
args[ii] = Short.MIN_VALUE;
break;
case INTEGER:
args[ii] = Integer.MIN_VALUE;
break;
case BIGINT:
args[ii] = Long.MIN_VALUE;
break;
case FLOAT:
args[ii] = VoltType.NULL_FLOAT;
break;
case TIMESTAMP:
args[ii] = new TimestampType(Long.MIN_VALUE);
break;
case STRING:
args[ii] = VoltType.NULL_STRING_OR_VARBINARY;
break;
case VARBINARY:
args[ii] = VoltType.NULL_STRING_OR_VARBINARY;
break;
case DECIMAL:
args[ii] = VoltType.NULL_DECIMAL;
break;
case GEOGRAPHY_POINT:
args[ii] = VoltType.NULL_POINT;
break;
case GEOGRAPHY:
args[ii] = VoltType.NULL_GEOGRAPHY;
break;
default:
throw new VoltAbortException("Unknown type " + type + " can not be converted to NULL representation for arg " + ii + " for SQL stmt: " + stmt.getText());
}
}
return ParameterSet.fromArrayNoCopy(args);
}
use of org.voltdb.VoltProcedure.VoltAbortException in project voltdb by VoltDB.
the class ProcedureRunner method voltQueueSQL.
public void voltQueueSQL(final String sql, Object... args) {
if (sql == null || sql.isEmpty()) {
throw new IllegalArgumentException("SQL statement '" + sql + "' is null or the empty string");
}
try {
AdHocPlannedStmtBatch batch = m_csp.plan(sql, args, m_isSinglePartition);
if (m_isReadOnly && !batch.isReadOnly()) {
throw new VoltAbortException("Attempted to queue DML adhoc sql '" + sql + "' from read only procedure");
}
assert (1 == batch.plannedStatements.size());
QueuedSQL queuedSQL = new QueuedSQL();
AdHocPlannedStatement plannedStatement = batch.plannedStatements.get(0);
long aggFragId = ActivePlanRepository.loadOrAddRefPlanFragment(plannedStatement.core.aggregatorHash, plannedStatement.core.aggregatorFragment, sql);
long collectorFragId = 0;
if (plannedStatement.core.collectorFragment != null) {
collectorFragId = ActivePlanRepository.loadOrAddRefPlanFragment(plannedStatement.core.collectorHash, plannedStatement.core.collectorFragment, sql);
}
queuedSQL.stmt = SQLStmtAdHocHelper.createWithPlan(plannedStatement.sql, aggFragId, plannedStatement.core.aggregatorHash, true, collectorFragId, plannedStatement.core.collectorHash, true, plannedStatement.core.isReplicatedTableDML, plannedStatement.core.readOnly, plannedStatement.core.parameterTypes, m_site);
Object[] argumentParams = args;
// supporting @AdHocSpForTest with queries that contain '?' parameters.
if (plannedStatement.hasExtractedParams()) {
if (args.length > 0) {
throw new VoltAbortException("Number of arguments provided was " + args.length + " where 0 were expected for statement: " + sql);
}
argumentParams = plannedStatement.extractedParamArray();
if (argumentParams.length != queuedSQL.stmt.statementParamTypes.length) {
String msg = String.format("The wrong number of arguments (" + argumentParams.length + " vs. the " + queuedSQL.stmt.statementParamTypes.length + " expected) were passed for the parameterized statement: %s", sql);
throw new VoltAbortException(msg);
}
}
queuedSQL.params = getCleanParams(queuedSQL.stmt, false, argumentParams);
m_batch.add(queuedSQL);
} catch (Exception e) {
if (e instanceof ExecutionException) {
throw new VoltAbortException(e.getCause());
}
if (e instanceof VoltAbortException) {
throw (VoltAbortException) e;
}
throw new VoltAbortException(e);
}
}
use of org.voltdb.VoltProcedure.VoltAbortException in project voltdb by VoltDB.
the class SysprocFragmentTask method processFragmentTask.
// Extracted the sysproc portion of ExecutionSite processFragmentTask(), then
// modified to work in the new world
public FragmentResponseMessage processFragmentTask(SiteProcedureConnection siteConnection) {
final FragmentResponseMessage currentFragResponse = new FragmentResponseMessage(m_fragmentMsg, m_initiator.getHSId());
currentFragResponse.setStatus(FragmentResponseMessage.SUCCESS, null);
for (int frag = 0; frag < m_fragmentMsg.getFragmentCount(); frag++) {
final long fragmentId = VoltSystemProcedure.hashToFragId(m_fragmentMsg.getPlanHash(frag));
// equivalent to dep.depId:
// final int outputDepId = m_fragmentMsg.getOutputDepId(frag);
final VoltTrace.TraceEventBatch traceLog = VoltTrace.log(VoltTrace.Category.SPSITE);
if (traceLog != null) {
traceLog.add(() -> VoltTrace.beginDuration("runfragmenttask", "txnId", TxnEgo.txnIdToString(getTxnId()), "partition", Integer.toString(siteConnection.getCorrespondingPartitionId()), "fragmentId", String.valueOf(fragmentId)));
}
ParameterSet params = m_fragmentMsg.getParameterSetForFragment(frag);
try {
// run the overloaded sysproc planfragment. pass an empty dependency
// set since remote (non-aggregator) fragments don't receive dependencies.
final DependencyPair dep = siteConnection.executeSysProcPlanFragment(m_txnState, m_inputDeps, fragmentId, params);
// @Shutdown returns null, handle it here
if (dep != null) {
currentFragResponse.addDependency(dep);
}
} catch (final EEException e) {
hostLog.l7dlog(Level.TRACE, LogKeys.host_ExecutionSite_ExceptionExecutingPF.name(), new Object[] { Encoder.hexEncode(m_fragmentMsg.getFragmentPlan(frag)) }, e);
currentFragResponse.setStatus(FragmentResponseMessage.UNEXPECTED_ERROR, e);
if (currentFragResponse.getTableCount() == 0) {
// Make sure the response has at least 1 result with a valid DependencyId
currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(m_fragmentMsg.getOutputDepId(0), m_rawDummyResult, 0, m_rawDummyResult.length));
}
break;
} catch (final SQLException e) {
hostLog.l7dlog(Level.TRACE, LogKeys.host_ExecutionSite_ExceptionExecutingPF.name(), new Object[] { Encoder.hexEncode(m_fragmentMsg.getFragmentPlan(frag)) }, e);
currentFragResponse.setStatus(FragmentResponseMessage.UNEXPECTED_ERROR, e);
if (currentFragResponse.getTableCount() == 0) {
// Make sure the response has at least 1 result with a valid DependencyId
currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(m_fragmentMsg.getOutputDepId(0), m_rawDummyResult, 0, m_rawDummyResult.length));
}
break;
} catch (final SpecifiedException e) {
// Note that with SpecifiedException, the error code here might get changed before
// the client/user sees it. It really just needs to indicate failure.
//
// Key point here vs the next catch block for VAE is to not wrap the subclass of
// SerializableException here to preserve it during the serialization.
//
currentFragResponse.setStatus(FragmentResponseMessage.USER_ERROR, e);
if (currentFragResponse.getTableCount() == 0) {
// Make sure the response has at least 1 result with a valid DependencyId
currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(m_fragmentMsg.getOutputDepId(0), m_rawDummyResult, 0, m_rawDummyResult.length));
}
} catch (final VoltAbortException e) {
currentFragResponse.setStatus(FragmentResponseMessage.USER_ERROR, new SerializableException(CoreUtils.throwableToString(e)));
if (currentFragResponse.getTableCount() == 0) {
// Make sure the response has at least 1 result with a valid DependencyId
currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(m_fragmentMsg.getOutputDepId(0), m_rawDummyResult, 0, m_rawDummyResult.length));
}
break;
}
if (traceLog != null) {
traceLog.add(VoltTrace::endDuration);
}
}
return currentFragResponse;
}
use of org.voltdb.VoltProcedure.VoltAbortException in project voltdb by VoltDB.
the class AsyncBenchmark method runBenchmark.
/**
* Core benchmark code. Connect. Initialize. Run the loop. Cleanup. Print
* Results.
*
* @throws Exception
* if anything unexpected happens.
*/
public void runBenchmark() throws Exception {
benchmarkThread = Thread.currentThread();
log.info(HORIZONTAL_RULE);
log.info(" Setup & Initialization");
log.info(HORIZONTAL_RULE);
// connect to one or more servers, loop until success
// first server in the list is a blessed node, we only connect to it
// second server in the list is the rejoinable node, we never connect
// to it in this part of the test
connect(config.servers.split(",")[0]);
// get the partition count
ClientResponse resp = client.callProcedure("@Statistics", "PARTITIONCOUNT", 0);
if (resp.getStatus() != ClientResponse.SUCCESS) {
log.error(_F("Get partition count failed %s\n", resp.getStatusString()));
throw new RuntimeException();
}
VoltTable[] tpc = resp.getResults();
nPartitions = 0;
while (tpc[0].advanceRow()) {
nPartitions = (int) tpc[0].getLong("PARTITION_COUNT");
}
log.info(_F("partition count: %d\n", nPartitions));
if (nPartitions < 2) {
log.error(_F("Less than 2 partitions\n", nPartitions));
System.exit(1);
}
client.callProcedure("Initialize", nPartitions);
log.info(HORIZONTAL_RULE);
log.info("Starting Benchmark");
log.info(HORIZONTAL_RULE);
// print periodic statistics to the console
benchmarkStartTS = System.currentTimeMillis();
schedulePeriodicStats();
// Run the benchmark loop for the requested duration
// The throughput may be throttled depending on client configuration
log.info("\nRunning benchmark...");
final long benchmarkEndTime = System.currentTimeMillis() + (1000l * config.duration);
//String qOps[] = {"*","/"};
String[] qOps = { "+", "+" };
int lastCatalog = 0;
while (runBenchmark && (benchmarkEndTime > System.currentTimeMillis())) {
// 50/50 multiply or divide operation
int r = rand.nextInt(2);
//choose a counter
int p = rand.nextInt(nPartitions);
// values 2-3
int c = rand.nextInt(1) + 2;
Tests tc;
if (testCase == null) {
tc = Tests.values()[rand.nextInt(Tests.values().length)];
//System.err.printf("selected test: %s\n", tc);
} else
tc = testCase;
totalAsync.getAndIncrement();
try {
switch(tc) {
case ADHOCSINGLEPARTPTN:
// single part adhoc query ENG-3886 also see ENG-4076
//System.err.printf("adhoc singlepart...\n");
client.callProcedure(new SequenceCallback(), "@AdHoc", "UPDATE COUNTERS_PTN set COUNTER=COUNTER" + qOps[r] + Integer.toString(c) + " WHERE id=" + Integer.toString(p) + ";");
totalAdHoc.getAndIncrement();
break;
case ADHOCMULTIPARTPTN:
// multipart adhoc query ENG-3887
//System.err.printf("adhoc multipart...\n");
client.callProcedure(new SequenceCallback(), "@AdHoc", "UPDATE COUNTERS_PTN set COUNTER=COUNTER" + qOps[r] + Integer.toString(c) + ";");
totalAdHoc.getAndIncrement();
break;
case ADHOCSINGLEPARTREP:
// multipart adhoc query ENG-3887
//System.err.printf("adhoc multipart...\n");
client.callProcedure(new SequenceCallback(), "@AdHoc", "UPDATE COUNTERS_REP set COUNTER=COUNTER" + qOps[r] + Integer.toString(c) + " WHERE id=" + Integer.toString(p) + ";");
totalAdHoc.getAndIncrement();
break;
case ADHOCMULTIPARTREP:
// multipart adhoc query ENG-3887
//System.err.printf("adhoc multipart...\n");
client.callProcedure(new SequenceCallback(), "@AdHoc", "UPDATE COUNTERS_REP set COUNTER=COUNTER" + qOps[r] + Integer.toString(c) + ";");
totalAdHoc.getAndIncrement();
break;
case UPDATEAPPLICATIONCATALOG:
// UpdateApplicationCatalog
// we want the update application catalog command to be issued during the rejoin
// but the client is async relative to killing and rejoining.
// also, the rejoin time will vary a lot depending on the nodes and sitesperhost.
// so long run times will be required to possibly hit the right timing.
// bottom line-this is not going to be a meaningful test when run for short durations.
ClientResponse response = null;
// Find out which catalog we are on
try {
response = client.callProcedure("@AdHoc", "Select count(*) from replicated;");
if (response.getStatus() == ClientResponse.SUCCESS) {
lastCatalog = 1;
} else {
lastCatalog = 0;
}
} catch (ProcCallException e) {
// expect a planner exception on catalog 0
//e.printStackTrace();
lastCatalog = 0;
} catch (Exception e) {
logStackTrace(e);
throw new RuntimeException();
}
// running ALL, we don't wait, otherwise go slow.
if (testCase != null) {
// really slow
Thread.sleep(rand.nextInt(20000) + 1);
}
// now, flip to the other catalog
// this runs as a synchronous tx (for now)
log.info(_F("updateapplicationcatalog %d...\n", lastCatalog));
// create catalog
String catPath = ".";
File[] catalog_files = { new File(catPath + "/LiveRejoinConsistency.jar"), new File(catPath + "/LiveRejoinConsistency2.jar") };
File file2 = new File(catPath + "/deployment.xml");
// Flip the catalog
lastCatalog = (lastCatalog + 1) % 2;
response = client.updateApplicationCatalog(catalog_files[lastCatalog], file2);
if (response.getStatus() != ClientResponse.SUCCESS) {
log.error(_F("UAC operation failed with %s\n", response.getStatusString()));
throw new RuntimeException();
} else {
successfulAsync.getAndIncrement();
// check if we're on the right catalog
try {
response = client.callProcedure("@AdHoc", "Select count(*) from replicated;");
switch(lastCatalog) {
case 0:
if (response.getStatus() == ClientResponse.SUCCESS) {
log.error("unexpected result for catalog 0\n");
throw new RuntimeException();
}
break;
case 1:
if (response.getStatus() != ClientResponse.SUCCESS) {
log.error("unexpected result for catalog 1\n");
throw new RuntimeException();
}
break;
default:
throw new RuntimeException("Invalid catalog switch value");
}
} catch (ProcCallException e) {
if (lastCatalog != 0) {
logStackTrace(e);
log.error(_F("unexpected result for catalog 1 in proccallexception %d\n%s\n", lastCatalog, e.getMessage()));
throw new RuntimeException();
}
}
}
break;
case WRSINGLEPARTSTOREDPROCPTN:
// single-part stored procedure
client.callProcedure(new SequenceCallback(), "getNextFromPtn", p, nPartitions);
break;
case WRMULTIPARTSTOREDPROCPTN:
// multi-part stored procedure
// Updates a partitioned table
client.callProcedure(new SequenceCallback(), "MPUpdatePtn");
case WRMULTIPARTSTOREDPROCREP:
// multi-part stored procedure
// Updates a replicated table
client.callProcedure(new SequenceCallback(), "MPUpdateRep");
break;
// this case is failing ENG-4097
case LOADSINGLEPARTITIONTABLEPTN:
case LOADMULTIPARTITIONTABLEREP:
// LoadSinglePartitionTable LoadMultiPartitionTable ENG-3885 part 1 of 2
// voltLoadTable is not client exposed
// voltLoadTable is used for the initial load on DR
// Get all the rows from the counter table and insert them into the
// like_counter table, then compare both copies of the target table after rejoin
response = null;
try {
response = client.callProcedure("getRowFromPtn", p);
if (response.getStatus() != ClientResponse.SUCCESS) {
log.error(_F("FATAL Unexpectd result getting source row %s\n", response.getStatusString()));
throw new RuntimeException();
}
} catch (ProcCallException e) {
//e.printStackTrace();
log.error(_F("unexpected exception getting source row\n %s\n", e.getMessage()));
}
VoltTable[] vt = response.getResults();
if (vt.length == 0) {
log.error(_F("FATAL VoltTable[] object has no elememts\n"));
throw new RuntimeException();
}
if (vt[0].getRowCount() != 1) {
log.error(_F("FATAL VoltTable object has wrong number of rows %d\n", vt[0].getRowCount()));
throw new RuntimeException();
}
VoltTable vt0 = vt[0];
// insert row into target table
try {
switch(tc) {
case LOADSINGLEPARTITIONTABLEPTN:
client.callProcedure(new SequenceCallback(), "@LoadSinglepartitionTable", "LIKE_COUNTERS_PTN", upsertMode, vt0);
break;
case LOADMULTIPARTITIONTABLEREP:
client.callProcedure(new SequenceCallback(), "@LoadMultipartitionTable", "LIKE_COUNTERS_REP", upsertMode, vt0);
break;
}
} catch (VoltAbortException e) {
log.error(_F("FATAL Load single/multi table failed with an exception\n%s\n", e.getMessage()));
throw new RuntimeException();
}
break;
default:
throw new RuntimeException("Invalid query selector switch value: '" + tc + "'");
}
} catch (NoConnectionsException e) {
logStackTrace(e);
throw new RuntimeException(e);
} catch (InterruptedException e) {
logStackTrace(e);
log.warn(_F("Caught InterrruptedException: %s\ntoString: %s\n", e.getMessage(), e.toString()));
//throw new RuntimeException(e);
} catch (IOException e) {
logStackTrace(e);
log.warn(_F("Caught IOException: %s\ntoString: %s\n", e.getMessage(), e.toString()));
//throw new RuntimeException(e);
} catch (Exception e) {
logStackTrace(e);
log.error(_F("Caught Exception: %s\ntoString: %s\n", e.getMessage(), e.toString()));
throw new RuntimeException(e);
}
Thread.yield();
}
// while
// cancel periodic stats printing
timer.cancel();
try {
// block until all outstanding txns return
log.info("draining connection...");
client.drain();
} catch (Exception e) {
}
// print a report
try {
printResults();
} catch (Exception e) {
}
// close down the client connections
try {
client.close();
} catch (Exception e) {
}
}
Aggregations