Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow resetting to pick up newest version with versioning optimization #369

Open
longquanzheng opened this issue Feb 21, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@longquanzheng
Copy link
Contributor

Potentially we could just set the version at starting workflow API call. and then the workflow code will use the version from input.
(in fact, this is what SWF (the ancestor of Cadence/Temporal) reccomends )

As Cadence/Temporal also allows us to upsert SA at start API, we could just use that as input + SA.

However, the downside of simply doing it is that we lose the ability to reset the workflow to beginning (firstWorkflowTask) to pick up the latest version, since the version is already fixed as input.

To minimize this side effect, we can do something like this at the beginning of the workflow code:

versionFromInput = workflow.getInfo().getSearchAttribute(TEMPORAL_GLBOAL_VERSION);
int actualVersion;
if !workflow.isReplay() {
   if MAX_VERSION_OF_ALL > versionFromInput {
        // this means that we can pick up the newer version(it's probably after a reset, or the start API code is outdated on max version)
        actualVersion = workflow.getVersion("global", Workflow.DEFAULT_VERSION, MAX_VERSION_OF_ALL); 
        // also need to overwrite the sa
        workflow.upsertSearchAttribute(TEMPORAL_GLBOAL_VERSION, actualVersion);
   }else if MAX_VERSION_OF_ALL < versionFromInput {
        throw new RuntimeException("this means the startWF API knows a version larger than this worker can support, we just fail the workflow task to retry");
   } else{
      // the ideal situation to save the two Temporal actions(version marker+upsertSA)
      actualVersion = versionFromInput;
   }
}else{
   // in replay mode, it will not cost anything
   // if there is no version marker in the history, it will return the MAX_INTEGER.
   // if there is a marker in the history, it will use the value from marker
   actualVersion = workflow.getVersion("global", Workflow.DEFAULT_VERSION, MAX_INTEGER);
   if actualVersion == MAX_INTEGER{
        // this means that there is no version marker in the history
        actualVersion = versionFromInput
   }else{
        // also call the upsertSearchAttribute so that we don't break the determinism...
        workflow.upsertSearchAttribute(TEMPORAL_GLBOAL_VERSION, actualVersion);
   }
}
@longquanzheng longquanzheng added the enhancement New feature or request label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant