use of org.voltdb.DependencyPair in project voltdb by VoltDB.
the class FragmentResponseMessage method getSerializedSize.
@Override
public int getSerializedSize() {
int msgsize = super.getSerializedSize();
msgsize += // executorHSId
8 + // destinationHSId
8 + // txnId
8 + // m_spHandle
8 + // status byte
1 + // dirty flag
1 + // node recovering flag
1 + // dependency count
2;
// one int per dependency ID and table length (0 = null)
msgsize += 8 * m_dependencyCount;
// Add the actual result lengths
for (DependencyPair depPair : m_dependencies) {
if (depPair != null) {
msgsize += depPair.getBufferDependency().limit();
}
}
if (m_exception != null) {
msgsize += m_exception.getSerializedSize();
} else {
//Still serialize exception length 0
msgsize += 4;
}
return msgsize;
}
use of org.voltdb.DependencyPair in project voltdb by VoltDB.
the class FragmentResponseMessage method flattenToBuffer.
@Override
public void flattenToBuffer(ByteBuffer buf) {
assert (m_exception == null || m_status != SUCCESS);
buf.put(VoltDbMessageFactory.FRAGMENT_RESPONSE_ID);
buf.putLong(m_executorHSId);
buf.putLong(m_destinationHSId);
buf.putLong(m_txnId);
buf.putLong(m_spHandle);
buf.put(m_status);
buf.put((byte) (m_dirty ? 1 : 0));
buf.put((byte) (m_recovering ? 1 : 0));
buf.putShort(m_dependencyCount);
for (DependencyPair depPair : m_dependencies) {
buf.putInt(depPair.depId);
ByteBuffer dep = depPair.getBufferDependency();
if (dep == null) {
buf.putInt(0);
} else {
buf.putInt(dep.remaining());
buf.put(dep);
}
}
if (m_exception != null) {
m_exception.serializeToBuffer(buf);
} else {
buf.putInt(0);
}
assert (buf.capacity() == buf.position());
buf.limit(buf.position());
}
use of org.voltdb.DependencyPair 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.DependencyPair in project voltdb by VoltDB.
the class FragmentResponseMessage method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("FRAGMENT_RESPONSE (FROM ");
sb.append(CoreUtils.hsIdToString(m_executorHSId));
sb.append(" TO ");
sb.append(CoreUtils.hsIdToString(m_destinationHSId));
sb.append(") FOR TXN ");
sb.append(TxnEgo.txnIdToString(m_txnId));
sb.append(", SP HANDLE: ");
sb.append(TxnEgo.txnIdToString(m_spHandle));
if (m_status == SUCCESS)
sb.append("\n SUCCESS");
else if (m_status == UNEXPECTED_ERROR)
sb.append("\n UNEXPECTED_ERROR");
else
sb.append("\n USER_ERROR");
if (m_dirty)
sb.append("\n DIRTY");
else
sb.append("\n PRISTINE");
if (m_respBufferable)
sb.append("\n BUFFERABLE");
else
sb.append("\n NOT BUFFERABLE");
for (int i = 0; i < m_dependencyCount; i++) {
DependencyPair dep = m_dependencies.get(i);
sb.append("\n DEP ").append(dep.depId);
VoltTable table = dep.getTableDependency();
sb.append(" WITH ").append(table.getRowCount()).append(" ROWS (");
for (int j = 0; j < table.getColumnCount(); j++) {
sb.append(table.getColumnName(j)).append(", ");
}
sb.setLength(sb.lastIndexOf(", "));
sb.append(")");
}
return sb.toString();
}
use of org.voltdb.DependencyPair in project voltdb by VoltDB.
the class ExecuteTask method executePlanFragment.
@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
if (fragmentId == SysProcFragmentId.PF_executeTask) {
assert (params.toArray()[0] != null);
byte[] payload = (byte[]) params.toArray()[0];
ByteBuffer buffer = ByteBuffer.wrap(payload);
int taskId = buffer.getInt();
TaskType taskType = TaskType.values()[taskId];
VoltTable result = null;
switch(taskType) {
// @VALIDATE_PARTITIONING is an existing system stored procedure, don't bother to provide another implementation here.
case GET_DR_TUPLESTREAM_STATE:
{
TupleStreamStateInfo stateInfo = context.getSiteProcedureConnection().getDRTupleStreamStateInfo();
result = createDRTupleStreamStateResultTable();
result.addRow(context.getHostId(), context.getPartitionId(), 0, stateInfo.partitionInfo.drId, stateInfo.partitionInfo.spUniqueId, stateInfo.partitionInfo.mpUniqueId, stateInfo.drVersion);
if (stateInfo.containsReplicatedStreamInfo) {
result.addRow(context.getHostId(), context.getPartitionId(), 1, stateInfo.replicatedInfo.drId, stateInfo.replicatedInfo.spUniqueId, stateInfo.replicatedInfo.mpUniqueId, stateInfo.drVersion);
}
break;
}
case SET_DR_SEQUENCE_NUMBERS:
{
result = new VoltTable(STATUS_SCHEMA);
result.addRow(STATUS_OK);
long partitionSequenceNumber = buffer.getLong();
long mpSequenceNumber = buffer.getLong();
context.getSiteProcedureConnection().setDRSequenceNumbers(partitionSequenceNumber, mpSequenceNumber);
break;
}
case SET_DR_PROTOCOL_VERSION:
{
result = new VoltTable(STATUS_SCHEMA);
result.addRow(STATUS_OK);
int drVersion = buffer.getInt();
int createStartStream = buffer.getInt();
if (createStartStream > 0) {
long uniqueId = m_runner.getUniqueId();
long spHandle = m_runner.getTxnState().getNotice().getSpHandle();
context.getSiteProcedureConnection().setDRProtocolVersion(drVersion, spHandle, uniqueId);
} else {
context.getSiteProcedureConnection().setDRProtocolVersion(drVersion);
}
break;
}
case SET_DRID_TRACKER_START:
{
result = new VoltTable(STATUS_SCHEMA, new ColumnInfo("LOCAL_UNIQUEID", VoltType.BIGINT));
try {
byte[] paramBuf = new byte[buffer.remaining()];
buffer.get(paramBuf);
ByteArrayInputStream bais = new ByteArrayInputStream(paramBuf);
ObjectInputStream ois = new ObjectInputStream(bais);
Map<Integer, DRLogSegmentId> lastAckedIds = (Map<Integer, DRLogSegmentId>) ois.readObject();
for (Entry<Integer, DRLogSegmentId> e : lastAckedIds.entrySet()) {
if (!DRLogSegmentId.isEmptyDRId(e.getValue().drId)) {
int producerPartitionId = e.getKey();
int producerClusterId = DRLogSegmentId.getClusterIdFromDRId(e.getValue().drId);
DRConsumerDrIdTracker tracker = DRConsumerDrIdTracker.createPartitionTracker(e.getValue().drId, e.getValue().spUniqueId, e.getValue().mpUniqueId, producerPartitionId);
context.appendApplyBinaryLogTxns(producerClusterId, producerPartitionId, -1L, tracker);
}
}
result.addRow(STATUS_OK, m_runner.getTxnState().uniqueId);
} catch (Exception e) {
e.printStackTrace();
result.addRow("FAILURE");
}
break;
}
case RESET_DR_APPLIED_TRACKER:
{
result = new VoltTable(STATUS_SCHEMA);
result.addRow(STATUS_OK);
context.resetDrAppliedTracker();
break;
}
case SET_MERGED_DRID_TRACKER:
{
result = new VoltTable(STATUS_SCHEMA);
try {
byte[] paramBuf = new byte[buffer.remaining()];
buffer.get(paramBuf);
ByteArrayInputStream bais = new ByteArrayInputStream(paramBuf);
ObjectInputStream ois = new ObjectInputStream(bais);
Map<Integer, Map<Integer, DRConsumerDrIdTracker>> clusterToPartitionMap = (Map<Integer, Map<Integer, DRConsumerDrIdTracker>>) ois.readObject();
context.recoverWithDrAppliedTrackers(clusterToPartitionMap);
result.addRow(STATUS_OK);
} catch (Exception e) {
e.printStackTrace();
result.addRow("FAILURE");
}
break;
}
case INIT_DRID_TRACKER:
{
result = new VoltTable(STATUS_SCHEMA);
try {
byte[] paramBuf = new byte[buffer.remaining()];
buffer.get(paramBuf);
ByteArrayInputStream bais = new ByteArrayInputStream(paramBuf);
ObjectInputStream ois = new ObjectInputStream(bais);
Map<Byte, Integer> clusterIdToPartitionCountMap = (Map<Byte, Integer>) ois.readObject();
context.initDRAppliedTracker(clusterIdToPartitionCountMap);
result.addRow(STATUS_OK);
} catch (Exception e) {
e.printStackTrace();
result.addRow("FAILURE");
}
break;
}
default:
throw new VoltAbortException("Unable to find the task associated with the given task id");
}
return new DependencyPair.TableDependencyPair(DEP_executeTask, result);
} else if (fragmentId == SysProcFragmentId.PF_executeTaskAggregate) {
VoltTable unionTable = VoltTableUtil.unionTables(dependencies.get(DEP_executeTask));
return new DependencyPair.TableDependencyPair(DEP_executeTaskAggregate, unionTable);
}
assert false;
return null;
}
Aggregations