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

Validation API should use low priority lock #4140

Merged
merged 4 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 11 additions & 2 deletions service/history/api/consistency_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type (
reqClock *clockspb.VectorClock,
consistencyPredicate MutableStateConsistencyPredicate,
workflowKey definition.WorkflowKey,
callerType workflow.CallerType,
) (WorkflowContext, error)
}

Expand Down Expand Up @@ -108,6 +109,7 @@ func (c *WorkflowConsistencyCheckerImpl) GetWorkflowContext(
reqClock *clockspb.VectorClock,
consistencyPredicate MutableStateConsistencyPredicate,
workflowKey definition.WorkflowKey,
callerType workflow.CallerType,
) (WorkflowContext, error) {
if reqClock != nil {
currentClock := c.shardContext.CurrentVectorClock()
Expand All @@ -117,6 +119,7 @@ func (c *WorkflowConsistencyCheckerImpl) GetWorkflowContext(
reqClock,
currentClock,
workflowKey,
callerType,
)
}
// request vector clock cannot is not comparable with current shard vector clock
Expand All @@ -133,6 +136,7 @@ func (c *WorkflowConsistencyCheckerImpl) GetWorkflowContext(
&shardOwnershipAsserted,
consistencyPredicate,
workflowKey,
callerType,
)
}
return c.getCurrentWorkflowContext(
Expand All @@ -141,6 +145,7 @@ func (c *WorkflowConsistencyCheckerImpl) GetWorkflowContext(
consistencyPredicate,
workflowKey.NamespaceID,
workflowKey.WorkflowID,
callerType,
)
}

Expand All @@ -149,6 +154,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowContextValidatedByClock(
reqClock *clockspb.VectorClock,
currentClock *clockspb.VectorClock,
workflowKey definition.WorkflowKey,
callerType workflow.CallerType,
) (WorkflowContext, error) {
cmpResult, err := vclock.Compare(reqClock, currentClock)
if err != nil {
Expand All @@ -170,7 +176,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowContextValidatedByClock(
WorkflowId: workflowKey.WorkflowID,
RunId: workflowKey.RunID,
},
workflow.CallerTypeAPI,
callerType,
)
if err != nil {
return nil, err
Expand All @@ -189,6 +195,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowContextValidatedByCheck(
shardOwnershipAsserted *bool,
consistencyPredicate MutableStateConsistencyPredicate,
workflowKey definition.WorkflowKey,
callerType workflow.CallerType,
) (WorkflowContext, error) {
if len(workflowKey.RunID) == 0 {
return nil, serviceerror.NewInternal(fmt.Sprintf(
Expand All @@ -203,7 +210,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowContextValidatedByCheck(
WorkflowId: workflowKey.WorkflowID,
RunId: workflowKey.RunID,
},
workflow.CallerTypeAPI,
callerType,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -245,6 +252,7 @@ func (c *WorkflowConsistencyCheckerImpl) getCurrentWorkflowContext(
consistencyPredicate MutableStateConsistencyPredicate,
namespaceID string,
workflowID string,
callerType workflow.CallerType,
) (WorkflowContext, error) {
runID, err := c.getCurrentRunID(
ctx,
Expand All @@ -260,6 +268,7 @@ func (c *WorkflowConsistencyCheckerImpl) getCurrentWorkflowContext(
shardOwnershipAsserted,
consistencyPredicate,
definition.NewWorkflowKey(namespaceID, workflowID, runID),
callerType,
)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions service/history/api/consistency_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck
&shardOwnershipAsserted,
BypassMutableStateConsistencyPredicate,
definition.NewWorkflowKey(s.namespaceID, s.workflowID, s.currentRunID),
workflow.CallerTypeAPI,
)
s.NoError(err)
s.Equal(mutableState, workflowContext.GetMutableState())
Expand Down Expand Up @@ -160,6 +161,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck
&shardOwnershipAsserted,
FailMutableStateConsistencyPredicate,
definition.NewWorkflowKey(s.namespaceID, s.workflowID, s.currentRunID),
workflow.CallerTypeAPI,
)
s.NoError(err)
s.Equal(mutableState2, workflowContext.GetMutableState())
Expand Down Expand Up @@ -192,6 +194,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck
&shardOwnershipAsserted,
FailMutableStateConsistencyPredicate,
definition.NewWorkflowKey(s.namespaceID, s.workflowID, s.currentRunID),
workflow.CallerTypeAPI,
)
s.IsType(&serviceerror.NotFound{}, err)
s.Nil(workflowContext)
Expand Down Expand Up @@ -224,6 +227,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck
&shardOwnershipAsserted,
FailMutableStateConsistencyPredicate,
definition.NewWorkflowKey(s.namespaceID, s.workflowID, s.currentRunID),
workflow.CallerTypeAPI,
)
s.IsType(&persistence.ShardOwnershipLostError{}, err)
s.Nil(workflowContext)
Expand Down Expand Up @@ -254,6 +258,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck
&shardOwnershipAsserted,
FailMutableStateConsistencyPredicate,
definition.NewWorkflowKey(s.namespaceID, s.workflowID, s.currentRunID),
workflow.CallerTypeAPI,
)
s.IsType(&serviceerror.Unavailable{}, err)
s.Nil(workflowContext)
Expand Down
1 change: 1 addition & 0 deletions service/history/api/deleteworkflow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func Invoke(
request.WorkflowExecution.WorkflowId,
request.WorkflowExecution.RunId,
),
workflow.CallerTypeTask,
)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions service/history/api/describemutablestate/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func Invoke(
req.Execution.WorkflowId,
req.Execution.RunId,
),
workflow.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions service/history/api/describeworkflow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func Invoke(
req.Request.Execution.WorkflowId,
req.Request.Execution.RunId,
),
workflow.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions service/history/api/get_workflow_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func GetMutableState(
nil,
BypassMutableStateConsistencyPredicate,
workflowKey,
workflow.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions service/history/api/queryworkflow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func Invoke(
nil,
api.BypassMutableStateConsistencyPredicate,
workflowKey,
workflow.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions service/history/api/refreshworkflow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func Invoke(
nil,
api.BypassMutableStateConsistencyPredicate,
workflowKey,
workflow.CallerTypeAPI,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be task?

)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions service/history/api/replication/generate_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"go.temporal.io/server/service/history/api"
"go.temporal.io/server/service/history/shard"
"go.temporal.io/server/service/history/tasks"
"go.temporal.io/server/service/history/workflow"
)

func GenerateTask(
Expand All @@ -57,6 +58,7 @@ func GenerateTask(
request.Execution.WorkflowId,
request.Execution.RunId,
),
workflow.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions service/history/api/resetworkflow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"go.temporal.io/server/service/history/api"
"go.temporal.io/server/service/history/ndc"
"go.temporal.io/server/service/history/shard"
"go.temporal.io/server/service/history/workflow"
)

func Invoke(
Expand Down Expand Up @@ -66,6 +67,7 @@ func Invoke(
workflowID,
baseRunID,
),
workflow.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -104,6 +106,7 @@ func Invoke(
workflowID,
currentRunID,
),
workflow.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions service/history/api/signalwithstartworkflow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"go.temporal.io/server/common/namespace"
"go.temporal.io/server/service/history/api"
"go.temporal.io/server/service/history/shard"
"go.temporal.io/server/service/history/workflow"
)

func Invoke(
Expand All @@ -59,6 +60,7 @@ func Invoke(
signalWithStartRequest.SignalWithStartRequest.WorkflowId,
"",
),
workflow.CallerTypeAPI,
)
switch err.(type) {
case nil:
Expand Down
1 change: 1 addition & 0 deletions service/history/api/update_workflow_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func GetAndUpdateWorkflowWithNew(
reqClock,
consistencyCheckFn,
workflowKey,
workflow.CallerTypeAPI,
)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions service/history/api/updateworkflow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func Invoke(
req.Request.WorkflowExecution.WorkflowId,
req.Request.WorkflowExecution.RunId,
),
workflow.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"go.temporal.io/server/service/history/api"
"go.temporal.io/server/service/history/consts"
"go.temporal.io/server/service/history/shard"
"go.temporal.io/server/service/history/workflow"
)

func Invoke(
Expand All @@ -61,6 +62,7 @@ func Invoke(
request.ParentExecution.WorkflowId,
request.ParentExecution.RunId,
),
workflow.CallerTypeTask,
)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions service/history/workflowRebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (r *workflowRebuilderImpl) rebuild(
nil,
api.BypassMutableStateConsistencyPredicate,
workflowKey,
workflow.CallerTypeAPI,
)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions service/history/workflowTaskHandlerCallbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func (handler *workflowTaskHandlerCallbacksImpl) handleWorkflowTaskCompleted(
token.WorkflowId,
token.RunId,
),
workflow.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -748,6 +749,7 @@ func (handler *workflowTaskHandlerCallbacksImpl) verifyFirstWorkflowTaskSchedule
req.WorkflowExecution.WorkflowId,
req.WorkflowExecution.RunId,
),
workflow.CallerTypeTask,
)
if err != nil {
return err
Expand Down