Clarification, how to use startUpdateWithStart(..)

Greetings. I’d like to ask for some documentation clarification.

(Temporal 1.26,2, Java SDK 1.27.1)

Here, it states:

Update-with-Start lets you send an Update that checks whether an already-running Workflow with that ID exists:

If the Workflow exists, the Update is processed.
If the Workflow does not exist, a new Workflow Execution is started with the given ID, and the Update is processed immediately after.

Now, my workflow has an @ExecuteMethod, and an @UpdateMethod.

When using startUpdateWithStart(..), mine looks like:

WorkflowClient
                    .startUpdateWithStart(
                        lockWorkflow::obtainLock,
                        lockRequest,
                        UpdateOptions.<Boolean>newBuilder()
                            .setWaitForStage(WorkflowUpdateStage.COMPLETED)
                            .build(),
                        new WithStartWorkflowOperation<>(
                            lockWorkflow::execute, lockRequest.maxNumLockHolders(), null))
                    .getResult();

. . . what is the call sequence into the workflow?

  1. @ExecuteWorkflow, then @UpdateWorkflow . . . . or . . . .
  2. @UpdateWorkflow, then @ExecuteWorkflow.

I think I’d expect 1, but I’m seeing 2. So, from the documentation, what is the definition of “a new Workflow Execution is started”?

Update: what if a workflow that has (a) @UpdateMethod, but also internally uses (b) continueAsNew – could it get into a state, when continuing, that @UpdateMethod could get called before @UpdatedMethod? That would a problem, as you’d be unable to consistently/reliably pass state into the workflow AND honor update calls correctly.

Any comments?

Thank you!

Sean

  1. @UpdateWorkflow, then @ExecuteWorkflow. Message handlers like Signal and Update are always run at a higher priority then the main workflow method. I don’t quite understand your update, but before you continue as new you should verify there are no more running update methods. See the message handling docs for more details here Workflow message passing - Java SDK | Temporal Platform Documentation

Here are the general docs to understand how it works.

I can see how you came to a different conclusion. We will look at updating it.