From 19a7443f15a4fd38dc076a3391b44537e38cbab0 Mon Sep 17 00:00:00 2001 From: xwduan Date: Tue, 26 Nov 2024 15:10:15 -0800 Subject: [PATCH] Do not process replication task when namespace is deleted --- .../history/replication/executable_task.go | 4 +++ .../replication/executable_task_test.go | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/service/history/replication/executable_task.go b/service/history/replication/executable_task.go index 7d292ddb5e6..0e3ae3cbb9d 100644 --- a/service/history/replication/executable_task.go +++ b/service/history/replication/executable_task.go @@ -32,6 +32,7 @@ import ( "time" commonpb "go.temporal.io/api/common/v1" + "go.temporal.io/api/enums/v1" "go.temporal.io/api/serviceerror" "go.temporal.io/server/api/adminservice/v1" enumsspb "go.temporal.io/server/api/enums/v1" @@ -593,6 +594,9 @@ func (e *ExecutableTaskImpl) GetNamespaceInfo( } e.namespace.Store(namespaceEntry.Name()) + if namespaceEntry.State() == enums.NAMESPACE_STATE_DELETED { + return namespaceEntry.Name().String(), false, nil + } shouldProcessTask := false FilterLoop: for _, targetCluster := range namespaceEntry.ClusterNames() { diff --git a/service/history/replication/executable_task_test.go b/service/history/replication/executable_task_test.go index 068b98bb1bd..42dd3d94f36 100644 --- a/service/history/replication/executable_task_test.go +++ b/service/history/replication/executable_task_test.go @@ -35,6 +35,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" commonpb "go.temporal.io/api/common/v1" + "go.temporal.io/api/enums/v1" "go.temporal.io/api/serviceerror" "go.temporal.io/server/api/adminservice/v1" "go.temporal.io/server/api/adminservicemock/v1" @@ -665,6 +666,34 @@ func (s *executableTaskSuite) TestGetNamespaceInfo_Skip() { s.False(toProcess) } +func (s *executableTaskSuite) TestGetNamespaceInfo_Deleted() { + namespaceID := uuid.NewString() + namespaceName := uuid.NewString() + namespaceEntry := namespace.FromPersistentState(&persistence.GetNamespaceResponse{ + Namespace: &persistencespb.NamespaceDetail{ + Info: &persistencespb.NamespaceInfo{ + Id: namespaceID, + Name: namespaceName, + State: enums.NAMESPACE_STATE_DELETED, + }, + Config: &persistencespb.NamespaceConfig{}, + ReplicationConfig: &persistencespb.NamespaceReplicationConfig{ + ActiveClusterName: cluster.TestAlternativeClusterName, + Clusters: []string{ + cluster.TestCurrentClusterName, + cluster.TestAlternativeClusterName, + }, + }, + }, + }) + s.namespaceCache.EXPECT().GetNamespaceByID(namespace.ID(namespaceID)).Return(namespaceEntry, nil).AnyTimes() + + name, toProcess, err := s.task.GetNamespaceInfo(context.Background(), namespaceID) + s.NoError(err) + s.Equal(namespaceName, name) + s.False(toProcess) +} + func (s *executableTaskSuite) TestGetNamespaceInfo_Error() { namespaceID := uuid.NewString() s.namespaceCache.EXPECT().GetNamespaceByID(namespace.ID(namespaceID)).Return(nil, errors.New("OwO")).AnyTimes()