Skip to content

Commit

Permalink
Check is global ns enabled in handler (#2541)
Browse files Browse the repository at this point in the history
  • Loading branch information
yux0 committed Feb 24, 2022
1 parent 749d2c6 commit 3b6d586
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions service/history/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,10 @@ func (h *Handler) ReplicateEventsV2(ctx context.Context, request *historyservice
return nil, errShuttingDown
}

if err := h.validateReplicationConfig(); err != nil {
return nil, err
}

namespaceID := namespace.ID(request.GetNamespaceId())
if namespaceID == "" {
return nil, h.convertError(errNamespaceNotSet)
Expand Down Expand Up @@ -1160,6 +1164,10 @@ func (h *Handler) SyncActivity(ctx context.Context, request *historyservice.Sync
return nil, errShuttingDown
}

if err := h.validateReplicationConfig(); err != nil {
return nil, err
}

namespaceID := namespace.ID(request.GetNamespaceId())
if request.GetNamespaceId() == "" || uuid.Parse(request.GetNamespaceId()) == nil {
return nil, h.convertError(errNamespaceNotSet)
Expand Down Expand Up @@ -1195,6 +1203,9 @@ func (h *Handler) GetReplicationMessages(ctx context.Context, request *historyse
if h.isStopped() {
return nil, errShuttingDown
}
if err := h.validateReplicationConfig(); err != nil {
return nil, err
}

var wg sync.WaitGroup
wg.Add(len(request.Tokens))
Expand Down Expand Up @@ -1248,6 +1259,9 @@ func (h *Handler) GetDLQReplicationMessages(ctx context.Context, request *histor
if h.isStopped() {
return nil, errShuttingDown
}
if err := h.validateReplicationConfig(); err != nil {
return nil, err
}

taskInfoPerShard := map[int32][]*replicationspb.ReplicationTaskInfo{}
// do batch based on workflow ID and run ID
Expand Down Expand Up @@ -1487,6 +1501,9 @@ func (h *Handler) GetReplicationStatus(
if h.isStopped() {
return nil, errShuttingDown
}
if err := h.validateReplicationConfig(); err != nil {
return nil, err
}

resp := &historyservice.GetReplicationStatusResponse{}
for _, shardID := range h.controller.ShardIDs() {
Expand Down Expand Up @@ -1525,6 +1542,13 @@ func (h *Handler) convertError(err error) error {
return err
}

func (h *Handler) validateReplicationConfig() error {
if !h.clusterMetadata.IsGlobalNamespaceEnabled() {
return serviceerror.NewUnavailable("The cluster has global namespace disabled. The operation is not supported.")
}
return nil
}

func validateTaskToken(taskToken *tokenspb.Task) error {
if taskToken.GetWorkflowId() == "" {
return errWorkflowIDNotSet
Expand Down

0 comments on commit 3b6d586

Please sign in to comment.