Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mutable state consistency check logic #2747

Merged
merged 7 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions client/history/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,6 @@ func (c *clientImpl) executeWithRedirect(ctx context.Context,
op func(ctx context.Context, client historyservice.HistoryServiceClient) error,
) error {

redirectLoop:
for {
err := common.IsValidContext(ctx)
if err != nil {
Expand All @@ -1174,7 +1173,6 @@ redirectLoop:
return err
}
client = ret.(historyservice.HistoryServiceClient)
continue redirectLoop
} else {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions common/metrics/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ const (
PersistenceGetOrCreateShardScope
// PersistenceUpdateShardScope tracks UpdateShard calls made by service to persistence layer
PersistenceUpdateShardScope
// PersistenceAssertShardOwnershipScope tracks UpdateShard calls made by service to persistence layer
PersistenceAssertShardOwnershipScope
// PersistenceCreateWorkflowExecutionScope tracks CreateWorkflowExecution calls made by service to persistence layer
PersistenceCreateWorkflowExecutionScope
// PersistenceGetWorkflowExecutionScope tracks GetWorkflowExecution calls made by service to persistence layer
Expand Down Expand Up @@ -1221,6 +1223,7 @@ var ScopeDefs = map[ServiceIdx]map[int]scopeDefinition{
UnknownScope: {operation: "Unknown"},
PersistenceGetOrCreateShardScope: {operation: "GetOrCreateShard"},
PersistenceUpdateShardScope: {operation: "UpdateShard"},
PersistenceAssertShardOwnershipScope: {operation: "AssertShardOwnership"},
PersistenceCreateWorkflowExecutionScope: {operation: "CreateWorkflowExecution"},
PersistenceGetWorkflowExecutionScope: {operation: "GetWorkflowExecution"},
PersistenceSetWorkflowExecutionScope: {operation: "SetWorkflowExecution"},
Expand Down
7 changes: 7 additions & 0 deletions common/persistence/cassandra/shard_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ func (d *ShardStore) UpdateShard(
return nil
}

func (d *ShardStore) AssertShardOwnership(
ctx context.Context,
request *p.AssertShardOwnershipRequest,
) error {
return nil
}

func (d *ShardStore) GetName() string {
return cassandraPersistenceName
}
Expand Down
10 changes: 10 additions & 0 deletions common/persistence/client/fault_injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,16 @@ func (s *FaultInjectionShardStore) UpdateShard(
return s.baseShardStore.UpdateShard(ctx, request)
}

func (s *FaultInjectionShardStore) AssertShardOwnership(
ctx context.Context,
request *persistence.AssertShardOwnershipRequest,
) error {
if err := s.ErrorGenerator.Generate(); err != nil {
return err
}
return s.baseShardStore.AssertShardOwnership(ctx, request)
}

func (s *FaultInjectionShardStore) UpdateRate(rate float64) {
s.ErrorGenerator.UpdateRate(rate)
}
8 changes: 8 additions & 0 deletions common/persistence/dataInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ type (
PreviousRangeID int64
}

// AssertShardOwnershipRequest is used to assert shard ownership
AssertShardOwnershipRequest struct {
ShardID int32
RangeID int64
}

// AddHistoryTasksRequest is used to write new tasks
AddHistoryTasksRequest struct {
ShardID int32
Expand Down Expand Up @@ -977,8 +983,10 @@ type (
ShardManager interface {
Closeable
GetName() string

GetOrCreateShard(ctx context.Context, request *GetOrCreateShardRequest) (*GetOrCreateShardResponse, error)
UpdateShard(ctx context.Context, request *UpdateShardRequest) error
AssertShardOwnership(ctx context.Context, request *AssertShardOwnershipRequest) error
}

// ExecutionManager is used to manage workflow executions
Expand Down
14 changes: 14 additions & 0 deletions common/persistence/dataInterfaces_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions common/persistence/mock/store_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/persistence/persistenceInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type (
GetClusterName() string
GetOrCreateShard(ctx context.Context, request *InternalGetOrCreateShardRequest) (*InternalGetOrCreateShardResponse, error)
UpdateShard(ctx context.Context, request *InternalUpdateShardRequest) error
AssertShardOwnership(ctx context.Context, request *AssertShardOwnershipRequest) error
}

// TaskStore is a lower level of TaskManager
Expand Down
17 changes: 17 additions & 0 deletions common/persistence/persistenceMetricClients.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ func (p *shardPersistenceClient) UpdateShard(
return err
}

func (p *shardPersistenceClient) AssertShardOwnership(
ctx context.Context,
request *AssertShardOwnershipRequest,
) error {
p.metricClient.IncCounter(metrics.PersistenceAssertShardOwnershipScope, metrics.PersistenceRequests)

sw := p.metricClient.StartTimer(metrics.PersistenceAssertShardOwnershipScope, metrics.PersistenceLatency)
err := p.persistence.AssertShardOwnership(ctx, request)
sw.Stop()

if err != nil {
p.updateErrorMetric(metrics.PersistenceAssertShardOwnershipScope, err)
}

return err
}

func (p *shardPersistenceClient) Close() {
p.persistence.Close()
}
Expand Down
12 changes: 12 additions & 0 deletions common/persistence/persistenceRateLimitedClients.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ func (p *shardRateLimitedPersistenceClient) UpdateShard(
return err
}

func (p *shardRateLimitedPersistenceClient) AssertShardOwnership(
ctx context.Context,
request *AssertShardOwnershipRequest,
) error {
if ok := p.rateLimiter.Allow(); !ok {
return ErrPersistenceLimitExceeded
}

err := p.persistence.AssertShardOwnership(ctx, request)
return err
}

func (p *shardRateLimitedPersistenceClient) Close() {
p.persistence.Close()
}
Expand Down
8 changes: 8 additions & 0 deletions common/persistence/shard_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"

persistencespb "go.temporal.io/server/api/persistence/v1"
"go.temporal.io/server/common/persistence/serialization"
"go.temporal.io/server/common/primitives/timestamp"
Expand Down Expand Up @@ -112,3 +113,10 @@ func (m *shardManagerImpl) UpdateShard(
}
return m.shardStore.UpdateShard(ctx, internalRequest)
}

func (m *shardManagerImpl) AssertShardOwnership(
ctx context.Context,
request *AssertShardOwnershipRequest,
) error {
return m.shardStore.AssertShardOwnership(ctx, request)
}
7 changes: 7 additions & 0 deletions common/persistence/sql/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ func (m *sqlShardStore) UpdateShard(
})
}

func (m *sqlShardStore) AssertShardOwnership(
ctx context.Context,
request *persistence.AssertShardOwnershipRequest,
) error {
return nil
}

// initiated by the owning shard
func lockShard(
ctx context.Context,
Expand Down
Loading