Search in sources :

Example 1 with TupleStreamStateInfo

use of org.voltdb.TupleStreamStateInfo 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)

Example 2 with TupleStreamStateInfo

use of org.voltdb.TupleStreamStateInfo in project voltdb by VoltDB.

the class Site method getDRTupleStreamStateInfo.

@Override
public TupleStreamStateInfo getDRTupleStreamStateInfo() {
    // Set the psetBuffer buffer capacity and clear the buffer
    m_ee.getParamBufferForExecuteTask(0);
    ByteBuffer resultBuffer = ByteBuffer.wrap(m_ee.executeTask(TaskType.GET_DR_TUPLESTREAM_STATE, ByteBuffer.allocate(0)));
    long partitionSequenceNumber = resultBuffer.getLong();
    long partitionSpUniqueId = resultBuffer.getLong();
    long partitionMpUniqueId = resultBuffer.getLong();
    int drVersion = resultBuffer.getInt();
    DRLogSegmentId partitionInfo = new DRLogSegmentId(partitionSequenceNumber, partitionSpUniqueId, partitionMpUniqueId);
    byte hasReplicatedStateInfo = resultBuffer.get();
    TupleStreamStateInfo info = null;
    if (hasReplicatedStateInfo != 0) {
        long replicatedSequenceNumber = resultBuffer.getLong();
        long replicatedSpUniqueId = resultBuffer.getLong();
        long replicatedMpUniqueId = resultBuffer.getLong();
        DRLogSegmentId replicatedInfo = new DRLogSegmentId(replicatedSequenceNumber, replicatedSpUniqueId, replicatedMpUniqueId);
        info = new TupleStreamStateInfo(partitionInfo, replicatedInfo, drVersion);
    } else {
        info = new TupleStreamStateInfo(partitionInfo, drVersion);
    }
    return info;
}
Also used : DRLogSegmentId(org.voltdb.DRLogSegmentId) ByteBuffer(java.nio.ByteBuffer) TupleStreamStateInfo(org.voltdb.TupleStreamStateInfo)

Aggregations

ByteBuffer (java.nio.ByteBuffer)2 DRLogSegmentId (org.voltdb.DRLogSegmentId)2 TupleStreamStateInfo (org.voltdb.TupleStreamStateInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 DRConsumerDrIdTracker (org.voltdb.DRConsumerDrIdTracker)1 DependencyPair (org.voltdb.DependencyPair)1 VoltTable (org.voltdb.VoltTable)1 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)1 TaskType (org.voltdb.jni.ExecutionEngine.TaskType)1