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
Long
VoltTable
VoltTable[]
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
Modifier and TypeClassDescriptionstatic class
Thrown from a stored procedure to abort a VoltCompoundProcedure.static final class
Represents the stages of processing of aVoltCompoundProcedure
.final class
Builds a list of execution stages for thisVoltCompoundProcedure
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
abortProcedure
(String reason) Indicates that processing of this compound procedure is being abandoned.final void
completeProcedure
(long result) All processing of this compound procedure is now complete.final void
completeProcedure
(VoltTable result) All processing of this compound procedure is now complete.final void
completeProcedure
(VoltTable[] result) All processing of this compound procedure is now complete.newStageList
(Consumer<org.voltdb.client.ClientResponse[]> consumer) Returns aVoltCompoundProcedure.StageListBuilder
for use in building the list of execution stages for this compound procedure.final void
queueProcedureCall
(String procName, Object... params) Queues an asynchronous procedure call, to be executed when the current stage returns.void
setAppStatusCode
(byte status) Set the application status code that will be returned to the client as part of theClientResponse
.void
setAppStatusString
(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.StageListBuilder
for 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();
run
method.- 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
queueProcedureCall
in 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
.queueProcedureCall
must only be called in the context of a thread that is executing either the initialrun
call, 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
CompoundProcAbortException
can 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:
setAppStatusCode
in 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:
setAppStatusString
in classorg.voltdb.VoltNonTransactionalProcedure
- Parameters:
message
- application-specific status string
-