( We are using Java SDK and this question is in that context )
I read that if the worker dies and is started again, the workflow will resume.
How is this possible considering that WF is Java? What if it was in the middle of a for() loop ? Will it resume from the exact position loop was in when the worker crashed?
Will the workflow private variables be restored when Workflow is resumed? What about Java volatile variables?
Will the search attributes be restored on the Workflows?
Yes, it is going to be resumed from the exact position. It is done by replaying the workflow code from the beginning. The assumption is that the workflow is deterministic which imposes some constraints on the way the code is written.
Yes, all variables will be restored. The same applies to volatile variables. But you don’t need them as any synchronization and locking primitives are prohibited within the workflow code.
Thank you for the response Maxim.
( Sorry ) it is still not clear what exactly is meant by resumability - I did read the link you sent )
Please consider the following
//@WorkflowInterface implementation
public class ProcessingWorkflow implements MyWorkflowInterface {
int instanceVar =0;
//@WorkflowMethod
String myWorkflow(Arguments args) {
instanceVar = foo() ;
int stackvar = bar() ;
for(int i = 0 ; i< 88 ; i++ )
//JVM/Worker crashes when i = 12
stackvar = i ;
}
}
}
In the above code, JVM/Worker crashes when the Java loop is midway ( i=12 ). When the Worker is restarted, will teh workflow resume starting from the middle of teh method with i = 13 ?
If it does not resume with i=13, will myWorkflow() method start executing from the beginning again ?
If it will restart from the beginning, what will be teh value of instanceVar ? ( will it be 0 ? or will it be the value it was when JVM crashed ? )
You want to add some blocking code (like workflow sleep or an activity invocation) in the loop. There is no any externally observable behavior while the loop is running so interrupting it or recovering in the middle is not really visible. For example the following code:
for(int i = 0 ; i< 88 ; i++ )
Workflow.sleep(1000);
//JVM/Worker crashes when i = 12
stackvar = i ;
}
will resume in the middle of the loop with i = 13.
( Thank you so very much Maxim for your diligent responses )
How is that possible - from a Java point of view, even if you use reflection to restore object variables - to start executing a method from the middle on a freshly created JVM ?
( unless you use some kind of byte code rewriting )
Earlier you mentioned " It is done by replaying the workflow code from the beginning"
Will you please explain how it is possible from a Java point of view.
@maxim: I opened up the video that you referenced but noticed that the video itself is shorter than 35 minutes. Could you restate where in the video the recovery procedure is explained?
Here is a presentation that explains the interaction model as well as recovery. The interaction starts from the slide 39. I presented it at a conference and we will post the video link as soon as it is available.