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

Repeated version #2248

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Repeated version #2248

wants to merge 8 commits into from

Conversation

mfateev
Copy link
Member

@mfateev mfateev commented Oct 1, 2024

What was changed

The new Workflow.getVersion overload to support versioning signal and other handlers as well as loop bodies.

Why?

Consider the following example:

for (int i=0; i<100; i++) {
     if (getVersion("fix1", DEFAULT_VERSION, 1) == DEFAULT_VERSION) {
         // OLD CODE
     } else {
         // NEW CODE
     }
}

If the change is introduced after the loop starts executing, all iterations are going to use
the default version, even if most of them happen after the change. This happens because the *
getVersion call returns the same version for all calls that share a changeId. The same issue *
arises when changing code in callbacks like signal or update handlers. Frequently, there is a
need for a new version used for newer iterations (or signal handler invocations).

The following solution supports updating the version of each iteration separately, as it
uses a different changeId for each iteration:

    for (int i=0; i<100; i++) {
        if (getVersion("fix1-" + i, DEFAULT_VERSION, 1) == DEFAULT_VERSION) {
            // OLD CODE
        } else {
            // NEW CODE
        }
    }

The drawback is a marker event as well as a search attribute update for each iteration. So, it
is not practical for the large number of iterations.

The newly added method provides an efficient alternative to the solution that uses a different changeId
for each iteration. It only inserts a marker when a version changes.

Here is how it could be used:

    for (int i=0; i<100; i++) {
        if (getVersion("fix1", String.valueOf(i), DEFAULT_VERSION, 1) == DEFAULT_VERSION) {
            // OLD CODE
        } else {
            // NEW CODE
        }
    }
  1. How was this tested:
    A unit test was added.

  2. Any docs updates needed?

Patching documentation for Java SDK should be updated.

@mfateev mfateev requested a review from a team as a code owner October 1, 2024 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant