Skip to content

Commit

Permalink
Do not process replication task when namespace is deleted (temporalio…
Browse files Browse the repository at this point in the history
…#6892)

## What changed?
<!-- Describe what has changed in this PR -->
Do not process replication task when namespace is deleted
## Why?
<!-- Tell your future self why have you made these changes -->
We can ignore the replication if namespace in current status is in
deleted status.
## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
unit test
## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
no risk
## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->
n/a
## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
yes
  • Loading branch information
xwduan authored Nov 26, 2024
1 parent dd44cf5 commit a247b85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions service/history/replication/executable_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down
29 changes: 29 additions & 0 deletions service/history/replication/executable_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a247b85

Please sign in to comment.