Class VoltCompoundProcedure
It is important to understand that a compound procedure does not provide transactional guarantees. If there is a failure during execution, in-progress transactions executed by the compound proc may be rolled back as usual, but completed transactions will not be.
Operation of a compound procedure is essentially asynchronous. In a typical pattern, calls are issued to other procedures, and the results of those calls are processed as they arrive. To facilitate this, the execution of the compound procedure is separated into 'stages'. A stage issues one or more procedure calls, and then exits. The next stage will be executed with the responses from the calls issued by the previous stage. Intermediate results and working values must be saved in member variables.
The last stage must complete the compound procedure, and return
a result, by calling completeProcedure. The result
must be one of the following types
LongVoltTableVoltTable[]
The compound procedure starts its execution in its run(...)
method, which must accept parameters compatible with the parameters provided
by the client. The run method must set up a list of
execution stages; the auxiliary class StageListBuilder
is provided to help with this. Any return value from run
is ignored, but must have a type acceptable to the Volt compiler.
The primitive type 'long' is recommended.
Execution of the compound procedure can be terminated prematurely
by calling abortProcedure or, equivalently, by throwing
a CompoundProcAbortException. This will be reported
to the client via the usual ClientResponse with
a status of COMPOUND_PROC_USER_ABORT.
- Since:
- 11.4.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown from a stored procedure to abort a VoltCompoundProcedure.static final classRepresents the stages of processing of aVoltCompoundProcedure.final classBuilds a list of execution stages for thisVoltCompoundProcedure. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidabortProcedure(String reason) Indicates that processing of this compound procedure is being abandoned.final voidcompleteProcedure(long result) All processing of this compound procedure is now complete.final voidcompleteProcedure(VoltTable result) All processing of this compound procedure is now complete.final voidcompleteProcedure(VoltTable[] result) All processing of this compound procedure is now complete.newStageList(Consumer<org.voltdb.client.ClientResponse[]> consumer) Returns aVoltCompoundProcedure.StageListBuilderfor use in building the list of execution stages for this compound procedure.final voidqueueProcedureCall(String procName, Object... params) Queues an asynchronous procedure call, to be executed when the current stage returns.voidsetAppStatusCode(byte status) Set the application status code that will be returned to the client as part of theClientResponse.voidsetAppStatusString(String message) Set the application status string that will be returned to the client as part of theClientResponse.Methods inherited from class org.voltdb.VoltNonTransactionalProcedure
callAllPartitionProcedure, callProcedure, getClusterId
-
Constructor Details
-
VoltCompoundProcedure
public VoltCompoundProcedure()
-
-
Method Details
-
newStageList
public final VoltCompoundProcedure.StageListBuilder newStageList(Consumer<org.voltdb.client.ClientResponse[]> consumer) Returns aVoltCompoundProcedure.StageListBuilderfor use in building the list of execution stages for this compound procedure. The initial stage is given as an argument; other stages can be added according to the needs of the application.Usage:
The stage list must be built during execution of your procedure'snewStageList(STAGE) .then(STAGE) .then(STAGE) .build();runmethod.- Parameters:
consumer- first stage handler- Returns:
- StageListBuilder instance of builder class
- See Also:
-
queueProcedureCall
Queues an asynchronous procedure call, to be executed when the current stage returns.The system supports parallel initiation. You can code several calls to
queueProcedureCallin a single stage. There is a system limit on the number of calls that can be queued in any one stage; this limit defaults to 10, but can be changed in the VoltDB deployment file.When all calls have completed, the next stage will be entered, with the results of all calls. The results will have the same order as calls issued to
queueProcedureCall.queueProcedureCallmust only be called in the context of a thread that is executing either the initialruncall, or one of the stages set up for the procedure.- Parameters:
procName- name of procedure to callparams- arguments as required by called procedure
-
completeProcedure
public final void completeProcedure(long result) All processing of this compound procedure is now complete. A response will be sent to the client. No more stages will be executed.If the current stage has queued any procedure calls before calling
completeProcedure, those calls will not be issued: execution is complete.- Parameters:
result- the result of the compound procedure
-
completeProcedure
All processing of this compound procedure is now complete. A response will be sent to the client. No more stages will be executed.If the current stage has queued any procedure calls before calling
completeProcedure, those calls will not be issued: execution is complete.- Parameters:
result- the result of the compound procedure
-
completeProcedure
All processing of this compound procedure is now complete. A response will be sent to the client. No more stages will be executed.If the current stage has queued any procedure calls before calling
completeProcedure, those calls will not be issued: execution is complete.- Parameters:
result- the result of the compound procedure
-
abortProcedure
Indicates that processing of this compound procedure is being abandoned. A response will be sent to the client with status set toCOMPOUND_PROC_USER_ABORT.Completed calls previously issued by the compound procedure will not be affected; there is no rollback of transactions.
This should be the last action taken by the compound procedure.
If the current stage has queued any procedure calls before calling
abortProcedure, those calls will not be issued: execution has concluded.Throwing a
CompoundProcAbortExceptioncan be used instead of callingabortProcedure, with the same effect.- Parameters:
reason- to be included in client response
-
setAppStatusCode
public void setAppStatusCode(byte status) Set the application status code that will be returned to the client as part of theClientResponse. This is distinct from the VoltDB-provided status code. The meaning is determined by your procedure and the application.- Overrides:
setAppStatusCodein classorg.voltdb.VoltNonTransactionalProcedure- Parameters:
status- application-specific status code
-
setAppStatusString
Set the application status string that will be returned to the client as part of theClientResponse. This is distinct from the VoltDB-provided status string. The meaning is determined by your procedure and the application.- Overrides:
setAppStatusStringin classorg.voltdb.VoltNonTransactionalProcedure- Parameters:
message- application-specific status string
-