Skip to content

Commit 5c23836

Browse files
authored
Fix handover callback (#3847)
1 parent 1c84aad commit 5c23836

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

service/history/historyEngine.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (e *historyEngineImpl) registerNamespaceStateChangeCallback() {
301301

302302
e.shard.GetNamespaceRegistry().RegisterStateChangeCallback(e, func(ns *namespace.Namespace, deletedFromDb bool) {
303303
if e.shard.GetClusterMetadata().IsGlobalNamespaceEnabled() {
304-
e.shard.UpdateHandoverNamespaces(ns, deletedFromDb)
304+
e.shard.UpdateHandoverNamespace(ns, deletedFromDb)
305305
}
306306

307307
if deletedFromDb {

service/history/shard/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type (
103103
// TODO: deprecate UpdateNamespaceNotificationVersion in v1.21 and remove
104104
// NamespaceNotificationVersion from shardInfo proto blob
105105
UpdateNamespaceNotificationVersion(namespaceNotificationVersion int64) error
106-
UpdateHandoverNamespaces(ns *namespace.Namespace, deletedFromDb bool)
106+
UpdateHandoverNamespace(ns *namespace.Namespace, deletedFromDb bool)
107107

108108
AppendHistoryEvents(ctx context.Context, request *persistence.AppendHistoryNodesRequest, namespaceID namespace.ID, execution commonpb.WorkflowExecution) (int, error)
109109

service/history/shard/context_impl.go

+17-19
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,17 @@ func (s *ContextImpl) UpdateNamespaceNotificationVersion(namespaceNotificationVe
578578
return nil
579579
}
580580

581-
func (s *ContextImpl) UpdateHandoverNamespaces(ns *namespace.Namespace, deletedFromDb bool) {
581+
func (s *ContextImpl) UpdateHandoverNamespace(ns *namespace.Namespace, deletedFromDb bool) {
582582
nsName := ns.Name()
583+
// NOTE: replication state field won't be replicated and currently we only update a namespace
584+
// to handover state from active cluster, so the second condition will always be true. Adding
585+
// it here to be more safe in case above assumption no longer holds in the future.
586+
isHandoverNamespace := ns.IsGlobalNamespace() &&
587+
ns.ActiveInCluster(s.GetClusterMetadata().GetCurrentClusterName()) &&
588+
ns.ReplicationState() == enums.REPLICATION_STATE_HANDOVER
583589

584590
s.wLock()
585-
if deletedFromDb {
591+
if deletedFromDb || !isHandoverNamespace {
586592
delete(s.handoverNamespaces, ns.Name())
587593
s.wUnlock()
588594
return
@@ -595,23 +601,15 @@ func (s *ContextImpl) UpdateHandoverNamespaces(ns *namespace.Namespace, deletedF
595601
maxReplicationTaskID = pendingMaxReplicationTaskID
596602
}
597603

598-
// NOTE: replication state field won't be replicated and currently we only update a namespace
599-
// to handover state from active cluster, so the second condition will always be true. Adding
600-
// it here to be more safe in case above assumption no longer holds in the future.
601-
if ns.IsGlobalNamespace() &&
602-
ns.ActiveInCluster(s.GetClusterMetadata().GetCurrentClusterName()) &&
603-
ns.ReplicationState() == enums.REPLICATION_STATE_HANDOVER {
604-
605-
if handover, ok := s.handoverNamespaces[nsName]; ok {
606-
if handover.NotificationVersion < ns.NotificationVersion() {
607-
handover.NotificationVersion = ns.NotificationVersion()
608-
handover.MaxReplicationTaskID = maxReplicationTaskID
609-
}
610-
} else {
611-
s.handoverNamespaces[nsName] = &namespaceHandOverInfo{
612-
NotificationVersion: ns.NotificationVersion(),
613-
MaxReplicationTaskID: maxReplicationTaskID,
614-
}
604+
if handover, ok := s.handoverNamespaces[nsName]; ok {
605+
if handover.NotificationVersion < ns.NotificationVersion() {
606+
handover.NotificationVersion = ns.NotificationVersion()
607+
handover.MaxReplicationTaskID = maxReplicationTaskID
608+
}
609+
} else {
610+
s.handoverNamespaces[nsName] = &namespaceHandOverInfo{
611+
NotificationVersion: ns.NotificationVersion(),
612+
MaxReplicationTaskID: maxReplicationTaskID,
615613
}
616614
}
617615

service/history/shard/context_mock.go

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)