Skip to content

Commit

Permalink
Generate namespace replication only with 2+ clusters (temporalio#2513)
Browse files Browse the repository at this point in the history
* Generate namespace replication only with 2+ clusters
  • Loading branch information
yux0 authored Feb 17, 2022
1 parent 24f6dc3 commit 1f2b291
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
34 changes: 15 additions & 19 deletions common/namespace/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,17 @@ func (d *HandlerImpl) RegisterNamespace(
return nil, err
}

if namespaceRequest.IsGlobalNamespace {
err = d.namespaceReplicator.HandleTransmissionTask(
enumsspb.NAMESPACE_OPERATION_CREATE,
namespaceRequest.Namespace.Info,
namespaceRequest.Namespace.Config,
namespaceRequest.Namespace.ReplicationConfig,
namespaceRequest.Namespace.ConfigVersion,
namespaceRequest.Namespace.FailoverVersion,
namespaceRequest.IsGlobalNamespace,
)
if err != nil {
return nil, err
}
err = d.namespaceReplicator.HandleTransmissionTask(
enumsspb.NAMESPACE_OPERATION_CREATE,
namespaceRequest.Namespace.Info,
namespaceRequest.Namespace.Config,
namespaceRequest.Namespace.ReplicationConfig,
namespaceRequest.Namespace.ConfigVersion,
namespaceRequest.Namespace.FailoverVersion,
namespaceRequest.IsGlobalNamespace,
)
if err != nil {
return nil, err
}

d.logger.Info("Register namespace succeeded",
Expand Down Expand Up @@ -572,12 +570,10 @@ func (d *HandlerImpl) UpdateNamespace(
}
}

if isGlobalNamespace {
err = d.namespaceReplicator.HandleTransmissionTask(enumsspb.NAMESPACE_OPERATION_UPDATE,
info, config, replicationConfig, configVersion, failoverVersion, isGlobalNamespace)
if err != nil {
return nil, err
}
err = d.namespaceReplicator.HandleTransmissionTask(enumsspb.NAMESPACE_OPERATION_UPDATE,
info, config, replicationConfig, configVersion, failoverVersion, isGlobalNamespace)
if err != nil {
return nil, err
}

response := &workflowservice.UpdateNamespaceResponse{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (s *namespaceHandlerGlobalNamespaceEnabledMasterClusterSuite) TestRegisterG
})
}

s.mockProducer.EXPECT().Publish(gomock.Any()).Return(nil)
s.mockProducer.EXPECT().Publish(gomock.Any()).Return(nil).Times(0)

retention := 1 * time.Hour * 24
registerResp, err := s.handler.RegisterNamespace(context.Background(), &workflowservice.RegisterNamespaceRequest{
Expand Down
1 change: 0 additions & 1 deletion common/namespace/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ func (s *namespaceHandlerCommonSuite) TestUpdateNamespace_PromoteLocalNamespace(
Namespace: namespace,
PromoteNamespace: true,
}
s.mockProducer.EXPECT().Publish(gomock.Any())
_, err = s.handler.UpdateNamespace(context.Background(), updateRequest)
s.NoError(err)

Expand Down
9 changes: 6 additions & 3 deletions common/namespace/transmissionTaskHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type (
replicationConfig *persistencespb.NamespaceReplicationConfig,
configVersion int64,
failoverVersion int64,
isGlobalNamespaceEnabled bool,
isGlobalNamespace bool,
) error
}

Expand Down Expand Up @@ -76,10 +76,13 @@ func (namespaceReplicator *namespaceReplicatorImpl) HandleTransmissionTask(
replicationConfig *persistencespb.NamespaceReplicationConfig,
configVersion int64,
failoverVersion int64,
isGlobalNamespaceEnabled bool,
isGlobalNamespace bool,
) error {

if !isGlobalNamespaceEnabled {
if !isGlobalNamespace {
return nil
}
if len(replicationConfig.Clusters) <= 1 {
return nil
}

Expand Down

0 comments on commit 1f2b291

Please sign in to comment.