use of org.voltdb.DRConsumerDrIdTracker in project voltdb by VoltDB.
the class ExecuteTask_SP method jsonifyTrackedDRData.
public static String jsonifyTrackedDRData(Pair<Long, Long> lastConsumerUniqueIds, Map<Integer, Map<Integer, DRConsumerDrIdTracker>> allProducerTrackers) throws JSONException {
JSONStringer stringer = new JSONStringer();
stringer.object();
stringer.keySymbolValuePair("lastConsumerSpUniqueId", lastConsumerUniqueIds.getFirst());
stringer.keySymbolValuePair("lastConsumerMpUniqueId", lastConsumerUniqueIds.getSecond());
stringer.key("trackers").object();
if (allProducerTrackers != null) {
for (Map.Entry<Integer, Map<Integer, DRConsumerDrIdTracker>> clusterTrackers : allProducerTrackers.entrySet()) {
stringer.key(Integer.toString(clusterTrackers.getKey())).object();
for (Map.Entry<Integer, DRConsumerDrIdTracker> e : clusterTrackers.getValue().entrySet()) {
stringer.key(e.getKey().toString());
stringer.value(e.getValue().toJSON());
}
stringer.endObject();
}
}
stringer.endObject();
stringer.endObject();
return stringer.toString();
}
use of org.voltdb.DRConsumerDrIdTracker in project voltdb by VoltDB.
the class RejoinProducer method doFinishingTask.
private void doFinishingTask(final SiteProcedureConnection siteConnection) {
/*
* Don't notify the rejoin coordinator yet. The stream snapshot may
* have not finished on all nodes, let the snapshot completion
* monitor tell the rejoin coordinator.
*
* This used to block on the completion interest, but this raced
* with fragments from the MPI that needed dummy responses. If the fragments
* came after the EOF then they wouldn't receive dummy responses
* and then the MPI wouldn't invoke SnapshotSaveAPI.logParticipatingHostCount
*/
final SiteTasker finishingTask = new SiteTasker() {
@Override
public void run(SiteProcedureConnection siteConnection) {
throw new RuntimeException("Unexpected execution of run method in rejoin producer.");
}
@Override
public void runForRejoin(SiteProcedureConnection siteConnection, TaskLog rejoinTaskLog) throws IOException {
if (!m_snapshotCompletionMonitor.isDone()) {
m_taskQueue.offer(this);
return;
}
SnapshotCompletionEvent event = null;
Map<String, Map<Integer, Pair<Long, Long>>> exportSequenceNumbers = null;
Map<Integer, Long> drSequenceNumbers = null;
Map<Integer, Map<Integer, Map<Integer, DRConsumerDrIdTracker>>> allConsumerSiteTrackers = null;
long clusterCreateTime = -1;
try {
event = m_snapshotCompletionMonitor.get();
if (!m_schemaHasNoTables) {
REJOINLOG.debug(m_whoami + "waiting on snapshot completion monitor.");
exportSequenceNumbers = event.exportSequenceNumbers;
m_completionAction.setSnapshotTxnId(event.multipartTxnId);
drSequenceNumbers = event.drSequenceNumbers;
allConsumerSiteTrackers = event.drMixedClusterSizeConsumerState;
clusterCreateTime = event.clusterCreateTime;
// Tells EE which DR version going to use
siteConnection.setDRProtocolVersion(event.drVersion);
}
REJOINLOG.debug(m_whoami + " monitor completed. Sending SNAPSHOT_FINISHED " + "and handing off to site.");
RejoinMessage snap_complete = new RejoinMessage(m_mailbox.getHSId(), Type.SNAPSHOT_FINISHED);
m_mailbox.send(m_coordinatorHsId, snap_complete);
} catch (InterruptedException crashme) {
VoltDB.crashLocalVoltDB("Interrupted awaiting snapshot completion.", true, crashme);
} catch (ExecutionException e) {
VoltDB.crashLocalVoltDB("Unexpected exception awaiting snapshot completion.", true, e);
}
if (exportSequenceNumbers == null) {
// Send empty sequence number map if the schema is empty (no tables).
exportSequenceNumbers = new HashMap<String, Map<Integer, Pair<Long, Long>>>();
}
setJoinComplete(siteConnection, exportSequenceNumbers, drSequenceNumbers, allConsumerSiteTrackers, m_schemaHasNoTables == false, /* requireExistingSequenceNumbers */
clusterCreateTime);
}
};
try {
finishingTask.runForRejoin(siteConnection, null);
} catch (IOException e) {
VoltDB.crashLocalVoltDB("Unexpected IOException in rejoin", true, e);
}
}
use of org.voltdb.DRConsumerDrIdTracker 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