randomUUID() changes after a reset, and a reset can't start after a sideEffect

Offen
#3,238 7 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
38/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
java

Rechercherichtung

Start with WorkflowStateMachines.randomUUID() and WorkflowTaskStateMachine.handleFailed() in the paths linked from the issue, then read the reset behavior and tests around those state machines. The issue asks for documentation and one of two behavior changes, but leaves the design choice open; completion needs a decision on the supported approach, documentation of reset behavior, and tests for the chosen behavior.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

enhancement

Is your feature request related to a problem? Please describe.

We use Workflow.randomUUID() to make idempotency keys for activities. The values stay the same across replays and activity retries. After a reset, they stay the same only for code that runs before the reset point:

UUID idempotencyKey1 = Workflow.randomUUID(); // seed: original run id, same after reset
activity1(idempotencyKey1);

// <-- reset here: seed switches to the new run id

UUID idempotencyKey2 = Workflow.randomUUID(); // new value after reset
activity2(idempotencyKey2);                   // failed mid-operation? reruns with a different key

If activity2 fails partway through its operation and we reset the workflow to fix it, activity2 runs again with a different key. The downstream system cannot tell that it is the same operation, and the operation happens twice.

The SDK does this on purpose. The code is the same from 1.37.0 through 1.41.1 and on main (links to v1.41.1):

sideEffect does not help, because a reset cannot start right after it

We tried recording the key with Workflow.sideEffect:

UUID idempotencyKey2 = Workflow.sideEffect(UUID.class, UUID::randomUUID);
activity2(idempotencyKey2);

To keep the key, we would need to reset right after the sideEffect marker, before activity2 is scheduled.
The server does not allow that. It accepts only workflow task events as a reset point.
workflow_resetter.go (v1.32.2) rejects others with:
"Can only reset workflow to event ID in range [WorkflowTaskScheduled +1, WorkflowTaskStarted + 1]".

The marker and the activity2 schedule are commands of the same workflow task, so there is no reset point between them:

10 WorkflowTaskStarted          <- reset point
11 WorkflowTaskCompleted        <- reset point
12 MarkerRecorded (key2)        ┐ commands of one workflow task,
13 ActivityTaskScheduled a2     ┘ no reset point between them

The closest reset point is before the marker, so the reset drops the marker.
The new run calls the function again and activity2 gets a different key.

Describe the solution you'd like

  1. Document randomUUID behaviour during reset
  2. One of:
  • Keep the original seed after a reset, as an opt-in worker or workflow option. The new run then produces the same randomUUID() values for the same sequence of calls.
  • Allow a reset to start after a MarkerRecorded event, so the new run keeps the sideEffect value and executes again from the next command.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Vorherrschende Sprache
Java
Sterne
447
Forks
278
Ø Merge
3 T. 22 Std.
Gemergte PRs (30 T.)
28

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus temporalio/sdk-java

Alle Issues in temporalio/sdk-java

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.