Search in sources :

Example 1 with DRConsumerDrIdTracker

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();
}
Also used : DRConsumerDrIdTracker(org.voltdb.DRConsumerDrIdTracker) JSONStringer(org.json_voltpatches.JSONStringer) Map(java.util.Map)

Example 2 with DRConsumerDrIdTracker

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);
    }
}
Also used : RejoinMessage(org.voltdb.messaging.RejoinMessage) TaskLog(org.voltdb.rejoin.TaskLog) SnapshotCompletionEvent(org.voltdb.SnapshotCompletionInterest.SnapshotCompletionEvent) IOException(java.io.IOException) SiteProcedureConnection(org.voltdb.SiteProcedureConnection) DRConsumerDrIdTracker(org.voltdb.DRConsumerDrIdTracker) ExecutionException(java.util.concurrent.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with DRConsumerDrIdTracker

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;
}
Also used : ColumnInfo(org.voltdb.VoltTable.ColumnInfo) ByteBuffer(java.nio.ByteBuffer) VoltTable(org.voltdb.VoltTable) TupleStreamStateInfo(org.voltdb.TupleStreamStateInfo) Entry(java.util.Map.Entry) ByteArrayInputStream(java.io.ByteArrayInputStream) DRConsumerDrIdTracker(org.voltdb.DRConsumerDrIdTracker) TaskType(org.voltdb.jni.ExecutionEngine.TaskType) DRLogSegmentId(org.voltdb.DRLogSegmentId) Map(java.util.Map) ObjectInputStream(java.io.ObjectInputStream) DependencyPair(org.voltdb.DependencyPair)

Aggregations

Map (java.util.Map)3 DRConsumerDrIdTracker (org.voltdb.DRConsumerDrIdTracker)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 ExecutionException (java.util.concurrent.ExecutionException)1 JSONStringer (org.json_voltpatches.JSONStringer)1 DRLogSegmentId (org.voltdb.DRLogSegmentId)1 DependencyPair (org.voltdb.DependencyPair)1 SiteProcedureConnection (org.voltdb.SiteProcedureConnection)1 SnapshotCompletionEvent (org.voltdb.SnapshotCompletionInterest.SnapshotCompletionEvent)1 TupleStreamStateInfo (org.voltdb.TupleStreamStateInfo)1 VoltTable (org.voltdb.VoltTable)1 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)1 TaskType (org.voltdb.jni.ExecutionEngine.TaskType)1 RejoinMessage (org.voltdb.messaging.RejoinMessage)1 TaskLog (org.voltdb.rejoin.TaskLog)1