Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion service/history/ndc/workflow_state_replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ func (r *WorkflowStateReplicatorImpl) applySnapshot(
}
snapshot := attribute.State
if localMutableState == nil {
return r.applySnapshotWhenWorkflowNotExist(
err := r.applySnapshotWhenWorkflowNotExist(
ctx,
namespaceID,
workflowID,
Expand All @@ -807,6 +807,31 @@ func (r *WorkflowStateReplicatorImpl) applySnapshot(
true,
versionedTransition.IsCloseTransferTaskAcked && versionedTransition.IsForceReplication,
)
if err != nil {
if !errors.Is(err, consts.ErrDuplicate) {
return err
}
// Handle duplicate error
ms, msErr := wfCtx.LoadMutableState(ctx, r.shardContext)
switch msErr.(type) {
case *serviceerror.NotFound:
return err
case nil:
// The previous run may replicate the first batch of workflow
// and this mutable state may update after acquire the workflow lock.
// Retry to apply snapshot with mutable state
localMutableState = ms
Comment thread
yux0 marked this conversation as resolved.
r.logger.Warn("duplicate error applying snapshot for new workflow; mutable state already exists, retrying with existing state",
tag.WorkflowNamespaceID(namespaceID.String()),
tag.WorkflowID(workflowID),
tag.WorkflowRunID(runID),
tag.ArchetypeID(archetypeID),
tag.Error(err),
)
default:
return err
}
}
}
return r.applySnapshotWhenWorkflowExist(
ctx,
Expand Down
2 changes: 1 addition & 1 deletion service/history/replication/raw_task_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ func (c *syncVersionedTransitionTaskConverter) convert(

progress := c.replicationCache.Get(taskInfo.RunID, targetClusterID)

if progress.VersionedTransitionSent(taskInfo.VersionedTransition) {
if progress != nil && progress.VersionedTransitionSent(taskInfo.VersionedTransition) {
return c.generateVerifyVersionedTransitionTask(taskInfo, mutableState)
}

Expand Down
10 changes: 0 additions & 10 deletions service/history/replication/sequential_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ type (
}
)

func NewSequentialTaskQueue(task TrackableExecutableTask) ctasks.SequentialTaskQueue[TrackableExecutableTask] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deadcode?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. I don't see anywhere use it

return &SequentialTaskQueue{
id: task.QueueID(),

taskQueue: collection.NewPriorityQueue[TrackableExecutableTask](
SequentialTaskQueueCompareLess,
),
}
}

func NewSequentialTaskQueueWithID(id any) ctasks.SequentialTaskQueue[TrackableExecutableTask] {
return &SequentialTaskQueue{
id: id,
Expand Down
Loading