Search in sources :

Example 1 with TaskType

use of org.voltdb.jni.ExecutionEngine.TaskType 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 TaskType

use of org.voltdb.jni.ExecutionEngine.TaskType in project voltdb by VoltDB.

the class ExecuteTask_SP method run.

/**
     * System procedure run hook.
     * Use the base class implementation.
     *
     * @param ctx  execution context
     * @param partitionParam  key for routing stored procedure to correct site
     * @param params          additional parameter(s) for the task to execute, first one is always task type
     */
public void run(SystemProcedureExecutionContext ctx, byte[] partitionParam, byte[] params) {
    assert params.length > 0;
    byte taskId = params[0];
    TaskType taskType = TaskType.values()[taskId];
    switch(taskType) {
        case SP_JAVA_GET_DRID_TRACKER:
            Map<Integer, Map<Integer, DRConsumerDrIdTracker>> drIdTrackers = ctx.getDrAppliedTrackers();
            Pair<Long, Long> lastConsumerUniqueIds = ctx.getDrLastAppliedUniqueIds();
            try {
                setAppStatusString(jsonifyTrackedDRData(lastConsumerUniqueIds, drIdTrackers));
            } catch (JSONException e) {
                throw new VoltAbortException("DRConsumerDrIdTracker could not be converted to JSON");
            }
            break;
        case RESET_DR_APPLIED_TRACKER_SINGLE:
            assert params.length == 2;
            byte clusterId = params[1];
            ctx.resetDrAppliedTracker(clusterId);
            break;
        default:
            throw new VoltAbortException("Unable to find the task associated with the given task id");
    }
}
Also used : TaskType(org.voltdb.jni.ExecutionEngine.TaskType) JSONException(org.json_voltpatches.JSONException) Map(java.util.Map)

Aggregations

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