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 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 ClientThread method runOne.
void runOne() throws Exception {
// 1/10th of txns roll back
byte shouldRollback = (byte) (m_random.nextInt(10) == 0 ? 1 : 0);
try {
String procName = null;
int expectedTables = 5;
switch(m_type) {
case PARTITIONED_SP:
procName = "UpdatePartitionedSP";
break;
case PARTITIONED_MP:
procName = "UpdatePartitionedMP";
expectedTables = 6;
break;
case REPLICATED:
procName = "UpdateReplicatedMP";
expectedTables = 6;
break;
case HYBRID:
procName = "UpdateBothMP";
expectedTables = 6;
break;
case ADHOC_MP:
procName = "UpdateReplicatedMPInProcAdHoc";
expectedTables = 6;
break;
}
byte[] payload = m_processor.generateForStore().getStoreValue();
ClientResponse response;
try {
response = m_client.callProcedure(procName, m_cid, m_nextRid, payload, shouldRollback);
} catch (Exception e) {
if (shouldRollback == 0) {
log.warn("ClientThread threw after " + m_txnsRun.get() + " calls while calling procedure: " + procName + " with args: cid: " + m_cid + ", nextRid: " + m_nextRid + ", payload: " + payload + ", shouldRollback: " + shouldRollback);
}
throw e;
}
// fake a proc call exception if we think one should be thrown
if (response.getStatus() != ClientResponse.SUCCESS) {
throw new UserProcCallException(response);
}
VoltTable[] results = response.getResults();
m_txnsRun.incrementAndGet();
if (results.length != expectedTables) {
hardStop(String.format("Client cid %d procedure %s returned %d results instead of %d", m_cid, procName, results.length, expectedTables), response);
}
VoltTable data = results[3];
VoltTable view = results[4];
try {
UpdateBaseProc.validateCIDData(data, view, "ClientThread:" + m_cid);
} catch (VoltAbortException vae) {
log.error("validateCIDData failed on: " + procName + ", shouldRollback: " + shouldRollback + " data: " + data);
throw vae;
}
} finally {
// ensure rid is incremented (if not rolled back intentionally)
if (shouldRollback == 0) {
m_nextRid++;
}
}
}
Aggregations