From cd2b63bd4341bb8c6f4fe8e484d23f3fddb126c8 Mon Sep 17 00:00:00 2001 From: Matt McShane Date: Tue, 6 Jun 2023 13:54:52 -0400 Subject: [PATCH] Take acceptedEventID write out of commit callback This value needs to be visible to the update completion message handler even in the case when the acceptance and completion come in the same message batch (i.e. workflow task). --- service/history/workflow/update/update.go | 8 ++++++-- service/history/workflow/update/update_test.go | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/service/history/workflow/update/update.go b/service/history/workflow/update/update.go index 23a8a82ce94..aafa7cbf60c 100644 --- a/service/history/workflow/update/update.go +++ b/service/history/workflow/update/update.go @@ -34,6 +34,7 @@ import ( protocolpb "go.temporal.io/api/protocol/v1" updatepb "go.temporal.io/api/update/v1" + "go.temporal.io/server/common" "go.temporal.io/server/common/future" "go.temporal.io/server/internal/effect" ) @@ -283,14 +284,17 @@ func (u *Update) onAcceptanceMsg( if err != nil { return err } + u.acceptedEventID = event.EventId u.setState(stateProvisionallyAccepted) eventStore.OnAfterCommit(func(context.Context) { u.request = nil - u.acceptedEventID = event.EventId u.setState(stateAccepted) u.accepted.(*future.FutureImpl[*failurepb.Failure]).Set(nil, nil) }) - eventStore.OnAfterRollback(func(context.Context) { u.setState(stateRequested) }) + eventStore.OnAfterRollback(func(context.Context) { + u.acceptedEventID = common.EmptyEventID + u.setState(stateRequested) + }) return nil } diff --git a/service/history/workflow/update/update_test.go b/service/history/workflow/update/update_test.go index 29acfad98bd..c7118aae153 100644 --- a/service/history/workflow/update/update_test.go +++ b/service/history/workflow/update/update_test.go @@ -575,7 +575,8 @@ func TestAcceptEventIDInCompletedEvent(t *testing.T) { t.Parallel() var ( ctx = context.Background() - store = mockEventStore{Controller: effect.Immediate(ctx)} + effects = effect.Buffer{} + store = mockEventStore{Controller: &effects} updateID = t.Name() + "-update-id" upd = update.New(updateID) req = updatepb.Request{ @@ -611,7 +612,9 @@ func TestAcceptEventIDInCompletedEvent(t *testing.T) { } require.NoError(t, upd.OnMessage(ctx, &req, store)) + effects.Apply(ctx) require.NoError(t, upd.OnMessage(ctx, &acpt, store)) require.NoError(t, upd.OnMessage(ctx, &resp, store)) + effects.Apply(ctx) require.Equal(t, wantAcceptedEventID, gotAcceptedEventID) }