diff --git a/common/deadlock/deadlock.go b/common/deadlock/deadlock.go index bb8cf974ae3..5ff9d9c51df 100644 --- a/common/deadlock/deadlock.go +++ b/common/deadlock/deadlock.go @@ -42,7 +42,7 @@ import ( "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/internal/goro" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" ) type ( @@ -57,7 +57,7 @@ type ( // root pingables: NamespaceRegistry namespace.Registry ClusterMetadata cluster.Metadata - ShardController shard.Controller `optional:"true"` + ShardController definition.ShardController `optional:"true"` } config struct { diff --git a/service/history/api/activity_util.go b/service/history/api/activity_util.go index ea56a8a6506..83eb85d81e6 100644 --- a/service/history/api/activity_util.go +++ b/service/history/api/activity_util.go @@ -31,7 +31,7 @@ import ( "go.temporal.io/api/serviceerror" tokenspb "go.temporal.io/server/api/token/v1" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) func SetActivityTaskRunID( @@ -64,7 +64,7 @@ func SetActivityTaskRunID( func GetActivityScheduledEventID( activityID string, - mutableState workflow.MutableState, + mutableState definition.MutableState, ) (int64, error) { if activityID == "" { diff --git a/service/history/api/consistency_checker.go b/service/history/api/consistency_checker.go index 3f19b8a2368..5b643ad9922 100644 --- a/service/history/api/consistency_checker.go +++ b/service/history/api/consistency_checker.go @@ -33,21 +33,19 @@ import ( clockspb "go.temporal.io/server/api/clock/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/vclock" - "go.temporal.io/server/service/history/workflow" ) type ( - MutableStateConsistencyPredicate func(mutableState workflow.MutableState) bool + MutableStateConsistencyPredicate func(mutableState definition.MutableState) bool WorkflowConsistencyChecker interface { - GetWorkflowCache() workflow.Cache + GetWorkflowCache() definition.WorkflowCache GetCurrentRunID( ctx context.Context, namespaceID string, @@ -62,14 +60,14 @@ type ( } WorkflowConsistencyCheckerImpl struct { - shardContext shard.Context - workflowCache workflow.Cache + shardContext definition.ShardContext + workflowCache definition.WorkflowCache } ) func NewWorkflowConsistencyChecker( - shardContext shard.Context, - workflowCache workflow.Cache, + shardContext definition.ShardContext, + workflowCache definition.WorkflowCache, ) *WorkflowConsistencyCheckerImpl { return &WorkflowConsistencyCheckerImpl{ shardContext: shardContext, @@ -77,7 +75,7 @@ func NewWorkflowConsistencyChecker( } } -func (c *WorkflowConsistencyCheckerImpl) GetWorkflowCache() workflow.Cache { +func (c *WorkflowConsistencyCheckerImpl) GetWorkflowCache() definition.WorkflowCache { return c.workflowCache } @@ -169,7 +167,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowContextValidatedByClock( WorkflowId: workflowKey.WorkflowID, RunId: workflowKey.RunID, }, - workflow.CallerTypeAPI, + definition.CallerTypeAPI, ) if err != nil { return nil, err @@ -202,7 +200,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowContextValidatedByCheck( WorkflowId: workflowKey.WorkflowID, RunId: workflowKey.RunID, }, - workflow.CallerTypeAPI, + definition.CallerTypeAPI, ) if err != nil { return nil, err @@ -318,7 +316,7 @@ func (c *WorkflowConsistencyCheckerImpl) getCurrentRunID( func assertShardOwnership( ctx context.Context, - shardContext shard.Context, + shardContext definition.ShardContext, shardOwnershipAsserted *bool, ) error { if !*shardOwnershipAsserted { @@ -329,13 +327,13 @@ func assertShardOwnership( } func BypassMutableStateConsistencyPredicate( - mutableState workflow.MutableState, + mutableState definition.MutableState, ) bool { return true } func FailMutableStateConsistencyPredicate( - mutableState workflow.MutableState, + mutableState definition.MutableState, ) bool { return false } @@ -344,7 +342,7 @@ func HistoryEventConsistencyPredicate( eventID int64, eventVersion int64, ) MutableStateConsistencyPredicate { - return func(mutableState workflow.MutableState) bool { + return func(mutableState definition.MutableState) bool { if eventVersion != 0 { _, err := versionhistory.FindFirstVersionHistoryIndexByVersionHistoryItem( mutableState.GetExecutionInfo().GetVersionHistories(), diff --git a/service/history/api/consistency_checker_test.go b/service/history/api/consistency_checker_test.go index ac71e01b0ae..11318f2cb93 100644 --- a/service/history/api/consistency_checker_test.go +++ b/service/history/api/consistency_checker_test.go @@ -39,12 +39,10 @@ import ( historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" - "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) type ( @@ -53,8 +51,8 @@ type ( *require.Assertions controller *gomock.Controller - shardContext *shard.MockContext - workflowCache *workflow.MockCache + shardContext *definition.MockShardContext + workflowCache *definition.MockWorkflowCache shardID int32 namespaceID string @@ -81,8 +79,8 @@ func (s *workflowConsistencyCheckerSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.shardContext = shard.NewMockContext(s.controller) - s.workflowCache = workflow.NewMockCache(s.controller) + s.shardContext = definition.NewMockShardContext(s.controller) + s.workflowCache = definition.NewMockWorkflowCache(s.controller) s.shardID = rand.Int31() s.namespaceID = uuid.New().String() @@ -102,8 +100,8 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck ctx := context.Background() shardOwnershipAsserted := false - wfContext := workflow.NewMockContext(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) + wfContext := definition.NewMockWorkflowContext(s.controller) + mutableState := definition.NewMockMutableState(s.controller) released := false releaseFn := func(err error) { released = true } @@ -114,7 +112,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck WorkflowId: s.workflowID, RunId: s.currentRunID, }, - workflow.CallerTypeAPI, + definition.CallerTypeAPI, ).Return(wfContext, releaseFn, nil) wfContext.EXPECT().LoadMutableState(ctx).Return(mutableState, nil) @@ -133,9 +131,9 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck ctx := context.Background() shardOwnershipAsserted := false - wfContext := workflow.NewMockContext(s.controller) - mutableState1 := workflow.NewMockMutableState(s.controller) - mutableState2 := workflow.NewMockMutableState(s.controller) + wfContext := definition.NewMockWorkflowContext(s.controller) + mutableState1 := definition.NewMockMutableState(s.controller) + mutableState2 := definition.NewMockMutableState(s.controller) released := false releaseFn := func(err error) { released = true } @@ -146,7 +144,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck WorkflowId: s.workflowID, RunId: s.currentRunID, }, - workflow.CallerTypeAPI, + definition.CallerTypeAPI, ).Return(wfContext, releaseFn, nil) gomock.InOrder( wfContext.EXPECT().LoadMutableState(ctx).Return(mutableState1, nil), @@ -169,7 +167,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck ctx := context.Background() shardOwnershipAsserted := false - wfContext := workflow.NewMockContext(s.controller) + wfContext := definition.NewMockWorkflowContext(s.controller) released := false releaseFn := func(err error) { released = true } @@ -180,7 +178,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck WorkflowId: s.workflowID, RunId: s.currentRunID, }, - workflow.CallerTypeAPI, + definition.CallerTypeAPI, ).Return(wfContext, releaseFn, nil) wfContext.EXPECT().LoadMutableState(ctx).Return(nil, serviceerror.NewNotFound("")) @@ -201,7 +199,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck ctx := context.Background() shardOwnershipAsserted := false - wfContext := workflow.NewMockContext(s.controller) + wfContext := definition.NewMockWorkflowContext(s.controller) released := false releaseFn := func(err error) { released = true } @@ -212,7 +210,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck WorkflowId: s.workflowID, RunId: s.currentRunID, }, - workflow.CallerTypeAPI, + definition.CallerTypeAPI, ).Return(wfContext, releaseFn, nil) wfContext.EXPECT().LoadMutableState(ctx).Return(nil, serviceerror.NewNotFound("")) @@ -233,7 +231,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck ctx := context.Background() shardOwnershipAsserted := false - wfContext := workflow.NewMockContext(s.controller) + wfContext := definition.NewMockWorkflowContext(s.controller) released := false releaseFn := func(err error) { released = true } @@ -244,7 +242,7 @@ func (s *workflowConsistencyCheckerSuite) TestGetWorkflowContextValidatedByCheck WorkflowId: s.workflowID, RunId: s.currentRunID, }, - workflow.CallerTypeAPI, + definition.CallerTypeAPI, ).Return(wfContext, releaseFn, nil) wfContext.EXPECT().LoadMutableState(ctx).Return(nil, serviceerror.NewUnavailable("")) @@ -412,7 +410,7 @@ func (s *workflowConsistencyCheckerSuite) TestHistoryEventConsistencyPredicate() for _, tc := range testCases { s.Run(tc.name, func() { - mockMutableState := workflow.NewMockMutableState(s.controller) + mockMutableState := definition.NewMockMutableState(s.controller) mockMutableState.EXPECT().GetExecutionInfo().Return(&persistencespb.WorkflowExecutionInfo{ VersionHistories: tc.versionHistories, }) diff --git a/service/history/api/create_workflow_util.go b/service/history/api/create_workflow_util.go index ff9c630880a..aee1aef39db 100644 --- a/service/history/api/create_workflow_util.go +++ b/service/history/api/create_workflow_util.go @@ -36,13 +36,12 @@ import ( "go.temporal.io/server/api/historyservice/v1" workflowspb "go.temporal.io/server/api/workflow/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/common/rpc/interceptor" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) @@ -55,7 +54,7 @@ type ( func NewWorkflowWithSignal( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, namespaceEntry *namespace.Namespace, workflowID string, runID string, @@ -122,12 +121,12 @@ func NewWorkflowWithSignal( func CreateMutableState( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, namespaceEntry *namespace.Namespace, executionTimeout *time.Duration, runTimeout *time.Duration, runID string, -) (workflow.MutableState, error) { +) (definition.MutableState, error) { newMutableState := workflow.NewMutableState( shard, shard.GetEventsCache(), @@ -142,7 +141,7 @@ func CreateMutableState( } func GenerateFirstWorkflowTask( - mutableState workflow.MutableState, + mutableState definition.MutableState, parentInfo *workflowspb.ParentExecutionInfo, startEvent *historypb.HistoryEvent, ) error { @@ -159,9 +158,9 @@ func GenerateFirstWorkflowTask( } func NewWorkflowVersionCheck( - shard shard.Context, + shard definition.ShardContext, prevLastWriteVersion int64, - newMutableState workflow.MutableState, + newMutableState definition.MutableState, ) error { if prevLastWriteVersion == common.EmptyVersion { return nil @@ -181,7 +180,7 @@ func NewWorkflowVersionCheck( func ValidateStart( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, namespaceEntry *namespace.Namespace, workflowID string, workflowInputSize int, @@ -229,7 +228,7 @@ func ValidateStart( func ValidateStartWorkflowExecutionRequest( ctx context.Context, request *workflowservice.StartWorkflowExecutionRequest, - shard shard.Context, + shard definition.ShardContext, namespaceEntry *namespace.Namespace, operation string, ) error { @@ -289,7 +288,7 @@ func ValidateStartWorkflowExecutionRequest( func OverrideStartWorkflowExecutionRequest( request *workflowservice.StartWorkflowExecutionRequest, operation string, - shard shard.Context, + shard definition.ShardContext, metricsHandler metrics.MetricsHandler, ) { // workflow execution timeout is left as is diff --git a/service/history/api/deleteworkflow/api.go b/service/history/api/deleteworkflow/api.go index 00e6b3ad59c..cf51cf78987 100644 --- a/service/history/api/deleteworkflow/api.go +++ b/service/history/api/deleteworkflow/api.go @@ -30,18 +30,17 @@ import ( commonpb "go.temporal.io/api/common/v1" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "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/definition" "go.temporal.io/server/service/history/workflow" ) func Invoke( ctx context.Context, request *historyservice.DeleteWorkflowExecutionRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, workflowDeleteManager workflow.DeleteManager, ) (_ *historyservice.DeleteWorkflowExecutionResponse, retError error) { diff --git a/service/history/api/describemutablestate/api.go b/service/history/api/describemutablestate/api.go index b7fdda2b4a3..0fdd656460f 100644 --- a/service/history/api/describemutablestate/api.go +++ b/service/history/api/describemutablestate/api.go @@ -28,17 +28,16 @@ import ( "context" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" "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/definition" "go.temporal.io/server/service/history/workflow" ) func Invoke( ctx context.Context, req *historyservice.DescribeMutableStateRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (_ *historyservice.DescribeMutableStateResponse, retError error) { namespaceID := namespace.ID(req.GetNamespaceId()) diff --git a/service/history/api/describeworkflow/api.go b/service/history/api/describeworkflow/api.go index 3ffe1fb1864..f0279789f9f 100644 --- a/service/history/api/describeworkflow/api.go +++ b/service/history/api/describeworkflow/api.go @@ -35,18 +35,17 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence/visibility/manager" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/api" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" ) func Invoke( ctx context.Context, req *historyservice.DescribeWorkflowExecutionRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, persistenceVisibilityMgr manager.VisibilityManager, ) (_ *historyservice.DescribeWorkflowExecutionResponse, retError error) { diff --git a/service/history/api/get_workflow_util.go b/service/history/api/get_workflow_util.go index 8e0c440544e..5d6c2f91d90 100644 --- a/service/history/api/get_workflow_util.go +++ b/service/history/api/get_workflow_util.go @@ -37,21 +37,18 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence/versionhistory" serviceerrors "go.temporal.io/server/common/serviceerror" - "go.temporal.io/server/service/history/events" - "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) func GetOrPollMutableState( ctx context.Context, request *historyservice.GetMutableStateRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker WorkflowConsistencyChecker, - eventNotifier events.Notifier, + eventNotifier definition.Notifier, ) (*historyservice.GetMutableStateResponse, error) { namespaceID := namespace.ID(request.GetNamespaceId()) @@ -176,7 +173,7 @@ func GetMutableState( } func MutableStateToGetResponse( - mutableState workflow.MutableState, + mutableState definition.MutableState, ) (*historyservice.GetMutableStateResponse, error) { currentBranchToken, err := mutableState.GetCurrentBranchToken() if err != nil { diff --git a/service/history/api/namespace.go b/service/history/api/namespace.go index 49912cdc855..f23fc991dd6 100644 --- a/service/history/api/namespace.go +++ b/service/history/api/namespace.go @@ -29,11 +29,11 @@ import ( "go.temporal.io/api/serviceerror" "go.temporal.io/server/common/namespace" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" ) func GetActiveNamespace( - shard shard.Context, + shard definition.ShardContext, namespaceUUID namespace.ID, ) (*namespace.Namespace, error) { diff --git a/service/history/api/queryworkflow/api.go b/service/history/api/queryworkflow/api.go index 6ac001ee283..fd82356f37f 100644 --- a/service/history/api/queryworkflow/api.go +++ b/service/history/api/queryworkflow/api.go @@ -36,21 +36,20 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/api/matchingservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/api" "go.temporal.io/server/service/history/api/resetstickytaskqueue" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) func Invoke( ctx context.Context, request *historyservice.QueryWorkflowRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, rawMatchingClient matchingservice.MatchingServiceClient, matchingClient matchingservice.MatchingServiceClient, @@ -221,7 +220,7 @@ func queryDirectlyThroughMatching( msResp *historyservice.GetMutableStateResponse, namespaceID string, queryRequest *workflowservice.QueryWorkflowRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, rawMatchingClient matchingservice.MatchingServiceClient, matchingClient matchingservice.MatchingServiceClient, diff --git a/service/history/api/reapplyevents/api.go b/service/history/api/reapplyevents/api.go index ed49b1d975c..b00ca427dbc 100644 --- a/service/history/api/reapplyevents/api.go +++ b/service/history/api/reapplyevents/api.go @@ -34,14 +34,13 @@ import ( historyspb "go.temporal.io/server/api/history/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/service/history/api" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/ndc" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/workflow" ) @@ -51,7 +50,7 @@ func Invoke( workflowID string, runID string, reapplyEvents []*historypb.HistoryEvent, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, workflowResetter ndc.WorkflowResetter, eventsReapplier ndc.EventsReapplier, diff --git a/service/history/api/recordactivitytaskheartbeat/api.go b/service/history/api/recordactivitytaskheartbeat/api.go index e45a4721fc0..18666b314a3 100644 --- a/service/history/api/recordactivitytaskheartbeat/api.go +++ b/service/history/api/recordactivitytaskheartbeat/api.go @@ -29,18 +29,17 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "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/definition" ) func Invoke( ctx context.Context, req *historyservice.RecordActivityTaskHeartbeatRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.RecordActivityTaskHeartbeatResponse, retError error) { _, err := api.GetActiveNamespace(shard, namespace.ID(req.GetNamespaceId())) diff --git a/service/history/api/recordactivitytaskstarted/api.go b/service/history/api/recordactivitytaskstarted/api.go index 571850e1835..e59508daf52 100644 --- a/service/history/api/recordactivitytaskstarted/api.go +++ b/service/history/api/recordactivitytaskstarted/api.go @@ -31,19 +31,18 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" serviceerrors "go.temporal.io/server/common/serviceerror" "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/definition" ) func Invoke( ctx context.Context, request *historyservice.RecordActivityTaskStartedRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.RecordActivityTaskStartedResponse, retError error) { namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(request.GetNamespaceId())) diff --git a/service/history/api/recordchildworkflowcompleted/api.go b/service/history/api/recordchildworkflowcompleted/api.go index cba45d057d3..45b0162fbd3 100644 --- a/service/history/api/recordchildworkflowcompleted/api.go +++ b/service/history/api/recordchildworkflowcompleted/api.go @@ -31,18 +31,16 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "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" + "go.temporal.io/server/service/history/definition" ) func Invoke( ctx context.Context, request *historyservice.RecordChildExecutionCompletedRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.RecordChildExecutionCompletedResponse, retError error) { _, err := api.GetActiveNamespace(shard, namespace.ID(request.GetNamespaceId())) @@ -56,7 +54,7 @@ func Invoke( err = api.GetAndUpdateWorkflowWithNew( ctx, request.Clock, - func(mutableState workflow.MutableState) bool { + func(mutableState definition.MutableState) bool { if !mutableState.IsWorkflowExecutionRunning() { // current branch already closed, we won't perform any operation, pass the check return true diff --git a/service/history/api/refreshworkflow/api.go b/service/history/api/refreshworkflow/api.go index 35e8cd61bbc..03a21fd2f97 100644 --- a/service/history/api/refreshworkflow/api.go +++ b/service/history/api/refreshworkflow/api.go @@ -27,18 +27,17 @@ package refreshworkflow import ( "context" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/service/history/api" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) func Invoke( ctx context.Context, workflowKey definition.WorkflowKey, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (retError error) { err := api.ValidateNamespaceUUID(namespace.ID(workflowKey.NamespaceID)) diff --git a/service/history/api/removesignalmutablestate/api.go b/service/history/api/removesignalmutablestate/api.go index 87b98ddd82b..851c1e93231 100644 --- a/service/history/api/removesignalmutablestate/api.go +++ b/service/history/api/removesignalmutablestate/api.go @@ -28,17 +28,16 @@ import ( "context" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "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/definition" ) func Invoke( ctx context.Context, req *historyservice.RemoveSignalMutableStateRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.RemoveSignalMutableStateResponse, retError error) { _, err := api.GetActiveNamespace(shard, namespace.ID(req.GetNamespaceId())) diff --git a/service/history/api/replication/generate_task.go b/service/history/api/replication/generate_task.go index be35b0870e0..b3389f9991d 100644 --- a/service/history/api/replication/generate_task.go +++ b/service/history/api/replication/generate_task.go @@ -28,18 +28,17 @@ import ( "context" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/service/history/api" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" ) func GenerateTask( ctx context.Context, request *historyservice.GenerateLastHistoryReplicationTasksRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (_ *historyservice.GenerateLastHistoryReplicationTasksResponse, retError error) { namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(request.GetNamespaceId())) diff --git a/service/history/api/replication/get_dlq_tasks.go b/service/history/api/replication/get_dlq_tasks.go index 4873a3deb1a..5bafafa65a6 100644 --- a/service/history/api/replication/get_dlq_tasks.go +++ b/service/history/api/replication/get_dlq_tasks.go @@ -29,13 +29,13 @@ import ( replicationspb "go.temporal.io/server/api/replication/v1" "go.temporal.io/server/common/log/tag" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/replication" - "go.temporal.io/server/service/history/shard" ) func GetDLQTasks( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, replicationAckMgr replication.AckManager, taskInfos []*replicationspb.ReplicationTaskInfo, ) ([]*replicationspb.ReplicationTask, error) { diff --git a/service/history/api/replication/get_tasks.go b/service/history/api/replication/get_tasks.go index dc467d2116b..77f7f3d413d 100644 --- a/service/history/api/replication/get_tasks.go +++ b/service/history/api/replication/get_tasks.go @@ -31,14 +31,14 @@ import ( replicationspb "go.temporal.io/server/api/replication/v1" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/persistence" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/replication" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" ) func GetTasks( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, replicationAckMgr replication.AckManager, pollingCluster string, ackMessageID int64, diff --git a/service/history/api/replication/status.go b/service/history/api/replication/status.go index f41b27f7bee..938474b9f17 100644 --- a/service/history/api/replication/status.go +++ b/service/history/api/replication/status.go @@ -29,14 +29,14 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/replication" - "go.temporal.io/server/service/history/shard" ) func GetStatus( ctx context.Context, request *historyservice.GetReplicationStatusRequest, - shard shard.Context, + shard definition.ShardContext, replicationAckMgr replication.AckManager, ) (_ *historyservice.ShardReplicationStatus, retError error) { resp := &historyservice.ShardReplicationStatus{ diff --git a/service/history/api/replicationadmin/get_dlq.go b/service/history/api/replicationadmin/get_dlq.go index 809360e20f9..7344ae7c08b 100644 --- a/service/history/api/replicationadmin/get_dlq.go +++ b/service/history/api/replicationadmin/get_dlq.go @@ -29,14 +29,14 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/replication" - "go.temporal.io/server/service/history/shard" ) func GetDLQ( ctx context.Context, request *historyservice.GetDLQMessagesRequest, - shard shard.Context, + shard definition.ShardContext, replicationDLQHandler replication.DLQHandler, ) (*historyservice.GetDLQMessagesResponse, error) { _, ok := shard.GetClusterMetadata().GetAllClusterInfo()[request.GetSourceCluster()] diff --git a/service/history/api/replicationadmin/merge_dlq.go b/service/history/api/replicationadmin/merge_dlq.go index 4356075e58a..ff196d7b4da 100644 --- a/service/history/api/replicationadmin/merge_dlq.go +++ b/service/history/api/replicationadmin/merge_dlq.go @@ -29,14 +29,14 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/replication" - "go.temporal.io/server/service/history/shard" ) func MergeDLQ( ctx context.Context, request *historyservice.MergeDLQMessagesRequest, - shard shard.Context, + shard definition.ShardContext, replicationDLQHandler replication.DLQHandler, ) (*historyservice.MergeDLQMessagesResponse, error) { _, ok := shard.GetClusterMetadata().GetAllClusterInfo()[request.GetSourceCluster()] diff --git a/service/history/api/replicationadmin/purge_dlq.go b/service/history/api/replicationadmin/purge_dlq.go index 7f904263256..669db4db48e 100644 --- a/service/history/api/replicationadmin/purge_dlq.go +++ b/service/history/api/replicationadmin/purge_dlq.go @@ -29,14 +29,14 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/replication" - "go.temporal.io/server/service/history/shard" ) func PurgeDLQ( ctx context.Context, request *historyservice.PurgeDLQMessagesRequest, - shard shard.Context, + shard definition.ShardContext, replicationDLQHandler replication.DLQHandler, ) (*historyservice.PurgeDLQMessagesResponse, error) { _, ok := shard.GetClusterMetadata().GetAllClusterInfo()[request.GetSourceCluster()] diff --git a/service/history/api/requestcancelworkflow/api.go b/service/history/api/requestcancelworkflow/api.go index 655e17f1743..d43d11e4729 100644 --- a/service/history/api/requestcancelworkflow/api.go +++ b/service/history/api/requestcancelworkflow/api.go @@ -28,17 +28,16 @@ import ( "context" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "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/definition" ) func Invoke( ctx context.Context, req *historyservice.RequestCancelWorkflowExecutionRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.RequestCancelWorkflowExecutionResponse, retError error) { namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(req.GetNamespaceId())) diff --git a/service/history/api/resetstickytaskqueue/api.go b/service/history/api/resetstickytaskqueue/api.go index 5cd1d0cc8ae..0ea59f5f3c4 100644 --- a/service/history/api/resetstickytaskqueue/api.go +++ b/service/history/api/resetstickytaskqueue/api.go @@ -28,17 +28,16 @@ import ( "context" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "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/definition" ) func Invoke( ctx context.Context, resetRequest *historyservice.ResetStickyTaskQueueRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (*historyservice.ResetStickyTaskQueueResponse, error) { namespaceID := namespace.ID(resetRequest.GetNamespaceId()) diff --git a/service/history/api/resetworkflow/api.go b/service/history/api/resetworkflow/api.go index a13c5e79ef2..51fab796e88 100644 --- a/service/history/api/resetworkflow/api.go +++ b/service/history/api/resetworkflow/api.go @@ -32,19 +32,18 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/service/history/api" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/ndc" - "go.temporal.io/server/service/history/shard" ) func Invoke( ctx context.Context, resetRequest *historyservice.ResetWorkflowExecutionRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (_ *historyservice.ResetWorkflowExecutionResponse, retError error) { namespaceID := namespace.ID(resetRequest.GetNamespaceId()) diff --git a/service/history/api/respondactivitytaskcanceled/api.go b/service/history/api/respondactivitytaskcanceled/api.go index 341ffbb60b3..d6461ea668f 100644 --- a/service/history/api/respondactivitytaskcanceled/api.go +++ b/service/history/api/respondactivitytaskcanceled/api.go @@ -30,18 +30,17 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "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/definition" ) func Invoke( ctx context.Context, req *historyservice.RespondActivityTaskCanceledRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.RespondActivityTaskCanceledResponse, retError error) { namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(req.GetNamespaceId())) diff --git a/service/history/api/respondactivitytaskcompleted/api.go b/service/history/api/respondactivitytaskcompleted/api.go index 30ae8939915..5cfef47161f 100644 --- a/service/history/api/respondactivitytaskcompleted/api.go +++ b/service/history/api/respondactivitytaskcompleted/api.go @@ -30,18 +30,17 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "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/definition" ) func Invoke( ctx context.Context, req *historyservice.RespondActivityTaskCompletedRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.RespondActivityTaskCompletedResponse, retError error) { namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(req.GetNamespaceId())) diff --git a/service/history/api/respondactivitytaskfailed/api.go b/service/history/api/respondactivitytaskfailed/api.go index fcb39984faa..33ff2d4be28 100644 --- a/service/history/api/respondactivitytaskfailed/api.go +++ b/service/history/api/respondactivitytaskfailed/api.go @@ -33,18 +33,17 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "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/definition" ) func Invoke( ctx context.Context, req *historyservice.RespondActivityTaskFailedRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.RespondActivityTaskFailedResponse, retError error) { namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(req.GetNamespaceId())) diff --git a/service/history/api/retry_util.go b/service/history/api/retry_util.go index 90d3dfdc0f8..cb87e0629dd 100644 --- a/service/history/api/retry_util.go +++ b/service/history/api/retry_util.go @@ -31,7 +31,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) func IsRetryableError(err error) bool { @@ -43,7 +43,7 @@ func IsRetryableError(err error) bool { } func IsHistoryEventOnCurrentBranch( - mutableState workflow.MutableState, + mutableState definition.MutableState, eventID int64, eventVersion int64, ) (bool, error) { diff --git a/service/history/api/signal_workflow_util.go b/service/history/api/signal_workflow_util.go index 1b8e0febd90..778044673a0 100644 --- a/service/history/api/signal_workflow_util.go +++ b/service/history/api/signal_workflow_util.go @@ -34,14 +34,13 @@ import ( "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/rpc/interceptor" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) func ValidateSignal( ctx context.Context, - shard shard.Context, - mutableState workflow.MutableState, + shard definition.ShardContext, + mutableState definition.MutableState, signalPayloadSize int, operation string, ) error { diff --git a/service/history/api/signalwithstartworkflow/api.go b/service/history/api/signalwithstartworkflow/api.go index fc90a146985..1e1960f1bf1 100644 --- a/service/history/api/signalwithstartworkflow/api.go +++ b/service/history/api/signalwithstartworkflow/api.go @@ -30,17 +30,16 @@ import ( "go.temporal.io/api/serviceerror" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "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/definition" ) func Invoke( ctx context.Context, signalWithStartRequest *historyservice.SignalWithStartWorkflowExecutionRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (_ *historyservice.SignalWithStartWorkflowExecutionResponse, retError error) { namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(signalWithStartRequest.GetNamespaceId())) diff --git a/service/history/api/signalwithstartworkflow/signal_with_start_workflow.go b/service/history/api/signalwithstartworkflow/signal_with_start_workflow.go index e412a7bb18e..76c9197b89c 100644 --- a/service/history/api/signalwithstartworkflow/signal_with_start_workflow.go +++ b/service/history/api/signalwithstartworkflow/signal_with_start_workflow.go @@ -36,13 +36,12 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/service/history/api" - "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) func SignalWithStartWorkflow( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, namespaceEntry *namespace.Namespace, currentWorkflowContext api.WorkflowContext, startRequest *historyservice.StartWorkflowExecutionRequest, @@ -77,7 +76,7 @@ func SignalWithStartWorkflow( func startAndSignalWorkflow( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, namespaceEntry *namespace.Namespace, currentWorkflowContext api.WorkflowContext, startRequest *historyservice.StartWorkflowExecutionRequest, @@ -177,7 +176,7 @@ func startAndSignalWorkflowActionFn( func startAndSignalWithCurrentWorkflow( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, currentWorkflowContext api.WorkflowContext, currentWorkflowUpdateAction api.UpdateWorkflowActionFunc, newWorkflowContext api.WorkflowContext, @@ -187,7 +186,7 @@ func startAndSignalWithCurrentWorkflow( ctx, currentWorkflowContext, currentWorkflowUpdateAction, - func() (workflow.Context, workflow.MutableState, error) { + func() (definition.WorkflowContext, definition.MutableState, error) { return newWorkflowContext.GetContext(), newWorkflowContext.GetMutableState(), nil }, ) @@ -200,7 +199,7 @@ func startAndSignalWithCurrentWorkflow( func startAndSignalWithoutCurrentWorkflow( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, casPredicate *api.CreateWorkflowCASPredicate, newWorkflowContext api.WorkflowContext, requestID string, @@ -208,7 +207,7 @@ func startAndSignalWithoutCurrentWorkflow( now := shard.GetTimeSource().Now() newWorkflow, newWorkflowEventsSeq, err := newWorkflowContext.GetMutableState().CloseTransactionAsSnapshot( now, - workflow.TransactionPolicyActive, + definition.TransactionPolicyActive, ) if err != nil { return "", err @@ -253,7 +252,7 @@ func startAndSignalWithoutCurrentWorkflow( func signalWorkflow( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, workflowContext api.WorkflowContext, request *workflowservice.SignalWithStartWorkflowExecutionRequest, ) error { diff --git a/service/history/api/signalwithstartworkflow/signal_with_start_workflow_test.go b/service/history/api/signalwithstartworkflow/signal_with_start_workflow_test.go index f187983c18a..57702f24f21 100644 --- a/service/history/api/signalwithstartworkflow/signal_with_start_workflow_test.go +++ b/service/history/api/signalwithstartworkflow/signal_with_start_workflow_test.go @@ -42,7 +42,7 @@ import ( "go.temporal.io/server/common/clock" "go.temporal.io/server/common/log" "go.temporal.io/server/service/history/api" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tests" "go.temporal.io/server/service/history/workflow" ) @@ -53,13 +53,13 @@ type ( *require.Assertions controller *gomock.Controller - shardContext *shard.MockContext + shardContext *definition.MockShardContext namespaceID string workflowID string - currentContext *workflow.MockContext - currentMutableState *workflow.MockMutableState + currentContext *definition.MockWorkflowContext + currentMutableState *definition.MockMutableState currentRunID string } ) @@ -80,13 +80,13 @@ func (s *signalWithStartWorkflowSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.shardContext = shard.NewMockContext(s.controller) + s.shardContext = definition.NewMockShardContext(s.controller) s.namespaceID = uuid.New().String() s.workflowID = uuid.New().String() - s.currentContext = workflow.NewMockContext(s.controller) - s.currentMutableState = workflow.NewMockMutableState(s.controller) + s.currentContext = definition.NewMockWorkflowContext(s.controller) + s.currentMutableState = definition.NewMockMutableState(s.controller) s.currentRunID = uuid.New().String() s.shardContext.EXPECT().GetConfig().Return(tests.NewDynamicConfig()).AnyTimes() @@ -145,7 +145,7 @@ func (s *signalWithStartWorkflowSuite) TestSignalWorkflow_NewWorkflowTask() { request.GetHeader(), ).Return(&history.HistoryEvent{}, nil) s.currentMutableState.EXPECT().HasPendingWorkflowTask().Return(false) - s.currentMutableState.EXPECT().AddWorkflowTaskScheduledEvent(false).Return(&workflow.WorkflowTaskInfo{}, nil) + s.currentMutableState.EXPECT().AddWorkflowTaskScheduledEvent(false).Return(&definition.WorkflowTaskInfo{}, nil) s.currentContext.EXPECT().UpdateWorkflowExecutionAsActive(ctx, gomock.Any()).Return(nil) err := signalWorkflow( diff --git a/service/history/api/signalworkflow/api.go b/service/history/api/signalworkflow/api.go index b589f34fe1b..bb6c10cae2d 100644 --- a/service/history/api/signalworkflow/api.go +++ b/service/history/api/signalworkflow/api.go @@ -28,17 +28,16 @@ import ( "context" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "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/definition" ) func Invoke( ctx context.Context, req *historyservice.SignalWorkflowExecutionRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.SignalWorkflowExecutionResponse, retError error) { namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(req.GetNamespaceId())) diff --git a/service/history/api/startworkflow/api.go b/service/history/api/startworkflow/api.go index 75f59fc39fe..a7fa2e38d84 100644 --- a/service/history/api/startworkflow/api.go +++ b/service/history/api/startworkflow/api.go @@ -31,20 +31,18 @@ import ( "go.temporal.io/api/serviceerror" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "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" + "go.temporal.io/server/service/history/definition" ) func Invoke( ctx context.Context, startRequest *historyservice.StartWorkflowExecutionRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.StartWorkflowExecutionResponse, retError error) { namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(startRequest.GetNamespaceId())) @@ -78,7 +76,7 @@ func Invoke( now := shard.GetTimeSource().Now() newWorkflow, newWorkflowEventsSeq, err := workflowContext.GetMutableState().CloseTransactionAsSnapshot( now, - workflow.TransactionPolicyActive, + definition.TransactionPolicyActive, ) if err != nil { return nil, err @@ -157,7 +155,7 @@ func Invoke( prevRunID, ), prevExecutionUpdateAction, - func() (workflow.Context, workflow.MutableState, error) { + func() (definition.WorkflowContext, definition.MutableState, error) { workflowContext, err := api.NewWorkflowWithSignal( ctx, shard, diff --git a/service/history/api/terminateworkflow/api.go b/service/history/api/terminateworkflow/api.go index ec85ae07fb9..277f90a43e5 100644 --- a/service/history/api/terminateworkflow/api.go +++ b/service/history/api/terminateworkflow/api.go @@ -28,18 +28,17 @@ import ( "context" "go.temporal.io/server/api/historyservice/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "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/definition" "go.temporal.io/server/service/history/workflow" ) func Invoke( ctx context.Context, req *historyservice.TerminateWorkflowExecutionRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.TerminateWorkflowExecutionResponse, retError error) { namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(req.GetNamespaceId())) diff --git a/service/history/api/update_workflow_util.go b/service/history/api/update_workflow_util.go index e61897490ca..39e7d2deda0 100644 --- a/service/history/api/update_workflow_util.go +++ b/service/history/api/update_workflow_util.go @@ -28,9 +28,7 @@ import ( "context" clockspb "go.temporal.io/server/api/clock/v1" - "go.temporal.io/server/common/definition" - "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) func GetAndUpdateWorkflowWithNew( @@ -39,8 +37,8 @@ func GetAndUpdateWorkflowWithNew( consistencyCheckFn MutableStateConsistencyPredicate, workflowKey definition.WorkflowKey, action UpdateWorkflowActionFunc, - newWorkflowFn func() (workflow.Context, workflow.MutableState, error), - shard shard.Context, + newWorkflowFn func() (definition.WorkflowContext, definition.MutableState, error), + shard definition.ShardContext, workflowConsistencyChecker WorkflowConsistencyChecker, ) (retError error) { workflowContext, err := workflowConsistencyChecker.GetWorkflowContext( @@ -58,11 +56,11 @@ func GetAndUpdateWorkflowWithNew( } func UpdateWorkflowWithNew( - shard shard.Context, + shard definition.ShardContext, ctx context.Context, workflowContext WorkflowContext, action UpdateWorkflowActionFunc, - newWorkflowFn func() (workflow.Context, workflow.MutableState, error), + newWorkflowFn func() (definition.WorkflowContext, definition.MutableState, error), ) (retError error) { // conduct caller action diff --git a/service/history/api/verifychildworkflowcompletionrecorded/api.go b/service/history/api/verifychildworkflowcompletionrecorded/api.go index 753b4a58b6f..90497047523 100644 --- a/service/history/api/verifychildworkflowcompletionrecorded/api.go +++ b/service/history/api/verifychildworkflowcompletionrecorded/api.go @@ -30,17 +30,16 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "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/definition" ) func Invoke( ctx context.Context, request *historyservice.VerifyChildExecutionCompletionRecordedRequest, - shard shard.Context, + shard definition.ShardContext, workflowConsistencyChecker api.WorkflowConsistencyChecker, ) (resp *historyservice.VerifyChildExecutionCompletionRecordedResponse, retError error) { namespaceID := namespace.ID(request.GetNamespaceId()) diff --git a/service/history/api/workflow_context.go b/service/history/api/workflow_context.go index aac62c7d29c..0bdb3830a6a 100644 --- a/service/history/api/workflow_context.go +++ b/service/history/api/workflow_context.go @@ -25,24 +25,23 @@ package api import ( - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) type WorkflowContext interface { - GetContext() workflow.Context - GetMutableState() workflow.MutableState - GetReleaseFn() workflow.ReleaseCacheFunc + GetContext() definition.WorkflowContext + GetMutableState() definition.MutableState + GetReleaseFn() definition.ReleaseFunc GetNamespaceEntry() *namespace.Namespace GetWorkflowKey() definition.WorkflowKey } type WorkflowContextImpl struct { - context workflow.Context - mutableState workflow.MutableState - releaseFn workflow.ReleaseCacheFunc + context definition.WorkflowContext + mutableState definition.MutableState + releaseFn definition.ReleaseFunc } type UpdateWorkflowAction struct { @@ -64,9 +63,9 @@ type UpdateWorkflowActionFunc func(WorkflowContext) (*UpdateWorkflowAction, erro var _ WorkflowContext = (*WorkflowContextImpl)(nil) func NewWorkflowContext( - context workflow.Context, - releaseFn workflow.ReleaseCacheFunc, - mutableState workflow.MutableState, + context definition.WorkflowContext, + releaseFn definition.ReleaseFunc, + mutableState definition.MutableState, ) *WorkflowContextImpl { return &WorkflowContextImpl{ @@ -76,15 +75,15 @@ func NewWorkflowContext( } } -func (w *WorkflowContextImpl) GetContext() workflow.Context { +func (w *WorkflowContextImpl) GetContext() definition.WorkflowContext { return w.context } -func (w *WorkflowContextImpl) GetMutableState() workflow.MutableState { +func (w *WorkflowContextImpl) GetMutableState() definition.MutableState { return w.mutableState } -func (w *WorkflowContextImpl) GetReleaseFn() workflow.ReleaseCacheFunc { +func (w *WorkflowContextImpl) GetReleaseFn() definition.ReleaseFunc { return w.releaseFn } diff --git a/service/history/cache_shard.go b/service/history/cache_shard.go new file mode 100644 index 00000000000..971e55e113d --- /dev/null +++ b/service/history/cache_shard.go @@ -0,0 +1,85 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package history + +import ( + "sync/atomic" + + "go.temporal.io/server/service/history/api" + "go.temporal.io/server/service/history/definition" + "go.temporal.io/server/service/history/workflow" +) + +type ( + Cache struct { + shardedCache []atomic.Value + } + shardedCache struct { + workflowConsistencyChecker api.WorkflowConsistencyChecker + shardContext definition.ShardContext + } +) + +func NewCache( + totalNumberOfShards int32, +) *Cache { + shardedCache := make([]atomic.Value, totalNumberOfShards) + for i := 0; i < int(totalNumberOfShards); i++ { + shardedCache[i] = atomic.Value{} + } + return &Cache{ + shardedCache: shardedCache, + } +} + +func (c *Cache) GetOrCreate( + shardContext definition.ShardContext, +) api.WorkflowConsistencyChecker { + atomicValue := &c.shardedCache[shardContext.GetShardID()-1] + oldCache := atomicValue.Load() + + if oldCache != nil && oldCache.(shardedCache).shardContext.IsValid() { + return oldCache.(shardedCache).workflowConsistencyChecker + } + + newCache := newShardedCache(shardContext) + if atomicValue.CompareAndSwap(oldCache, newCache) { + return newCache.workflowConsistencyChecker + } else { + return c.GetOrCreate(shardContext) + } +} + +func newShardedCache( + shardContext definition.ShardContext, +) shardedCache { + return shardedCache{ + shardContext: shardContext, + workflowConsistencyChecker: api.NewWorkflowConsistencyChecker( + shardContext, + workflow.NewCache(shardContext), + ), + } +} diff --git a/service/history/cache_shard_test.go b/service/history/cache_shard_test.go new file mode 100644 index 00000000000..d81a99e3140 --- /dev/null +++ b/service/history/cache_shard_test.go @@ -0,0 +1,221 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package history + +import ( + "sync" + "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "go.temporal.io/server/common/dynamicconfig" + "go.temporal.io/server/common/log" + "go.temporal.io/server/common/metrics" + "go.temporal.io/server/service/history/api" + "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" +) + +type ( + shardedCacheSuite struct { + suite.Suite + *require.Assertions + + controller *gomock.Controller + shardContext *definition.MockShardContext + } +) + +func TestShardedCacheSuite(t *testing.T) { + s := new(shardedCacheSuite) + suite.Run(t, s) +} + +func (s *shardedCacheSuite) SetupSuite() { +} + +func (s *shardedCacheSuite) SetupTest() { + s.Assertions = require.New(s.T()) + s.controller = gomock.NewController(s.T()) + s.shardContext = definition.NewMockShardContext(s.controller) +} + +func (s *shardedCacheSuite) TearDownTest() { + s.controller.Finish() +} + +func (s *shardedCacheSuite) TestInit() { + numShards := int32(1) + shardedCache := NewCache(numShards) + config := configs.NewConfig(dynamicconfig.NewNoopCollection(), numShards, false, "") + logger := log.NewTestLogger() + metricsHandler := metrics.NoopMetricsHandler + + s.shardContext.EXPECT().GetShardID().Return(int32(1)).AnyTimes() + s.shardContext.EXPECT().GetConfig().Return(config).AnyTimes() + s.shardContext.EXPECT().GetLogger().Return(logger).AnyTimes() + s.shardContext.EXPECT().GetMetricsHandler().Return(metricsHandler).AnyTimes() + + checker := shardedCache.GetOrCreate(s.shardContext) + s.NotNil(checker) + +} + +func (s *shardedCacheSuite) TestGet() { + numShards := int32(1) + shardedCache := NewCache(numShards) + config := configs.NewConfig(dynamicconfig.NewNoopCollection(), numShards, false, "") + logger := log.NewTestLogger() + metricsHandler := metrics.NoopMetricsHandler + + s.shardContext.EXPECT().GetShardID().Return(int32(1)).AnyTimes() + s.shardContext.EXPECT().GetConfig().Return(config).AnyTimes() + s.shardContext.EXPECT().GetLogger().Return(logger).AnyTimes() + s.shardContext.EXPECT().GetMetricsHandler().Return(metricsHandler).AnyTimes() + + checker0 := shardedCache.GetOrCreate(s.shardContext) + + s.shardContext.EXPECT().IsValid().Return(true) + checker1 := shardedCache.GetOrCreate(s.shardContext) + s.True(checker0 == checker1) +} + +func (s *shardedCacheSuite) TestRecreate() { + numShards := int32(1) + shardedCache := NewCache(numShards) + config := configs.NewConfig(dynamicconfig.NewNoopCollection(), numShards, false, "") + logger := log.NewTestLogger() + metricsHandler := metrics.NoopMetricsHandler + + s.shardContext.EXPECT().GetShardID().Return(int32(1)).AnyTimes() + s.shardContext.EXPECT().GetConfig().Return(config).AnyTimes() + s.shardContext.EXPECT().GetLogger().Return(logger).AnyTimes() + s.shardContext.EXPECT().GetMetricsHandler().Return(metricsHandler).AnyTimes() + + checker0 := shardedCache.GetOrCreate(s.shardContext) + s.shardContext.EXPECT().IsValid().Return(false) + + newShardContext := definition.NewMockShardContext(s.controller) + newShardContext.EXPECT().GetShardID().Return(int32(1)).AnyTimes() + newShardContext.EXPECT().GetConfig().Return(config).AnyTimes() + newShardContext.EXPECT().GetLogger().Return(logger).AnyTimes() + newShardContext.EXPECT().GetMetricsHandler().Return(metricsHandler).AnyTimes() + checker1 := shardedCache.GetOrCreate(newShardContext) + s.True(checker0 != checker1) +} + +func (s *shardedCacheSuite) TestConcurrency_Init() { + numShards := int32(1) + shardedCache := NewCache(numShards) + config := configs.NewConfig(dynamicconfig.NewNoopCollection(), numShards, false, "") + logger := log.NewTestLogger() + metricsHandler := metrics.NoopMetricsHandler + + s.shardContext.EXPECT().GetShardID().Return(int32(1)).AnyTimes() + s.shardContext.EXPECT().GetConfig().Return(config).AnyTimes() + s.shardContext.EXPECT().GetLogger().Return(logger).AnyTimes() + s.shardContext.EXPECT().GetMetricsHandler().Return(metricsHandler).AnyTimes() + s.shardContext.EXPECT().IsValid().Return(true).AnyTimes() + + concurrency := 128 + var startWG sync.WaitGroup + var endWG sync.WaitGroup + startWG.Add(concurrency) + endWG.Add(concurrency) + + var lock sync.Mutex + var cache api.WorkflowConsistencyChecker + + for i := 0; i < concurrency; i++ { + go func() { + startWG.Wait() + defer endWG.Done() + + actualCache := shardedCache.GetOrCreate(s.shardContext) + lock.Lock() + defer lock.Unlock() + if cache == nil { + cache = actualCache + } else { + s.True(cache == actualCache) + } + }() + startWG.Done() + } + endWG.Wait() +} + +func (s *shardedCacheSuite) TestConcurrency_Recreate() { + numShards := int32(1) + shardedCache := NewCache(numShards) + config := configs.NewConfig(dynamicconfig.NewNoopCollection(), numShards, false, "") + logger := log.NewTestLogger() + metricsHandler := metrics.NoopMetricsHandler + + s.shardContext.EXPECT().GetShardID().Return(int32(1)).AnyTimes() + s.shardContext.EXPECT().GetConfig().Return(config).AnyTimes() + s.shardContext.EXPECT().GetLogger().Return(logger).AnyTimes() + s.shardContext.EXPECT().GetMetricsHandler().Return(metricsHandler).AnyTimes() + invalidCache := shardedCache.GetOrCreate(s.shardContext) + s.shardContext.EXPECT().IsValid().Return(false).AnyTimes() + + newShardContext := definition.NewMockShardContext(s.controller) + newShardContext.EXPECT().GetShardID().Return(int32(1)).AnyTimes() + newShardContext.EXPECT().GetConfig().Return(config).AnyTimes() + newShardContext.EXPECT().GetLogger().Return(logger).AnyTimes() + newShardContext.EXPECT().GetMetricsHandler().Return(metricsHandler).AnyTimes() + newShardContext.EXPECT().IsValid().Return(true).AnyTimes() + + concurrency := 128 + var startWG sync.WaitGroup + var endWG sync.WaitGroup + startWG.Add(concurrency) + endWG.Add(concurrency) + + var lock sync.Mutex + var cache api.WorkflowConsistencyChecker + + for i := 0; i < concurrency; i++ { + go func() { + startWG.Wait() + defer endWG.Done() + + actualCache := shardedCache.GetOrCreate(newShardContext) + s.True(invalidCache != actualCache) + + lock.Lock() + defer lock.Unlock() + if cache == nil { + cache = actualCache + } else { + s.True(cache == actualCache) + } + }() + startWG.Done() + } + endWG.Wait() +} diff --git a/service/history/commandChecker.go b/service/history/commandChecker.go index 711db7c017c..aa768562a28 100644 --- a/service/history/commandChecker.go +++ b/service/history/commandChecker.go @@ -47,7 +47,7 @@ import ( "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) type ( @@ -73,7 +73,7 @@ type ( workflowSizeChecker struct { workflowSizeLimits - mutableState workflow.MutableState + mutableState definition.MutableState searchAttributesValidator *searchattribute.Validator executionStats *persistencespb.ExecutionStats metricsHandler metrics.MetricsHandler @@ -103,7 +103,7 @@ func newCommandAttrValidator( func newWorkflowSizeChecker( limits workflowSizeLimits, - mutableState workflow.MutableState, + mutableState definition.MutableState, searchAttributesValidator *searchattribute.Validator, executionStats *persistencespb.ExecutionStats, metricsHandler metrics.MetricsHandler, diff --git a/service/history/commandChecker_test.go b/service/history/commandChecker_test.go index 58fe9d43d95..dec87d8077e 100644 --- a/service/history/commandChecker_test.go +++ b/service/history/commandChecker_test.go @@ -42,7 +42,6 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" @@ -52,8 +51,8 @@ import ( "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tests" - "go.temporal.io/server/service/history/workflow" ) var ( @@ -791,7 +790,7 @@ func TestWorkflowSizeChecker_NumChildWorkflows(t *testing.T) { } { t.Run(c.Name, func(t *testing.T) { ctrl := gomock.NewController(t) - mutableState := workflow.NewMockMutableState(ctrl) + mutableState := definition.NewMockMutableState(ctrl) logger := log.NewMockLogger(ctrl) metricsHandler := metrics.NewMockMetricsHandler(ctrl) diff --git a/service/history/shard/engine.go b/service/history/definition/engine.go similarity index 98% rename from service/history/shard/engine.go rename to service/history/definition/engine.go index c1174c8c4bb..d0a0daa57d9 100644 --- a/service/history/shard/engine.go +++ b/service/history/definition/engine.go @@ -24,7 +24,7 @@ //go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination engine_mock.go -package shard +package definition import ( "context" @@ -37,7 +37,6 @@ import ( replicationspb "go.temporal.io/server/api/replication/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/namespace" - "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/tasks" ) @@ -88,7 +87,7 @@ type ( GetReplicationStatus(ctx context.Context, request *historyservice.GetReplicationStatusRequest) (*historyservice.ShardReplicationStatus, error) UpdateWorkflow(ctx context.Context, request *historyservice.UpdateWorkflowRequest) (*historyservice.UpdateWorkflowResponse, error) - NotifyNewHistoryEvent(event *events.Notification) + NotifyNewHistoryEvent(event *Notification) NotifyNewTasks(clusterName string, tasks map[tasks.Category][]tasks.Task) } ) diff --git a/service/history/shard/engine_mock.go b/service/history/definition/engine_mock.go similarity index 81% rename from service/history/shard/engine_mock.go rename to service/history/definition/engine_mock.go index 5a385d938e1..6ae4869e117 100644 --- a/service/history/shard/engine_mock.go +++ b/service/history/definition/engine_mock.go @@ -25,8 +25,8 @@ // Code generated by MockGen. DO NOT EDIT. // Source: engine.go -// Package shard is a generated GoMock package. -package shard +// Package definition is a generated GoMock package. +package definition import ( context "context" @@ -34,12 +34,11 @@ import ( time "time" gomock "github.com/golang/mock/gomock" - common "go.temporal.io/api/common/v1" - history "go.temporal.io/api/history/v1" - historyservice "go.temporal.io/server/api/historyservice/v1" - repication "go.temporal.io/server/api/replication/v1" + v1 "go.temporal.io/api/common/v1" + v10 "go.temporal.io/api/history/v1" + v11 "go.temporal.io/server/api/historyservice/v1" + v12 "go.temporal.io/server/api/replication/v1" namespace "go.temporal.io/server/common/namespace" - events "go.temporal.io/server/service/history/events" tasks "go.temporal.io/server/service/history/tasks" ) @@ -67,10 +66,10 @@ func (m *MockEngine) EXPECT() *MockEngineMockRecorder { } // DeleteWorkflowExecution mocks base method. -func (m *MockEngine) DeleteWorkflowExecution(ctx context.Context, deleteRequest *historyservice.DeleteWorkflowExecutionRequest) (*historyservice.DeleteWorkflowExecutionResponse, error) { +func (m *MockEngine) DeleteWorkflowExecution(ctx context.Context, deleteRequest *v11.DeleteWorkflowExecutionRequest) (*v11.DeleteWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeleteWorkflowExecution", ctx, deleteRequest) - ret0, _ := ret[0].(*historyservice.DeleteWorkflowExecutionResponse) + ret0, _ := ret[0].(*v11.DeleteWorkflowExecutionResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -82,10 +81,10 @@ func (mr *MockEngineMockRecorder) DeleteWorkflowExecution(ctx, deleteRequest int } // DescribeMutableState mocks base method. -func (m *MockEngine) DescribeMutableState(ctx context.Context, request *historyservice.DescribeMutableStateRequest) (*historyservice.DescribeMutableStateResponse, error) { +func (m *MockEngine) DescribeMutableState(ctx context.Context, request *v11.DescribeMutableStateRequest) (*v11.DescribeMutableStateResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DescribeMutableState", ctx, request) - ret0, _ := ret[0].(*historyservice.DescribeMutableStateResponse) + ret0, _ := ret[0].(*v11.DescribeMutableStateResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -97,10 +96,10 @@ func (mr *MockEngineMockRecorder) DescribeMutableState(ctx, request interface{}) } // DescribeWorkflowExecution mocks base method. -func (m *MockEngine) DescribeWorkflowExecution(ctx context.Context, request *historyservice.DescribeWorkflowExecutionRequest) (*historyservice.DescribeWorkflowExecutionResponse, error) { +func (m *MockEngine) DescribeWorkflowExecution(ctx context.Context, request *v11.DescribeWorkflowExecutionRequest) (*v11.DescribeWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DescribeWorkflowExecution", ctx, request) - ret0, _ := ret[0].(*historyservice.DescribeWorkflowExecutionResponse) + ret0, _ := ret[0].(*v11.DescribeWorkflowExecutionResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -112,10 +111,10 @@ func (mr *MockEngineMockRecorder) DescribeWorkflowExecution(ctx, request interfa } // GenerateLastHistoryReplicationTasks mocks base method. -func (m *MockEngine) GenerateLastHistoryReplicationTasks(ctx context.Context, request *historyservice.GenerateLastHistoryReplicationTasksRequest) (*historyservice.GenerateLastHistoryReplicationTasksResponse, error) { +func (m *MockEngine) GenerateLastHistoryReplicationTasks(ctx context.Context, request *v11.GenerateLastHistoryReplicationTasksRequest) (*v11.GenerateLastHistoryReplicationTasksResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GenerateLastHistoryReplicationTasks", ctx, request) - ret0, _ := ret[0].(*historyservice.GenerateLastHistoryReplicationTasksResponse) + ret0, _ := ret[0].(*v11.GenerateLastHistoryReplicationTasksResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -127,10 +126,10 @@ func (mr *MockEngineMockRecorder) GenerateLastHistoryReplicationTasks(ctx, reque } // GetDLQMessages mocks base method. -func (m *MockEngine) GetDLQMessages(ctx context.Context, messagesRequest *historyservice.GetDLQMessagesRequest) (*historyservice.GetDLQMessagesResponse, error) { +func (m *MockEngine) GetDLQMessages(ctx context.Context, messagesRequest *v11.GetDLQMessagesRequest) (*v11.GetDLQMessagesResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDLQMessages", ctx, messagesRequest) - ret0, _ := ret[0].(*historyservice.GetDLQMessagesResponse) + ret0, _ := ret[0].(*v11.GetDLQMessagesResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -142,10 +141,10 @@ func (mr *MockEngineMockRecorder) GetDLQMessages(ctx, messagesRequest interface{ } // GetDLQReplicationMessages mocks base method. -func (m *MockEngine) GetDLQReplicationMessages(ctx context.Context, taskInfos []*repication.ReplicationTaskInfo) ([]*repication.ReplicationTask, error) { +func (m *MockEngine) GetDLQReplicationMessages(ctx context.Context, taskInfos []*v12.ReplicationTaskInfo) ([]*v12.ReplicationTask, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDLQReplicationMessages", ctx, taskInfos) - ret0, _ := ret[0].([]*repication.ReplicationTask) + ret0, _ := ret[0].([]*v12.ReplicationTask) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -157,10 +156,10 @@ func (mr *MockEngineMockRecorder) GetDLQReplicationMessages(ctx, taskInfos inter } // GetMutableState mocks base method. -func (m *MockEngine) GetMutableState(ctx context.Context, request *historyservice.GetMutableStateRequest) (*historyservice.GetMutableStateResponse, error) { +func (m *MockEngine) GetMutableState(ctx context.Context, request *v11.GetMutableStateRequest) (*v11.GetMutableStateResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetMutableState", ctx, request) - ret0, _ := ret[0].(*historyservice.GetMutableStateResponse) + ret0, _ := ret[0].(*v11.GetMutableStateResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -172,10 +171,10 @@ func (mr *MockEngineMockRecorder) GetMutableState(ctx, request interface{}) *gom } // GetReplicationMessages mocks base method. -func (m *MockEngine) GetReplicationMessages(ctx context.Context, pollingCluster string, ackMessageID int64, ackTimestamp time.Time, queryMessageID int64) (*repication.ReplicationMessages, error) { +func (m *MockEngine) GetReplicationMessages(ctx context.Context, pollingCluster string, ackMessageID int64, ackTimestamp time.Time, queryMessageID int64) (*v12.ReplicationMessages, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetReplicationMessages", ctx, pollingCluster, ackMessageID, ackTimestamp, queryMessageID) - ret0, _ := ret[0].(*repication.ReplicationMessages) + ret0, _ := ret[0].(*v12.ReplicationMessages) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -187,10 +186,10 @@ func (mr *MockEngineMockRecorder) GetReplicationMessages(ctx, pollingCluster, ac } // GetReplicationStatus mocks base method. -func (m *MockEngine) GetReplicationStatus(ctx context.Context, request *historyservice.GetReplicationStatusRequest) (*historyservice.ShardReplicationStatus, error) { +func (m *MockEngine) GetReplicationStatus(ctx context.Context, request *v11.GetReplicationStatusRequest) (*v11.ShardReplicationStatus, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetReplicationStatus", ctx, request) - ret0, _ := ret[0].(*historyservice.ShardReplicationStatus) + ret0, _ := ret[0].(*v11.ShardReplicationStatus) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -202,10 +201,10 @@ func (mr *MockEngineMockRecorder) GetReplicationStatus(ctx, request interface{}) } // MergeDLQMessages mocks base method. -func (m *MockEngine) MergeDLQMessages(ctx context.Context, messagesRequest *historyservice.MergeDLQMessagesRequest) (*historyservice.MergeDLQMessagesResponse, error) { +func (m *MockEngine) MergeDLQMessages(ctx context.Context, messagesRequest *v11.MergeDLQMessagesRequest) (*v11.MergeDLQMessagesResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "MergeDLQMessages", ctx, messagesRequest) - ret0, _ := ret[0].(*historyservice.MergeDLQMessagesResponse) + ret0, _ := ret[0].(*v11.MergeDLQMessagesResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -217,7 +216,7 @@ func (mr *MockEngineMockRecorder) MergeDLQMessages(ctx, messagesRequest interfac } // NotifyNewHistoryEvent mocks base method. -func (m *MockEngine) NotifyNewHistoryEvent(event *events.Notification) { +func (m *MockEngine) NotifyNewHistoryEvent(event *Notification) { m.ctrl.T.Helper() m.ctrl.Call(m, "NotifyNewHistoryEvent", event) } @@ -241,10 +240,10 @@ func (mr *MockEngineMockRecorder) NotifyNewTasks(clusterName, tasks interface{}) } // PollMutableState mocks base method. -func (m *MockEngine) PollMutableState(ctx context.Context, request *historyservice.PollMutableStateRequest) (*historyservice.PollMutableStateResponse, error) { +func (m *MockEngine) PollMutableState(ctx context.Context, request *v11.PollMutableStateRequest) (*v11.PollMutableStateResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PollMutableState", ctx, request) - ret0, _ := ret[0].(*historyservice.PollMutableStateResponse) + ret0, _ := ret[0].(*v11.PollMutableStateResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -256,10 +255,10 @@ func (mr *MockEngineMockRecorder) PollMutableState(ctx, request interface{}) *go } // PurgeDLQMessages mocks base method. -func (m *MockEngine) PurgeDLQMessages(ctx context.Context, messagesRequest *historyservice.PurgeDLQMessagesRequest) (*historyservice.PurgeDLQMessagesResponse, error) { +func (m *MockEngine) PurgeDLQMessages(ctx context.Context, messagesRequest *v11.PurgeDLQMessagesRequest) (*v11.PurgeDLQMessagesResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PurgeDLQMessages", ctx, messagesRequest) - ret0, _ := ret[0].(*historyservice.PurgeDLQMessagesResponse) + ret0, _ := ret[0].(*v11.PurgeDLQMessagesResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -271,10 +270,10 @@ func (mr *MockEngineMockRecorder) PurgeDLQMessages(ctx, messagesRequest interfac } // QueryWorkflow mocks base method. -func (m *MockEngine) QueryWorkflow(ctx context.Context, request *historyservice.QueryWorkflowRequest) (*historyservice.QueryWorkflowResponse, error) { +func (m *MockEngine) QueryWorkflow(ctx context.Context, request *v11.QueryWorkflowRequest) (*v11.QueryWorkflowResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "QueryWorkflow", ctx, request) - ret0, _ := ret[0].(*historyservice.QueryWorkflowResponse) + ret0, _ := ret[0].(*v11.QueryWorkflowResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -286,7 +285,7 @@ func (mr *MockEngineMockRecorder) QueryWorkflow(ctx, request interface{}) *gomoc } // ReapplyEvents mocks base method. -func (m *MockEngine) ReapplyEvents(ctx context.Context, namespaceUUID namespace.ID, workflowID, runID string, events []*history.HistoryEvent) error { +func (m *MockEngine) ReapplyEvents(ctx context.Context, namespaceUUID namespace.ID, workflowID, runID string, events []*v10.HistoryEvent) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ReapplyEvents", ctx, namespaceUUID, workflowID, runID, events) ret0, _ := ret[0].(error) @@ -300,7 +299,7 @@ func (mr *MockEngineMockRecorder) ReapplyEvents(ctx, namespaceUUID, workflowID, } // RebuildMutableState mocks base method. -func (m *MockEngine) RebuildMutableState(ctx context.Context, namespaceUUID namespace.ID, execution common.WorkflowExecution) error { +func (m *MockEngine) RebuildMutableState(ctx context.Context, namespaceUUID namespace.ID, execution v1.WorkflowExecution) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RebuildMutableState", ctx, namespaceUUID, execution) ret0, _ := ret[0].(error) @@ -314,10 +313,10 @@ func (mr *MockEngineMockRecorder) RebuildMutableState(ctx, namespaceUUID, execut } // RecordActivityTaskHeartbeat mocks base method. -func (m *MockEngine) RecordActivityTaskHeartbeat(ctx context.Context, request *historyservice.RecordActivityTaskHeartbeatRequest) (*historyservice.RecordActivityTaskHeartbeatResponse, error) { +func (m *MockEngine) RecordActivityTaskHeartbeat(ctx context.Context, request *v11.RecordActivityTaskHeartbeatRequest) (*v11.RecordActivityTaskHeartbeatResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RecordActivityTaskHeartbeat", ctx, request) - ret0, _ := ret[0].(*historyservice.RecordActivityTaskHeartbeatResponse) + ret0, _ := ret[0].(*v11.RecordActivityTaskHeartbeatResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -329,10 +328,10 @@ func (mr *MockEngineMockRecorder) RecordActivityTaskHeartbeat(ctx, request inter } // RecordActivityTaskStarted mocks base method. -func (m *MockEngine) RecordActivityTaskStarted(ctx context.Context, request *historyservice.RecordActivityTaskStartedRequest) (*historyservice.RecordActivityTaskStartedResponse, error) { +func (m *MockEngine) RecordActivityTaskStarted(ctx context.Context, request *v11.RecordActivityTaskStartedRequest) (*v11.RecordActivityTaskStartedResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RecordActivityTaskStarted", ctx, request) - ret0, _ := ret[0].(*historyservice.RecordActivityTaskStartedResponse) + ret0, _ := ret[0].(*v11.RecordActivityTaskStartedResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -344,10 +343,10 @@ func (mr *MockEngineMockRecorder) RecordActivityTaskStarted(ctx, request interfa } // RecordChildExecutionCompleted mocks base method. -func (m *MockEngine) RecordChildExecutionCompleted(ctx context.Context, request *historyservice.RecordChildExecutionCompletedRequest) (*historyservice.RecordChildExecutionCompletedResponse, error) { +func (m *MockEngine) RecordChildExecutionCompleted(ctx context.Context, request *v11.RecordChildExecutionCompletedRequest) (*v11.RecordChildExecutionCompletedResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RecordChildExecutionCompleted", ctx, request) - ret0, _ := ret[0].(*historyservice.RecordChildExecutionCompletedResponse) + ret0, _ := ret[0].(*v11.RecordChildExecutionCompletedResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -359,10 +358,10 @@ func (mr *MockEngineMockRecorder) RecordChildExecutionCompleted(ctx, request int } // RecordWorkflowTaskStarted mocks base method. -func (m *MockEngine) RecordWorkflowTaskStarted(ctx context.Context, request *historyservice.RecordWorkflowTaskStartedRequest) (*historyservice.RecordWorkflowTaskStartedResponse, error) { +func (m *MockEngine) RecordWorkflowTaskStarted(ctx context.Context, request *v11.RecordWorkflowTaskStartedRequest) (*v11.RecordWorkflowTaskStartedResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RecordWorkflowTaskStarted", ctx, request) - ret0, _ := ret[0].(*historyservice.RecordWorkflowTaskStartedResponse) + ret0, _ := ret[0].(*v11.RecordWorkflowTaskStartedResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -374,7 +373,7 @@ func (mr *MockEngineMockRecorder) RecordWorkflowTaskStarted(ctx, request interfa } // RefreshWorkflowTasks mocks base method. -func (m *MockEngine) RefreshWorkflowTasks(ctx context.Context, namespaceUUID namespace.ID, execution common.WorkflowExecution) error { +func (m *MockEngine) RefreshWorkflowTasks(ctx context.Context, namespaceUUID namespace.ID, execution v1.WorkflowExecution) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RefreshWorkflowTasks", ctx, namespaceUUID, execution) ret0, _ := ret[0].(error) @@ -388,10 +387,10 @@ func (mr *MockEngineMockRecorder) RefreshWorkflowTasks(ctx, namespaceUUID, execu } // RemoveSignalMutableState mocks base method. -func (m *MockEngine) RemoveSignalMutableState(ctx context.Context, request *historyservice.RemoveSignalMutableStateRequest) (*historyservice.RemoveSignalMutableStateResponse, error) { +func (m *MockEngine) RemoveSignalMutableState(ctx context.Context, request *v11.RemoveSignalMutableStateRequest) (*v11.RemoveSignalMutableStateResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RemoveSignalMutableState", ctx, request) - ret0, _ := ret[0].(*historyservice.RemoveSignalMutableStateResponse) + ret0, _ := ret[0].(*v11.RemoveSignalMutableStateResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -403,7 +402,7 @@ func (mr *MockEngineMockRecorder) RemoveSignalMutableState(ctx, request interfac } // ReplicateEventsV2 mocks base method. -func (m *MockEngine) ReplicateEventsV2(ctx context.Context, request *historyservice.ReplicateEventsV2Request) error { +func (m *MockEngine) ReplicateEventsV2(ctx context.Context, request *v11.ReplicateEventsV2Request) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ReplicateEventsV2", ctx, request) ret0, _ := ret[0].(error) @@ -417,7 +416,7 @@ func (mr *MockEngineMockRecorder) ReplicateEventsV2(ctx, request interface{}) *g } // ReplicateWorkflowState mocks base method. -func (m *MockEngine) ReplicateWorkflowState(ctx context.Context, request *historyservice.ReplicateWorkflowStateRequest) error { +func (m *MockEngine) ReplicateWorkflowState(ctx context.Context, request *v11.ReplicateWorkflowStateRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ReplicateWorkflowState", ctx, request) ret0, _ := ret[0].(error) @@ -431,10 +430,10 @@ func (mr *MockEngineMockRecorder) ReplicateWorkflowState(ctx, request interface{ } // RequestCancelWorkflowExecution mocks base method. -func (m *MockEngine) RequestCancelWorkflowExecution(ctx context.Context, request *historyservice.RequestCancelWorkflowExecutionRequest) (*historyservice.RequestCancelWorkflowExecutionResponse, error) { +func (m *MockEngine) RequestCancelWorkflowExecution(ctx context.Context, request *v11.RequestCancelWorkflowExecutionRequest) (*v11.RequestCancelWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RequestCancelWorkflowExecution", ctx, request) - ret0, _ := ret[0].(*historyservice.RequestCancelWorkflowExecutionResponse) + ret0, _ := ret[0].(*v11.RequestCancelWorkflowExecutionResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -446,10 +445,10 @@ func (mr *MockEngineMockRecorder) RequestCancelWorkflowExecution(ctx, request in } // ResetStickyTaskQueue mocks base method. -func (m *MockEngine) ResetStickyTaskQueue(ctx context.Context, resetRequest *historyservice.ResetStickyTaskQueueRequest) (*historyservice.ResetStickyTaskQueueResponse, error) { +func (m *MockEngine) ResetStickyTaskQueue(ctx context.Context, resetRequest *v11.ResetStickyTaskQueueRequest) (*v11.ResetStickyTaskQueueResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ResetStickyTaskQueue", ctx, resetRequest) - ret0, _ := ret[0].(*historyservice.ResetStickyTaskQueueResponse) + ret0, _ := ret[0].(*v11.ResetStickyTaskQueueResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -461,10 +460,10 @@ func (mr *MockEngineMockRecorder) ResetStickyTaskQueue(ctx, resetRequest interfa } // ResetWorkflowExecution mocks base method. -func (m *MockEngine) ResetWorkflowExecution(ctx context.Context, request *historyservice.ResetWorkflowExecutionRequest) (*historyservice.ResetWorkflowExecutionResponse, error) { +func (m *MockEngine) ResetWorkflowExecution(ctx context.Context, request *v11.ResetWorkflowExecutionRequest) (*v11.ResetWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ResetWorkflowExecution", ctx, request) - ret0, _ := ret[0].(*historyservice.ResetWorkflowExecutionResponse) + ret0, _ := ret[0].(*v11.ResetWorkflowExecutionResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -476,10 +475,10 @@ func (mr *MockEngineMockRecorder) ResetWorkflowExecution(ctx, request interface{ } // RespondActivityTaskCanceled mocks base method. -func (m *MockEngine) RespondActivityTaskCanceled(ctx context.Context, request *historyservice.RespondActivityTaskCanceledRequest) (*historyservice.RespondActivityTaskCanceledResponse, error) { +func (m *MockEngine) RespondActivityTaskCanceled(ctx context.Context, request *v11.RespondActivityTaskCanceledRequest) (*v11.RespondActivityTaskCanceledResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RespondActivityTaskCanceled", ctx, request) - ret0, _ := ret[0].(*historyservice.RespondActivityTaskCanceledResponse) + ret0, _ := ret[0].(*v11.RespondActivityTaskCanceledResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -491,10 +490,10 @@ func (mr *MockEngineMockRecorder) RespondActivityTaskCanceled(ctx, request inter } // RespondActivityTaskCompleted mocks base method. -func (m *MockEngine) RespondActivityTaskCompleted(ctx context.Context, request *historyservice.RespondActivityTaskCompletedRequest) (*historyservice.RespondActivityTaskCompletedResponse, error) { +func (m *MockEngine) RespondActivityTaskCompleted(ctx context.Context, request *v11.RespondActivityTaskCompletedRequest) (*v11.RespondActivityTaskCompletedResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RespondActivityTaskCompleted", ctx, request) - ret0, _ := ret[0].(*historyservice.RespondActivityTaskCompletedResponse) + ret0, _ := ret[0].(*v11.RespondActivityTaskCompletedResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -506,10 +505,10 @@ func (mr *MockEngineMockRecorder) RespondActivityTaskCompleted(ctx, request inte } // RespondActivityTaskFailed mocks base method. -func (m *MockEngine) RespondActivityTaskFailed(ctx context.Context, request *historyservice.RespondActivityTaskFailedRequest) (*historyservice.RespondActivityTaskFailedResponse, error) { +func (m *MockEngine) RespondActivityTaskFailed(ctx context.Context, request *v11.RespondActivityTaskFailedRequest) (*v11.RespondActivityTaskFailedResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RespondActivityTaskFailed", ctx, request) - ret0, _ := ret[0].(*historyservice.RespondActivityTaskFailedResponse) + ret0, _ := ret[0].(*v11.RespondActivityTaskFailedResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -521,10 +520,10 @@ func (mr *MockEngineMockRecorder) RespondActivityTaskFailed(ctx, request interfa } // RespondWorkflowTaskCompleted mocks base method. -func (m *MockEngine) RespondWorkflowTaskCompleted(ctx context.Context, request *historyservice.RespondWorkflowTaskCompletedRequest) (*historyservice.RespondWorkflowTaskCompletedResponse, error) { +func (m *MockEngine) RespondWorkflowTaskCompleted(ctx context.Context, request *v11.RespondWorkflowTaskCompletedRequest) (*v11.RespondWorkflowTaskCompletedResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RespondWorkflowTaskCompleted", ctx, request) - ret0, _ := ret[0].(*historyservice.RespondWorkflowTaskCompletedResponse) + ret0, _ := ret[0].(*v11.RespondWorkflowTaskCompletedResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -536,7 +535,7 @@ func (mr *MockEngineMockRecorder) RespondWorkflowTaskCompleted(ctx, request inte } // RespondWorkflowTaskFailed mocks base method. -func (m *MockEngine) RespondWorkflowTaskFailed(ctx context.Context, request *historyservice.RespondWorkflowTaskFailedRequest) error { +func (m *MockEngine) RespondWorkflowTaskFailed(ctx context.Context, request *v11.RespondWorkflowTaskFailedRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RespondWorkflowTaskFailed", ctx, request) ret0, _ := ret[0].(error) @@ -550,7 +549,7 @@ func (mr *MockEngineMockRecorder) RespondWorkflowTaskFailed(ctx, request interfa } // ScheduleWorkflowTask mocks base method. -func (m *MockEngine) ScheduleWorkflowTask(ctx context.Context, request *historyservice.ScheduleWorkflowTaskRequest) error { +func (m *MockEngine) ScheduleWorkflowTask(ctx context.Context, request *v11.ScheduleWorkflowTaskRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ScheduleWorkflowTask", ctx, request) ret0, _ := ret[0].(error) @@ -564,10 +563,10 @@ func (mr *MockEngineMockRecorder) ScheduleWorkflowTask(ctx, request interface{}) } // SignalWithStartWorkflowExecution mocks base method. -func (m *MockEngine) SignalWithStartWorkflowExecution(ctx context.Context, request *historyservice.SignalWithStartWorkflowExecutionRequest) (*historyservice.SignalWithStartWorkflowExecutionResponse, error) { +func (m *MockEngine) SignalWithStartWorkflowExecution(ctx context.Context, request *v11.SignalWithStartWorkflowExecutionRequest) (*v11.SignalWithStartWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SignalWithStartWorkflowExecution", ctx, request) - ret0, _ := ret[0].(*historyservice.SignalWithStartWorkflowExecutionResponse) + ret0, _ := ret[0].(*v11.SignalWithStartWorkflowExecutionResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -579,10 +578,10 @@ func (mr *MockEngineMockRecorder) SignalWithStartWorkflowExecution(ctx, request } // SignalWorkflowExecution mocks base method. -func (m *MockEngine) SignalWorkflowExecution(ctx context.Context, request *historyservice.SignalWorkflowExecutionRequest) (*historyservice.SignalWorkflowExecutionResponse, error) { +func (m *MockEngine) SignalWorkflowExecution(ctx context.Context, request *v11.SignalWorkflowExecutionRequest) (*v11.SignalWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SignalWorkflowExecution", ctx, request) - ret0, _ := ret[0].(*historyservice.SignalWorkflowExecutionResponse) + ret0, _ := ret[0].(*v11.SignalWorkflowExecutionResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -606,10 +605,10 @@ func (mr *MockEngineMockRecorder) Start() *gomock.Call { } // StartWorkflowExecution mocks base method. -func (m *MockEngine) StartWorkflowExecution(ctx context.Context, request *historyservice.StartWorkflowExecutionRequest) (*historyservice.StartWorkflowExecutionResponse, error) { +func (m *MockEngine) StartWorkflowExecution(ctx context.Context, request *v11.StartWorkflowExecutionRequest) (*v11.StartWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StartWorkflowExecution", ctx, request) - ret0, _ := ret[0].(*historyservice.StartWorkflowExecutionResponse) + ret0, _ := ret[0].(*v11.StartWorkflowExecutionResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -633,7 +632,7 @@ func (mr *MockEngineMockRecorder) Stop() *gomock.Call { } // SyncActivity mocks base method. -func (m *MockEngine) SyncActivity(ctx context.Context, request *historyservice.SyncActivityRequest) error { +func (m *MockEngine) SyncActivity(ctx context.Context, request *v11.SyncActivityRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SyncActivity", ctx, request) ret0, _ := ret[0].(error) @@ -647,7 +646,7 @@ func (mr *MockEngineMockRecorder) SyncActivity(ctx, request interface{}) *gomock } // SyncShardStatus mocks base method. -func (m *MockEngine) SyncShardStatus(ctx context.Context, request *historyservice.SyncShardStatusRequest) error { +func (m *MockEngine) SyncShardStatus(ctx context.Context, request *v11.SyncShardStatusRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SyncShardStatus", ctx, request) ret0, _ := ret[0].(error) @@ -661,10 +660,10 @@ func (mr *MockEngineMockRecorder) SyncShardStatus(ctx, request interface{}) *gom } // TerminateWorkflowExecution mocks base method. -func (m *MockEngine) TerminateWorkflowExecution(ctx context.Context, request *historyservice.TerminateWorkflowExecutionRequest) (*historyservice.TerminateWorkflowExecutionResponse, error) { +func (m *MockEngine) TerminateWorkflowExecution(ctx context.Context, request *v11.TerminateWorkflowExecutionRequest) (*v11.TerminateWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "TerminateWorkflowExecution", ctx, request) - ret0, _ := ret[0].(*historyservice.TerminateWorkflowExecutionResponse) + ret0, _ := ret[0].(*v11.TerminateWorkflowExecutionResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -676,10 +675,10 @@ func (mr *MockEngineMockRecorder) TerminateWorkflowExecution(ctx, request interf } // UpdateWorkflow mocks base method. -func (m *MockEngine) UpdateWorkflow(ctx context.Context, request *historyservice.UpdateWorkflowRequest) (*historyservice.UpdateWorkflowResponse, error) { +func (m *MockEngine) UpdateWorkflow(ctx context.Context, request *v11.UpdateWorkflowRequest) (*v11.UpdateWorkflowResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateWorkflow", ctx, request) - ret0, _ := ret[0].(*historyservice.UpdateWorkflowResponse) + ret0, _ := ret[0].(*v11.UpdateWorkflowResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -691,10 +690,10 @@ func (mr *MockEngineMockRecorder) UpdateWorkflow(ctx, request interface{}) *gomo } // VerifyChildExecutionCompletionRecorded mocks base method. -func (m *MockEngine) VerifyChildExecutionCompletionRecorded(ctx context.Context, request *historyservice.VerifyChildExecutionCompletionRecordedRequest) (*historyservice.VerifyChildExecutionCompletionRecordedResponse, error) { +func (m *MockEngine) VerifyChildExecutionCompletionRecorded(ctx context.Context, request *v11.VerifyChildExecutionCompletionRecordedRequest) (*v11.VerifyChildExecutionCompletionRecordedResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "VerifyChildExecutionCompletionRecorded", ctx, request) - ret0, _ := ret[0].(*historyservice.VerifyChildExecutionCompletionRecordedResponse) + ret0, _ := ret[0].(*v11.VerifyChildExecutionCompletionRecordedResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -706,7 +705,7 @@ func (mr *MockEngineMockRecorder) VerifyChildExecutionCompletionRecorded(ctx, re } // VerifyFirstWorkflowTaskScheduled mocks base method. -func (m *MockEngine) VerifyFirstWorkflowTaskScheduled(ctx context.Context, request *historyservice.VerifyFirstWorkflowTaskScheduledRequest) error { +func (m *MockEngine) VerifyFirstWorkflowTaskScheduled(ctx context.Context, request *v11.VerifyFirstWorkflowTaskScheduledRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "VerifyFirstWorkflowTaskScheduled", ctx, request) ret0, _ := ret[0].(error) diff --git a/service/history/definition/event_cache.go b/service/history/definition/event_cache.go new file mode 100644 index 00000000000..336aa6ce12a --- /dev/null +++ b/service/history/definition/event_cache.go @@ -0,0 +1,51 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination event_cache_mock.go + +package definition + +import ( + "context" + + historypb "go.temporal.io/api/history/v1" + + "go.temporal.io/server/common/namespace" +) + +type ( + EventKey struct { + NamespaceID namespace.ID + WorkflowID string + RunID string + EventID int64 + Version int64 + } + + EventCache interface { + GetEvent(ctx context.Context, key EventKey, firstEventID int64, branchToken []byte) (*historypb.HistoryEvent, error) + PutEvent(key EventKey, event *historypb.HistoryEvent) + DeleteEvent(key EventKey) + } +) diff --git a/service/history/definition/event_cache_mock.go b/service/history/definition/event_cache_mock.go new file mode 100644 index 00000000000..5f3425d5302 --- /dev/null +++ b/service/history/definition/event_cache_mock.go @@ -0,0 +1,99 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Code generated by MockGen. DO NOT EDIT. +// Source: event_cache.go + +// Package definition is a generated GoMock package. +package definition + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + v1 "go.temporal.io/api/history/v1" +) + +// MockEventCache is a mock of EventCache interface. +type MockEventCache struct { + ctrl *gomock.Controller + recorder *MockEventCacheMockRecorder +} + +// MockEventCacheMockRecorder is the mock recorder for MockEventCache. +type MockEventCacheMockRecorder struct { + mock *MockEventCache +} + +// NewMockEventCache creates a new mock instance. +func NewMockEventCache(ctrl *gomock.Controller) *MockEventCache { + mock := &MockEventCache{ctrl: ctrl} + mock.recorder = &MockEventCacheMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEventCache) EXPECT() *MockEventCacheMockRecorder { + return m.recorder +} + +// DeleteEvent mocks base method. +func (m *MockEventCache) DeleteEvent(key EventKey) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "DeleteEvent", key) +} + +// DeleteEvent indicates an expected call of DeleteEvent. +func (mr *MockEventCacheMockRecorder) DeleteEvent(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteEvent", reflect.TypeOf((*MockEventCache)(nil).DeleteEvent), key) +} + +// GetEvent mocks base method. +func (m *MockEventCache) GetEvent(ctx context.Context, key EventKey, firstEventID int64, branchToken []byte) (*v1.HistoryEvent, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetEvent", ctx, key, firstEventID, branchToken) + ret0, _ := ret[0].(*v1.HistoryEvent) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetEvent indicates an expected call of GetEvent. +func (mr *MockEventCacheMockRecorder) GetEvent(ctx, key, firstEventID, branchToken interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEvent", reflect.TypeOf((*MockEventCache)(nil).GetEvent), ctx, key, firstEventID, branchToken) +} + +// PutEvent mocks base method. +func (m *MockEventCache) PutEvent(key EventKey, event *v1.HistoryEvent) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "PutEvent", key, event) +} + +// PutEvent indicates an expected call of PutEvent. +func (mr *MockEventCacheMockRecorder) PutEvent(key, event interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutEvent", reflect.TypeOf((*MockEventCache)(nil).PutEvent), key, event) +} diff --git a/service/history/definition/event_notifier.go b/service/history/definition/event_notifier.go new file mode 100644 index 00000000000..c96c49eacba --- /dev/null +++ b/service/history/definition/event_notifier.go @@ -0,0 +1,87 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination event_notifier_mock.go + +package definition + +import ( + "time" + + commonpb "go.temporal.io/api/common/v1" + enumspb "go.temporal.io/api/enums/v1" + + enumsspb "go.temporal.io/server/api/enums/v1" + "go.temporal.io/server/common" + "go.temporal.io/server/common/definition" +) + +type ( + Notifier interface { + common.Daemon + NotifyNewHistoryEvent(event *Notification) + WatchHistoryEvent(identifier definition.WorkflowKey) (string, chan *Notification, error) + UnwatchHistoryEvent(identifier definition.WorkflowKey, subscriberID string) error + } + + Notification struct { + ID definition.WorkflowKey + LastFirstEventID int64 + LastFirstEventTxnID int64 + NextEventID int64 + PreviousStartedEventID int64 + Timestamp time.Time + CurrentBranchToken []byte + WorkflowState enumsspb.WorkflowExecutionState + WorkflowStatus enumspb.WorkflowExecutionStatus + } +) + +func NewNotification( + namespaceID string, + workflowExecution *commonpb.WorkflowExecution, + lastFirstEventID int64, + lastFirstEventTxnID int64, + nextEventID int64, + previousStartedEventID int64, + currentBranchToken []byte, + workflowState enumsspb.WorkflowExecutionState, + workflowStatus enumspb.WorkflowExecutionStatus, +) *Notification { + + return &Notification{ + ID: definition.NewWorkflowKey( + namespaceID, + workflowExecution.GetWorkflowId(), + workflowExecution.GetRunId(), + ), + LastFirstEventID: lastFirstEventID, + LastFirstEventTxnID: lastFirstEventTxnID, + NextEventID: nextEventID, + PreviousStartedEventID: previousStartedEventID, + CurrentBranchToken: currentBranchToken, + WorkflowState: workflowState, + WorkflowStatus: workflowStatus, + } +} diff --git a/service/history/definition/event_notifier_mock.go b/service/history/definition/event_notifier_mock.go new file mode 100644 index 00000000000..f46a32adedc --- /dev/null +++ b/service/history/definition/event_notifier_mock.go @@ -0,0 +1,125 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Code generated by MockGen. DO NOT EDIT. +// Source: event_notifier.go + +// Package definition is a generated GoMock package. +package definition + +import ( + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + definition "go.temporal.io/server/common/definition" +) + +// MockNotifier is a mock of Notifier interface. +type MockNotifier struct { + ctrl *gomock.Controller + recorder *MockNotifierMockRecorder +} + +// MockNotifierMockRecorder is the mock recorder for MockNotifier. +type MockNotifierMockRecorder struct { + mock *MockNotifier +} + +// NewMockNotifier creates a new mock instance. +func NewMockNotifier(ctrl *gomock.Controller) *MockNotifier { + mock := &MockNotifier{ctrl: ctrl} + mock.recorder = &MockNotifierMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockNotifier) EXPECT() *MockNotifierMockRecorder { + return m.recorder +} + +// NotifyNewHistoryEvent mocks base method. +func (m *MockNotifier) NotifyNewHistoryEvent(event *Notification) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "NotifyNewHistoryEvent", event) +} + +// NotifyNewHistoryEvent indicates an expected call of NotifyNewHistoryEvent. +func (mr *MockNotifierMockRecorder) NotifyNewHistoryEvent(event interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NotifyNewHistoryEvent", reflect.TypeOf((*MockNotifier)(nil).NotifyNewHistoryEvent), event) +} + +// Start mocks base method. +func (m *MockNotifier) Start() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Start") +} + +// Start indicates an expected call of Start. +func (mr *MockNotifierMockRecorder) Start() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockNotifier)(nil).Start)) +} + +// Stop mocks base method. +func (m *MockNotifier) Stop() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Stop") +} + +// Stop indicates an expected call of Stop. +func (mr *MockNotifierMockRecorder) Stop() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockNotifier)(nil).Stop)) +} + +// UnwatchHistoryEvent mocks base method. +func (m *MockNotifier) UnwatchHistoryEvent(identifier definition.WorkflowKey, subscriberID string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnwatchHistoryEvent", identifier, subscriberID) + ret0, _ := ret[0].(error) + return ret0 +} + +// UnwatchHistoryEvent indicates an expected call of UnwatchHistoryEvent. +func (mr *MockNotifierMockRecorder) UnwatchHistoryEvent(identifier, subscriberID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnwatchHistoryEvent", reflect.TypeOf((*MockNotifier)(nil).UnwatchHistoryEvent), identifier, subscriberID) +} + +// WatchHistoryEvent mocks base method. +func (m *MockNotifier) WatchHistoryEvent(identifier definition.WorkflowKey) (string, chan *Notification, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WatchHistoryEvent", identifier) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(chan *Notification) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// WatchHistoryEvent indicates an expected call of WatchHistoryEvent. +func (mr *MockNotifierMockRecorder) WatchHistoryEvent(identifier interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchHistoryEvent", reflect.TypeOf((*MockNotifier)(nil).WatchHistoryEvent), identifier) +} diff --git a/service/history/definition/history_builder.go b/service/history/definition/history_builder.go new file mode 100644 index 00000000000..95432b7f7d9 --- /dev/null +++ b/service/history/definition/history_builder.go @@ -0,0 +1,336 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination history_builder_mock.go + +package definition + +import ( + "time" + + commandpb "go.temporal.io/api/command/v1" + commonpb "go.temporal.io/api/common/v1" + enumspb "go.temporal.io/api/enums/v1" + failurepb "go.temporal.io/api/failure/v1" + historypb "go.temporal.io/api/history/v1" + taskqueuepb "go.temporal.io/api/taskqueue/v1" + workflowpb "go.temporal.io/api/workflow/v1" + + "go.temporal.io/server/api/historyservice/v1" + "go.temporal.io/server/common/namespace" +) + +type ( + HistoryMutation struct { + // events to be persist to events table + DBEventsBatches [][]*historypb.HistoryEvent + // events to be buffer in execution table + DBBufferBatch []*historypb.HistoryEvent + // whether to clear buffer events on DB + DBClearBuffer bool + // accumulated buffered events, equal to all buffer events from execution table + MemBufferBatch []*historypb.HistoryEvent + // scheduled to started event ID mapping for flushed buffered event + ScheduledIDToStartedID map[int64]int64 + } + + HistoryBuilder interface { + AddWorkflowExecutionStartedEvent( + startTime time.Time, + request *historyservice.StartWorkflowExecutionRequest, + resetPoints *workflowpb.ResetPoints, + prevRunID string, + firstRunID string, + originalRunID string, + ) *historypb.HistoryEvent + + AddWorkflowTaskScheduledEvent( + taskQueue *taskqueuepb.TaskQueue, + startToCloseTimeout *time.Duration, + attempt int32, + now time.Time, + ) *historypb.HistoryEvent + + AddWorkflowTaskStartedEvent( + scheduledEventID int64, + requestID string, + identity string, + now time.Time, + ) *historypb.HistoryEvent + + AddWorkflowTaskCompletedEvent( + scheduledEventID int64, + startedEventID int64, + identity string, + checksum string, + ) *historypb.HistoryEvent + AddWorkflowTaskTimedOutEvent( + scheduledEventID int64, + startedEventID int64, + timeoutType enumspb.TimeoutType, + ) *historypb.HistoryEvent + AddWorkflowTaskFailedEvent( + scheduledEventID int64, + startedEventID int64, + cause enumspb.WorkflowTaskFailedCause, + failure *failurepb.Failure, + identity string, + baseRunID string, + newRunID string, + forkEventVersion int64, + checksum string, + ) *historypb.HistoryEvent + AddActivityTaskScheduledEvent( + workflowTaskCompletedEventID int64, + command *commandpb.ScheduleActivityTaskCommandAttributes, + ) *historypb.HistoryEvent + AddActivityTaskStartedEvent( + scheduledEventID int64, + attempt int32, + requestID string, + identity string, + lastFailure *failurepb.Failure, + ) *historypb.HistoryEvent + AddActivityTaskCompletedEvent( + scheduledEventID int64, + startedEventID int64, + identity string, + result *commonpb.Payloads, + ) *historypb.HistoryEvent + AddActivityTaskFailedEvent( + scheduledEventID int64, + startedEventID int64, + failure *failurepb.Failure, + retryState enumspb.RetryState, + identity string, + ) *historypb.HistoryEvent + AddActivityTaskTimedOutEvent( + scheduledEventID, + startedEventID int64, + timeoutFailure *failurepb.Failure, + retryState enumspb.RetryState, + ) *historypb.HistoryEvent + AddCompletedWorkflowEvent( + workflowTaskCompletedEventID int64, + command *commandpb.CompleteWorkflowExecutionCommandAttributes, + newExecutionRunID string, + ) *historypb.HistoryEvent + AddFailWorkflowEvent( + workflowTaskCompletedEventID int64, + retryState enumspb.RetryState, + command *commandpb.FailWorkflowExecutionCommandAttributes, + newExecutionRunID string, + ) *historypb.HistoryEvent + AddTimeoutWorkflowEvent( + retryState enumspb.RetryState, + newExecutionRunID string, + ) *historypb.HistoryEvent + AddWorkflowExecutionTerminatedEvent( + reason string, + details *commonpb.Payloads, + identity string, + ) *historypb.HistoryEvent + AddContinuedAsNewEvent( + workflowTaskCompletedEventID int64, + newRunID string, + command *commandpb.ContinueAsNewWorkflowExecutionCommandAttributes, + ) *historypb.HistoryEvent + AddTimerStartedEvent( + workflowTaskCompletedEventID int64, + command *commandpb.StartTimerCommandAttributes, + ) *historypb.HistoryEvent + AddTimerFiredEvent( + startedEventID int64, + timerID string, + ) *historypb.HistoryEvent + AddActivityTaskCancelRequestedEvent( + workflowTaskCompletedEventID int64, + scheduledEventID int64, + ) *historypb.HistoryEvent + AddActivityTaskCanceledEvent( + scheduledEventID int64, + startedEventID int64, + latestCancelRequestedEventID int64, + details *commonpb.Payloads, + identity string, + ) *historypb.HistoryEvent + AddTimerCanceledEvent( + workflowTaskCompletedEventID int64, + startedEventID int64, + timerID string, + identity string, + ) *historypb.HistoryEvent + AddWorkflowExecutionCancelRequestedEvent( + request *historyservice.RequestCancelWorkflowExecutionRequest, + ) *historypb.HistoryEvent + AddWorkflowExecutionCanceledEvent( + workflowTaskCompletedEventID int64, + command *commandpb.CancelWorkflowExecutionCommandAttributes, + ) *historypb.HistoryEvent + AddRequestCancelExternalWorkflowExecutionInitiatedEvent( + workflowTaskCompletedEventID int64, + command *commandpb.RequestCancelExternalWorkflowExecutionCommandAttributes, + targetNamespaceID namespace.ID, + ) *historypb.HistoryEvent + AddRequestCancelExternalWorkflowExecutionFailedEvent( + workflowTaskCompletedEventID int64, + initiatedEventID int64, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + workflowID string, + runID string, + cause enumspb.CancelExternalWorkflowExecutionFailedCause, + ) *historypb.HistoryEvent + AddExternalWorkflowExecutionCancelRequested( + initiatedEventID int64, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + workflowID string, + runID string, + ) *historypb.HistoryEvent + AddSignalExternalWorkflowExecutionInitiatedEvent( + workflowTaskCompletedEventID int64, + command *commandpb.SignalExternalWorkflowExecutionCommandAttributes, + targetNamespaceID namespace.ID, + ) *historypb.HistoryEvent + AddUpsertWorkflowSearchAttributesEvent( + workflowTaskCompletedEventID int64, + command *commandpb.UpsertWorkflowSearchAttributesCommandAttributes, + ) *historypb.HistoryEvent + AddWorkflowPropertiesModifiedEvent( + workflowTaskCompletedEventID int64, + command *commandpb.ModifyWorkflowPropertiesCommandAttributes, + ) *historypb.HistoryEvent + AddSignalExternalWorkflowExecutionFailedEvent( + workflowTaskCompletedEventID int64, + initiatedEventID int64, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + workflowID string, + runID string, + control string, + cause enumspb.SignalExternalWorkflowExecutionFailedCause, + ) *historypb.HistoryEvent + AddExternalWorkflowExecutionSignaled( + initiatedEventID int64, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + workflowID string, + runID string, + control string, + ) *historypb.HistoryEvent + AddMarkerRecordedEvent( + workflowTaskCompletedEventID int64, + command *commandpb.RecordMarkerCommandAttributes, + ) *historypb.HistoryEvent + AddWorkflowExecutionSignaledEvent( + signalName string, + input *commonpb.Payloads, + identity string, + header *commonpb.Header, + ) *historypb.HistoryEvent + AddStartChildWorkflowExecutionInitiatedEvent( + workflowTaskCompletedEventID int64, + command *commandpb.StartChildWorkflowExecutionCommandAttributes, + targetNamespaceID namespace.ID, + ) *historypb.HistoryEvent + AddChildWorkflowExecutionStartedEvent( + initiatedID int64, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + execution *commonpb.WorkflowExecution, + workflowType *commonpb.WorkflowType, + header *commonpb.Header, + ) *historypb.HistoryEvent + AddStartChildWorkflowExecutionFailedEvent( + workflowTaskCompletedEventID int64, + initiatedID int64, + cause enumspb.StartChildWorkflowExecutionFailedCause, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + workflowID string, + workflowType *commonpb.WorkflowType, + control string, + ) *historypb.HistoryEvent + AddChildWorkflowExecutionCompletedEvent( + initiatedID int64, + startedEventID int64, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + execution *commonpb.WorkflowExecution, + workflowType *commonpb.WorkflowType, + result *commonpb.Payloads, + ) *historypb.HistoryEvent + AddChildWorkflowExecutionFailedEvent( + initiatedID int64, + startedEventID int64, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + execution *commonpb.WorkflowExecution, + workflowType *commonpb.WorkflowType, + failure *failurepb.Failure, + retryState enumspb.RetryState, + ) *historypb.HistoryEvent + AddChildWorkflowExecutionCanceledEvent( + initiatedID int64, + startedEventID int64, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + execution *commonpb.WorkflowExecution, + workflowType *commonpb.WorkflowType, + details *commonpb.Payloads, + ) *historypb.HistoryEvent + AddChildWorkflowExecutionTerminatedEvent( + initiatedID int64, + startedEventID int64, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + execution *commonpb.WorkflowExecution, + workflowType *commonpb.WorkflowType, + ) *historypb.HistoryEvent + AddChildWorkflowExecutionTimedOutEvent( + initiatedID int64, + startedEventID int64, + targetNamespace namespace.Name, + targetNamespaceID namespace.ID, + execution *commonpb.WorkflowExecution, + workflowType *commonpb.WorkflowType, + retryState enumspb.RetryState, + ) *historypb.HistoryEvent + HasBufferEvents() bool + BufferEventSize() int + NextEventID() int64 + FlushBufferToCurrentBatch() map[int64]int64 + FlushAndCreateNewBatch() + Finish( + flushBufferEvent bool, + ) (*HistoryMutation, error) + HasActivityFinishEvent( + scheduledEventID int64, + ) bool + GetAndRemoveTimerFireEvent( + timerID string, + ) *historypb.HistoryEvent + } +) diff --git a/service/history/definition/history_builder_mock.go b/service/history/definition/history_builder_mock.go new file mode 100644 index 00000000000..0b148256c3f --- /dev/null +++ b/service/history/definition/history_builder_mock.go @@ -0,0 +1,753 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Code generated by MockGen. DO NOT EDIT. +// Source: history_builder.go + +// Package definition is a generated GoMock package. +package definition + +import ( + reflect "reflect" + time "time" + + gomock "github.com/golang/mock/gomock" + v1 "go.temporal.io/api/command/v1" + v10 "go.temporal.io/api/common/v1" + v11 "go.temporal.io/api/enums/v1" + v12 "go.temporal.io/api/failure/v1" + v13 "go.temporal.io/api/history/v1" + v14 "go.temporal.io/api/taskqueue/v1" + v15 "go.temporal.io/api/workflow/v1" + v16 "go.temporal.io/server/api/historyservice/v1" + namespace "go.temporal.io/server/common/namespace" +) + +// MockHistoryBuilder is a mock of HistoryBuilder interface. +type MockHistoryBuilder struct { + ctrl *gomock.Controller + recorder *MockHistoryBuilderMockRecorder +} + +// MockHistoryBuilderMockRecorder is the mock recorder for MockHistoryBuilder. +type MockHistoryBuilderMockRecorder struct { + mock *MockHistoryBuilder +} + +// NewMockHistoryBuilder creates a new mock instance. +func NewMockHistoryBuilder(ctrl *gomock.Controller) *MockHistoryBuilder { + mock := &MockHistoryBuilder{ctrl: ctrl} + mock.recorder = &MockHistoryBuilderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHistoryBuilder) EXPECT() *MockHistoryBuilderMockRecorder { + return m.recorder +} + +// AddActivityTaskCancelRequestedEvent mocks base method. +func (m *MockHistoryBuilder) AddActivityTaskCancelRequestedEvent(workflowTaskCompletedEventID, scheduledEventID int64) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddActivityTaskCancelRequestedEvent", workflowTaskCompletedEventID, scheduledEventID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddActivityTaskCancelRequestedEvent indicates an expected call of AddActivityTaskCancelRequestedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddActivityTaskCancelRequestedEvent(workflowTaskCompletedEventID, scheduledEventID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddActivityTaskCancelRequestedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddActivityTaskCancelRequestedEvent), workflowTaskCompletedEventID, scheduledEventID) +} + +// AddActivityTaskCanceledEvent mocks base method. +func (m *MockHistoryBuilder) AddActivityTaskCanceledEvent(scheduledEventID, startedEventID, latestCancelRequestedEventID int64, details *v10.Payloads, identity string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddActivityTaskCanceledEvent", scheduledEventID, startedEventID, latestCancelRequestedEventID, details, identity) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddActivityTaskCanceledEvent indicates an expected call of AddActivityTaskCanceledEvent. +func (mr *MockHistoryBuilderMockRecorder) AddActivityTaskCanceledEvent(scheduledEventID, startedEventID, latestCancelRequestedEventID, details, identity interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddActivityTaskCanceledEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddActivityTaskCanceledEvent), scheduledEventID, startedEventID, latestCancelRequestedEventID, details, identity) +} + +// AddActivityTaskCompletedEvent mocks base method. +func (m *MockHistoryBuilder) AddActivityTaskCompletedEvent(scheduledEventID, startedEventID int64, identity string, result *v10.Payloads) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddActivityTaskCompletedEvent", scheduledEventID, startedEventID, identity, result) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddActivityTaskCompletedEvent indicates an expected call of AddActivityTaskCompletedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddActivityTaskCompletedEvent(scheduledEventID, startedEventID, identity, result interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddActivityTaskCompletedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddActivityTaskCompletedEvent), scheduledEventID, startedEventID, identity, result) +} + +// AddActivityTaskFailedEvent mocks base method. +func (m *MockHistoryBuilder) AddActivityTaskFailedEvent(scheduledEventID, startedEventID int64, failure *v12.Failure, retryState v11.RetryState, identity string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddActivityTaskFailedEvent", scheduledEventID, startedEventID, failure, retryState, identity) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddActivityTaskFailedEvent indicates an expected call of AddActivityTaskFailedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddActivityTaskFailedEvent(scheduledEventID, startedEventID, failure, retryState, identity interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddActivityTaskFailedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddActivityTaskFailedEvent), scheduledEventID, startedEventID, failure, retryState, identity) +} + +// AddActivityTaskScheduledEvent mocks base method. +func (m *MockHistoryBuilder) AddActivityTaskScheduledEvent(workflowTaskCompletedEventID int64, command *v1.ScheduleActivityTaskCommandAttributes) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddActivityTaskScheduledEvent", workflowTaskCompletedEventID, command) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddActivityTaskScheduledEvent indicates an expected call of AddActivityTaskScheduledEvent. +func (mr *MockHistoryBuilderMockRecorder) AddActivityTaskScheduledEvent(workflowTaskCompletedEventID, command interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddActivityTaskScheduledEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddActivityTaskScheduledEvent), workflowTaskCompletedEventID, command) +} + +// AddActivityTaskStartedEvent mocks base method. +func (m *MockHistoryBuilder) AddActivityTaskStartedEvent(scheduledEventID int64, attempt int32, requestID, identity string, lastFailure *v12.Failure) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddActivityTaskStartedEvent", scheduledEventID, attempt, requestID, identity, lastFailure) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddActivityTaskStartedEvent indicates an expected call of AddActivityTaskStartedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddActivityTaskStartedEvent(scheduledEventID, attempt, requestID, identity, lastFailure interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddActivityTaskStartedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddActivityTaskStartedEvent), scheduledEventID, attempt, requestID, identity, lastFailure) +} + +// AddActivityTaskTimedOutEvent mocks base method. +func (m *MockHistoryBuilder) AddActivityTaskTimedOutEvent(scheduledEventID, startedEventID int64, timeoutFailure *v12.Failure, retryState v11.RetryState) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddActivityTaskTimedOutEvent", scheduledEventID, startedEventID, timeoutFailure, retryState) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddActivityTaskTimedOutEvent indicates an expected call of AddActivityTaskTimedOutEvent. +func (mr *MockHistoryBuilderMockRecorder) AddActivityTaskTimedOutEvent(scheduledEventID, startedEventID, timeoutFailure, retryState interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddActivityTaskTimedOutEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddActivityTaskTimedOutEvent), scheduledEventID, startedEventID, timeoutFailure, retryState) +} + +// AddChildWorkflowExecutionCanceledEvent mocks base method. +func (m *MockHistoryBuilder) AddChildWorkflowExecutionCanceledEvent(initiatedID, startedEventID int64, targetNamespace namespace.Name, targetNamespaceID namespace.ID, execution *v10.WorkflowExecution, workflowType *v10.WorkflowType, details *v10.Payloads) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddChildWorkflowExecutionCanceledEvent", initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, details) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddChildWorkflowExecutionCanceledEvent indicates an expected call of AddChildWorkflowExecutionCanceledEvent. +func (mr *MockHistoryBuilderMockRecorder) AddChildWorkflowExecutionCanceledEvent(initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, details interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddChildWorkflowExecutionCanceledEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddChildWorkflowExecutionCanceledEvent), initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, details) +} + +// AddChildWorkflowExecutionCompletedEvent mocks base method. +func (m *MockHistoryBuilder) AddChildWorkflowExecutionCompletedEvent(initiatedID, startedEventID int64, targetNamespace namespace.Name, targetNamespaceID namespace.ID, execution *v10.WorkflowExecution, workflowType *v10.WorkflowType, result *v10.Payloads) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddChildWorkflowExecutionCompletedEvent", initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, result) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddChildWorkflowExecutionCompletedEvent indicates an expected call of AddChildWorkflowExecutionCompletedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddChildWorkflowExecutionCompletedEvent(initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, result interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddChildWorkflowExecutionCompletedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddChildWorkflowExecutionCompletedEvent), initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, result) +} + +// AddChildWorkflowExecutionFailedEvent mocks base method. +func (m *MockHistoryBuilder) AddChildWorkflowExecutionFailedEvent(initiatedID, startedEventID int64, targetNamespace namespace.Name, targetNamespaceID namespace.ID, execution *v10.WorkflowExecution, workflowType *v10.WorkflowType, failure *v12.Failure, retryState v11.RetryState) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddChildWorkflowExecutionFailedEvent", initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, failure, retryState) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddChildWorkflowExecutionFailedEvent indicates an expected call of AddChildWorkflowExecutionFailedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddChildWorkflowExecutionFailedEvent(initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, failure, retryState interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddChildWorkflowExecutionFailedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddChildWorkflowExecutionFailedEvent), initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, failure, retryState) +} + +// AddChildWorkflowExecutionStartedEvent mocks base method. +func (m *MockHistoryBuilder) AddChildWorkflowExecutionStartedEvent(initiatedID int64, targetNamespace namespace.Name, targetNamespaceID namespace.ID, execution *v10.WorkflowExecution, workflowType *v10.WorkflowType, header *v10.Header) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddChildWorkflowExecutionStartedEvent", initiatedID, targetNamespace, targetNamespaceID, execution, workflowType, header) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddChildWorkflowExecutionStartedEvent indicates an expected call of AddChildWorkflowExecutionStartedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddChildWorkflowExecutionStartedEvent(initiatedID, targetNamespace, targetNamespaceID, execution, workflowType, header interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddChildWorkflowExecutionStartedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddChildWorkflowExecutionStartedEvent), initiatedID, targetNamespace, targetNamespaceID, execution, workflowType, header) +} + +// AddChildWorkflowExecutionTerminatedEvent mocks base method. +func (m *MockHistoryBuilder) AddChildWorkflowExecutionTerminatedEvent(initiatedID, startedEventID int64, targetNamespace namespace.Name, targetNamespaceID namespace.ID, execution *v10.WorkflowExecution, workflowType *v10.WorkflowType) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddChildWorkflowExecutionTerminatedEvent", initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddChildWorkflowExecutionTerminatedEvent indicates an expected call of AddChildWorkflowExecutionTerminatedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddChildWorkflowExecutionTerminatedEvent(initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddChildWorkflowExecutionTerminatedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddChildWorkflowExecutionTerminatedEvent), initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType) +} + +// AddChildWorkflowExecutionTimedOutEvent mocks base method. +func (m *MockHistoryBuilder) AddChildWorkflowExecutionTimedOutEvent(initiatedID, startedEventID int64, targetNamespace namespace.Name, targetNamespaceID namespace.ID, execution *v10.WorkflowExecution, workflowType *v10.WorkflowType, retryState v11.RetryState) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddChildWorkflowExecutionTimedOutEvent", initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, retryState) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddChildWorkflowExecutionTimedOutEvent indicates an expected call of AddChildWorkflowExecutionTimedOutEvent. +func (mr *MockHistoryBuilderMockRecorder) AddChildWorkflowExecutionTimedOutEvent(initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, retryState interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddChildWorkflowExecutionTimedOutEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddChildWorkflowExecutionTimedOutEvent), initiatedID, startedEventID, targetNamespace, targetNamespaceID, execution, workflowType, retryState) +} + +// AddCompletedWorkflowEvent mocks base method. +func (m *MockHistoryBuilder) AddCompletedWorkflowEvent(workflowTaskCompletedEventID int64, command *v1.CompleteWorkflowExecutionCommandAttributes, newExecutionRunID string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddCompletedWorkflowEvent", workflowTaskCompletedEventID, command, newExecutionRunID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddCompletedWorkflowEvent indicates an expected call of AddCompletedWorkflowEvent. +func (mr *MockHistoryBuilderMockRecorder) AddCompletedWorkflowEvent(workflowTaskCompletedEventID, command, newExecutionRunID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddCompletedWorkflowEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddCompletedWorkflowEvent), workflowTaskCompletedEventID, command, newExecutionRunID) +} + +// AddContinuedAsNewEvent mocks base method. +func (m *MockHistoryBuilder) AddContinuedAsNewEvent(workflowTaskCompletedEventID int64, newRunID string, command *v1.ContinueAsNewWorkflowExecutionCommandAttributes) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddContinuedAsNewEvent", workflowTaskCompletedEventID, newRunID, command) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddContinuedAsNewEvent indicates an expected call of AddContinuedAsNewEvent. +func (mr *MockHistoryBuilderMockRecorder) AddContinuedAsNewEvent(workflowTaskCompletedEventID, newRunID, command interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddContinuedAsNewEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddContinuedAsNewEvent), workflowTaskCompletedEventID, newRunID, command) +} + +// AddExternalWorkflowExecutionCancelRequested mocks base method. +func (m *MockHistoryBuilder) AddExternalWorkflowExecutionCancelRequested(initiatedEventID int64, targetNamespace namespace.Name, targetNamespaceID namespace.ID, workflowID, runID string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddExternalWorkflowExecutionCancelRequested", initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddExternalWorkflowExecutionCancelRequested indicates an expected call of AddExternalWorkflowExecutionCancelRequested. +func (mr *MockHistoryBuilderMockRecorder) AddExternalWorkflowExecutionCancelRequested(initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddExternalWorkflowExecutionCancelRequested", reflect.TypeOf((*MockHistoryBuilder)(nil).AddExternalWorkflowExecutionCancelRequested), initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID) +} + +// AddExternalWorkflowExecutionSignaled mocks base method. +func (m *MockHistoryBuilder) AddExternalWorkflowExecutionSignaled(initiatedEventID int64, targetNamespace namespace.Name, targetNamespaceID namespace.ID, workflowID, runID, control string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddExternalWorkflowExecutionSignaled", initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID, control) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddExternalWorkflowExecutionSignaled indicates an expected call of AddExternalWorkflowExecutionSignaled. +func (mr *MockHistoryBuilderMockRecorder) AddExternalWorkflowExecutionSignaled(initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID, control interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddExternalWorkflowExecutionSignaled", reflect.TypeOf((*MockHistoryBuilder)(nil).AddExternalWorkflowExecutionSignaled), initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID, control) +} + +// AddFailWorkflowEvent mocks base method. +func (m *MockHistoryBuilder) AddFailWorkflowEvent(workflowTaskCompletedEventID int64, retryState v11.RetryState, command *v1.FailWorkflowExecutionCommandAttributes, newExecutionRunID string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddFailWorkflowEvent", workflowTaskCompletedEventID, retryState, command, newExecutionRunID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddFailWorkflowEvent indicates an expected call of AddFailWorkflowEvent. +func (mr *MockHistoryBuilderMockRecorder) AddFailWorkflowEvent(workflowTaskCompletedEventID, retryState, command, newExecutionRunID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddFailWorkflowEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddFailWorkflowEvent), workflowTaskCompletedEventID, retryState, command, newExecutionRunID) +} + +// AddMarkerRecordedEvent mocks base method. +func (m *MockHistoryBuilder) AddMarkerRecordedEvent(workflowTaskCompletedEventID int64, command *v1.RecordMarkerCommandAttributes) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddMarkerRecordedEvent", workflowTaskCompletedEventID, command) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddMarkerRecordedEvent indicates an expected call of AddMarkerRecordedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddMarkerRecordedEvent(workflowTaskCompletedEventID, command interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddMarkerRecordedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddMarkerRecordedEvent), workflowTaskCompletedEventID, command) +} + +// AddRequestCancelExternalWorkflowExecutionFailedEvent mocks base method. +func (m *MockHistoryBuilder) AddRequestCancelExternalWorkflowExecutionFailedEvent(workflowTaskCompletedEventID, initiatedEventID int64, targetNamespace namespace.Name, targetNamespaceID namespace.ID, workflowID, runID string, cause v11.CancelExternalWorkflowExecutionFailedCause) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddRequestCancelExternalWorkflowExecutionFailedEvent", workflowTaskCompletedEventID, initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID, cause) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddRequestCancelExternalWorkflowExecutionFailedEvent indicates an expected call of AddRequestCancelExternalWorkflowExecutionFailedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddRequestCancelExternalWorkflowExecutionFailedEvent(workflowTaskCompletedEventID, initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID, cause interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRequestCancelExternalWorkflowExecutionFailedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddRequestCancelExternalWorkflowExecutionFailedEvent), workflowTaskCompletedEventID, initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID, cause) +} + +// AddRequestCancelExternalWorkflowExecutionInitiatedEvent mocks base method. +func (m *MockHistoryBuilder) AddRequestCancelExternalWorkflowExecutionInitiatedEvent(workflowTaskCompletedEventID int64, command *v1.RequestCancelExternalWorkflowExecutionCommandAttributes, targetNamespaceID namespace.ID) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddRequestCancelExternalWorkflowExecutionInitiatedEvent", workflowTaskCompletedEventID, command, targetNamespaceID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddRequestCancelExternalWorkflowExecutionInitiatedEvent indicates an expected call of AddRequestCancelExternalWorkflowExecutionInitiatedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddRequestCancelExternalWorkflowExecutionInitiatedEvent(workflowTaskCompletedEventID, command, targetNamespaceID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRequestCancelExternalWorkflowExecutionInitiatedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddRequestCancelExternalWorkflowExecutionInitiatedEvent), workflowTaskCompletedEventID, command, targetNamespaceID) +} + +// AddSignalExternalWorkflowExecutionFailedEvent mocks base method. +func (m *MockHistoryBuilder) AddSignalExternalWorkflowExecutionFailedEvent(workflowTaskCompletedEventID, initiatedEventID int64, targetNamespace namespace.Name, targetNamespaceID namespace.ID, workflowID, runID, control string, cause v11.SignalExternalWorkflowExecutionFailedCause) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddSignalExternalWorkflowExecutionFailedEvent", workflowTaskCompletedEventID, initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID, control, cause) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddSignalExternalWorkflowExecutionFailedEvent indicates an expected call of AddSignalExternalWorkflowExecutionFailedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddSignalExternalWorkflowExecutionFailedEvent(workflowTaskCompletedEventID, initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID, control, cause interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddSignalExternalWorkflowExecutionFailedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddSignalExternalWorkflowExecutionFailedEvent), workflowTaskCompletedEventID, initiatedEventID, targetNamespace, targetNamespaceID, workflowID, runID, control, cause) +} + +// AddSignalExternalWorkflowExecutionInitiatedEvent mocks base method. +func (m *MockHistoryBuilder) AddSignalExternalWorkflowExecutionInitiatedEvent(workflowTaskCompletedEventID int64, command *v1.SignalExternalWorkflowExecutionCommandAttributes, targetNamespaceID namespace.ID) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddSignalExternalWorkflowExecutionInitiatedEvent", workflowTaskCompletedEventID, command, targetNamespaceID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddSignalExternalWorkflowExecutionInitiatedEvent indicates an expected call of AddSignalExternalWorkflowExecutionInitiatedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddSignalExternalWorkflowExecutionInitiatedEvent(workflowTaskCompletedEventID, command, targetNamespaceID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddSignalExternalWorkflowExecutionInitiatedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddSignalExternalWorkflowExecutionInitiatedEvent), workflowTaskCompletedEventID, command, targetNamespaceID) +} + +// AddStartChildWorkflowExecutionFailedEvent mocks base method. +func (m *MockHistoryBuilder) AddStartChildWorkflowExecutionFailedEvent(workflowTaskCompletedEventID, initiatedID int64, cause v11.StartChildWorkflowExecutionFailedCause, targetNamespace namespace.Name, targetNamespaceID namespace.ID, workflowID string, workflowType *v10.WorkflowType, control string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddStartChildWorkflowExecutionFailedEvent", workflowTaskCompletedEventID, initiatedID, cause, targetNamespace, targetNamespaceID, workflowID, workflowType, control) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddStartChildWorkflowExecutionFailedEvent indicates an expected call of AddStartChildWorkflowExecutionFailedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddStartChildWorkflowExecutionFailedEvent(workflowTaskCompletedEventID, initiatedID, cause, targetNamespace, targetNamespaceID, workflowID, workflowType, control interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddStartChildWorkflowExecutionFailedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddStartChildWorkflowExecutionFailedEvent), workflowTaskCompletedEventID, initiatedID, cause, targetNamespace, targetNamespaceID, workflowID, workflowType, control) +} + +// AddStartChildWorkflowExecutionInitiatedEvent mocks base method. +func (m *MockHistoryBuilder) AddStartChildWorkflowExecutionInitiatedEvent(workflowTaskCompletedEventID int64, command *v1.StartChildWorkflowExecutionCommandAttributes, targetNamespaceID namespace.ID) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddStartChildWorkflowExecutionInitiatedEvent", workflowTaskCompletedEventID, command, targetNamespaceID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddStartChildWorkflowExecutionInitiatedEvent indicates an expected call of AddStartChildWorkflowExecutionInitiatedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddStartChildWorkflowExecutionInitiatedEvent(workflowTaskCompletedEventID, command, targetNamespaceID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddStartChildWorkflowExecutionInitiatedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddStartChildWorkflowExecutionInitiatedEvent), workflowTaskCompletedEventID, command, targetNamespaceID) +} + +// AddTimeoutWorkflowEvent mocks base method. +func (m *MockHistoryBuilder) AddTimeoutWorkflowEvent(retryState v11.RetryState, newExecutionRunID string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddTimeoutWorkflowEvent", retryState, newExecutionRunID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddTimeoutWorkflowEvent indicates an expected call of AddTimeoutWorkflowEvent. +func (mr *MockHistoryBuilderMockRecorder) AddTimeoutWorkflowEvent(retryState, newExecutionRunID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddTimeoutWorkflowEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddTimeoutWorkflowEvent), retryState, newExecutionRunID) +} + +// AddTimerCanceledEvent mocks base method. +func (m *MockHistoryBuilder) AddTimerCanceledEvent(workflowTaskCompletedEventID, startedEventID int64, timerID, identity string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddTimerCanceledEvent", workflowTaskCompletedEventID, startedEventID, timerID, identity) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddTimerCanceledEvent indicates an expected call of AddTimerCanceledEvent. +func (mr *MockHistoryBuilderMockRecorder) AddTimerCanceledEvent(workflowTaskCompletedEventID, startedEventID, timerID, identity interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddTimerCanceledEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddTimerCanceledEvent), workflowTaskCompletedEventID, startedEventID, timerID, identity) +} + +// AddTimerFiredEvent mocks base method. +func (m *MockHistoryBuilder) AddTimerFiredEvent(startedEventID int64, timerID string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddTimerFiredEvent", startedEventID, timerID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddTimerFiredEvent indicates an expected call of AddTimerFiredEvent. +func (mr *MockHistoryBuilderMockRecorder) AddTimerFiredEvent(startedEventID, timerID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddTimerFiredEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddTimerFiredEvent), startedEventID, timerID) +} + +// AddTimerStartedEvent mocks base method. +func (m *MockHistoryBuilder) AddTimerStartedEvent(workflowTaskCompletedEventID int64, command *v1.StartTimerCommandAttributes) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddTimerStartedEvent", workflowTaskCompletedEventID, command) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddTimerStartedEvent indicates an expected call of AddTimerStartedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddTimerStartedEvent(workflowTaskCompletedEventID, command interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddTimerStartedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddTimerStartedEvent), workflowTaskCompletedEventID, command) +} + +// AddUpsertWorkflowSearchAttributesEvent mocks base method. +func (m *MockHistoryBuilder) AddUpsertWorkflowSearchAttributesEvent(workflowTaskCompletedEventID int64, command *v1.UpsertWorkflowSearchAttributesCommandAttributes) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddUpsertWorkflowSearchAttributesEvent", workflowTaskCompletedEventID, command) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddUpsertWorkflowSearchAttributesEvent indicates an expected call of AddUpsertWorkflowSearchAttributesEvent. +func (mr *MockHistoryBuilderMockRecorder) AddUpsertWorkflowSearchAttributesEvent(workflowTaskCompletedEventID, command interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUpsertWorkflowSearchAttributesEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddUpsertWorkflowSearchAttributesEvent), workflowTaskCompletedEventID, command) +} + +// AddWorkflowExecutionCancelRequestedEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowExecutionCancelRequestedEvent(request *v16.RequestCancelWorkflowExecutionRequest) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowExecutionCancelRequestedEvent", request) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowExecutionCancelRequestedEvent indicates an expected call of AddWorkflowExecutionCancelRequestedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowExecutionCancelRequestedEvent(request interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowExecutionCancelRequestedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowExecutionCancelRequestedEvent), request) +} + +// AddWorkflowExecutionCanceledEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowExecutionCanceledEvent(workflowTaskCompletedEventID int64, command *v1.CancelWorkflowExecutionCommandAttributes) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowExecutionCanceledEvent", workflowTaskCompletedEventID, command) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowExecutionCanceledEvent indicates an expected call of AddWorkflowExecutionCanceledEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowExecutionCanceledEvent(workflowTaskCompletedEventID, command interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowExecutionCanceledEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowExecutionCanceledEvent), workflowTaskCompletedEventID, command) +} + +// AddWorkflowExecutionSignaledEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowExecutionSignaledEvent(signalName string, input *v10.Payloads, identity string, header *v10.Header) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowExecutionSignaledEvent", signalName, input, identity, header) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowExecutionSignaledEvent indicates an expected call of AddWorkflowExecutionSignaledEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowExecutionSignaledEvent(signalName, input, identity, header interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowExecutionSignaledEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowExecutionSignaledEvent), signalName, input, identity, header) +} + +// AddWorkflowExecutionStartedEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowExecutionStartedEvent(startTime time.Time, request *v16.StartWorkflowExecutionRequest, resetPoints *v15.ResetPoints, prevRunID, firstRunID, originalRunID string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowExecutionStartedEvent", startTime, request, resetPoints, prevRunID, firstRunID, originalRunID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowExecutionStartedEvent indicates an expected call of AddWorkflowExecutionStartedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowExecutionStartedEvent(startTime, request, resetPoints, prevRunID, firstRunID, originalRunID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowExecutionStartedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowExecutionStartedEvent), startTime, request, resetPoints, prevRunID, firstRunID, originalRunID) +} + +// AddWorkflowExecutionTerminatedEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowExecutionTerminatedEvent(reason string, details *v10.Payloads, identity string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowExecutionTerminatedEvent", reason, details, identity) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowExecutionTerminatedEvent indicates an expected call of AddWorkflowExecutionTerminatedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowExecutionTerminatedEvent(reason, details, identity interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowExecutionTerminatedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowExecutionTerminatedEvent), reason, details, identity) +} + +// AddWorkflowPropertiesModifiedEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowPropertiesModifiedEvent(workflowTaskCompletedEventID int64, command *v1.ModifyWorkflowPropertiesCommandAttributes) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowPropertiesModifiedEvent", workflowTaskCompletedEventID, command) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowPropertiesModifiedEvent indicates an expected call of AddWorkflowPropertiesModifiedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowPropertiesModifiedEvent(workflowTaskCompletedEventID, command interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowPropertiesModifiedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowPropertiesModifiedEvent), workflowTaskCompletedEventID, command) +} + +// AddWorkflowTaskCompletedEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowTaskCompletedEvent(scheduledEventID, startedEventID int64, identity, checksum string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowTaskCompletedEvent", scheduledEventID, startedEventID, identity, checksum) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowTaskCompletedEvent indicates an expected call of AddWorkflowTaskCompletedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowTaskCompletedEvent(scheduledEventID, startedEventID, identity, checksum interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowTaskCompletedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowTaskCompletedEvent), scheduledEventID, startedEventID, identity, checksum) +} + +// AddWorkflowTaskFailedEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowTaskFailedEvent(scheduledEventID, startedEventID int64, cause v11.WorkflowTaskFailedCause, failure *v12.Failure, identity, baseRunID, newRunID string, forkEventVersion int64, checksum string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowTaskFailedEvent", scheduledEventID, startedEventID, cause, failure, identity, baseRunID, newRunID, forkEventVersion, checksum) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowTaskFailedEvent indicates an expected call of AddWorkflowTaskFailedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowTaskFailedEvent(scheduledEventID, startedEventID, cause, failure, identity, baseRunID, newRunID, forkEventVersion, checksum interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowTaskFailedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowTaskFailedEvent), scheduledEventID, startedEventID, cause, failure, identity, baseRunID, newRunID, forkEventVersion, checksum) +} + +// AddWorkflowTaskScheduledEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowTaskScheduledEvent(taskQueue *v14.TaskQueue, startToCloseTimeout *time.Duration, attempt int32, now time.Time) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowTaskScheduledEvent", taskQueue, startToCloseTimeout, attempt, now) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowTaskScheduledEvent indicates an expected call of AddWorkflowTaskScheduledEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowTaskScheduledEvent(taskQueue, startToCloseTimeout, attempt, now interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowTaskScheduledEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowTaskScheduledEvent), taskQueue, startToCloseTimeout, attempt, now) +} + +// AddWorkflowTaskStartedEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowTaskStartedEvent(scheduledEventID int64, requestID, identity string, now time.Time) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowTaskStartedEvent", scheduledEventID, requestID, identity, now) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowTaskStartedEvent indicates an expected call of AddWorkflowTaskStartedEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowTaskStartedEvent(scheduledEventID, requestID, identity, now interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowTaskStartedEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowTaskStartedEvent), scheduledEventID, requestID, identity, now) +} + +// AddWorkflowTaskTimedOutEvent mocks base method. +func (m *MockHistoryBuilder) AddWorkflowTaskTimedOutEvent(scheduledEventID, startedEventID int64, timeoutType v11.TimeoutType) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorkflowTaskTimedOutEvent", scheduledEventID, startedEventID, timeoutType) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// AddWorkflowTaskTimedOutEvent indicates an expected call of AddWorkflowTaskTimedOutEvent. +func (mr *MockHistoryBuilderMockRecorder) AddWorkflowTaskTimedOutEvent(scheduledEventID, startedEventID, timeoutType interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorkflowTaskTimedOutEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).AddWorkflowTaskTimedOutEvent), scheduledEventID, startedEventID, timeoutType) +} + +// BufferEventSize mocks base method. +func (m *MockHistoryBuilder) BufferEventSize() int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BufferEventSize") + ret0, _ := ret[0].(int) + return ret0 +} + +// BufferEventSize indicates an expected call of BufferEventSize. +func (mr *MockHistoryBuilderMockRecorder) BufferEventSize() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BufferEventSize", reflect.TypeOf((*MockHistoryBuilder)(nil).BufferEventSize)) +} + +// Finish mocks base method. +func (m *MockHistoryBuilder) Finish(flushBufferEvent bool) (*HistoryMutation, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Finish", flushBufferEvent) + ret0, _ := ret[0].(*HistoryMutation) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Finish indicates an expected call of Finish. +func (mr *MockHistoryBuilderMockRecorder) Finish(flushBufferEvent interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Finish", reflect.TypeOf((*MockHistoryBuilder)(nil).Finish), flushBufferEvent) +} + +// FlushAndCreateNewBatch mocks base method. +func (m *MockHistoryBuilder) FlushAndCreateNewBatch() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "FlushAndCreateNewBatch") +} + +// FlushAndCreateNewBatch indicates an expected call of FlushAndCreateNewBatch. +func (mr *MockHistoryBuilderMockRecorder) FlushAndCreateNewBatch() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FlushAndCreateNewBatch", reflect.TypeOf((*MockHistoryBuilder)(nil).FlushAndCreateNewBatch)) +} + +// FlushBufferToCurrentBatch mocks base method. +func (m *MockHistoryBuilder) FlushBufferToCurrentBatch() map[int64]int64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FlushBufferToCurrentBatch") + ret0, _ := ret[0].(map[int64]int64) + return ret0 +} + +// FlushBufferToCurrentBatch indicates an expected call of FlushBufferToCurrentBatch. +func (mr *MockHistoryBuilderMockRecorder) FlushBufferToCurrentBatch() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FlushBufferToCurrentBatch", reflect.TypeOf((*MockHistoryBuilder)(nil).FlushBufferToCurrentBatch)) +} + +// GetAndRemoveTimerFireEvent mocks base method. +func (m *MockHistoryBuilder) GetAndRemoveTimerFireEvent(timerID string) *v13.HistoryEvent { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAndRemoveTimerFireEvent", timerID) + ret0, _ := ret[0].(*v13.HistoryEvent) + return ret0 +} + +// GetAndRemoveTimerFireEvent indicates an expected call of GetAndRemoveTimerFireEvent. +func (mr *MockHistoryBuilderMockRecorder) GetAndRemoveTimerFireEvent(timerID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAndRemoveTimerFireEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).GetAndRemoveTimerFireEvent), timerID) +} + +// HasActivityFinishEvent mocks base method. +func (m *MockHistoryBuilder) HasActivityFinishEvent(scheduledEventID int64) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasActivityFinishEvent", scheduledEventID) + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasActivityFinishEvent indicates an expected call of HasActivityFinishEvent. +func (mr *MockHistoryBuilderMockRecorder) HasActivityFinishEvent(scheduledEventID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasActivityFinishEvent", reflect.TypeOf((*MockHistoryBuilder)(nil).HasActivityFinishEvent), scheduledEventID) +} + +// HasBufferEvents mocks base method. +func (m *MockHistoryBuilder) HasBufferEvents() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasBufferEvents") + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasBufferEvents indicates an expected call of HasBufferEvents. +func (mr *MockHistoryBuilderMockRecorder) HasBufferEvents() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasBufferEvents", reflect.TypeOf((*MockHistoryBuilder)(nil).HasBufferEvents)) +} + +// NextEventID mocks base method. +func (m *MockHistoryBuilder) NextEventID() int64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NextEventID") + ret0, _ := ret[0].(int64) + return ret0 +} + +// NextEventID indicates an expected call of NextEventID. +func (mr *MockHistoryBuilderMockRecorder) NextEventID() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NextEventID", reflect.TypeOf((*MockHistoryBuilder)(nil).NextEventID)) +} diff --git a/service/history/workflow/mutable_state.go b/service/history/definition/mutable_state.go similarity index 98% rename from service/history/workflow/mutable_state.go rename to service/history/definition/mutable_state.go index cd52dec67f0..83a1ba0603f 100644 --- a/service/history/workflow/mutable_state.go +++ b/service/history/definition/mutable_state.go @@ -24,7 +24,7 @@ //go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination mutable_state_mock.go -package workflow +package definition import ( "context" @@ -44,7 +44,6 @@ import ( historyspb "go.temporal.io/server/api/history/v1" "go.temporal.io/server/api/historyservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" @@ -62,8 +61,6 @@ func (policy TransactionPolicy) Ptr() *TransactionPolicy { return &policy } -var emptyTasks = []tasks.Task{} - type ( // TODO: This should be part of persistence layer WorkflowTaskInfo struct { @@ -194,9 +191,9 @@ type ( IsSignalRequested(requestID string) bool IsStickyTaskQueueEnabled() bool IsWorkflowExecutionRunning() bool - IsResourceDuplicated(resourceDedupKey definition.DeduplicationID) bool + IsResourceDuplicated(resourceDedupKey DeduplicationID) bool IsWorkflowPendingOnWorkflowTaskBackoff() bool - UpdateDuplicatedResource(resourceDedupKey definition.DeduplicationID) + UpdateDuplicatedResource(resourceDedupKey DeduplicationID) ReplicateActivityInfo(*historyservice.SyncActivityRequest, bool) error ReplicateActivityTaskCancelRequestedEvent(*historypb.HistoryEvent) error ReplicateActivityTaskCanceledEvent(*historypb.HistoryEvent) error @@ -240,7 +237,7 @@ type ( ReplicateWorkflowExecutionTerminatedEvent(int64, *historypb.HistoryEvent) error ReplicateWorkflowExecutionTimedoutEvent(int64, *historypb.HistoryEvent) error SetCurrentBranchToken(branchToken []byte) error - SetHistoryBuilder(hBuilder *HistoryBuilder) + SetHistoryBuilder(hBuilder HistoryBuilder) SetHistoryTree(ctx context.Context, executionTimeout *time.Duration, runTimeout *time.Duration, treeID string) error UpdateActivity(*persistencespb.ActivityInfo) error UpdateActivityWithTimerHeartbeat(*persistencespb.ActivityInfo, time.Time) error diff --git a/service/history/workflow/mutable_state_mock.go b/service/history/definition/mutable_state_mock.go similarity index 99% rename from service/history/workflow/mutable_state_mock.go rename to service/history/definition/mutable_state_mock.go index 1e4de620068..0aa87e373bd 100644 --- a/service/history/workflow/mutable_state_mock.go +++ b/service/history/definition/mutable_state_mock.go @@ -25,8 +25,8 @@ // Code generated by MockGen. DO NOT EDIT. // Source: mutable_state.go -// Package workflow is a generated GoMock package. -package workflow +// Package definition is a generated GoMock package. +package definition import ( context "context" @@ -1651,7 +1651,7 @@ func (mr *MockMutableStateMockRecorder) IsCurrentWorkflowGuaranteed() *gomock.Ca } // IsResourceDuplicated mocks base method. -func (m *MockMutableState) IsResourceDuplicated(resourceDedupKey definition.DeduplicationID) bool { +func (m *MockMutableState) IsResourceDuplicated(resourceDedupKey DeduplicationID) bool { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "IsResourceDuplicated", resourceDedupKey) ret0, _ := ret[0].(bool) @@ -2356,7 +2356,7 @@ func (mr *MockMutableStateMockRecorder) SetCurrentBranchToken(branchToken interf } // SetHistoryBuilder mocks base method. -func (m *MockMutableState) SetHistoryBuilder(hBuilder *HistoryBuilder) { +func (m *MockMutableState) SetHistoryBuilder(hBuilder HistoryBuilder) { m.ctrl.T.Helper() m.ctrl.Call(m, "SetHistoryBuilder", hBuilder) } @@ -2463,7 +2463,7 @@ func (mr *MockMutableStateMockRecorder) UpdateCurrentVersion(version, forceUpdat } // UpdateDuplicatedResource mocks base method. -func (m *MockMutableState) UpdateDuplicatedResource(resourceDedupKey definition.DeduplicationID) { +func (m *MockMutableState) UpdateDuplicatedResource(resourceDedupKey DeduplicationID) { m.ctrl.T.Helper() m.ctrl.Call(m, "UpdateDuplicatedResource", resourceDedupKey) } diff --git a/service/history/definition/query.go b/service/history/definition/query.go new file mode 100644 index 00000000000..b027f726a79 --- /dev/null +++ b/service/history/definition/query.go @@ -0,0 +1,47 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package definition + +import ( + querypb "go.temporal.io/api/query/v1" +) + +type ( + QueryCompletionType int + + QueryCompletionState struct { + Type QueryCompletionType + Result *querypb.WorkflowQueryResult + Err error + } + + Query interface { + GetID() string + GetCompletionCh() <-chan struct{} + GetQueryInput() *querypb.WorkflowQuery + GetCompletionState() (*QueryCompletionState, error) + SetCompletionState(*QueryCompletionState) error + } +) diff --git a/service/history/definition/query_registry.go b/service/history/definition/query_registry.go new file mode 100644 index 00000000000..9210d28f5f2 --- /dev/null +++ b/service/history/definition/query_registry.go @@ -0,0 +1,51 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package definition + +import ( + querypb "go.temporal.io/api/query/v1" +) + +type ( + QueryRegistry interface { + HasBufferedQuery() bool + GetBufferedIDs() []string + HasCompletedQuery() bool + GetCompletedIDs() []string + HasUnblockedQuery() bool + GetUnblockedIDs() []string + HasFailedQuery() bool + GetFailedIDs() []string + + GetQueryCompletionCh(string) (<-chan struct{}, error) + GetQueryInput(string) (*querypb.WorkflowQuery, error) + GetCompletionState(string) (*QueryCompletionState, error) + + BufferQuery(queryInput *querypb.WorkflowQuery) (string, <-chan struct{}) + SetCompletionState(string, *QueryCompletionState) error + RemoveQuery(id string) + Clear() + } +) diff --git a/common/definition/resource_dedup.go b/service/history/definition/resource_dedup.go similarity index 100% rename from common/definition/resource_dedup.go rename to service/history/definition/resource_dedup.go diff --git a/common/definition/resource_dedup_test.go b/service/history/definition/resource_dedup_test.go similarity index 100% rename from common/definition/resource_dedup_test.go rename to service/history/definition/resource_dedup_test.go diff --git a/service/history/shard/context.go b/service/history/definition/shard_context.go similarity index 93% rename from service/history/shard/context.go rename to service/history/definition/shard_context.go index 3ddcfbfc8e5..5843dcee0f8 100644 --- a/service/history/shard/context.go +++ b/service/history/definition/shard_context.go @@ -22,7 +22,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -package shard +//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination shard_context_mock.go + +package definition import ( "context" @@ -37,7 +39,6 @@ import ( "go.temporal.io/server/common/archiver" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" @@ -45,21 +46,18 @@ import ( "go.temporal.io/server/common/persistence/serialization" "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/tasks" ) -//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination context_mock.go - type ( - // Context represents a history engine shard - Context interface { + // ShardContext represents a history engine shard + ShardContext interface { GetShardID() int32 GetExecutionManager() persistence.ExecutionManager GetNamespaceRegistry() namespace.Registry GetClusterMetadata() cluster.Metadata GetConfig() *configs.Config - GetEventsCache() events.Cache + GetEventsCache() EventCache GetLogger() log.Logger GetThrottledLogger() log.Logger GetMetricsHandler() metrics.MetricsHandler @@ -116,7 +114,7 @@ type ( GetWorkflowExecution(ctx context.Context, request *persistence.GetWorkflowExecutionRequest) (*persistence.GetWorkflowExecutionResponse, error) // DeleteWorkflowExecution deletes workflow execution, current workflow execution, and add task to delete visibility. // If branchToken != nil, then delete history also, otherwise leave history. - DeleteWorkflowExecution(ctx context.Context, workflowKey definition.WorkflowKey, branchToken []byte, startTime *time.Time, closeTime *time.Time, closeExecutionVisibilityTaskID int64) error + DeleteWorkflowExecution(ctx context.Context, workflowKey WorkflowKey, branchToken []byte, startTime *time.Time, closeTime *time.Time, closeExecutionVisibilityTaskID int64) error GetRemoteAdminClient(cluster string) (adminservice.AdminServiceClient, error) GetHistoryClient() historyservice.HistoryServiceClient @@ -126,6 +124,7 @@ type ( GetSearchAttributesMapper() searchattribute.Mapper GetArchivalMetadata() archiver.ArchivalMetadata + IsValid() bool Unload() } ) diff --git a/service/history/shard/context_mock.go b/service/history/definition/shard_context_mock.go similarity index 56% rename from service/history/shard/context_mock.go rename to service/history/definition/shard_context_mock.go index 09cfac2cfc5..0a5740fdc96 100644 --- a/service/history/shard/context_mock.go +++ b/service/history/definition/shard_context_mock.go @@ -23,10 +23,10 @@ // THE SOFTWARE. // Code generated by MockGen. DO NOT EDIT. -// Source: context.go +// Source: shard_context.go -// Package shard is a generated GoMock package. -package shard +// Package definition is a generated GoMock package. +package definition import ( context "context" @@ -42,7 +42,6 @@ import ( archiver "go.temporal.io/server/common/archiver" clock "go.temporal.io/server/common/clock" cluster "go.temporal.io/server/common/cluster" - definition "go.temporal.io/server/common/definition" log "go.temporal.io/server/common/log" metrics "go.temporal.io/server/common/metrics" namespace "go.temporal.io/server/common/namespace" @@ -50,35 +49,34 @@ import ( serialization "go.temporal.io/server/common/persistence/serialization" searchattribute "go.temporal.io/server/common/searchattribute" configs "go.temporal.io/server/service/history/configs" - events "go.temporal.io/server/service/history/events" tasks "go.temporal.io/server/service/history/tasks" ) -// MockContext is a mock of Context interface. -type MockContext struct { +// MockShardContext is a mock of ShardContext interface. +type MockShardContext struct { ctrl *gomock.Controller - recorder *MockContextMockRecorder + recorder *MockShardContextMockRecorder } -// MockContextMockRecorder is the mock recorder for MockContext. -type MockContextMockRecorder struct { - mock *MockContext +// MockShardContextMockRecorder is the mock recorder for MockShardContext. +type MockShardContextMockRecorder struct { + mock *MockShardContext } -// NewMockContext creates a new mock instance. -func NewMockContext(ctrl *gomock.Controller) *MockContext { - mock := &MockContext{ctrl: ctrl} - mock.recorder = &MockContextMockRecorder{mock} +// NewMockShardContext creates a new mock instance. +func NewMockShardContext(ctrl *gomock.Controller) *MockShardContext { + mock := &MockShardContext{ctrl: ctrl} + mock.recorder = &MockShardContextMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockContext) EXPECT() *MockContextMockRecorder { +func (m *MockShardContext) EXPECT() *MockShardContextMockRecorder { return m.recorder } // AddTasks mocks base method. -func (m *MockContext) AddTasks(ctx context.Context, request *persistence.AddHistoryTasksRequest) error { +func (m *MockShardContext) AddTasks(ctx context.Context, request *persistence.AddHistoryTasksRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddTasks", ctx, request) ret0, _ := ret[0].(error) @@ -86,13 +84,13 @@ func (m *MockContext) AddTasks(ctx context.Context, request *persistence.AddHist } // AddTasks indicates an expected call of AddTasks. -func (mr *MockContextMockRecorder) AddTasks(ctx, request interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) AddTasks(ctx, request interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddTasks", reflect.TypeOf((*MockContext)(nil).AddTasks), ctx, request) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddTasks", reflect.TypeOf((*MockShardContext)(nil).AddTasks), ctx, request) } // AppendHistoryEvents mocks base method. -func (m *MockContext) AppendHistoryEvents(ctx context.Context, request *persistence.AppendHistoryNodesRequest, namespaceID namespace.ID, execution v1.WorkflowExecution) (int, error) { +func (m *MockShardContext) AppendHistoryEvents(ctx context.Context, request *persistence.AppendHistoryNodesRequest, namespaceID namespace.ID, execution v1.WorkflowExecution) (int, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AppendHistoryEvents", ctx, request, namespaceID, execution) ret0, _ := ret[0].(int) @@ -101,13 +99,13 @@ func (m *MockContext) AppendHistoryEvents(ctx context.Context, request *persiste } // AppendHistoryEvents indicates an expected call of AppendHistoryEvents. -func (mr *MockContextMockRecorder) AppendHistoryEvents(ctx, request, namespaceID, execution interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) AppendHistoryEvents(ctx, request, namespaceID, execution interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppendHistoryEvents", reflect.TypeOf((*MockContext)(nil).AppendHistoryEvents), ctx, request, namespaceID, execution) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppendHistoryEvents", reflect.TypeOf((*MockShardContext)(nil).AppendHistoryEvents), ctx, request, namespaceID, execution) } // AssertOwnership mocks base method. -func (m *MockContext) AssertOwnership(ctx context.Context) error { +func (m *MockShardContext) AssertOwnership(ctx context.Context) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AssertOwnership", ctx) ret0, _ := ret[0].(error) @@ -115,13 +113,13 @@ func (m *MockContext) AssertOwnership(ctx context.Context) error { } // AssertOwnership indicates an expected call of AssertOwnership. -func (mr *MockContextMockRecorder) AssertOwnership(ctx interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) AssertOwnership(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AssertOwnership", reflect.TypeOf((*MockContext)(nil).AssertOwnership), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AssertOwnership", reflect.TypeOf((*MockShardContext)(nil).AssertOwnership), ctx) } // ConflictResolveWorkflowExecution mocks base method. -func (m *MockContext) ConflictResolveWorkflowExecution(ctx context.Context, request *persistence.ConflictResolveWorkflowExecutionRequest) (*persistence.ConflictResolveWorkflowExecutionResponse, error) { +func (m *MockShardContext) ConflictResolveWorkflowExecution(ctx context.Context, request *persistence.ConflictResolveWorkflowExecutionRequest) (*persistence.ConflictResolveWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ConflictResolveWorkflowExecution", ctx, request) ret0, _ := ret[0].(*persistence.ConflictResolveWorkflowExecutionResponse) @@ -130,13 +128,13 @@ func (m *MockContext) ConflictResolveWorkflowExecution(ctx context.Context, requ } // ConflictResolveWorkflowExecution indicates an expected call of ConflictResolveWorkflowExecution. -func (mr *MockContextMockRecorder) ConflictResolveWorkflowExecution(ctx, request interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) ConflictResolveWorkflowExecution(ctx, request interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConflictResolveWorkflowExecution", reflect.TypeOf((*MockContext)(nil).ConflictResolveWorkflowExecution), ctx, request) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConflictResolveWorkflowExecution", reflect.TypeOf((*MockShardContext)(nil).ConflictResolveWorkflowExecution), ctx, request) } // CreateWorkflowExecution mocks base method. -func (m *MockContext) CreateWorkflowExecution(ctx context.Context, request *persistence.CreateWorkflowExecutionRequest) (*persistence.CreateWorkflowExecutionResponse, error) { +func (m *MockShardContext) CreateWorkflowExecution(ctx context.Context, request *persistence.CreateWorkflowExecutionRequest) (*persistence.CreateWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateWorkflowExecution", ctx, request) ret0, _ := ret[0].(*persistence.CreateWorkflowExecutionResponse) @@ -145,13 +143,13 @@ func (m *MockContext) CreateWorkflowExecution(ctx context.Context, request *pers } // CreateWorkflowExecution indicates an expected call of CreateWorkflowExecution. -func (mr *MockContextMockRecorder) CreateWorkflowExecution(ctx, request interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) CreateWorkflowExecution(ctx, request interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateWorkflowExecution", reflect.TypeOf((*MockContext)(nil).CreateWorkflowExecution), ctx, request) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateWorkflowExecution", reflect.TypeOf((*MockShardContext)(nil).CreateWorkflowExecution), ctx, request) } // CurrentVectorClock mocks base method. -func (m *MockContext) CurrentVectorClock() *v11.VectorClock { +func (m *MockShardContext) CurrentVectorClock() *v11.VectorClock { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CurrentVectorClock") ret0, _ := ret[0].(*v11.VectorClock) @@ -159,13 +157,13 @@ func (m *MockContext) CurrentVectorClock() *v11.VectorClock { } // CurrentVectorClock indicates an expected call of CurrentVectorClock. -func (mr *MockContextMockRecorder) CurrentVectorClock() *gomock.Call { +func (mr *MockShardContextMockRecorder) CurrentVectorClock() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CurrentVectorClock", reflect.TypeOf((*MockContext)(nil).CurrentVectorClock)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CurrentVectorClock", reflect.TypeOf((*MockShardContext)(nil).CurrentVectorClock)) } // DeleteFailoverLevel mocks base method. -func (m *MockContext) DeleteFailoverLevel(category tasks.Category, failoverID string) error { +func (m *MockShardContext) DeleteFailoverLevel(category tasks.Category, failoverID string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeleteFailoverLevel", category, failoverID) ret0, _ := ret[0].(error) @@ -173,13 +171,13 @@ func (m *MockContext) DeleteFailoverLevel(category tasks.Category, failoverID st } // DeleteFailoverLevel indicates an expected call of DeleteFailoverLevel. -func (mr *MockContextMockRecorder) DeleteFailoverLevel(category, failoverID interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) DeleteFailoverLevel(category, failoverID interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteFailoverLevel", reflect.TypeOf((*MockContext)(nil).DeleteFailoverLevel), category, failoverID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteFailoverLevel", reflect.TypeOf((*MockShardContext)(nil).DeleteFailoverLevel), category, failoverID) } // DeleteWorkflowExecution mocks base method. -func (m *MockContext) DeleteWorkflowExecution(ctx context.Context, workflowKey definition.WorkflowKey, branchToken []byte, startTime, closeTime *time.Time, closeExecutionVisibilityTaskID int64) error { +func (m *MockShardContext) DeleteWorkflowExecution(ctx context.Context, workflowKey WorkflowKey, branchToken []byte, startTime, closeTime *time.Time, closeExecutionVisibilityTaskID int64) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeleteWorkflowExecution", ctx, workflowKey, branchToken, startTime, closeTime, closeExecutionVisibilityTaskID) ret0, _ := ret[0].(error) @@ -187,13 +185,13 @@ func (m *MockContext) DeleteWorkflowExecution(ctx context.Context, workflowKey d } // DeleteWorkflowExecution indicates an expected call of DeleteWorkflowExecution. -func (mr *MockContextMockRecorder) DeleteWorkflowExecution(ctx, workflowKey, branchToken, startTime, closeTime, closeExecutionVisibilityTaskID interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) DeleteWorkflowExecution(ctx, workflowKey, branchToken, startTime, closeTime, closeExecutionVisibilityTaskID interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteWorkflowExecution", reflect.TypeOf((*MockContext)(nil).DeleteWorkflowExecution), ctx, workflowKey, branchToken, startTime, closeTime, closeExecutionVisibilityTaskID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteWorkflowExecution", reflect.TypeOf((*MockShardContext)(nil).DeleteWorkflowExecution), ctx, workflowKey, branchToken, startTime, closeTime, closeExecutionVisibilityTaskID) } // GenerateTaskID mocks base method. -func (m *MockContext) GenerateTaskID() (int64, error) { +func (m *MockShardContext) GenerateTaskID() (int64, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GenerateTaskID") ret0, _ := ret[0].(int64) @@ -202,13 +200,13 @@ func (m *MockContext) GenerateTaskID() (int64, error) { } // GenerateTaskID indicates an expected call of GenerateTaskID. -func (mr *MockContextMockRecorder) GenerateTaskID() *gomock.Call { +func (mr *MockShardContextMockRecorder) GenerateTaskID() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateTaskID", reflect.TypeOf((*MockContext)(nil).GenerateTaskID)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateTaskID", reflect.TypeOf((*MockShardContext)(nil).GenerateTaskID)) } // GenerateTaskIDs mocks base method. -func (m *MockContext) GenerateTaskIDs(number int) ([]int64, error) { +func (m *MockShardContext) GenerateTaskIDs(number int) ([]int64, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GenerateTaskIDs", number) ret0, _ := ret[0].([]int64) @@ -217,13 +215,13 @@ func (m *MockContext) GenerateTaskIDs(number int) ([]int64, error) { } // GenerateTaskIDs indicates an expected call of GenerateTaskIDs. -func (mr *MockContextMockRecorder) GenerateTaskIDs(number interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GenerateTaskIDs(number interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateTaskIDs", reflect.TypeOf((*MockContext)(nil).GenerateTaskIDs), number) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateTaskIDs", reflect.TypeOf((*MockShardContext)(nil).GenerateTaskIDs), number) } // GetAllFailoverLevels mocks base method. -func (m *MockContext) GetAllFailoverLevels(category tasks.Category) map[string]persistence.FailoverLevel { +func (m *MockShardContext) GetAllFailoverLevels(category tasks.Category) map[string]persistence.FailoverLevel { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAllFailoverLevels", category) ret0, _ := ret[0].(map[string]persistence.FailoverLevel) @@ -231,13 +229,13 @@ func (m *MockContext) GetAllFailoverLevels(category tasks.Category) map[string]p } // GetAllFailoverLevels indicates an expected call of GetAllFailoverLevels. -func (mr *MockContextMockRecorder) GetAllFailoverLevels(category interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetAllFailoverLevels(category interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllFailoverLevels", reflect.TypeOf((*MockContext)(nil).GetAllFailoverLevels), category) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllFailoverLevels", reflect.TypeOf((*MockShardContext)(nil).GetAllFailoverLevels), category) } // GetArchivalMetadata mocks base method. -func (m *MockContext) GetArchivalMetadata() archiver.ArchivalMetadata { +func (m *MockShardContext) GetArchivalMetadata() archiver.ArchivalMetadata { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetArchivalMetadata") ret0, _ := ret[0].(archiver.ArchivalMetadata) @@ -245,13 +243,13 @@ func (m *MockContext) GetArchivalMetadata() archiver.ArchivalMetadata { } // GetArchivalMetadata indicates an expected call of GetArchivalMetadata. -func (mr *MockContextMockRecorder) GetArchivalMetadata() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetArchivalMetadata() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetArchivalMetadata", reflect.TypeOf((*MockContext)(nil).GetArchivalMetadata)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetArchivalMetadata", reflect.TypeOf((*MockShardContext)(nil).GetArchivalMetadata)) } // GetClusterMetadata mocks base method. -func (m *MockContext) GetClusterMetadata() cluster.Metadata { +func (m *MockShardContext) GetClusterMetadata() cluster.Metadata { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetClusterMetadata") ret0, _ := ret[0].(cluster.Metadata) @@ -259,13 +257,13 @@ func (m *MockContext) GetClusterMetadata() cluster.Metadata { } // GetClusterMetadata indicates an expected call of GetClusterMetadata. -func (mr *MockContextMockRecorder) GetClusterMetadata() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetClusterMetadata() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetClusterMetadata", reflect.TypeOf((*MockContext)(nil).GetClusterMetadata)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetClusterMetadata", reflect.TypeOf((*MockShardContext)(nil).GetClusterMetadata)) } // GetConfig mocks base method. -func (m *MockContext) GetConfig() *configs.Config { +func (m *MockShardContext) GetConfig() *configs.Config { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetConfig") ret0, _ := ret[0].(*configs.Config) @@ -273,13 +271,13 @@ func (m *MockContext) GetConfig() *configs.Config { } // GetConfig indicates an expected call of GetConfig. -func (mr *MockContextMockRecorder) GetConfig() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetConfig() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConfig", reflect.TypeOf((*MockContext)(nil).GetConfig)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConfig", reflect.TypeOf((*MockShardContext)(nil).GetConfig)) } // GetCurrentExecution mocks base method. -func (m *MockContext) GetCurrentExecution(ctx context.Context, request *persistence.GetCurrentExecutionRequest) (*persistence.GetCurrentExecutionResponse, error) { +func (m *MockShardContext) GetCurrentExecution(ctx context.Context, request *persistence.GetCurrentExecutionRequest) (*persistence.GetCurrentExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetCurrentExecution", ctx, request) ret0, _ := ret[0].(*persistence.GetCurrentExecutionResponse) @@ -288,13 +286,13 @@ func (m *MockContext) GetCurrentExecution(ctx context.Context, request *persiste } // GetCurrentExecution indicates an expected call of GetCurrentExecution. -func (mr *MockContextMockRecorder) GetCurrentExecution(ctx, request interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetCurrentExecution(ctx, request interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentExecution", reflect.TypeOf((*MockContext)(nil).GetCurrentExecution), ctx, request) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentExecution", reflect.TypeOf((*MockShardContext)(nil).GetCurrentExecution), ctx, request) } // GetCurrentTime mocks base method. -func (m *MockContext) GetCurrentTime(cluster string) time.Time { +func (m *MockShardContext) GetCurrentTime(cluster string) time.Time { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetCurrentTime", cluster) ret0, _ := ret[0].(time.Time) @@ -302,13 +300,13 @@ func (m *MockContext) GetCurrentTime(cluster string) time.Time { } // GetCurrentTime indicates an expected call of GetCurrentTime. -func (mr *MockContextMockRecorder) GetCurrentTime(cluster interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetCurrentTime(cluster interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentTime", reflect.TypeOf((*MockContext)(nil).GetCurrentTime), cluster) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentTime", reflect.TypeOf((*MockShardContext)(nil).GetCurrentTime), cluster) } // GetEngine mocks base method. -func (m *MockContext) GetEngine(ctx context.Context) (Engine, error) { +func (m *MockShardContext) GetEngine(ctx context.Context) (Engine, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetEngine", ctx) ret0, _ := ret[0].(Engine) @@ -317,27 +315,27 @@ func (m *MockContext) GetEngine(ctx context.Context) (Engine, error) { } // GetEngine indicates an expected call of GetEngine. -func (mr *MockContextMockRecorder) GetEngine(ctx interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetEngine(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEngine", reflect.TypeOf((*MockContext)(nil).GetEngine), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEngine", reflect.TypeOf((*MockShardContext)(nil).GetEngine), ctx) } // GetEventsCache mocks base method. -func (m *MockContext) GetEventsCache() events.Cache { +func (m *MockShardContext) GetEventsCache() EventCache { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetEventsCache") - ret0, _ := ret[0].(events.Cache) + ret0, _ := ret[0].(EventCache) return ret0 } // GetEventsCache indicates an expected call of GetEventsCache. -func (mr *MockContextMockRecorder) GetEventsCache() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetEventsCache() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEventsCache", reflect.TypeOf((*MockContext)(nil).GetEventsCache)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEventsCache", reflect.TypeOf((*MockShardContext)(nil).GetEventsCache)) } // GetExecutionManager mocks base method. -func (m *MockContext) GetExecutionManager() persistence.ExecutionManager { +func (m *MockShardContext) GetExecutionManager() persistence.ExecutionManager { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetExecutionManager") ret0, _ := ret[0].(persistence.ExecutionManager) @@ -345,13 +343,13 @@ func (m *MockContext) GetExecutionManager() persistence.ExecutionManager { } // GetExecutionManager indicates an expected call of GetExecutionManager. -func (mr *MockContextMockRecorder) GetExecutionManager() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetExecutionManager() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetExecutionManager", reflect.TypeOf((*MockContext)(nil).GetExecutionManager)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetExecutionManager", reflect.TypeOf((*MockShardContext)(nil).GetExecutionManager)) } // GetHistoryClient mocks base method. -func (m *MockContext) GetHistoryClient() v12.HistoryServiceClient { +func (m *MockShardContext) GetHistoryClient() v12.HistoryServiceClient { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetHistoryClient") ret0, _ := ret[0].(v12.HistoryServiceClient) @@ -359,13 +357,13 @@ func (m *MockContext) GetHistoryClient() v12.HistoryServiceClient { } // GetHistoryClient indicates an expected call of GetHistoryClient. -func (mr *MockContextMockRecorder) GetHistoryClient() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetHistoryClient() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHistoryClient", reflect.TypeOf((*MockContext)(nil).GetHistoryClient)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHistoryClient", reflect.TypeOf((*MockShardContext)(nil).GetHistoryClient)) } // GetLastUpdatedTime mocks base method. -func (m *MockContext) GetLastUpdatedTime() time.Time { +func (m *MockShardContext) GetLastUpdatedTime() time.Time { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetLastUpdatedTime") ret0, _ := ret[0].(time.Time) @@ -373,13 +371,13 @@ func (m *MockContext) GetLastUpdatedTime() time.Time { } // GetLastUpdatedTime indicates an expected call of GetLastUpdatedTime. -func (mr *MockContextMockRecorder) GetLastUpdatedTime() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetLastUpdatedTime() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLastUpdatedTime", reflect.TypeOf((*MockContext)(nil).GetLastUpdatedTime)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLastUpdatedTime", reflect.TypeOf((*MockShardContext)(nil).GetLastUpdatedTime)) } // GetLogger mocks base method. -func (m *MockContext) GetLogger() log.Logger { +func (m *MockShardContext) GetLogger() log.Logger { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetLogger") ret0, _ := ret[0].(log.Logger) @@ -387,13 +385,13 @@ func (m *MockContext) GetLogger() log.Logger { } // GetLogger indicates an expected call of GetLogger. -func (mr *MockContextMockRecorder) GetLogger() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetLogger() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLogger", reflect.TypeOf((*MockContext)(nil).GetLogger)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLogger", reflect.TypeOf((*MockShardContext)(nil).GetLogger)) } // GetMaxTaskIDForCurrentRangeID mocks base method. -func (m *MockContext) GetMaxTaskIDForCurrentRangeID() int64 { +func (m *MockShardContext) GetMaxTaskIDForCurrentRangeID() int64 { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetMaxTaskIDForCurrentRangeID") ret0, _ := ret[0].(int64) @@ -401,13 +399,13 @@ func (m *MockContext) GetMaxTaskIDForCurrentRangeID() int64 { } // GetMaxTaskIDForCurrentRangeID indicates an expected call of GetMaxTaskIDForCurrentRangeID. -func (mr *MockContextMockRecorder) GetMaxTaskIDForCurrentRangeID() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetMaxTaskIDForCurrentRangeID() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMaxTaskIDForCurrentRangeID", reflect.TypeOf((*MockContext)(nil).GetMaxTaskIDForCurrentRangeID)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMaxTaskIDForCurrentRangeID", reflect.TypeOf((*MockShardContext)(nil).GetMaxTaskIDForCurrentRangeID)) } // GetMetricsHandler mocks base method. -func (m *MockContext) GetMetricsHandler() metrics.MetricsHandler { +func (m *MockShardContext) GetMetricsHandler() metrics.MetricsHandler { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetMetricsHandler") ret0, _ := ret[0].(metrics.MetricsHandler) @@ -415,13 +413,13 @@ func (m *MockContext) GetMetricsHandler() metrics.MetricsHandler { } // GetMetricsHandler indicates an expected call of GetMetricsHandler. -func (mr *MockContextMockRecorder) GetMetricsHandler() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetMetricsHandler() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMetricsHandler", reflect.TypeOf((*MockContext)(nil).GetMetricsHandler)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMetricsHandler", reflect.TypeOf((*MockShardContext)(nil).GetMetricsHandler)) } // GetNamespaceNotificationVersion mocks base method. -func (m *MockContext) GetNamespaceNotificationVersion() int64 { +func (m *MockShardContext) GetNamespaceNotificationVersion() int64 { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetNamespaceNotificationVersion") ret0, _ := ret[0].(int64) @@ -429,13 +427,13 @@ func (m *MockContext) GetNamespaceNotificationVersion() int64 { } // GetNamespaceNotificationVersion indicates an expected call of GetNamespaceNotificationVersion. -func (mr *MockContextMockRecorder) GetNamespaceNotificationVersion() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetNamespaceNotificationVersion() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNamespaceNotificationVersion", reflect.TypeOf((*MockContext)(nil).GetNamespaceNotificationVersion)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNamespaceNotificationVersion", reflect.TypeOf((*MockShardContext)(nil).GetNamespaceNotificationVersion)) } // GetNamespaceRegistry mocks base method. -func (m *MockContext) GetNamespaceRegistry() namespace.Registry { +func (m *MockShardContext) GetNamespaceRegistry() namespace.Registry { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetNamespaceRegistry") ret0, _ := ret[0].(namespace.Registry) @@ -443,13 +441,13 @@ func (m *MockContext) GetNamespaceRegistry() namespace.Registry { } // GetNamespaceRegistry indicates an expected call of GetNamespaceRegistry. -func (mr *MockContextMockRecorder) GetNamespaceRegistry() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetNamespaceRegistry() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNamespaceRegistry", reflect.TypeOf((*MockContext)(nil).GetNamespaceRegistry)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNamespaceRegistry", reflect.TypeOf((*MockShardContext)(nil).GetNamespaceRegistry)) } // GetPayloadSerializer mocks base method. -func (m *MockContext) GetPayloadSerializer() serialization.Serializer { +func (m *MockShardContext) GetPayloadSerializer() serialization.Serializer { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetPayloadSerializer") ret0, _ := ret[0].(serialization.Serializer) @@ -457,13 +455,13 @@ func (m *MockContext) GetPayloadSerializer() serialization.Serializer { } // GetPayloadSerializer indicates an expected call of GetPayloadSerializer. -func (mr *MockContextMockRecorder) GetPayloadSerializer() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetPayloadSerializer() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPayloadSerializer", reflect.TypeOf((*MockContext)(nil).GetPayloadSerializer)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPayloadSerializer", reflect.TypeOf((*MockShardContext)(nil).GetPayloadSerializer)) } // GetQueueAckLevel mocks base method. -func (m *MockContext) GetQueueAckLevel(category tasks.Category) tasks.Key { +func (m *MockShardContext) GetQueueAckLevel(category tasks.Category) tasks.Key { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetQueueAckLevel", category) ret0, _ := ret[0].(tasks.Key) @@ -471,13 +469,13 @@ func (m *MockContext) GetQueueAckLevel(category tasks.Category) tasks.Key { } // GetQueueAckLevel indicates an expected call of GetQueueAckLevel. -func (mr *MockContextMockRecorder) GetQueueAckLevel(category interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetQueueAckLevel(category interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueueAckLevel", reflect.TypeOf((*MockContext)(nil).GetQueueAckLevel), category) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueueAckLevel", reflect.TypeOf((*MockShardContext)(nil).GetQueueAckLevel), category) } // GetQueueClusterAckLevel mocks base method. -func (m *MockContext) GetQueueClusterAckLevel(category tasks.Category, cluster string) tasks.Key { +func (m *MockShardContext) GetQueueClusterAckLevel(category tasks.Category, cluster string) tasks.Key { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetQueueClusterAckLevel", category, cluster) ret0, _ := ret[0].(tasks.Key) @@ -485,13 +483,13 @@ func (m *MockContext) GetQueueClusterAckLevel(category tasks.Category, cluster s } // GetQueueClusterAckLevel indicates an expected call of GetQueueClusterAckLevel. -func (mr *MockContextMockRecorder) GetQueueClusterAckLevel(category, cluster interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetQueueClusterAckLevel(category, cluster interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueueClusterAckLevel", reflect.TypeOf((*MockContext)(nil).GetQueueClusterAckLevel), category, cluster) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueueClusterAckLevel", reflect.TypeOf((*MockShardContext)(nil).GetQueueClusterAckLevel), category, cluster) } // GetQueueExclusiveHighReadWatermark mocks base method. -func (m *MockContext) GetQueueExclusiveHighReadWatermark(category tasks.Category, cluster string, singleProcessorMode bool) tasks.Key { +func (m *MockShardContext) GetQueueExclusiveHighReadWatermark(category tasks.Category, cluster string, singleProcessorMode bool) tasks.Key { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetQueueExclusiveHighReadWatermark", category, cluster, singleProcessorMode) ret0, _ := ret[0].(tasks.Key) @@ -499,13 +497,13 @@ func (m *MockContext) GetQueueExclusiveHighReadWatermark(category tasks.Category } // GetQueueExclusiveHighReadWatermark indicates an expected call of GetQueueExclusiveHighReadWatermark. -func (mr *MockContextMockRecorder) GetQueueExclusiveHighReadWatermark(category, cluster, singleProcessorMode interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetQueueExclusiveHighReadWatermark(category, cluster, singleProcessorMode interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueueExclusiveHighReadWatermark", reflect.TypeOf((*MockContext)(nil).GetQueueExclusiveHighReadWatermark), category, cluster, singleProcessorMode) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueueExclusiveHighReadWatermark", reflect.TypeOf((*MockShardContext)(nil).GetQueueExclusiveHighReadWatermark), category, cluster, singleProcessorMode) } // GetQueueState mocks base method. -func (m *MockContext) GetQueueState(category tasks.Category) (*v13.QueueState, bool) { +func (m *MockShardContext) GetQueueState(category tasks.Category) (*v13.QueueState, bool) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetQueueState", category) ret0, _ := ret[0].(*v13.QueueState) @@ -514,13 +512,13 @@ func (m *MockContext) GetQueueState(category tasks.Category) (*v13.QueueState, b } // GetQueueState indicates an expected call of GetQueueState. -func (mr *MockContextMockRecorder) GetQueueState(category interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetQueueState(category interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueueState", reflect.TypeOf((*MockContext)(nil).GetQueueState), category) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueueState", reflect.TypeOf((*MockShardContext)(nil).GetQueueState), category) } // GetRemoteAdminClient mocks base method. -func (m *MockContext) GetRemoteAdminClient(cluster string) (v10.AdminServiceClient, error) { +func (m *MockShardContext) GetRemoteAdminClient(cluster string) (v10.AdminServiceClient, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetRemoteAdminClient", cluster) ret0, _ := ret[0].(v10.AdminServiceClient) @@ -529,13 +527,13 @@ func (m *MockContext) GetRemoteAdminClient(cluster string) (v10.AdminServiceClie } // GetRemoteAdminClient indicates an expected call of GetRemoteAdminClient. -func (mr *MockContextMockRecorder) GetRemoteAdminClient(cluster interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetRemoteAdminClient(cluster interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRemoteAdminClient", reflect.TypeOf((*MockContext)(nil).GetRemoteAdminClient), cluster) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRemoteAdminClient", reflect.TypeOf((*MockShardContext)(nil).GetRemoteAdminClient), cluster) } // GetReplicationStatus mocks base method. -func (m *MockContext) GetReplicationStatus(cluster []string) (map[string]*v12.ShardReplicationStatusPerCluster, map[string]*v12.HandoverNamespaceInfo, error) { +func (m *MockShardContext) GetReplicationStatus(cluster []string) (map[string]*v12.ShardReplicationStatusPerCluster, map[string]*v12.HandoverNamespaceInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetReplicationStatus", cluster) ret0, _ := ret[0].(map[string]*v12.ShardReplicationStatusPerCluster) @@ -545,13 +543,13 @@ func (m *MockContext) GetReplicationStatus(cluster []string) (map[string]*v12.Sh } // GetReplicationStatus indicates an expected call of GetReplicationStatus. -func (mr *MockContextMockRecorder) GetReplicationStatus(cluster interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetReplicationStatus(cluster interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetReplicationStatus", reflect.TypeOf((*MockContext)(nil).GetReplicationStatus), cluster) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetReplicationStatus", reflect.TypeOf((*MockShardContext)(nil).GetReplicationStatus), cluster) } // GetReplicatorDLQAckLevel mocks base method. -func (m *MockContext) GetReplicatorDLQAckLevel(sourceCluster string) int64 { +func (m *MockShardContext) GetReplicatorDLQAckLevel(sourceCluster string) int64 { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetReplicatorDLQAckLevel", sourceCluster) ret0, _ := ret[0].(int64) @@ -559,13 +557,13 @@ func (m *MockContext) GetReplicatorDLQAckLevel(sourceCluster string) int64 { } // GetReplicatorDLQAckLevel indicates an expected call of GetReplicatorDLQAckLevel. -func (mr *MockContextMockRecorder) GetReplicatorDLQAckLevel(sourceCluster interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetReplicatorDLQAckLevel(sourceCluster interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetReplicatorDLQAckLevel", reflect.TypeOf((*MockContext)(nil).GetReplicatorDLQAckLevel), sourceCluster) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetReplicatorDLQAckLevel", reflect.TypeOf((*MockShardContext)(nil).GetReplicatorDLQAckLevel), sourceCluster) } // GetSearchAttributesMapper mocks base method. -func (m *MockContext) GetSearchAttributesMapper() searchattribute.Mapper { +func (m *MockShardContext) GetSearchAttributesMapper() searchattribute.Mapper { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetSearchAttributesMapper") ret0, _ := ret[0].(searchattribute.Mapper) @@ -573,13 +571,13 @@ func (m *MockContext) GetSearchAttributesMapper() searchattribute.Mapper { } // GetSearchAttributesMapper indicates an expected call of GetSearchAttributesMapper. -func (mr *MockContextMockRecorder) GetSearchAttributesMapper() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetSearchAttributesMapper() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSearchAttributesMapper", reflect.TypeOf((*MockContext)(nil).GetSearchAttributesMapper)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSearchAttributesMapper", reflect.TypeOf((*MockShardContext)(nil).GetSearchAttributesMapper)) } // GetSearchAttributesProvider mocks base method. -func (m *MockContext) GetSearchAttributesProvider() searchattribute.Provider { +func (m *MockShardContext) GetSearchAttributesProvider() searchattribute.Provider { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetSearchAttributesProvider") ret0, _ := ret[0].(searchattribute.Provider) @@ -587,13 +585,13 @@ func (m *MockContext) GetSearchAttributesProvider() searchattribute.Provider { } // GetSearchAttributesProvider indicates an expected call of GetSearchAttributesProvider. -func (mr *MockContextMockRecorder) GetSearchAttributesProvider() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetSearchAttributesProvider() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSearchAttributesProvider", reflect.TypeOf((*MockContext)(nil).GetSearchAttributesProvider)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSearchAttributesProvider", reflect.TypeOf((*MockShardContext)(nil).GetSearchAttributesProvider)) } // GetShardID mocks base method. -func (m *MockContext) GetShardID() int32 { +func (m *MockShardContext) GetShardID() int32 { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetShardID") ret0, _ := ret[0].(int32) @@ -601,13 +599,13 @@ func (m *MockContext) GetShardID() int32 { } // GetShardID indicates an expected call of GetShardID. -func (mr *MockContextMockRecorder) GetShardID() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetShardID() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetShardID", reflect.TypeOf((*MockContext)(nil).GetShardID)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetShardID", reflect.TypeOf((*MockShardContext)(nil).GetShardID)) } // GetThrottledLogger mocks base method. -func (m *MockContext) GetThrottledLogger() log.Logger { +func (m *MockShardContext) GetThrottledLogger() log.Logger { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetThrottledLogger") ret0, _ := ret[0].(log.Logger) @@ -615,13 +613,13 @@ func (m *MockContext) GetThrottledLogger() log.Logger { } // GetThrottledLogger indicates an expected call of GetThrottledLogger. -func (mr *MockContextMockRecorder) GetThrottledLogger() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetThrottledLogger() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetThrottledLogger", reflect.TypeOf((*MockContext)(nil).GetThrottledLogger)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetThrottledLogger", reflect.TypeOf((*MockShardContext)(nil).GetThrottledLogger)) } // GetTimeSource mocks base method. -func (m *MockContext) GetTimeSource() clock.TimeSource { +func (m *MockShardContext) GetTimeSource() clock.TimeSource { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTimeSource") ret0, _ := ret[0].(clock.TimeSource) @@ -629,13 +627,13 @@ func (m *MockContext) GetTimeSource() clock.TimeSource { } // GetTimeSource indicates an expected call of GetTimeSource. -func (mr *MockContextMockRecorder) GetTimeSource() *gomock.Call { +func (mr *MockShardContextMockRecorder) GetTimeSource() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTimeSource", reflect.TypeOf((*MockContext)(nil).GetTimeSource)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTimeSource", reflect.TypeOf((*MockShardContext)(nil).GetTimeSource)) } // GetWorkflowExecution mocks base method. -func (m *MockContext) GetWorkflowExecution(ctx context.Context, request *persistence.GetWorkflowExecutionRequest) (*persistence.GetWorkflowExecutionResponse, error) { +func (m *MockShardContext) GetWorkflowExecution(ctx context.Context, request *persistence.GetWorkflowExecutionRequest) (*persistence.GetWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetWorkflowExecution", ctx, request) ret0, _ := ret[0].(*persistence.GetWorkflowExecutionResponse) @@ -644,13 +642,27 @@ func (m *MockContext) GetWorkflowExecution(ctx context.Context, request *persist } // GetWorkflowExecution indicates an expected call of GetWorkflowExecution. -func (mr *MockContextMockRecorder) GetWorkflowExecution(ctx, request interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) GetWorkflowExecution(ctx, request interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWorkflowExecution", reflect.TypeOf((*MockContext)(nil).GetWorkflowExecution), ctx, request) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWorkflowExecution", reflect.TypeOf((*MockShardContext)(nil).GetWorkflowExecution), ctx, request) +} + +// IsValid mocks base method. +func (m *MockShardContext) IsValid() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsValid") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsValid indicates an expected call of IsValid. +func (mr *MockShardContextMockRecorder) IsValid() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsValid", reflect.TypeOf((*MockShardContext)(nil).IsValid)) } // NewVectorClock mocks base method. -func (m *MockContext) NewVectorClock() (*v11.VectorClock, error) { +func (m *MockShardContext) NewVectorClock() (*v11.VectorClock, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "NewVectorClock") ret0, _ := ret[0].(*v11.VectorClock) @@ -659,25 +671,25 @@ func (m *MockContext) NewVectorClock() (*v11.VectorClock, error) { } // NewVectorClock indicates an expected call of NewVectorClock. -func (mr *MockContextMockRecorder) NewVectorClock() *gomock.Call { +func (mr *MockShardContextMockRecorder) NewVectorClock() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewVectorClock", reflect.TypeOf((*MockContext)(nil).NewVectorClock)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewVectorClock", reflect.TypeOf((*MockShardContext)(nil).NewVectorClock)) } // SetCurrentTime mocks base method. -func (m *MockContext) SetCurrentTime(cluster string, currentTime time.Time) { +func (m *MockShardContext) SetCurrentTime(cluster string, currentTime time.Time) { m.ctrl.T.Helper() m.ctrl.Call(m, "SetCurrentTime", cluster, currentTime) } // SetCurrentTime indicates an expected call of SetCurrentTime. -func (mr *MockContextMockRecorder) SetCurrentTime(cluster, currentTime interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) SetCurrentTime(cluster, currentTime interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetCurrentTime", reflect.TypeOf((*MockContext)(nil).SetCurrentTime), cluster, currentTime) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetCurrentTime", reflect.TypeOf((*MockShardContext)(nil).SetCurrentTime), cluster, currentTime) } // SetWorkflowExecution mocks base method. -func (m *MockContext) SetWorkflowExecution(ctx context.Context, request *persistence.SetWorkflowExecutionRequest) (*persistence.SetWorkflowExecutionResponse, error) { +func (m *MockShardContext) SetWorkflowExecution(ctx context.Context, request *persistence.SetWorkflowExecutionRequest) (*persistence.SetWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetWorkflowExecution", ctx, request) ret0, _ := ret[0].(*persistence.SetWorkflowExecutionResponse) @@ -686,25 +698,25 @@ func (m *MockContext) SetWorkflowExecution(ctx context.Context, request *persist } // SetWorkflowExecution indicates an expected call of SetWorkflowExecution. -func (mr *MockContextMockRecorder) SetWorkflowExecution(ctx, request interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) SetWorkflowExecution(ctx, request interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetWorkflowExecution", reflect.TypeOf((*MockContext)(nil).SetWorkflowExecution), ctx, request) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetWorkflowExecution", reflect.TypeOf((*MockShardContext)(nil).SetWorkflowExecution), ctx, request) } // Unload mocks base method. -func (m *MockContext) Unload() { +func (m *MockShardContext) Unload() { m.ctrl.T.Helper() m.ctrl.Call(m, "Unload") } // Unload indicates an expected call of Unload. -func (mr *MockContextMockRecorder) Unload() *gomock.Call { +func (mr *MockShardContextMockRecorder) Unload() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unload", reflect.TypeOf((*MockContext)(nil).Unload)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unload", reflect.TypeOf((*MockShardContext)(nil).Unload)) } // UpdateFailoverLevel mocks base method. -func (m *MockContext) UpdateFailoverLevel(category tasks.Category, failoverID string, level persistence.FailoverLevel) error { +func (m *MockShardContext) UpdateFailoverLevel(category tasks.Category, failoverID string, level persistence.FailoverLevel) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateFailoverLevel", category, failoverID, level) ret0, _ := ret[0].(error) @@ -712,25 +724,25 @@ func (m *MockContext) UpdateFailoverLevel(category tasks.Category, failoverID st } // UpdateFailoverLevel indicates an expected call of UpdateFailoverLevel. -func (mr *MockContextMockRecorder) UpdateFailoverLevel(category, failoverID, level interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) UpdateFailoverLevel(category, failoverID, level interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateFailoverLevel", reflect.TypeOf((*MockContext)(nil).UpdateFailoverLevel), category, failoverID, level) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateFailoverLevel", reflect.TypeOf((*MockShardContext)(nil).UpdateFailoverLevel), category, failoverID, level) } // UpdateHandoverNamespaces mocks base method. -func (m *MockContext) UpdateHandoverNamespaces(newNamespaces []*namespace.Namespace, maxRepTaskID int64) { +func (m *MockShardContext) UpdateHandoverNamespaces(newNamespaces []*namespace.Namespace, maxRepTaskID int64) { m.ctrl.T.Helper() m.ctrl.Call(m, "UpdateHandoverNamespaces", newNamespaces, maxRepTaskID) } // UpdateHandoverNamespaces indicates an expected call of UpdateHandoverNamespaces. -func (mr *MockContextMockRecorder) UpdateHandoverNamespaces(newNamespaces, maxRepTaskID interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) UpdateHandoverNamespaces(newNamespaces, maxRepTaskID interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateHandoverNamespaces", reflect.TypeOf((*MockContext)(nil).UpdateHandoverNamespaces), newNamespaces, maxRepTaskID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateHandoverNamespaces", reflect.TypeOf((*MockShardContext)(nil).UpdateHandoverNamespaces), newNamespaces, maxRepTaskID) } // UpdateNamespaceNotificationVersion mocks base method. -func (m *MockContext) UpdateNamespaceNotificationVersion(namespaceNotificationVersion int64) error { +func (m *MockShardContext) UpdateNamespaceNotificationVersion(namespaceNotificationVersion int64) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateNamespaceNotificationVersion", namespaceNotificationVersion) ret0, _ := ret[0].(error) @@ -738,13 +750,13 @@ func (m *MockContext) UpdateNamespaceNotificationVersion(namespaceNotificationVe } // UpdateNamespaceNotificationVersion indicates an expected call of UpdateNamespaceNotificationVersion. -func (mr *MockContextMockRecorder) UpdateNamespaceNotificationVersion(namespaceNotificationVersion interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) UpdateNamespaceNotificationVersion(namespaceNotificationVersion interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateNamespaceNotificationVersion", reflect.TypeOf((*MockContext)(nil).UpdateNamespaceNotificationVersion), namespaceNotificationVersion) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateNamespaceNotificationVersion", reflect.TypeOf((*MockShardContext)(nil).UpdateNamespaceNotificationVersion), namespaceNotificationVersion) } // UpdateQueueAckLevel mocks base method. -func (m *MockContext) UpdateQueueAckLevel(category tasks.Category, ackLevel tasks.Key) error { +func (m *MockShardContext) UpdateQueueAckLevel(category tasks.Category, ackLevel tasks.Key) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateQueueAckLevel", category, ackLevel) ret0, _ := ret[0].(error) @@ -752,13 +764,13 @@ func (m *MockContext) UpdateQueueAckLevel(category tasks.Category, ackLevel task } // UpdateQueueAckLevel indicates an expected call of UpdateQueueAckLevel. -func (mr *MockContextMockRecorder) UpdateQueueAckLevel(category, ackLevel interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) UpdateQueueAckLevel(category, ackLevel interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateQueueAckLevel", reflect.TypeOf((*MockContext)(nil).UpdateQueueAckLevel), category, ackLevel) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateQueueAckLevel", reflect.TypeOf((*MockShardContext)(nil).UpdateQueueAckLevel), category, ackLevel) } // UpdateQueueClusterAckLevel mocks base method. -func (m *MockContext) UpdateQueueClusterAckLevel(category tasks.Category, cluster string, ackLevel tasks.Key) error { +func (m *MockShardContext) UpdateQueueClusterAckLevel(category tasks.Category, cluster string, ackLevel tasks.Key) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateQueueClusterAckLevel", category, cluster, ackLevel) ret0, _ := ret[0].(error) @@ -766,13 +778,13 @@ func (m *MockContext) UpdateQueueClusterAckLevel(category tasks.Category, cluste } // UpdateQueueClusterAckLevel indicates an expected call of UpdateQueueClusterAckLevel. -func (mr *MockContextMockRecorder) UpdateQueueClusterAckLevel(category, cluster, ackLevel interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) UpdateQueueClusterAckLevel(category, cluster, ackLevel interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateQueueClusterAckLevel", reflect.TypeOf((*MockContext)(nil).UpdateQueueClusterAckLevel), category, cluster, ackLevel) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateQueueClusterAckLevel", reflect.TypeOf((*MockShardContext)(nil).UpdateQueueClusterAckLevel), category, cluster, ackLevel) } // UpdateQueueState mocks base method. -func (m *MockContext) UpdateQueueState(category tasks.Category, state *v13.QueueState) error { +func (m *MockShardContext) UpdateQueueState(category tasks.Category, state *v13.QueueState) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateQueueState", category, state) ret0, _ := ret[0].(error) @@ -780,25 +792,25 @@ func (m *MockContext) UpdateQueueState(category tasks.Category, state *v13.Queue } // UpdateQueueState indicates an expected call of UpdateQueueState. -func (mr *MockContextMockRecorder) UpdateQueueState(category, state interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) UpdateQueueState(category, state interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateQueueState", reflect.TypeOf((*MockContext)(nil).UpdateQueueState), category, state) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateQueueState", reflect.TypeOf((*MockShardContext)(nil).UpdateQueueState), category, state) } // UpdateRemoteClusterInfo mocks base method. -func (m *MockContext) UpdateRemoteClusterInfo(cluster string, ackTaskID int64, ackTimestamp time.Time) { +func (m *MockShardContext) UpdateRemoteClusterInfo(cluster string, ackTaskID int64, ackTimestamp time.Time) { m.ctrl.T.Helper() m.ctrl.Call(m, "UpdateRemoteClusterInfo", cluster, ackTaskID, ackTimestamp) } // UpdateRemoteClusterInfo indicates an expected call of UpdateRemoteClusterInfo. -func (mr *MockContextMockRecorder) UpdateRemoteClusterInfo(cluster, ackTaskID, ackTimestamp interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) UpdateRemoteClusterInfo(cluster, ackTaskID, ackTimestamp interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRemoteClusterInfo", reflect.TypeOf((*MockContext)(nil).UpdateRemoteClusterInfo), cluster, ackTaskID, ackTimestamp) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRemoteClusterInfo", reflect.TypeOf((*MockShardContext)(nil).UpdateRemoteClusterInfo), cluster, ackTaskID, ackTimestamp) } // UpdateReplicatorDLQAckLevel mocks base method. -func (m *MockContext) UpdateReplicatorDLQAckLevel(sourCluster string, ackLevel int64) error { +func (m *MockShardContext) UpdateReplicatorDLQAckLevel(sourCluster string, ackLevel int64) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateReplicatorDLQAckLevel", sourCluster, ackLevel) ret0, _ := ret[0].(error) @@ -806,13 +818,13 @@ func (m *MockContext) UpdateReplicatorDLQAckLevel(sourCluster string, ackLevel i } // UpdateReplicatorDLQAckLevel indicates an expected call of UpdateReplicatorDLQAckLevel. -func (mr *MockContextMockRecorder) UpdateReplicatorDLQAckLevel(sourCluster, ackLevel interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) UpdateReplicatorDLQAckLevel(sourCluster, ackLevel interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateReplicatorDLQAckLevel", reflect.TypeOf((*MockContext)(nil).UpdateReplicatorDLQAckLevel), sourCluster, ackLevel) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateReplicatorDLQAckLevel", reflect.TypeOf((*MockShardContext)(nil).UpdateReplicatorDLQAckLevel), sourCluster, ackLevel) } // UpdateWorkflowExecution mocks base method. -func (m *MockContext) UpdateWorkflowExecution(ctx context.Context, request *persistence.UpdateWorkflowExecutionRequest) (*persistence.UpdateWorkflowExecutionResponse, error) { +func (m *MockShardContext) UpdateWorkflowExecution(ctx context.Context, request *persistence.UpdateWorkflowExecutionRequest) (*persistence.UpdateWorkflowExecutionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateWorkflowExecution", ctx, request) ret0, _ := ret[0].(*persistence.UpdateWorkflowExecutionResponse) @@ -821,7 +833,7 @@ func (m *MockContext) UpdateWorkflowExecution(ctx context.Context, request *pers } // UpdateWorkflowExecution indicates an expected call of UpdateWorkflowExecution. -func (mr *MockContextMockRecorder) UpdateWorkflowExecution(ctx, request interface{}) *gomock.Call { +func (mr *MockShardContextMockRecorder) UpdateWorkflowExecution(ctx, request interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecution", reflect.TypeOf((*MockContext)(nil).UpdateWorkflowExecution), ctx, request) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecution", reflect.TypeOf((*MockShardContext)(nil).UpdateWorkflowExecution), ctx, request) } diff --git a/service/history/shard/controller.go b/service/history/definition/shard_controller.go similarity index 88% rename from service/history/shard/controller.go rename to service/history/definition/shard_controller.go index 4f955b01aa9..5e839a81ef7 100644 --- a/service/history/shard/controller.go +++ b/service/history/definition/shard_controller.go @@ -22,22 +22,22 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -package shard +//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination shard_controller_mock.go + +package definition import ( "go.temporal.io/server/common" "go.temporal.io/server/common/namespace" ) -//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination controller_mock.go - type ( - Controller interface { + ShardController interface { common.Daemon common.Pingable - GetShardByID(shardID int32) (Context, error) - GetShardByNamespaceWorkflow(namespaceID namespace.ID, workflowID string) (Context, error) + GetShardByID(shardID int32) (ShardContext, error) + GetShardByNamespaceWorkflow(namespaceID namespace.ID, workflowID string) (ShardContext, error) CloseShardByID(shardID int32) ShardIDs() []int32 } diff --git a/service/history/shard/controller_mock.go b/service/history/definition/shard_controller_mock.go similarity index 60% rename from service/history/shard/controller_mock.go rename to service/history/definition/shard_controller_mock.go index d5ad3ced8b0..6f1a774d2be 100644 --- a/service/history/shard/controller_mock.go +++ b/service/history/definition/shard_controller_mock.go @@ -23,10 +23,10 @@ // THE SOFTWARE. // Code generated by MockGen. DO NOT EDIT. -// Source: controller.go +// Source: shard_controller.go -// Package shard is a generated GoMock package. -package shard +// Package definition is a generated GoMock package. +package definition import ( reflect "reflect" @@ -36,43 +36,43 @@ import ( namespace "go.temporal.io/server/common/namespace" ) -// MockController is a mock of Controller interface. -type MockController struct { +// MockShardController is a mock of ShardController interface. +type MockShardController struct { ctrl *gomock.Controller - recorder *MockControllerMockRecorder + recorder *MockShardControllerMockRecorder } -// MockControllerMockRecorder is the mock recorder for MockController. -type MockControllerMockRecorder struct { - mock *MockController +// MockShardControllerMockRecorder is the mock recorder for MockShardController. +type MockShardControllerMockRecorder struct { + mock *MockShardController } -// NewMockController creates a new mock instance. -func NewMockController(ctrl *gomock.Controller) *MockController { - mock := &MockController{ctrl: ctrl} - mock.recorder = &MockControllerMockRecorder{mock} +// NewMockShardController creates a new mock instance. +func NewMockShardController(ctrl *gomock.Controller) *MockShardController { + mock := &MockShardController{ctrl: ctrl} + mock.recorder = &MockShardControllerMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockController) EXPECT() *MockControllerMockRecorder { +func (m *MockShardController) EXPECT() *MockShardControllerMockRecorder { return m.recorder } // CloseShardByID mocks base method. -func (m *MockController) CloseShardByID(shardID int32) { +func (m *MockShardController) CloseShardByID(shardID int32) { m.ctrl.T.Helper() m.ctrl.Call(m, "CloseShardByID", shardID) } // CloseShardByID indicates an expected call of CloseShardByID. -func (mr *MockControllerMockRecorder) CloseShardByID(shardID interface{}) *gomock.Call { +func (mr *MockShardControllerMockRecorder) CloseShardByID(shardID interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseShardByID", reflect.TypeOf((*MockController)(nil).CloseShardByID), shardID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseShardByID", reflect.TypeOf((*MockShardController)(nil).CloseShardByID), shardID) } // GetPingChecks mocks base method. -func (m *MockController) GetPingChecks() []common.PingCheck { +func (m *MockShardController) GetPingChecks() []common.PingCheck { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetPingChecks") ret0, _ := ret[0].([]common.PingCheck) @@ -80,43 +80,43 @@ func (m *MockController) GetPingChecks() []common.PingCheck { } // GetPingChecks indicates an expected call of GetPingChecks. -func (mr *MockControllerMockRecorder) GetPingChecks() *gomock.Call { +func (mr *MockShardControllerMockRecorder) GetPingChecks() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPingChecks", reflect.TypeOf((*MockController)(nil).GetPingChecks)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPingChecks", reflect.TypeOf((*MockShardController)(nil).GetPingChecks)) } // GetShardByID mocks base method. -func (m *MockController) GetShardByID(shardID int32) (Context, error) { +func (m *MockShardController) GetShardByID(shardID int32) (ShardContext, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetShardByID", shardID) - ret0, _ := ret[0].(Context) + ret0, _ := ret[0].(ShardContext) ret1, _ := ret[1].(error) return ret0, ret1 } // GetShardByID indicates an expected call of GetShardByID. -func (mr *MockControllerMockRecorder) GetShardByID(shardID interface{}) *gomock.Call { +func (mr *MockShardControllerMockRecorder) GetShardByID(shardID interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetShardByID", reflect.TypeOf((*MockController)(nil).GetShardByID), shardID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetShardByID", reflect.TypeOf((*MockShardController)(nil).GetShardByID), shardID) } // GetShardByNamespaceWorkflow mocks base method. -func (m *MockController) GetShardByNamespaceWorkflow(namespaceID namespace.ID, workflowID string) (Context, error) { +func (m *MockShardController) GetShardByNamespaceWorkflow(namespaceID namespace.ID, workflowID string) (ShardContext, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetShardByNamespaceWorkflow", namespaceID, workflowID) - ret0, _ := ret[0].(Context) + ret0, _ := ret[0].(ShardContext) ret1, _ := ret[1].(error) return ret0, ret1 } // GetShardByNamespaceWorkflow indicates an expected call of GetShardByNamespaceWorkflow. -func (mr *MockControllerMockRecorder) GetShardByNamespaceWorkflow(namespaceID, workflowID interface{}) *gomock.Call { +func (mr *MockShardControllerMockRecorder) GetShardByNamespaceWorkflow(namespaceID, workflowID interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetShardByNamespaceWorkflow", reflect.TypeOf((*MockController)(nil).GetShardByNamespaceWorkflow), namespaceID, workflowID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetShardByNamespaceWorkflow", reflect.TypeOf((*MockShardController)(nil).GetShardByNamespaceWorkflow), namespaceID, workflowID) } // ShardIDs mocks base method. -func (m *MockController) ShardIDs() []int32 { +func (m *MockShardController) ShardIDs() []int32 { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ShardIDs") ret0, _ := ret[0].([]int32) @@ -124,31 +124,31 @@ func (m *MockController) ShardIDs() []int32 { } // ShardIDs indicates an expected call of ShardIDs. -func (mr *MockControllerMockRecorder) ShardIDs() *gomock.Call { +func (mr *MockShardControllerMockRecorder) ShardIDs() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ShardIDs", reflect.TypeOf((*MockController)(nil).ShardIDs)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ShardIDs", reflect.TypeOf((*MockShardController)(nil).ShardIDs)) } // Start mocks base method. -func (m *MockController) Start() { +func (m *MockShardController) Start() { m.ctrl.T.Helper() m.ctrl.Call(m, "Start") } // Start indicates an expected call of Start. -func (mr *MockControllerMockRecorder) Start() *gomock.Call { +func (mr *MockShardControllerMockRecorder) Start() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockController)(nil).Start)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockShardController)(nil).Start)) } // Stop mocks base method. -func (m *MockController) Stop() { +func (m *MockShardController) Stop() { m.ctrl.T.Helper() m.ctrl.Call(m, "Stop") } // Stop indicates an expected call of Stop. -func (mr *MockControllerMockRecorder) Stop() *gomock.Call { +func (mr *MockShardControllerMockRecorder) Stop() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockController)(nil).Stop)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockShardController)(nil).Stop)) } diff --git a/service/history/definition/workflow_cache.go b/service/history/definition/workflow_cache.go new file mode 100644 index 00000000000..f85e5e3ce20 --- /dev/null +++ b/service/history/definition/workflow_cache.go @@ -0,0 +1,48 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination workflow_cache_mock.go + +package definition + +import ( + "context" + + commonpb "go.temporal.io/api/common/v1" + + "go.temporal.io/server/common/namespace" +) + +type ( + ReleaseFunc func(err error) + + WorkflowCache interface { + GetOrCreateWorkflowExecution( + ctx context.Context, + namespaceID namespace.ID, + execution commonpb.WorkflowExecution, + caller CallerType, + ) (WorkflowContext, ReleaseFunc, error) + } +) diff --git a/service/history/definition/workflow_cache_mock.go b/service/history/definition/workflow_cache_mock.go new file mode 100644 index 00000000000..0cdf846aad4 --- /dev/null +++ b/service/history/definition/workflow_cache_mock.go @@ -0,0 +1,77 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Code generated by MockGen. DO NOT EDIT. +// Source: workflow_cache.go + +// Package definition is a generated GoMock package. +package definition + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + v1 "go.temporal.io/api/common/v1" + namespace "go.temporal.io/server/common/namespace" +) + +// MockWorkflowCache is a mock of WorkflowCache interface. +type MockWorkflowCache struct { + ctrl *gomock.Controller + recorder *MockWorkflowCacheMockRecorder +} + +// MockWorkflowCacheMockRecorder is the mock recorder for MockWorkflowCache. +type MockWorkflowCacheMockRecorder struct { + mock *MockWorkflowCache +} + +// NewMockWorkflowCache creates a new mock instance. +func NewMockWorkflowCache(ctrl *gomock.Controller) *MockWorkflowCache { + mock := &MockWorkflowCache{ctrl: ctrl} + mock.recorder = &MockWorkflowCacheMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWorkflowCache) EXPECT() *MockWorkflowCacheMockRecorder { + return m.recorder +} + +// GetOrCreateWorkflowExecution mocks base method. +func (m *MockWorkflowCache) GetOrCreateWorkflowExecution(ctx context.Context, namespaceID namespace.ID, execution v1.WorkflowExecution, caller CallerType) (WorkflowContext, ReleaseFunc, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetOrCreateWorkflowExecution", ctx, namespaceID, execution, caller) + ret0, _ := ret[0].(WorkflowContext) + ret1, _ := ret[1].(ReleaseFunc) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetOrCreateWorkflowExecution indicates an expected call of GetOrCreateWorkflowExecution. +func (mr *MockWorkflowCacheMockRecorder) GetOrCreateWorkflowExecution(ctx, namespaceID, execution, caller interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrCreateWorkflowExecution", reflect.TypeOf((*MockWorkflowCache)(nil).GetOrCreateWorkflowExecution), ctx, namespaceID, execution, caller) +} diff --git a/service/history/definition/workflow_context.go b/service/history/definition/workflow_context.go new file mode 100644 index 00000000000..137f6ff7174 --- /dev/null +++ b/service/history/definition/workflow_context.go @@ -0,0 +1,123 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination workflow_context_mock.go + +package definition + +import ( + "context" + "time" + + persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/common/definition" + "go.temporal.io/server/common/persistence" +) + +const ( + CallerTypeAPI CallerType = 0 + CallerTypeTask CallerType = 1 +) + +type ( + CallerType int + + WorkflowContext interface { + GetWorkflowKey() definition.WorkflowKey + + LoadMutableState(ctx context.Context) (MutableState, error) + LoadExecutionStats(ctx context.Context) (*persistencespb.ExecutionStats, error) + Clear() + + Lock(ctx context.Context, caller CallerType) error + Unlock(caller CallerType) + + GetHistorySize() int64 + SetHistorySize(size int64) + + ReapplyEvents( + eventBatches []*persistence.WorkflowEvents, + ) error + + PersistWorkflowEvents( + ctx context.Context, + workflowEvents *persistence.WorkflowEvents, + ) (int64, error) + + CreateWorkflowExecution( + ctx context.Context, + now time.Time, + createMode persistence.CreateWorkflowMode, + prevRunID string, + prevLastWriteVersion int64, + newMutableState MutableState, + newWorkflow *persistence.WorkflowSnapshot, + newWorkflowEvents []*persistence.WorkflowEvents, + ) error + ConflictResolveWorkflowExecution( + ctx context.Context, + now time.Time, + conflictResolveMode persistence.ConflictResolveWorkflowMode, + resetMutableState MutableState, + newContext WorkflowContext, + newMutableState MutableState, + currentContext WorkflowContext, + currentMutableState MutableState, + currentTransactionPolicy *TransactionPolicy, + ) error + UpdateWorkflowExecutionAsActive( + ctx context.Context, + now time.Time, + ) error + UpdateWorkflowExecutionWithNewAsActive( + ctx context.Context, + now time.Time, + newContext WorkflowContext, + newMutableState MutableState, + ) error + UpdateWorkflowExecutionAsPassive( + ctx context.Context, + now time.Time, + ) error + UpdateWorkflowExecutionWithNewAsPassive( + ctx context.Context, + now time.Time, + newContext WorkflowContext, + newMutableState MutableState, + ) error + UpdateWorkflowExecutionWithNew( + ctx context.Context, + now time.Time, + updateMode persistence.UpdateWorkflowMode, + newContext WorkflowContext, + newMutableState MutableState, + currentWorkflowTransactionPolicy TransactionPolicy, + newWorkflowTransactionPolicy *TransactionPolicy, + ) error + SetWorkflowExecution( + ctx context.Context, + now time.Time, + ) error + } +) diff --git a/service/history/workflow/context_mock.go b/service/history/definition/workflow_context_mock.go similarity index 52% rename from service/history/workflow/context_mock.go rename to service/history/definition/workflow_context_mock.go index 6ce51318a96..28e4e48c640 100644 --- a/service/history/workflow/context_mock.go +++ b/service/history/definition/workflow_context_mock.go @@ -23,10 +23,10 @@ // THE SOFTWARE. // Code generated by MockGen. DO NOT EDIT. -// Source: context.go +// Source: workflow_context.go -// Package workflow is a generated GoMock package. -package workflow +// Package definition is a generated GoMock package. +package definition import ( context "context" @@ -39,43 +39,43 @@ import ( persistence "go.temporal.io/server/common/persistence" ) -// MockContext is a mock of Context interface. -type MockContext struct { +// MockWorkflowContext is a mock of WorkflowContext interface. +type MockWorkflowContext struct { ctrl *gomock.Controller - recorder *MockContextMockRecorder + recorder *MockWorkflowContextMockRecorder } -// MockContextMockRecorder is the mock recorder for MockContext. -type MockContextMockRecorder struct { - mock *MockContext +// MockWorkflowContextMockRecorder is the mock recorder for MockWorkflowContext. +type MockWorkflowContextMockRecorder struct { + mock *MockWorkflowContext } -// NewMockContext creates a new mock instance. -func NewMockContext(ctrl *gomock.Controller) *MockContext { - mock := &MockContext{ctrl: ctrl} - mock.recorder = &MockContextMockRecorder{mock} +// NewMockWorkflowContext creates a new mock instance. +func NewMockWorkflowContext(ctrl *gomock.Controller) *MockWorkflowContext { + mock := &MockWorkflowContext{ctrl: ctrl} + mock.recorder = &MockWorkflowContextMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockContext) EXPECT() *MockContextMockRecorder { +func (m *MockWorkflowContext) EXPECT() *MockWorkflowContextMockRecorder { return m.recorder } // Clear mocks base method. -func (m *MockContext) Clear() { +func (m *MockWorkflowContext) Clear() { m.ctrl.T.Helper() m.ctrl.Call(m, "Clear") } // Clear indicates an expected call of Clear. -func (mr *MockContextMockRecorder) Clear() *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) Clear() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clear", reflect.TypeOf((*MockContext)(nil).Clear)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clear", reflect.TypeOf((*MockWorkflowContext)(nil).Clear)) } // ConflictResolveWorkflowExecution mocks base method. -func (m *MockContext) ConflictResolveWorkflowExecution(ctx context.Context, now time.Time, conflictResolveMode persistence.ConflictResolveWorkflowMode, resetMutableState MutableState, newContext Context, newMutableState MutableState, currentContext Context, currentMutableState MutableState, currentTransactionPolicy *TransactionPolicy) error { +func (m *MockWorkflowContext) ConflictResolveWorkflowExecution(ctx context.Context, now time.Time, conflictResolveMode persistence.ConflictResolveWorkflowMode, resetMutableState MutableState, newContext WorkflowContext, newMutableState MutableState, currentContext WorkflowContext, currentMutableState MutableState, currentTransactionPolicy *TransactionPolicy) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ConflictResolveWorkflowExecution", ctx, now, conflictResolveMode, resetMutableState, newContext, newMutableState, currentContext, currentMutableState, currentTransactionPolicy) ret0, _ := ret[0].(error) @@ -83,13 +83,13 @@ func (m *MockContext) ConflictResolveWorkflowExecution(ctx context.Context, now } // ConflictResolveWorkflowExecution indicates an expected call of ConflictResolveWorkflowExecution. -func (mr *MockContextMockRecorder) ConflictResolveWorkflowExecution(ctx, now, conflictResolveMode, resetMutableState, newContext, newMutableState, currentContext, currentMutableState, currentTransactionPolicy interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) ConflictResolveWorkflowExecution(ctx, now, conflictResolveMode, resetMutableState, newContext, newMutableState, currentContext, currentMutableState, currentTransactionPolicy interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConflictResolveWorkflowExecution", reflect.TypeOf((*MockContext)(nil).ConflictResolveWorkflowExecution), ctx, now, conflictResolveMode, resetMutableState, newContext, newMutableState, currentContext, currentMutableState, currentTransactionPolicy) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConflictResolveWorkflowExecution", reflect.TypeOf((*MockWorkflowContext)(nil).ConflictResolveWorkflowExecution), ctx, now, conflictResolveMode, resetMutableState, newContext, newMutableState, currentContext, currentMutableState, currentTransactionPolicy) } // CreateWorkflowExecution mocks base method. -func (m *MockContext) CreateWorkflowExecution(ctx context.Context, now time.Time, createMode persistence.CreateWorkflowMode, prevRunID string, prevLastWriteVersion int64, newMutableState MutableState, newWorkflow *persistence.WorkflowSnapshot, newWorkflowEvents []*persistence.WorkflowEvents) error { +func (m *MockWorkflowContext) CreateWorkflowExecution(ctx context.Context, now time.Time, createMode persistence.CreateWorkflowMode, prevRunID string, prevLastWriteVersion int64, newMutableState MutableState, newWorkflow *persistence.WorkflowSnapshot, newWorkflowEvents []*persistence.WorkflowEvents) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateWorkflowExecution", ctx, now, createMode, prevRunID, prevLastWriteVersion, newMutableState, newWorkflow, newWorkflowEvents) ret0, _ := ret[0].(error) @@ -97,13 +97,13 @@ func (m *MockContext) CreateWorkflowExecution(ctx context.Context, now time.Time } // CreateWorkflowExecution indicates an expected call of CreateWorkflowExecution. -func (mr *MockContextMockRecorder) CreateWorkflowExecution(ctx, now, createMode, prevRunID, prevLastWriteVersion, newMutableState, newWorkflow, newWorkflowEvents interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) CreateWorkflowExecution(ctx, now, createMode, prevRunID, prevLastWriteVersion, newMutableState, newWorkflow, newWorkflowEvents interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateWorkflowExecution", reflect.TypeOf((*MockContext)(nil).CreateWorkflowExecution), ctx, now, createMode, prevRunID, prevLastWriteVersion, newMutableState, newWorkflow, newWorkflowEvents) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateWorkflowExecution", reflect.TypeOf((*MockWorkflowContext)(nil).CreateWorkflowExecution), ctx, now, createMode, prevRunID, prevLastWriteVersion, newMutableState, newWorkflow, newWorkflowEvents) } // GetHistorySize mocks base method. -func (m *MockContext) GetHistorySize() int64 { +func (m *MockWorkflowContext) GetHistorySize() int64 { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetHistorySize") ret0, _ := ret[0].(int64) @@ -111,13 +111,13 @@ func (m *MockContext) GetHistorySize() int64 { } // GetHistorySize indicates an expected call of GetHistorySize. -func (mr *MockContextMockRecorder) GetHistorySize() *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) GetHistorySize() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHistorySize", reflect.TypeOf((*MockContext)(nil).GetHistorySize)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHistorySize", reflect.TypeOf((*MockWorkflowContext)(nil).GetHistorySize)) } // GetWorkflowKey mocks base method. -func (m *MockContext) GetWorkflowKey() definition.WorkflowKey { +func (m *MockWorkflowContext) GetWorkflowKey() definition.WorkflowKey { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetWorkflowKey") ret0, _ := ret[0].(definition.WorkflowKey) @@ -125,13 +125,13 @@ func (m *MockContext) GetWorkflowKey() definition.WorkflowKey { } // GetWorkflowKey indicates an expected call of GetWorkflowKey. -func (mr *MockContextMockRecorder) GetWorkflowKey() *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) GetWorkflowKey() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWorkflowKey", reflect.TypeOf((*MockContext)(nil).GetWorkflowKey)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWorkflowKey", reflect.TypeOf((*MockWorkflowContext)(nil).GetWorkflowKey)) } // LoadExecutionStats mocks base method. -func (m *MockContext) LoadExecutionStats(ctx context.Context) (*v1.ExecutionStats, error) { +func (m *MockWorkflowContext) LoadExecutionStats(ctx context.Context) (*v1.ExecutionStats, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "LoadExecutionStats", ctx) ret0, _ := ret[0].(*v1.ExecutionStats) @@ -140,13 +140,13 @@ func (m *MockContext) LoadExecutionStats(ctx context.Context) (*v1.ExecutionStat } // LoadExecutionStats indicates an expected call of LoadExecutionStats. -func (mr *MockContextMockRecorder) LoadExecutionStats(ctx interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) LoadExecutionStats(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadExecutionStats", reflect.TypeOf((*MockContext)(nil).LoadExecutionStats), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadExecutionStats", reflect.TypeOf((*MockWorkflowContext)(nil).LoadExecutionStats), ctx) } // LoadMutableState mocks base method. -func (m *MockContext) LoadMutableState(ctx context.Context) (MutableState, error) { +func (m *MockWorkflowContext) LoadMutableState(ctx context.Context) (MutableState, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "LoadMutableState", ctx) ret0, _ := ret[0].(MutableState) @@ -155,13 +155,13 @@ func (m *MockContext) LoadMutableState(ctx context.Context) (MutableState, error } // LoadMutableState indicates an expected call of LoadMutableState. -func (mr *MockContextMockRecorder) LoadMutableState(ctx interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) LoadMutableState(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadMutableState", reflect.TypeOf((*MockContext)(nil).LoadMutableState), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadMutableState", reflect.TypeOf((*MockWorkflowContext)(nil).LoadMutableState), ctx) } // Lock mocks base method. -func (m *MockContext) Lock(ctx context.Context, caller CallerType) error { +func (m *MockWorkflowContext) Lock(ctx context.Context, caller CallerType) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Lock", ctx, caller) ret0, _ := ret[0].(error) @@ -169,13 +169,13 @@ func (m *MockContext) Lock(ctx context.Context, caller CallerType) error { } // Lock indicates an expected call of Lock. -func (mr *MockContextMockRecorder) Lock(ctx, caller interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) Lock(ctx, caller interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Lock", reflect.TypeOf((*MockContext)(nil).Lock), ctx, caller) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Lock", reflect.TypeOf((*MockWorkflowContext)(nil).Lock), ctx, caller) } // PersistWorkflowEvents mocks base method. -func (m *MockContext) PersistWorkflowEvents(ctx context.Context, workflowEvents *persistence.WorkflowEvents) (int64, error) { +func (m *MockWorkflowContext) PersistWorkflowEvents(ctx context.Context, workflowEvents *persistence.WorkflowEvents) (int64, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PersistWorkflowEvents", ctx, workflowEvents) ret0, _ := ret[0].(int64) @@ -184,13 +184,13 @@ func (m *MockContext) PersistWorkflowEvents(ctx context.Context, workflowEvents } // PersistWorkflowEvents indicates an expected call of PersistWorkflowEvents. -func (mr *MockContextMockRecorder) PersistWorkflowEvents(ctx, workflowEvents interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) PersistWorkflowEvents(ctx, workflowEvents interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PersistWorkflowEvents", reflect.TypeOf((*MockContext)(nil).PersistWorkflowEvents), ctx, workflowEvents) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PersistWorkflowEvents", reflect.TypeOf((*MockWorkflowContext)(nil).PersistWorkflowEvents), ctx, workflowEvents) } // ReapplyEvents mocks base method. -func (m *MockContext) ReapplyEvents(eventBatches []*persistence.WorkflowEvents) error { +func (m *MockWorkflowContext) ReapplyEvents(eventBatches []*persistence.WorkflowEvents) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ReapplyEvents", eventBatches) ret0, _ := ret[0].(error) @@ -198,25 +198,25 @@ func (m *MockContext) ReapplyEvents(eventBatches []*persistence.WorkflowEvents) } // ReapplyEvents indicates an expected call of ReapplyEvents. -func (mr *MockContextMockRecorder) ReapplyEvents(eventBatches interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) ReapplyEvents(eventBatches interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReapplyEvents", reflect.TypeOf((*MockContext)(nil).ReapplyEvents), eventBatches) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReapplyEvents", reflect.TypeOf((*MockWorkflowContext)(nil).ReapplyEvents), eventBatches) } // SetHistorySize mocks base method. -func (m *MockContext) SetHistorySize(size int64) { +func (m *MockWorkflowContext) SetHistorySize(size int64) { m.ctrl.T.Helper() m.ctrl.Call(m, "SetHistorySize", size) } // SetHistorySize indicates an expected call of SetHistorySize. -func (mr *MockContextMockRecorder) SetHistorySize(size interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) SetHistorySize(size interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetHistorySize", reflect.TypeOf((*MockContext)(nil).SetHistorySize), size) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetHistorySize", reflect.TypeOf((*MockWorkflowContext)(nil).SetHistorySize), size) } // SetWorkflowExecution mocks base method. -func (m *MockContext) SetWorkflowExecution(ctx context.Context, now time.Time) error { +func (m *MockWorkflowContext) SetWorkflowExecution(ctx context.Context, now time.Time) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetWorkflowExecution", ctx, now) ret0, _ := ret[0].(error) @@ -224,25 +224,25 @@ func (m *MockContext) SetWorkflowExecution(ctx context.Context, now time.Time) e } // SetWorkflowExecution indicates an expected call of SetWorkflowExecution. -func (mr *MockContextMockRecorder) SetWorkflowExecution(ctx, now interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) SetWorkflowExecution(ctx, now interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetWorkflowExecution", reflect.TypeOf((*MockContext)(nil).SetWorkflowExecution), ctx, now) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetWorkflowExecution", reflect.TypeOf((*MockWorkflowContext)(nil).SetWorkflowExecution), ctx, now) } // Unlock mocks base method. -func (m *MockContext) Unlock(caller CallerType) { +func (m *MockWorkflowContext) Unlock(caller CallerType) { m.ctrl.T.Helper() m.ctrl.Call(m, "Unlock", caller) } // Unlock indicates an expected call of Unlock. -func (mr *MockContextMockRecorder) Unlock(caller interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) Unlock(caller interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unlock", reflect.TypeOf((*MockContext)(nil).Unlock), caller) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unlock", reflect.TypeOf((*MockWorkflowContext)(nil).Unlock), caller) } // UpdateWorkflowExecutionAsActive mocks base method. -func (m *MockContext) UpdateWorkflowExecutionAsActive(ctx context.Context, now time.Time) error { +func (m *MockWorkflowContext) UpdateWorkflowExecutionAsActive(ctx context.Context, now time.Time) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateWorkflowExecutionAsActive", ctx, now) ret0, _ := ret[0].(error) @@ -250,13 +250,13 @@ func (m *MockContext) UpdateWorkflowExecutionAsActive(ctx context.Context, now t } // UpdateWorkflowExecutionAsActive indicates an expected call of UpdateWorkflowExecutionAsActive. -func (mr *MockContextMockRecorder) UpdateWorkflowExecutionAsActive(ctx, now interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) UpdateWorkflowExecutionAsActive(ctx, now interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecutionAsActive", reflect.TypeOf((*MockContext)(nil).UpdateWorkflowExecutionAsActive), ctx, now) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecutionAsActive", reflect.TypeOf((*MockWorkflowContext)(nil).UpdateWorkflowExecutionAsActive), ctx, now) } // UpdateWorkflowExecutionAsPassive mocks base method. -func (m *MockContext) UpdateWorkflowExecutionAsPassive(ctx context.Context, now time.Time) error { +func (m *MockWorkflowContext) UpdateWorkflowExecutionAsPassive(ctx context.Context, now time.Time) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateWorkflowExecutionAsPassive", ctx, now) ret0, _ := ret[0].(error) @@ -264,13 +264,13 @@ func (m *MockContext) UpdateWorkflowExecutionAsPassive(ctx context.Context, now } // UpdateWorkflowExecutionAsPassive indicates an expected call of UpdateWorkflowExecutionAsPassive. -func (mr *MockContextMockRecorder) UpdateWorkflowExecutionAsPassive(ctx, now interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) UpdateWorkflowExecutionAsPassive(ctx, now interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecutionAsPassive", reflect.TypeOf((*MockContext)(nil).UpdateWorkflowExecutionAsPassive), ctx, now) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecutionAsPassive", reflect.TypeOf((*MockWorkflowContext)(nil).UpdateWorkflowExecutionAsPassive), ctx, now) } // UpdateWorkflowExecutionWithNew mocks base method. -func (m *MockContext) UpdateWorkflowExecutionWithNew(ctx context.Context, now time.Time, updateMode persistence.UpdateWorkflowMode, newContext Context, newMutableState MutableState, currentWorkflowTransactionPolicy TransactionPolicy, newWorkflowTransactionPolicy *TransactionPolicy) error { +func (m *MockWorkflowContext) UpdateWorkflowExecutionWithNew(ctx context.Context, now time.Time, updateMode persistence.UpdateWorkflowMode, newContext WorkflowContext, newMutableState MutableState, currentWorkflowTransactionPolicy TransactionPolicy, newWorkflowTransactionPolicy *TransactionPolicy) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateWorkflowExecutionWithNew", ctx, now, updateMode, newContext, newMutableState, currentWorkflowTransactionPolicy, newWorkflowTransactionPolicy) ret0, _ := ret[0].(error) @@ -278,13 +278,13 @@ func (m *MockContext) UpdateWorkflowExecutionWithNew(ctx context.Context, now ti } // UpdateWorkflowExecutionWithNew indicates an expected call of UpdateWorkflowExecutionWithNew. -func (mr *MockContextMockRecorder) UpdateWorkflowExecutionWithNew(ctx, now, updateMode, newContext, newMutableState, currentWorkflowTransactionPolicy, newWorkflowTransactionPolicy interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) UpdateWorkflowExecutionWithNew(ctx, now, updateMode, newContext, newMutableState, currentWorkflowTransactionPolicy, newWorkflowTransactionPolicy interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecutionWithNew", reflect.TypeOf((*MockContext)(nil).UpdateWorkflowExecutionWithNew), ctx, now, updateMode, newContext, newMutableState, currentWorkflowTransactionPolicy, newWorkflowTransactionPolicy) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecutionWithNew", reflect.TypeOf((*MockWorkflowContext)(nil).UpdateWorkflowExecutionWithNew), ctx, now, updateMode, newContext, newMutableState, currentWorkflowTransactionPolicy, newWorkflowTransactionPolicy) } // UpdateWorkflowExecutionWithNewAsActive mocks base method. -func (m *MockContext) UpdateWorkflowExecutionWithNewAsActive(ctx context.Context, now time.Time, newContext Context, newMutableState MutableState) error { +func (m *MockWorkflowContext) UpdateWorkflowExecutionWithNewAsActive(ctx context.Context, now time.Time, newContext WorkflowContext, newMutableState MutableState) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateWorkflowExecutionWithNewAsActive", ctx, now, newContext, newMutableState) ret0, _ := ret[0].(error) @@ -292,13 +292,13 @@ func (m *MockContext) UpdateWorkflowExecutionWithNewAsActive(ctx context.Context } // UpdateWorkflowExecutionWithNewAsActive indicates an expected call of UpdateWorkflowExecutionWithNewAsActive. -func (mr *MockContextMockRecorder) UpdateWorkflowExecutionWithNewAsActive(ctx, now, newContext, newMutableState interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) UpdateWorkflowExecutionWithNewAsActive(ctx, now, newContext, newMutableState interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecutionWithNewAsActive", reflect.TypeOf((*MockContext)(nil).UpdateWorkflowExecutionWithNewAsActive), ctx, now, newContext, newMutableState) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecutionWithNewAsActive", reflect.TypeOf((*MockWorkflowContext)(nil).UpdateWorkflowExecutionWithNewAsActive), ctx, now, newContext, newMutableState) } // UpdateWorkflowExecutionWithNewAsPassive mocks base method. -func (m *MockContext) UpdateWorkflowExecutionWithNewAsPassive(ctx context.Context, now time.Time, newContext Context, newMutableState MutableState) error { +func (m *MockWorkflowContext) UpdateWorkflowExecutionWithNewAsPassive(ctx context.Context, now time.Time, newContext WorkflowContext, newMutableState MutableState) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateWorkflowExecutionWithNewAsPassive", ctx, now, newContext, newMutableState) ret0, _ := ret[0].(error) @@ -306,7 +306,7 @@ func (m *MockContext) UpdateWorkflowExecutionWithNewAsPassive(ctx context.Contex } // UpdateWorkflowExecutionWithNewAsPassive indicates an expected call of UpdateWorkflowExecutionWithNewAsPassive. -func (mr *MockContextMockRecorder) UpdateWorkflowExecutionWithNewAsPassive(ctx, now, newContext, newMutableState interface{}) *gomock.Call { +func (mr *MockWorkflowContextMockRecorder) UpdateWorkflowExecutionWithNewAsPassive(ctx, now, newContext, newMutableState interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecutionWithNewAsPassive", reflect.TypeOf((*MockContext)(nil).UpdateWorkflowExecutionWithNewAsPassive), ctx, now, newContext, newMutableState) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateWorkflowExecutionWithNewAsPassive", reflect.TypeOf((*MockWorkflowContext)(nil).UpdateWorkflowExecutionWithNewAsPassive), ctx, now, newContext, newMutableState) } diff --git a/service/history/definition/workflow_key.go b/service/history/definition/workflow_key.go new file mode 100644 index 00000000000..be2c859ae55 --- /dev/null +++ b/service/history/definition/workflow_key.go @@ -0,0 +1,33 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package definition + +import ( + "go.temporal.io/server/common/definition" +) + +type WorkflowKey = definition.WorkflowKey + +var NewWorkflowKey = definition.NewWorkflowKey diff --git a/service/history/events/cache.go b/service/history/events/cache.go index d716db027cc..a4d9e28699a 100644 --- a/service/history/events/cache.go +++ b/service/history/events/cache.go @@ -38,25 +38,11 @@ import ( "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" - "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" + "go.temporal.io/server/service/history/definition" ) type ( - EventKey struct { - NamespaceID namespace.ID - WorkflowID string - RunID string - EventID int64 - Version int64 - } - - Cache interface { - GetEvent(ctx context.Context, key EventKey, firstEventID int64, branchToken []byte) (*historypb.HistoryEvent, error) - PutEvent(key EventKey, event *historypb.HistoryEvent) - DeleteEvent(key EventKey) - } - CacheImpl struct { cache.Cache eventsMgr persistence.ExecutionManager @@ -71,7 +57,7 @@ var ( errEventNotFoundInBatch = serviceerror.NewInternal("History event not found within expected batch") ) -var _ Cache = (*CacheImpl)(nil) +var _ definition.EventCache = (*CacheImpl)(nil) func NewEventsCache( shardID int32, @@ -97,7 +83,7 @@ func NewEventsCache( } } -func (e *CacheImpl) validateKey(key EventKey) bool { +func (e *CacheImpl) validateKey(key definition.EventKey) bool { if len(key.NamespaceID) == 0 || len(key.WorkflowID) == 0 || len(key.RunID) == 0 || key.EventID < common.FirstEventID { // This is definitely a bug, but just warn and don't crash so we can find anywhere this happens. e.logger.Warn("one or more ids is invalid in event cache", @@ -110,7 +96,7 @@ func (e *CacheImpl) validateKey(key EventKey) bool { return true } -func (e *CacheImpl) GetEvent(ctx context.Context, key EventKey, firstEventID int64, branchToken []byte) (*historypb.HistoryEvent, error) { +func (e *CacheImpl) GetEvent(ctx context.Context, key definition.EventKey, firstEventID int64, branchToken []byte) (*historypb.HistoryEvent, error) { handler := e.metricsHandler.WithTags(metrics.OperationTag(metrics.EventsCacheGetEventScope)) handler.Counter(metrics.CacheRequests.GetMetricName()).Record(1) startTime := time.Now().UTC() @@ -146,7 +132,7 @@ func (e *CacheImpl) GetEvent(ctx context.Context, key EventKey, firstEventID int return event, nil } -func (e *CacheImpl) PutEvent(key EventKey, event *historypb.HistoryEvent) { +func (e *CacheImpl) PutEvent(key definition.EventKey, event *historypb.HistoryEvent) { handler := e.metricsHandler.WithTags(metrics.OperationTag(metrics.EventsCachePutEventScope)) handler.Counter(metrics.CacheRequests.GetMetricName()).Record(1) startTime := time.Now().UTC() @@ -158,7 +144,7 @@ func (e *CacheImpl) PutEvent(key EventKey, event *historypb.HistoryEvent) { e.Put(key, event) } -func (e *CacheImpl) DeleteEvent(key EventKey) { +func (e *CacheImpl) DeleteEvent(key definition.EventKey) { handler := e.metricsHandler.WithTags(metrics.OperationTag(metrics.EventsCacheDeleteEventScope)) handler.Counter(metrics.CacheRequests.GetMetricName()).Record(1) startTime := time.Now().UTC() @@ -170,7 +156,7 @@ func (e *CacheImpl) DeleteEvent(key EventKey) { func (e *CacheImpl) getHistoryEventFromStore( ctx context.Context, - key EventKey, + key definition.EventKey, firstEventID int64, branchToken []byte, ) (*historypb.HistoryEvent, error) { diff --git a/service/history/events/cache_test.go b/service/history/events/cache_test.go index 0353078c979..67102a2f729 100644 --- a/service/history/events/cache_test.go +++ b/service/history/events/cache_test.go @@ -41,6 +41,7 @@ import ( "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" + "go.temporal.io/server/service/history/definition" ) type ( @@ -111,11 +112,11 @@ func (s *eventsCacheSuite) TestEventsCacheHitSuccess() { } s.cache.PutEvent( - EventKey{namespaceID, workflowID, runID, eventID, common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, eventID, common.EmptyVersion}, event) actualEvent, err := s.cache.GetEvent( context.Background(), - EventKey{namespaceID, workflowID, runID, eventID, common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, eventID, common.EmptyVersion}, eventID, nil) s.Nil(err) s.Equal(event, actualEvent) @@ -170,11 +171,11 @@ func (s *eventsCacheSuite) TestEventsCacheMissMultiEventsBatchV2Success() { }, nil) s.cache.PutEvent( - EventKey{namespaceID, workflowID, runID, event2.GetEventId(), common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, event2.GetEventId(), common.EmptyVersion}, event2) actualEvent, err := s.cache.GetEvent( context.Background(), - EventKey{namespaceID, workflowID, runID, event6.GetEventId(), common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, event6.GetEventId(), common.EmptyVersion}, event1.GetEventId(), []byte("store_token")) s.Nil(err) s.Equal(event6, actualEvent) @@ -198,7 +199,7 @@ func (s *eventsCacheSuite) TestEventsCacheMissV2Failure() { actualEvent, err := s.cache.GetEvent( context.Background(), - EventKey{namespaceID, workflowID, runID, int64(14), common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, int64(14), common.EmptyVersion}, int64(11), []byte("store_token")) s.Nil(actualEvent) s.Equal(expectedErr, err) @@ -233,15 +234,15 @@ func (s *eventsCacheSuite) TestEventsCacheDisableSuccess() { }, nil) s.cache.PutEvent( - EventKey{namespaceID, workflowID, runID, event1.GetEventId(), common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, event1.GetEventId(), common.EmptyVersion}, event1) s.cache.PutEvent( - EventKey{namespaceID, workflowID, runID, event2.GetEventId(), common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, event2.GetEventId(), common.EmptyVersion}, event2) s.cache.disabled = true actualEvent, err := s.cache.GetEvent( context.Background(), - EventKey{namespaceID, workflowID, runID, event2.GetEventId(), common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, event2.GetEventId(), common.EmptyVersion}, event2.GetEventId(), []byte("store_token")) s.Nil(err) s.Equal(event2, actualEvent) @@ -272,12 +273,12 @@ func (s *eventsCacheSuite) TestEventsCacheGetCachesResult() { gotEvent1, _ := s.cache.GetEvent( context.Background(), - EventKey{namespaceID, workflowID, runID, int64(14), common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, int64(14), common.EmptyVersion}, int64(11), branchToken) s.Equal(gotEvent1, event1) gotEvent2, _ := s.cache.GetEvent( context.Background(), - EventKey{namespaceID, workflowID, runID, int64(14), common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, int64(14), common.EmptyVersion}, int64(11), branchToken) s.Equal(gotEvent2, event1) } @@ -306,17 +307,17 @@ func (s *eventsCacheSuite) TestEventsCacheInvalidKey() { }, nil).Times(2) // will be called twice since the key is invalid s.cache.PutEvent( - EventKey{namespaceID, workflowID, runID, event1.EventId, common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, event1.EventId, common.EmptyVersion}, event1) gotEvent1, _ := s.cache.GetEvent( context.Background(), - EventKey{namespaceID, workflowID, runID, int64(14), common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, int64(14), common.EmptyVersion}, int64(11), branchToken) s.Equal(gotEvent1, event1) gotEvent2, _ := s.cache.GetEvent( context.Background(), - EventKey{namespaceID, workflowID, runID, int64(14), common.EmptyVersion}, + definition.EventKey{namespaceID, workflowID, runID, int64(14), common.EmptyVersion}, int64(11), branchToken) s.Equal(gotEvent2, event1) } diff --git a/service/history/events/events_cache_mock.go b/service/history/events/events_cache_mock.go index 87ea198bc82..96a353fe334 100644 --- a/service/history/events/events_cache_mock.go +++ b/service/history/events/events_cache_mock.go @@ -27,73 +27,3 @@ // Package events is a generated GoMock package. package events - -import ( - context "context" - reflect "reflect" - - gomock "github.com/golang/mock/gomock" - v1 "go.temporal.io/api/history/v1" -) - -// MockCache is a mock of Cache interface. -type MockCache struct { - ctrl *gomock.Controller - recorder *MockCacheMockRecorder -} - -// MockCacheMockRecorder is the mock recorder for MockCache. -type MockCacheMockRecorder struct { - mock *MockCache -} - -// NewMockCache creates a new mock instance. -func NewMockCache(ctrl *gomock.Controller) *MockCache { - mock := &MockCache{ctrl: ctrl} - mock.recorder = &MockCacheMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockCache) EXPECT() *MockCacheMockRecorder { - return m.recorder -} - -// DeleteEvent mocks base method. -func (m *MockCache) DeleteEvent(key EventKey) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "DeleteEvent", key) -} - -// DeleteEvent indicates an expected call of DeleteEvent. -func (mr *MockCacheMockRecorder) DeleteEvent(key interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteEvent", reflect.TypeOf((*MockCache)(nil).DeleteEvent), key) -} - -// GetEvent mocks base method. -func (m *MockCache) GetEvent(ctx context.Context, key EventKey, firstEventID int64, branchToken []byte) (*v1.HistoryEvent, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetEvent", ctx, key, firstEventID, branchToken) - ret0, _ := ret[0].(*v1.HistoryEvent) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetEvent indicates an expected call of GetEvent. -func (mr *MockCacheMockRecorder) GetEvent(ctx, key, firstEventID, branchToken interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEvent", reflect.TypeOf((*MockCache)(nil).GetEvent), ctx, key, firstEventID, branchToken) -} - -// PutEvent mocks base method. -func (m *MockCache) PutEvent(key EventKey, event *v1.HistoryEvent) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "PutEvent", key, event) -} - -// PutEvent indicates an expected call of PutEvent. -func (mr *MockCacheMockRecorder) PutEvent(key, event interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutEvent", reflect.TypeOf((*MockCache)(nil).PutEvent), key, event) -} diff --git a/service/history/events/notifier.go b/service/history/events/notifier.go index a81eea38708..03f2edbc567 100644 --- a/service/history/events/notifier.go +++ b/service/history/events/notifier.go @@ -29,17 +29,14 @@ import ( "time" "github.com/pborman/uuid" - commonpb "go.temporal.io/api/common/v1" - enumspb "go.temporal.io/api/enums/v1" "go.temporal.io/api/serviceerror" - enumsspb "go.temporal.io/server/api/enums/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/collection" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" + "go.temporal.io/server/service/history/definition" ) const ( @@ -47,25 +44,6 @@ const ( ) type ( - Notifier interface { - common.Daemon - NotifyNewHistoryEvent(event *Notification) - WatchHistoryEvent(identifier definition.WorkflowKey) (string, chan *Notification, error) - UnwatchHistoryEvent(identifier definition.WorkflowKey, subscriberID string) error - } - - Notification struct { - ID definition.WorkflowKey - LastFirstEventID int64 - LastFirstEventTxnID int64 - NextEventID int64 - PreviousStartedEventID int64 - Timestamp time.Time - CurrentBranchToken []byte - WorkflowState enumsspb.WorkflowExecutionState - WorkflowStatus enumspb.WorkflowExecutionStatus - } - NotifierImpl struct { timeSource clock.TimeSource metricsHandler metrics.MetricsHandler @@ -74,7 +52,7 @@ type ( // stop signal channel closeChan chan bool // this channel will never close - eventsChan chan *Notification + eventsChan chan *definition.Notification // function which calculate the shard ID from given namespaceID and workflowID pair workflowIDToShardID func(namespace.ID, string) int32 @@ -86,35 +64,7 @@ type ( } ) -var _ Notifier = (*NotifierImpl)(nil) - -func NewNotification( - namespaceID string, - workflowExecution *commonpb.WorkflowExecution, - lastFirstEventID int64, - lastFirstEventTxnID int64, - nextEventID int64, - previousStartedEventID int64, - currentBranchToken []byte, - workflowState enumsspb.WorkflowExecutionState, - workflowStatus enumspb.WorkflowExecutionStatus, -) *Notification { - - return &Notification{ - ID: definition.NewWorkflowKey( - namespaceID, - workflowExecution.GetWorkflowId(), - workflowExecution.GetRunId(), - ), - LastFirstEventID: lastFirstEventID, - LastFirstEventTxnID: lastFirstEventTxnID, - NextEventID: nextEventID, - PreviousStartedEventID: previousStartedEventID, - CurrentBranchToken: currentBranchToken, - WorkflowState: workflowState, - WorkflowStatus: workflowStatus, - } -} +var _ definition.Notifier = (*NotifierImpl)(nil) func NewNotifier( timeSource clock.TimeSource, @@ -123,7 +73,7 @@ func NewNotifier( ) *NotifierImpl { hashFn := func(key interface{}) uint32 { - notification, ok := key.(Notification) + notification, ok := key.(definition.Notification) if !ok { return 0 } @@ -134,7 +84,7 @@ func NewNotifier( metricsHandler: metricsHandler.WithTags(metrics.OperationTag(metrics.HistoryEventNotificationScope)), status: common.DaemonStatusInitialized, closeChan: make(chan bool), - eventsChan: make(chan *Notification, eventsChanSize), + eventsChan: make(chan *definition.Notification, eventsChanSize), workflowIDToShardID: workflowIDToShardID, @@ -143,16 +93,16 @@ func NewNotifier( } func (notifier *NotifierImpl) WatchHistoryEvent( - identifier definition.WorkflowKey) (string, chan *Notification, error) { + identifier definition.WorkflowKey) (string, chan *definition.Notification, error) { - channel := make(chan *Notification, 1) + channel := make(chan *definition.Notification, 1) subscriberID := uuid.New() - subscribers := map[string]chan *Notification{ + subscribers := map[string]chan *definition.Notification{ subscriberID: channel, } _, _, err := notifier.eventsPubsubs.PutOrDo(identifier, subscribers, func(key interface{}, value interface{}) error { - subscribers := value.(map[string]chan *Notification) + subscribers := value.(map[string]chan *definition.Notification) if _, ok := subscribers[subscriberID]; ok { // UUID collision @@ -174,7 +124,7 @@ func (notifier *NotifierImpl) UnwatchHistoryEvent( success := true notifier.eventsPubsubs.RemoveIf(identifier, func(key interface{}, value interface{}) bool { - subscribers := value.(map[string]chan *Notification) + subscribers := value.(map[string]chan *definition.Notification) if _, ok := subscribers[subscriberID]; !ok { // cannot find the subscribe ID, which means there is a bug @@ -194,13 +144,13 @@ func (notifier *NotifierImpl) UnwatchHistoryEvent( return nil } -func (notifier *NotifierImpl) dispatchHistoryEventNotification(event *Notification) { +func (notifier *NotifierImpl) dispatchHistoryEventNotification(event *definition.Notification) { identifier := event.ID startTime := time.Now().UTC() defer notifier.metricsHandler.Timer(metrics.HistoryEventNotificationFanoutLatency.GetMetricName()).Record(time.Since(startTime)) _, _, _ = notifier.eventsPubsubs.GetAndDo(identifier, func(key interface{}, value interface{}) error { - subscribers := value.(map[string]chan *Notification) + subscribers := value.(map[string]chan *definition.Notification) for _, channel := range subscribers { select { @@ -214,7 +164,7 @@ func (notifier *NotifierImpl) dispatchHistoryEventNotification(event *Notificati }) } -func (notifier *NotifierImpl) enqueueHistoryEventNotification(event *Notification) { +func (notifier *NotifierImpl) enqueueHistoryEventNotification(event *definition.Notification) { // set the Timestamp just before enqueuing the event event.Timestamp = notifier.timeSource.Now() select { @@ -258,6 +208,6 @@ func (notifier *NotifierImpl) Stop() { close(notifier.closeChan) } -func (notifier *NotifierImpl) NotifyNewHistoryEvent(event *Notification) { +func (notifier *NotifierImpl) NotifyNewHistoryEvent(event *definition.Notification) { notifier.enqueueHistoryEventNotification(event) } diff --git a/service/history/events/notifier_test.go b/service/history/events/notifier_test.go index 1630e0cba9b..3c7b652df53 100644 --- a/service/history/events/notifier_test.go +++ b/service/history/events/notifier_test.go @@ -36,9 +36,9 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" "go.temporal.io/server/common/clock" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" + "go.temporal.io/server/service/history/definition" ) type ( @@ -94,7 +94,7 @@ func (s *notifierSuite) TestSingleSubscriberWatchingEvents() { workflowState := enumsspb.WORKFLOW_EXECUTION_STATE_CREATED workflowStatus := enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING branchToken := make([]byte, 0) - historyEvent := NewNotification(namespaceID, execution, lastFirstEventID, lastFirstEventTxnID, nextEventID, previousStartedEventID, branchToken, workflowState, workflowStatus) + historyEvent := definition.NewNotification(namespaceID, execution, lastFirstEventID, lastFirstEventTxnID, nextEventID, previousStartedEventID, branchToken, workflowState, workflowStatus) timerChan := time.NewTimer(time.Second * 2).C subscriberID, channel, err := s.notifier.WatchHistoryEvent(definition.NewWorkflowKey(namespaceID, execution.GetWorkflowId(), execution.GetRunId())) @@ -126,7 +126,7 @@ func (s *notifierSuite) TestMultipleSubscriberWatchingEvents() { workflowState := enumsspb.WORKFLOW_EXECUTION_STATE_CREATED workflowStatus := enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING branchToken := make([]byte, 0) - historyEvent := NewNotification(namespaceID, execution, lastFirstEventID, lastFirstEventTxnID, nextEventID, previousStartedEventID, branchToken, workflowState, workflowStatus) + historyEvent := definition.NewNotification(namespaceID, execution, lastFirstEventID, lastFirstEventTxnID, nextEventID, previousStartedEventID, branchToken, workflowState, workflowStatus) timerChan := time.NewTimer(time.Second * 5).C subscriberCount := 100 diff --git a/service/history/fx.go b/service/history/fx.go index bd988a654f5..8d0d4c47992 100644 --- a/service/history/fx.go +++ b/service/history/fx.go @@ -55,7 +55,9 @@ import ( "go.temporal.io/server/service/history/api" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/events" + "go.temporal.io/server/service/history/ndc" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/workflow" warchiver "go.temporal.io/server/service/worker/archiver" @@ -67,6 +69,7 @@ var Module = fx.Options( shard.Module, fx.Provide(dynamicconfig.NewCollection), fx.Provide(ConfigProvider), // might be worth just using provider for configs.Config directly + fx.Provide(WorkflowCacheProvider), fx.Provide(RetryableInterceptorProvider), fx.Provide(TelemetryInterceptorProvider), fx.Provide(RateLimitInterceptorProvider), @@ -77,6 +80,7 @@ var Module = fx.Options( fx.Provide(PersistenceRateLimitingParamsProvider), fx.Provide(ServiceResolverProvider), fx.Provide(EventNotifierProvider), + fx.Provide(EventReapplierProvider), fx.Provide(ArchivalClientProvider), fx.Provide(HistoryEngineFactoryProvider), fx.Provide(HandlerProvider), @@ -116,28 +120,34 @@ func ServiceResolverProvider(membershipMonitor membership.Monitor) (membership.S func HandlerProvider(args NewHandlerArgs) *Handler { handler := &Handler{ - status: common.DaemonStatusInitialized, - config: args.Config, - tokenSerializer: common.NewProtoTaskTokenSerializer(), - logger: args.Logger, - throttledLogger: args.ThrottledLogger, - persistenceExecutionManager: args.PersistenceExecutionManager, - persistenceShardManager: args.PersistenceShardManager, - persistenceVisibilityManager: args.PersistenceVisibilityManager, - historyServiceResolver: args.HistoryServiceResolver, - metricsHandler: args.MetricsHandler, - payloadSerializer: args.PayloadSerializer, - timeSource: args.TimeSource, - namespaceRegistry: args.NamespaceRegistry, - saProvider: args.SaProvider, - saMapper: args.SaMapper, - clusterMetadata: args.ClusterMetadata, - archivalMetadata: args.ArchivalMetadata, - hostInfoProvider: args.HostInfoProvider, - controller: args.ShardController, - eventNotifier: args.EventNotifier, - replicationTaskFetcherFactory: args.ReplicationTaskFetcherFactory, - tracer: args.TracerProvider.Tracer(consts.LibraryName), + status: common.DaemonStatusInitialized, + archivalClient: args.ArchivalClient, + config: args.Config, + clientBean: args.ClientBean, + tokenSerializer: common.NewProtoTaskTokenSerializer(), + logger: args.Logger, + throttledLogger: args.ThrottledLogger, + persistenceExecutionManager: args.PersistenceExecutionManager, + persistenceShardManager: args.PersistenceShardManager, + persistenceVisibilityManager: args.PersistenceVisibilityManager, + historyServiceResolver: args.HistoryServiceResolver, + metricsHandler: args.MetricsHandler, + matchingClient: args.MatchingClient, + payloadSerializer: args.PayloadSerializer, + timeSource: args.TimeSource, + namespaceRegistry: args.NamespaceRegistry, + saProvider: args.SaProvider, + saMapper: args.SaMapper, + clusterMetadata: args.ClusterMetadata, + archivalMetadata: args.ArchivalMetadata, + hostInfoProvider: args.HostInfoProvider, + controller: args.ShardController, + eventNotifier: args.EventNotifier, + eventSerializer: args.EventSerializer, + replicationTaskFetcherFactory: args.ReplicationTaskFetcherFactory, + replicationTaskExecutorProvider: args.ReplicationTaskExecutorProvider, + tracer: args.TracerProvider.Tracer(consts.LibraryName), + workflowCache: args.WorkflowCache, } // prevent us from trying to serve requests before shard controller is started and ready @@ -164,6 +174,12 @@ func ConfigProvider( esConfig.GetVisibilityIndex()) } +func WorkflowCacheProvider( + config *configs.Config, +) *Cache { + return NewCache(config.NumberOfShards) +} + func ThrottledLoggerRpsFnProvider(serviceConfig *configs.Config) resource.ThrottledLoggerRpsFn { return func() float64 { return float64(serviceConfig.ThrottledLogRPS()) } } @@ -259,7 +275,7 @@ func EventNotifierProvider( timeSource clock.TimeSource, metricsHandler metrics.MetricsHandler, config *configs.Config, -) events.Notifier { +) definition.Notifier { return events.NewNotifier( timeSource, metricsHandler, @@ -267,6 +283,16 @@ func EventNotifierProvider( ) } +func EventReapplierProvider( + metricsHandler metrics.MetricsHandler, + logger log.SnTaggedLogger, +) ndc.EventsReapplier { + return ndc.NewEventsReapplier( + metricsHandler, + logger, + ) +} + func ArchivalClientProvider( archiverProvider provider.ArchiverProvider, sdkClientFactory sdk.ClientFactory, diff --git a/service/history/handler.go b/service/history/handler.go index 7c278c3fb07..e4e3c7be889 100644 --- a/service/history/handler.go +++ b/service/history/handler.go @@ -44,6 +44,7 @@ import ( namespacespb "go.temporal.io/server/api/namespace/v1" replicationspb "go.temporal.io/server/api/replication/v1" tokenspb "go.temporal.io/server/api/token/v1" + "go.temporal.io/server/client" "go.temporal.io/server/common" "go.temporal.io/server/common/archiver" "go.temporal.io/server/common/clock" @@ -59,14 +60,39 @@ import ( "go.temporal.io/server/common/persistence/visibility/manager" "go.temporal.io/server/common/persistence/visibility/store/standard/cassandra" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/common/resource" "go.temporal.io/server/common/searchattribute" serviceerrors "go.temporal.io/server/common/serviceerror" "go.temporal.io/server/service/history/api" + "go.temporal.io/server/service/history/api/deleteworkflow" + "go.temporal.io/server/service/history/api/describemutablestate" + "go.temporal.io/server/service/history/api/describeworkflow" + "go.temporal.io/server/service/history/api/queryworkflow" + "go.temporal.io/server/service/history/api/reapplyevents" + "go.temporal.io/server/service/history/api/recordactivitytaskheartbeat" + "go.temporal.io/server/service/history/api/recordactivitytaskstarted" + "go.temporal.io/server/service/history/api/recordchildworkflowcompleted" + "go.temporal.io/server/service/history/api/refreshworkflow" + "go.temporal.io/server/service/history/api/removesignalmutablestate" + replicationapi "go.temporal.io/server/service/history/api/replication" + "go.temporal.io/server/service/history/api/requestcancelworkflow" + "go.temporal.io/server/service/history/api/resetstickytaskqueue" + "go.temporal.io/server/service/history/api/resetworkflow" + "go.temporal.io/server/service/history/api/respondactivitytaskcanceled" + "go.temporal.io/server/service/history/api/respondactivitytaskcompleted" + "go.temporal.io/server/service/history/api/respondactivitytaskfailed" + "go.temporal.io/server/service/history/api/signalwithstartworkflow" + "go.temporal.io/server/service/history/api/signalworkflow" + "go.temporal.io/server/service/history/api/startworkflow" + "go.temporal.io/server/service/history/api/terminateworkflow" + "go.temporal.io/server/service/history/api/verifychildworkflowcompletionrecorded" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/events" + "go.temporal.io/server/service/history/definition" + "go.temporal.io/server/service/history/ndc" "go.temporal.io/server/service/history/replication" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" + "go.temporal.io/server/service/history/workflow" + archiverclient "go.temporal.io/server/service/worker/archiver" ) type ( @@ -75,53 +101,69 @@ type ( Handler struct { status int32 - tokenSerializer common.TaskTokenSerializer - startWG sync.WaitGroup - config *configs.Config - eventNotifier events.Notifier - replicationTaskFetcherFactory replication.TaskFetcherFactory - logger log.Logger - throttledLogger log.Logger - persistenceExecutionManager persistence.ExecutionManager - persistenceShardManager persistence.ShardManager - persistenceVisibilityManager manager.VisibilityManager - historyServiceResolver membership.ServiceResolver - metricsHandler metrics.MetricsHandler - payloadSerializer serialization.Serializer - timeSource clock.TimeSource - namespaceRegistry namespace.Registry - saProvider searchattribute.Provider - saMapper searchattribute.Mapper - clusterMetadata cluster.Metadata - archivalMetadata archiver.ArchivalMetadata - hostInfoProvider membership.HostInfoProvider - controller shard.Controller - tracer trace.Tracer + archivalClient archiverclient.Client + clientBean client.Bean + tokenSerializer common.TaskTokenSerializer + startWG sync.WaitGroup + config *configs.Config + eventNotifier definition.Notifier + eventReapplier ndc.EventsReapplier + eventSerializer serialization.Serializer + logger log.Logger + throttledLogger log.Logger + persistenceExecutionManager persistence.ExecutionManager + persistenceShardManager persistence.ShardManager + persistenceVisibilityManager manager.VisibilityManager + historyServiceResolver membership.ServiceResolver + metricsHandler metrics.MetricsHandler + matchingClient resource.MatchingClient + rawMatchingClient resource.MatchingRawClient + payloadSerializer serialization.Serializer + timeSource clock.TimeSource + namespaceRegistry namespace.Registry + saProvider searchattribute.Provider + saMapper searchattribute.Mapper + clusterMetadata cluster.Metadata + archivalMetadata archiver.ArchivalMetadata + hostInfoProvider membership.HostInfoProvider + controller definition.ShardController + replicationTaskFetcherFactory replication.TaskFetcherFactory + replicationTaskExecutorProvider replication.TaskExecutorProvider + tracer trace.Tracer + workflowCache *Cache } NewHandlerArgs struct { fx.In - Config *configs.Config - Logger log.SnTaggedLogger - ThrottledLogger log.ThrottledLogger - PersistenceExecutionManager persistence.ExecutionManager - PersistenceShardManager persistence.ShardManager - PersistenceVisibilityManager manager.VisibilityManager - HistoryServiceResolver membership.ServiceResolver - MetricsHandler metrics.MetricsHandler - PayloadSerializer serialization.Serializer - TimeSource clock.TimeSource - NamespaceRegistry namespace.Registry - SaProvider searchattribute.Provider - SaMapper searchattribute.Mapper - ClusterMetadata cluster.Metadata - ArchivalMetadata archiver.ArchivalMetadata - HostInfoProvider membership.HostInfoProvider - ShardController shard.Controller - EventNotifier events.Notifier - ReplicationTaskFetcherFactory replication.TaskFetcherFactory - TracerProvider trace.TracerProvider + Config *configs.Config + ArchivalClient archiverclient.Client + ArchivalMetadata archiver.ArchivalMetadata + ClientBean client.Bean + ClusterMetadata cluster.Metadata + EventNotifier definition.Notifier + EventReapplier ndc.EventsReapplier + EventSerializer serialization.Serializer + HistoryServiceResolver membership.ServiceResolver + HostInfoProvider membership.HostInfoProvider + Logger log.SnTaggedLogger + ThrottledLogger log.ThrottledLogger + MatchingClient resource.MatchingClient + RawMatchingClient resource.MatchingRawClient + MetricsHandler metrics.MetricsHandler + NamespaceRegistry namespace.Registry + PayloadSerializer serialization.Serializer + PersistenceExecutionManager persistence.ExecutionManager + PersistenceShardManager persistence.ShardManager + PersistenceVisibilityManager manager.VisibilityManager + ReplicationTaskExecutorProvider replication.TaskExecutorProvider + ReplicationTaskFetcherFactory replication.TaskFetcherFactory + SaMapper searchattribute.Mapper + SaProvider searchattribute.Provider + ShardController definition.ShardController + TimeSource clock.TimeSource + TracerProvider trace.TracerProvider + WorkflowCache *Cache } ) @@ -210,16 +252,11 @@ func (h *Handler) RecordActivityTaskHeartbeat(ctx context.Context, request *hist if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := recordactivitytaskheartbeat.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - response, err2 := engine.RecordActivityTaskHeartbeat(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - return response, nil } @@ -239,12 +276,8 @@ func (h *Handler) RecordActivityTaskStarted(ctx context.Context, request *histor if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) - if err != nil { - return nil, h.convertError(err) - } - - response, err := engine.RecordActivityTaskStarted(ctx, request) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := recordactivitytaskstarted.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } @@ -323,17 +356,12 @@ func (h *Handler) RespondActivityTaskCompleted(ctx context.Context, request *his if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := respondactivitytaskcompleted.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.RespondActivityTaskCompleted(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } // RespondActivityTaskFailed - records failure of an activity task @@ -362,17 +390,12 @@ func (h *Handler) RespondActivityTaskFailed(ctx context.Context, request *histor if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := respondactivitytaskfailed.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.RespondActivityTaskFailed(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } // RespondActivityTaskCanceled - records failure of an activity task @@ -401,17 +424,12 @@ func (h *Handler) RespondActivityTaskCanceled(ctx context.Context, request *hist if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := respondactivitytaskcanceled.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.RespondActivityTaskCanceled(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } // RespondWorkflowTaskCompleted - records completion of a workflow task @@ -520,13 +538,8 @@ func (h *Handler) StartWorkflowExecution(ctx context.Context, request *historyse if err != nil { return nil, h.convertError(err) } - - engine, err := shardContext.GetEngine(ctx) - if err != nil { - return nil, h.convertError(err) - } - - response, err := engine.StartWorkflowExecution(ctx, request) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := startworkflow.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } @@ -634,15 +647,19 @@ func (h *Handler) RebuildMutableState(ctx context.Context, request *historyservi if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) - if err != nil { - return nil, h.convertError(err) - } - - if err := engine.RebuildMutableState(ctx, namespaceID, commonpb.WorkflowExecution{ - WorkflowId: workflowExecution.WorkflowId, - RunId: workflowExecution.RunId, - }); err != nil { + workflowCache := h.workflowCache.GetOrCreate(shardContext) + if err := NewWorkflowRebuilder( + shardContext, + workflowCache.GetWorkflowCache(), + shardContext.GetLogger(), + ).rebuild( + ctx, + definition.NewWorkflowKey( + request.GetNamespaceId(), + workflowExecution.GetWorkflowId(), + workflowExecution.GetRunId(), + ), + ); err != nil { return nil, h.convertError(err) } return &historyservice.RebuildMutableStateResponse{}, nil @@ -668,16 +685,12 @@ func (h *Handler) DescribeMutableState(ctx context.Context, request *historyserv if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := describemutablestate.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.DescribeMutableState(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - return resp, nil + return response, nil } // GetMutableState - returns the id of the next event in the execution's history @@ -700,16 +713,12 @@ func (h *Handler) GetMutableState(ctx context.Context, request *historyservice.G if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := api.GetOrPollMutableState(ctx, request, shardContext, workflowCache, h.eventNotifier) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.GetMutableState(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - return resp, nil + return response, nil } // PollMutableState - returns the id of the next event in the execution's history @@ -732,16 +741,38 @@ func (h *Handler) PollMutableState(ctx context.Context, request *historyservice. if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := api.GetOrPollMutableState( + ctx, + &historyservice.GetMutableStateRequest{ + NamespaceId: request.GetNamespaceId(), + Execution: request.Execution, + ExpectedNextEventId: request.ExpectedNextEventId, + CurrentBranchToken: request.CurrentBranchToken, + }, + shardContext, + workflowCache, + h.eventNotifier, + ) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.PollMutableState(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - return resp, nil + return &historyservice.PollMutableStateResponse{ + Execution: response.Execution, + WorkflowType: response.WorkflowType, + NextEventId: response.NextEventId, + PreviousStartedEventId: response.PreviousStartedEventId, + LastFirstEventId: response.LastFirstEventId, + LastFirstEventTxnId: response.LastFirstEventTxnId, + TaskQueue: response.TaskQueue, + StickyTaskQueue: response.StickyTaskQueue, + StickyTaskQueueScheduleToStartTimeout: response.StickyTaskQueueScheduleToStartTimeout, + CurrentBranchToken: response.CurrentBranchToken, + VersionHistories: response.VersionHistories, + WorkflowState: response.WorkflowState, + WorkflowStatus: response.WorkflowStatus, + FirstExecutionRunId: response.FirstExecutionRunId, + }, nil } // DescribeWorkflowExecution returns information about the specified workflow execution. @@ -764,16 +795,12 @@ func (h *Handler) DescribeWorkflowExecution(ctx context.Context, request *histor if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := describeworkflow.Invoke(ctx, request, shardContext, workflowCache, h.persistenceVisibilityManager) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.DescribeWorkflowExecution(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - return resp, nil + return response, nil } // RequestCancelWorkflowExecution - requests cancellation of a workflow @@ -791,28 +818,17 @@ func (h *Handler) RequestCancelWorkflowExecution(ctx context.Context, request *h } cancelRequest := request.CancelRequest - h.logger.Debug("RequestCancelWorkflowExecution", - tag.WorkflowNamespace(cancelRequest.GetNamespace()), - tag.WorkflowNamespaceID(request.GetNamespaceId()), - tag.WorkflowID(cancelRequest.WorkflowExecution.GetWorkflowId()), - tag.WorkflowRunID(cancelRequest.WorkflowExecution.GetRunId())) - workflowID := cancelRequest.WorkflowExecution.GetWorkflowId() shardContext, err := h.controller.GetShardByNamespaceWorkflow(namespaceID, workflowID) if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := requestcancelworkflow.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.RequestCancelWorkflowExecution(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } // SignalWorkflowExecution is used to send a signal event to running workflow execution. This results in @@ -836,17 +852,12 @@ func (h *Handler) SignalWorkflowExecution(ctx context.Context, request *historys if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := signalworkflow.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.SignalWorkflowExecution(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } // SignalWithStartWorkflowExecution is used to ensure sending a signal event to a workflow execution. @@ -873,13 +884,10 @@ func (h *Handler) SignalWithStartWorkflowExecution(ctx context.Context, request if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) - if err != nil { - return nil, h.convertError(err) - } + workflowCache := h.workflowCache.GetOrCreate(shardContext) for { - resp, err2 := engine.SignalWithStartWorkflowExecution(ctx, request) + resp, err2 := signalwithstartworkflow.Invoke(ctx, request, shardContext, workflowCache) if err2 == nil { return resp, nil } @@ -930,17 +938,12 @@ func (h *Handler) RemoveSignalMutableState(ctx context.Context, request *history if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := removesignalmutablestate.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.RemoveSignalMutableState(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } // TerminateWorkflowExecution terminates an existing workflow execution by recording WorkflowExecutionTerminated event @@ -964,17 +967,12 @@ func (h *Handler) TerminateWorkflowExecution(ctx context.Context, request *histo if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := terminateworkflow.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.TerminateWorkflowExecution(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } func (h *Handler) DeleteWorkflowExecution(ctx context.Context, request *historyservice.DeleteWorkflowExecutionRequest) (_ *historyservice.DeleteWorkflowExecutionResponse, retError error) { @@ -996,12 +994,15 @@ func (h *Handler) DeleteWorkflowExecution(ctx context.Context, request *historys if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) - if err != nil { - return nil, h.convertError(err) - } - - resp, err := engine.DeleteWorkflowExecution(ctx, request) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + workflowDeleteManager := workflow.NewDeleteManager( + shardContext, + workflowCache.GetWorkflowCache(), + h.config, + h.archivalClient, + shardContext.GetTimeSource(), + ) + resp, err := deleteworkflow.Invoke(ctx, request, shardContext, workflowCache, workflowDeleteManager) if err != nil { return nil, h.convertError(err) } @@ -1029,17 +1030,12 @@ func (h *Handler) ResetWorkflowExecution(ctx context.Context, request *historyse if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := resetworkflow.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.ResetWorkflowExecution(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } // QueryWorkflow queries a workflow. @@ -1061,17 +1057,12 @@ func (h *Handler) QueryWorkflow(ctx context.Context, request *historyservice.Que if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := queryworkflow.Invoke(ctx, request, shardContext, workflowCache, h.matchingClient, h.rawMatchingClient) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.QueryWorkflow(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } // ScheduleWorkflowTask is used for creating a workflow task for already started workflow execution. This is mainly @@ -1178,17 +1169,12 @@ func (h *Handler) RecordChildExecutionCompleted(ctx context.Context, request *hi if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := recordchildworkflowcompleted.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.RecordChildExecutionCompleted(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } func (h *Handler) VerifyChildExecutionCompletionRecorded( @@ -1215,17 +1201,12 @@ func (h *Handler) VerifyChildExecutionCompletionRecorded( if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := verifychildworkflowcompletionrecorded.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err2 := engine.VerifyChildExecutionCompletionRecorded(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - - return resp, nil + return response, nil } // ResetStickyTaskQueue reset the volatile information in mutable state of a given workflow. @@ -1251,17 +1232,12 @@ func (h *Handler) ResetStickyTaskQueue(ctx context.Context, request *historyserv if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + response, err := resetstickytaskqueue.Invoke(ctx, request, shardContext, workflowCache) if err != nil { return nil, h.convertError(err) } - - resp, err := engine.ResetStickyTaskQueue(ctx, request) - if err != nil { - return nil, h.convertError(err) - } - - return resp, nil + return response, nil } // ReplicateEventsV2 is called by processor to replicate history events for passive namespaces @@ -1288,16 +1264,18 @@ func (h *Handler) ReplicateEventsV2(ctx context.Context, request *historyservice if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + historyReplicator := ndc.NewHistoryReplicator( + shardContext, + workflowCache.GetWorkflowCache(), + h.eventReapplier, + h.logger, + h.eventSerializer, + ) + err = historyReplicator.ApplyEvents(ctx, request) if err != nil { return nil, h.convertError(err) } - - err2 := engine.ReplicateEventsV2(ctx, request) - if err2 != nil { - return nil, h.convertError(err2) - } - return &historyservice.ReplicateEventsV2Response{}, nil } @@ -1370,16 +1348,16 @@ func (h *Handler) SyncActivity(ctx context.Context, request *historyservice.Sync if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) - if err != nil { - return nil, h.convertError(err) - } - - err = engine.SyncActivity(ctx, request) + workflowCache := h.workflowCache.GetOrCreate(shardContext) + activityReplicator := ndc.NewActivityReplicator( + shardContext, + workflowCache.GetWorkflowCache(), + h.logger, + ) + err = activityReplicator.SyncActivity(ctx, request) if err != nil { return nil, h.convertError(err) } - return &historyservice.SyncActivityResponse{}, nil } @@ -1531,16 +1509,9 @@ func (h *Handler) ReapplyEvents(ctx context.Context, request *historyservice.Rea } namespaceID := namespace.ID(request.GetNamespaceId()) - workflowID := request.GetRequest().GetWorkflowExecution().GetWorkflowId() - shardContext, err := h.controller.GetShardByNamespaceWorkflow(namespaceID, workflowID) - if err != nil { - return nil, h.convertError(err) - } - engine, err := shardContext.GetEngine(ctx) - if err != nil { - return nil, h.convertError(err) - } - + execution := request.GetRequest().GetWorkflowExecution() + workflowID := execution.GetWorkflowId() + runID := execution.GetRunId() // deserialize history event object historyEvents, err := h.payloadSerializer.DeserializeEvents(&commonpb.DataBlob{ EncodingType: enumspb.ENCODING_TYPE_PROTO3, @@ -1550,14 +1521,28 @@ func (h *Handler) ReapplyEvents(ctx context.Context, request *historyservice.Rea return nil, h.convertError(err) } - execution := request.GetRequest().GetWorkflowExecution() - if err := engine.ReapplyEvents( + shardContext, err := h.controller.GetShardByNamespaceWorkflow(namespaceID, workflowID) + if err != nil { + return nil, h.convertError(err) + } + workflowCache := h.workflowCache.GetOrCreate(shardContext) + workflowResetter := ndc.NewWorkflowResetter( + shardContext, + workflowCache.GetWorkflowCache(), + h.logger, + ) + err = reapplyevents.Invoke( ctx, namespace.ID(request.GetNamespaceId()), - execution.GetWorkflowId(), - execution.GetRunId(), + workflowID, + runID, historyEvents, - ); err != nil { + shardContext, + workflowCache, + workflowResetter, + h.eventReapplier, + ) + if err != nil { return nil, h.convertError(err) } return &historyservice.ReapplyEventsResponse{}, nil @@ -1654,25 +1639,20 @@ func (h *Handler) RefreshWorkflowTasks(ctx context.Context, request *historyserv if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) - if err != nil { - return nil, h.convertError(err) - } - - err = engine.RefreshWorkflowTasks( + workflowCache := h.workflowCache.GetOrCreate(shardContext) + err = refreshworkflow.Invoke( ctx, - namespaceID, - commonpb.WorkflowExecution{ - WorkflowId: execution.WorkflowId, - RunId: execution.RunId, - }, + definition.NewWorkflowKey( + request.NamespaceId, + request.Request.GetExecution().GetWorkflowId(), + request.Request.GetExecution().GetRunId(), + ), + shardContext, + workflowCache, ) - if err != nil { - err = h.convertError(err) - return nil, err + return nil, h.convertError(err) } - return &historyservice.RefreshWorkflowTasksResponse{}, nil } @@ -1693,18 +1673,12 @@ func (h *Handler) GenerateLastHistoryReplicationTasks( if err != nil { return nil, h.convertError(err) } - engine, err := shardContext.GetEngine(ctx) - if err != nil { - return nil, h.convertError(err) - } - - resp, err := engine.GenerateLastHistoryReplicationTasks(ctx, request) - + workflowCache := h.workflowCache.GetOrCreate(shardContext) + resp, err := replicationapi.GenerateTask(ctx, request, shardContext, workflowCache) if err != nil { err = h.convertError(err) return nil, err } - return resp, nil } diff --git a/service/history/historyEngine.go b/service/history/historyEngine.go index 562ef8109c0..40760a65ef7 100644 --- a/service/history/historyEngine.go +++ b/service/history/historyEngine.go @@ -41,7 +41,6 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" @@ -78,11 +77,10 @@ import ( "go.temporal.io/server/service/history/api/verifychildworkflowcompletionrecorded" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/events" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/ndc" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/replication" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/workflow" "go.temporal.io/server/service/worker/archiver" @@ -96,7 +94,7 @@ type ( historyEngineImpl struct { status int32 currentClusterName string - shard shard.Context + shard definition.ShardContext timeSource clock.TimeSource workflowTaskHandler workflowTaskHandlerCallbacks clusterMetadata cluster.Metadata @@ -106,7 +104,7 @@ type ( nDCReplicator ndc.HistoryReplicator nDCActivityReplicator ndc.ActivityReplicator replicationProcessorMgr common.Daemon - eventNotifier events.Notifier + eventNotifier definition.Notifier tokenSerializer common.TaskTokenSerializer metricsHandler metrics.MetricsHandler logger log.Logger @@ -130,14 +128,14 @@ type ( // NewEngineWithShardContext creates an instance of history engine func NewEngineWithShardContext( - shard shard.Context, + shard definition.ShardContext, clientBean client.Bean, matchingClient matchingservice.MatchingServiceClient, sdkClientFactory sdk.ClientFactory, - eventNotifier events.Notifier, + eventNotifier definition.Notifier, + eventsReapplier ndc.EventsReapplier, config *configs.Config, rawMatchingClient matchingservice.MatchingServiceClient, - workflowCache workflow.Cache, archivalClient archiver.Client, eventSerializer serialization.Serializer, queueProcessorFactories []QueueFactory, @@ -146,7 +144,7 @@ func NewEngineWithShardContext( workflowConsistencyChecker api.WorkflowConsistencyChecker, tracerProvider trace.TracerProvider, persistenceVisibilityMgr manager.VisibilityManager, -) shard.Engine { +) definition.Engine { currentClusterName := shard.GetClusterMetadata().GetCurrentClusterName() logger := shard.GetLogger() @@ -154,7 +152,7 @@ func NewEngineWithShardContext( workflowDeleteManager := workflow.NewDeleteManager( shard, - workflowCache, + workflowConsistencyChecker.GetWorkflowCache(), config, archivalClient, shard.GetTimeSource(), @@ -179,46 +177,45 @@ func NewEngineWithShardContext( persistenceVisibilityMgr: persistenceVisibilityMgr, workflowDeleteManager: workflowDeleteManager, eventSerializer: eventSerializer, + eventsReapplier: eventsReapplier, workflowConsistencyChecker: workflowConsistencyChecker, tracer: tracerProvider.Tracer(consts.LibraryName), } historyEngImpl.queueProcessors = make(map[tasks.Category]queues.Queue) for _, factory := range queueProcessorFactories { - processor := factory.CreateQueue(shard, workflowCache) + processor := factory.CreateQueue(shard, workflowConsistencyChecker.GetWorkflowCache()) historyEngImpl.queueProcessors[processor.Category()] = processor } - historyEngImpl.eventsReapplier = ndc.NewEventsReapplier(shard.GetMetricsHandler(), logger) - if shard.GetClusterMetadata().IsGlobalNamespaceEnabled() { historyEngImpl.replicationAckMgr = replication.NewAckManager( shard, - workflowCache, + workflowConsistencyChecker.GetWorkflowCache(), executionManager, logger, ) historyEngImpl.nDCReplicator = ndc.NewHistoryReplicator( shard, - workflowCache, + workflowConsistencyChecker.GetWorkflowCache(), historyEngImpl.eventsReapplier, logger, eventSerializer, ) historyEngImpl.nDCActivityReplicator = ndc.NewActivityReplicator( shard, - workflowCache, + workflowConsistencyChecker.GetWorkflowCache(), logger, ) } historyEngImpl.workflowRebuilder = NewWorkflowRebuilder( shard, - workflowCache, + workflowConsistencyChecker.GetWorkflowCache(), logger, ) historyEngImpl.workflowResetter = ndc.NewWorkflowResetter( shard, - workflowCache, + workflowConsistencyChecker.GetWorkflowCache(), logger, ) @@ -234,7 +231,7 @@ func NewEngineWithShardContext( historyEngImpl.replicationDLQHandler = replication.NewLazyDLQHandler( shard, workflowDeleteManager, - workflowCache, + workflowConsistencyChecker.GetWorkflowCache(), clientBean, replicationTaskExecutorProvider, ) @@ -242,7 +239,7 @@ func NewEngineWithShardContext( config, shard, historyEngImpl, - workflowCache, + workflowConsistencyChecker.GetWorkflowCache(), workflowDeleteManager, clientBean, eventSerializer, @@ -714,7 +711,7 @@ func (e *historyEngineImpl) ResetWorkflowExecution( } func (e *historyEngineImpl) NotifyNewHistoryEvent( - notification *events.Notification, + notification *definition.Notification, ) { e.eventNotifier.NotifyNewHistoryEvent(notification) diff --git a/service/history/historyEngine2_test.go b/service/history/historyEngine2_test.go index da4d52e6fcb..711444005fd 100644 --- a/service/history/historyEngine2_test.go +++ b/service/history/historyEngine2_test.go @@ -45,6 +45,7 @@ import ( "go.temporal.io/server/common/payload" "go.temporal.io/server/common/searchattribute" + "go.temporal.io/server/service/history/definition" enumsspb "go.temporal.io/server/api/enums/v1" historyspb "go.temporal.io/server/api/history/v1" @@ -86,11 +87,11 @@ type ( mockTxProcessor *queues.MockQueue mockTimerProcessor *queues.MockQueue mockVisibilityProcessor *queues.MockQueue - mockEventsCache *events.MockCache + mockEventsCache *definition.MockEventCache mockNamespaceCache *namespace.MockRegistry mockClusterMetadata *cluster.MockMetadata - workflowCache workflow.Cache + workflowCache definition.WorkflowCache historyEngine *historyEngineImpl mockExecutionMgr *persistence.MockExecutionManager @@ -449,7 +450,7 @@ func (s *engine2Suite) TestRecordWorkflowTaskStartedSuccess() { metrics.AddMetricsContext(context.Background()), tests.NamespaceID, workflowExecution, - workflow.CallerTypeAPI, + definition.CallerTypeTask, ) s.NoError(err) loadedMS, err := ctx.LoadMutableState(context.Background()) @@ -550,7 +551,7 @@ func (s *engine2Suite) TestRecordActivityTaskStartedSuccess() { s.mockEventsCache.EXPECT().GetEvent( gomock.Any(), - events.EventKey{ + definition.EventKey{ NamespaceID: namespaceID, WorkflowID: workflowExecution.GetWorkflowId(), RunID: workflowExecution.GetRunId(), @@ -760,7 +761,7 @@ func (s *engine2Suite) createExecutionStartedState( we commonpb.WorkflowExecution, tl string, identity string, startWorkflowTask bool, -) workflow.MutableState { +) definition.MutableState { return s.createExecutionStartedStateWithParent(we, tl, nil, identity, startWorkflowTask) } @@ -769,7 +770,7 @@ func (s *engine2Suite) createExecutionStartedStateWithParent( parentInfo *workflowspb.ParentExecutionInfo, identity string, startWorkflowTask bool, -) workflow.MutableState { +) definition.MutableState { ms := workflow.TestLocalMutableState(s.historyEngine.shard, s.mockEventsCache, tests.LocalNamespaceEntry, s.logger, we.GetRunId()) addWorkflowExecutionStartedEventWithParent(ms, we, "wType", tl, payloads.EncodeString("input"), 100*time.Second, 50*time.Second, 200*time.Second, parentInfo, identity) @@ -1807,7 +1808,7 @@ func (s *engine2Suite) TestRefreshWorkflowTasks() { s.mockExecutionMgr.EXPECT().AddHistoryTasks(gomock.Any(), gomock.Any()).Return(nil) s.mockEventsCache.EXPECT().GetEvent( gomock.Any(), - events.EventKey{ + definition.EventKey{ NamespaceID: tests.NamespaceID, WorkflowID: execution.GetWorkflowId(), RunID: execution.GetRunId(), @@ -1819,7 +1820,7 @@ func (s *engine2Suite) TestRefreshWorkflowTasks() { ).Return(startEvent, nil).AnyTimes() s.mockEventsCache.EXPECT().GetEvent( gomock.Any(), - events.EventKey{ + definition.EventKey{ NamespaceID: tests.NamespaceID, WorkflowID: execution.GetWorkflowId(), RunID: execution.GetRunId(), @@ -1834,12 +1835,12 @@ func (s *engine2Suite) TestRefreshWorkflowTasks() { s.NoError(err) } -func (s *engine2Suite) getMutableState(namespaceID namespace.ID, we commonpb.WorkflowExecution) workflow.MutableState { +func (s *engine2Suite) getMutableState(namespaceID namespace.ID, we commonpb.WorkflowExecution) definition.MutableState { weContext, release, err := s.workflowCache.GetOrCreateWorkflowExecution( metrics.AddMetricsContext(context.Background()), namespaceID, we, - workflow.CallerTypeAPI, + definition.CallerTypeTask, ) if err != nil { return nil diff --git a/service/history/historyEngine3_eventsv2_test.go b/service/history/historyEngine3_eventsv2_test.go index 1b2bfd2bb8c..a3f179012f1 100644 --- a/service/history/historyEngine3_eventsv2_test.go +++ b/service/history/historyEngine3_eventsv2_test.go @@ -52,6 +52,7 @@ import ( "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/api" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" @@ -70,10 +71,10 @@ type ( mockTxProcessor *queues.MockQueue mockTimerProcessor *queues.MockQueue mockVisibilityProcessor *queues.MockQueue - mockEventsCache *events.MockCache + mockEventsCache *definition.MockEventCache mockNamespaceCache *namespace.MockRegistry mockClusterMetadata *cluster.MockMetadata - workflowCache workflow.Cache + workflowCache definition.WorkflowCache historyEngine *historyEngineImpl mockExecutionMgr *persistence.MockExecutionManager diff --git a/service/history/historyEngineFactory.go b/service/history/historyEngineFactory.go index 6a5fcfd5256..4c16f018369 100644 --- a/service/history/historyEngineFactory.go +++ b/service/history/historyEngineFactory.go @@ -33,12 +33,10 @@ import ( "go.temporal.io/server/common/persistence/visibility/manager" "go.temporal.io/server/common/resource" "go.temporal.io/server/common/sdk" - "go.temporal.io/server/service/history/api" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/events" + "go.temporal.io/server/service/history/definition" + "go.temporal.io/server/service/history/ndc" "go.temporal.io/server/service/history/replication" - "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" "go.temporal.io/server/service/worker/archiver" ) @@ -49,10 +47,10 @@ type ( ClientBean client.Bean MatchingClient resource.MatchingClient SdkClientFactory sdk.ClientFactory - EventNotifier events.Notifier + EventNotifier definition.Notifier + EventsReapplier ndc.EventsReapplier Config *configs.Config RawMatchingClient resource.MatchingRawClient - NewCacheFn workflow.NewCacheFn ArchivalClient archiver.Client EventSerializer serialization.Serializer QueueFactories []QueueFactory `group:"queueFactory"` @@ -60,6 +58,7 @@ type ( ReplicationTaskExecutorProvider replication.TaskExecutorProvider TracerProvider trace.TracerProvider PersistenceVisibilityMgr manager.VisibilityManager + WorkflowCache *Cache } historyEngineFactory struct { @@ -68,19 +67,18 @@ type ( ) func (f *historyEngineFactory) CreateEngine( - shard shard.Context, -) shard.Engine { - workflowCache := f.NewCacheFn(shard) - workflowConsistencyChecker := api.NewWorkflowConsistencyChecker(shard, workflowCache) + shard definition.ShardContext, +) definition.Engine { + workflowConsistencyChecker := f.WorkflowCache.GetOrCreate(shard) return NewEngineWithShardContext( shard, f.ClientBean, f.MatchingClient, f.SdkClientFactory, f.EventNotifier, + f.EventsReapplier, f.Config, f.RawMatchingClient, - workflowCache, f.ArchivalClient, f.EventSerializer, f.QueueFactories, diff --git a/service/history/historyEngine_test.go b/service/history/historyEngine_test.go index 26f2d1c21a2..ba44543c1b2 100644 --- a/service/history/historyEngine_test.go +++ b/service/history/historyEngine_test.go @@ -71,6 +71,7 @@ import ( "go.temporal.io/server/service/history/api" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/ndc" "go.temporal.io/server/service/history/queues" @@ -97,12 +98,12 @@ type ( mockEventsReapplier *ndc.MockEventsReapplier mockWorkflowResetter *ndc.MockWorkflowResetter - workflowCache workflow.Cache + workflowCache definition.WorkflowCache mockHistoryEngine *historyEngineImpl mockExecutionMgr *persistence.MockExecutionManager mockShardManager *persistence.MockShardManager - eventsCache events.Cache + eventsCache definition.EventCache config *configs.Config } ) @@ -382,7 +383,7 @@ func (s *engineSuite) TestGetMutableStateLongPoll_CurrentBranchChanged() { WorkflowId: execution.WorkflowId, RunId: execution.RunId, } - s.mockHistoryEngine.eventNotifier.NotifyNewHistoryEvent(events.NewNotification( + s.mockHistoryEngine.eventNotifier.NotifyNewHistoryEvent(definition.NewNotification( "tests.NamespaceID", newExecution, int64(1), @@ -645,7 +646,7 @@ func (s *engineSuite) TestQueryWorkflow_ConsistentQueryBufferFull() { context.Background(), tests.NamespaceID, execution, - workflow.CallerTypeAPI, + definition.CallerTypeTask, ) s.NoError(err) loadedMS, err := ctx.LoadMutableState(context.Background()) @@ -697,7 +698,7 @@ func (s *engineSuite) TestQueryWorkflow_WorkflowTaskDispatch_Complete() { buffered := qr.GetBufferedIDs() for _, id := range buffered { resultType := enumspb.QUERY_RESULT_TYPE_ANSWERED - succeededCompletionState := &workflow.QueryCompletionState{ + succeededCompletionState := &definition.QueryCompletionState{ Type: workflow.QueryCompletionTypeSucceeded, Result: &querypb.WorkflowQueryResult{ ResultType: resultType, @@ -768,7 +769,7 @@ func (s *engineSuite) TestQueryWorkflow_WorkflowTaskDispatch_Unblocked() { qr := ms1.GetQueryRegistry() buffered := qr.GetBufferedIDs() for _, id := range buffered { - s.NoError(qr.SetCompletionState(id, &workflow.QueryCompletionState{Type: workflow.QueryCompletionTypeUnblocked})) + s.NoError(qr.SetCompletionState(id, &definition.QueryCompletionState{Type: workflow.QueryCompletionTypeUnblocked})) state, err := qr.GetCompletionState(id) s.NoError(err) s.Equal(workflow.QueryCompletionTypeUnblocked, state.Type) @@ -4269,7 +4270,7 @@ func (s *engineSuite) TestRequestCancel_RespondWorkflowTaskCompleted_SuccessWith context.Background(), tests.NamespaceID, we, - workflow.CallerTypeAPI, + definition.CallerTypeTask, ) s.NoError(err) loadedMS, err := ctx.LoadMutableState(context.Background()) @@ -4624,7 +4625,7 @@ func (s *engineSuite) TestCancelTimer_RespondWorkflowTaskCompleted_TimerFired() wt2 := addWorkflowTaskScheduledEvent(ms) addWorkflowTaskStartedEvent(ms, wt2.ScheduledEventID, tl, identity) addTimerFiredEvent(ms, timerID) - _, _, err := ms.CloseTransactionAsMutation(time.Now().UTC(), workflow.TransactionPolicyActive) + _, _, err := ms.CloseTransactionAsMutation(time.Now().UTC(), definition.TransactionPolicyActive) s.Nil(err) wfMs := workflow.TestCloneToProto(ms) @@ -5060,12 +5061,12 @@ func (s *engineSuite) TestReapplyEvents_ResetWorkflow() { s.NoError(err) } -func (s *engineSuite) getMutableState(testNamespaceID namespace.ID, we commonpb.WorkflowExecution) workflow.MutableState { +func (s *engineSuite) getMutableState(testNamespaceID namespace.ID, we commonpb.WorkflowExecution) definition.MutableState { context, release, err := s.workflowCache.GetOrCreateWorkflowExecution( context.Background(), tests.NamespaceID, we, - workflow.CallerTypeAPI, + definition.CallerTypeTask, ) if err != nil { return nil @@ -5076,14 +5077,14 @@ func (s *engineSuite) getMutableState(testNamespaceID namespace.ID, we commonpb. } func (s *engineSuite) getActivityScheduledEvent( - ms workflow.MutableState, + ms definition.MutableState, scheduledEventID int64, ) *historypb.HistoryEvent { event, _ := ms.GetActivityScheduledEvent(context.Background(), scheduledEventID) return event } -func addWorkflowExecutionStartedEventWithParent(ms workflow.MutableState, workflowExecution commonpb.WorkflowExecution, +func addWorkflowExecutionStartedEventWithParent(ms definition.MutableState, workflowExecution commonpb.WorkflowExecution, workflowType, taskQueue string, input *commonpb.Payloads, executionTimeout, runTimeout, taskTimeout time.Duration, parentInfo *workflowspb.ParentExecutionInfo, identity string) *historypb.HistoryEvent { @@ -5111,24 +5112,24 @@ func addWorkflowExecutionStartedEventWithParent(ms workflow.MutableState, workfl return event } -func addWorkflowExecutionStartedEvent(ms workflow.MutableState, workflowExecution commonpb.WorkflowExecution, +func addWorkflowExecutionStartedEvent(ms definition.MutableState, workflowExecution commonpb.WorkflowExecution, workflowType, taskQueue string, input *commonpb.Payloads, executionTimeout, runTimeout, taskTimeout time.Duration, identity string) *historypb.HistoryEvent { return addWorkflowExecutionStartedEventWithParent(ms, workflowExecution, workflowType, taskQueue, input, executionTimeout, runTimeout, taskTimeout, nil, identity) } -func addWorkflowTaskScheduledEvent(ms workflow.MutableState) *workflow.WorkflowTaskInfo { +func addWorkflowTaskScheduledEvent(ms definition.MutableState) *definition.WorkflowTaskInfo { workflowTask, _ := ms.AddWorkflowTaskScheduledEvent(false) return workflowTask } -func addWorkflowTaskStartedEvent(ms workflow.MutableState, scheduledEventID int64, taskQueue, +func addWorkflowTaskStartedEvent(ms definition.MutableState, scheduledEventID int64, taskQueue, identity string) *historypb.HistoryEvent { return addWorkflowTaskStartedEventWithRequestID(ms, scheduledEventID, tests.RunID, taskQueue, identity) } -func addWorkflowTaskStartedEventWithRequestID(ms workflow.MutableState, scheduledEventID int64, requestID string, +func addWorkflowTaskStartedEventWithRequestID(ms definition.MutableState, scheduledEventID int64, requestID string, taskQueue, identity string) *historypb.HistoryEvent { event, _, _ := ms.AddWorkflowTaskStartedEvent( scheduledEventID, @@ -5140,7 +5141,7 @@ func addWorkflowTaskStartedEventWithRequestID(ms workflow.MutableState, schedule return event } -func addWorkflowTaskCompletedEvent(ms workflow.MutableState, scheduledEventID, startedEventID int64, identity string) *historypb.HistoryEvent { +func addWorkflowTaskCompletedEvent(ms definition.MutableState, scheduledEventID, startedEventID int64, identity string) *historypb.HistoryEvent { event, _ := ms.AddWorkflowTaskCompletedEvent(scheduledEventID, startedEventID, &workflowservice.RespondWorkflowTaskCompletedRequest{ Identity: identity, }, configs.DefaultHistoryMaxAutoResetPoints) @@ -5151,7 +5152,7 @@ func addWorkflowTaskCompletedEvent(ms workflow.MutableState, scheduledEventID, s } func addActivityTaskScheduledEvent( - ms workflow.MutableState, + ms definition.MutableState, workflowTaskCompletedID int64, activityID, activityType, taskQueue string, @@ -5178,7 +5179,7 @@ func addActivityTaskScheduledEvent( } func addActivityTaskScheduledEventWithRetry( - ms workflow.MutableState, + ms definition.MutableState, workflowTaskCompletedID int64, activityID, activityType, taskQueue string, @@ -5205,13 +5206,13 @@ func addActivityTaskScheduledEventWithRetry( return event, ai } -func addActivityTaskStartedEvent(ms workflow.MutableState, scheduledEventID int64, identity string) *historypb.HistoryEvent { +func addActivityTaskStartedEvent(ms definition.MutableState, scheduledEventID int64, identity string) *historypb.HistoryEvent { ai, _ := ms.GetActivityInfo(scheduledEventID) event, _ := ms.AddActivityTaskStartedEvent(ai, scheduledEventID, tests.RunID, identity) return event } -func addActivityTaskCompletedEvent(ms workflow.MutableState, scheduledEventID, startedEventID int64, result *commonpb.Payloads, +func addActivityTaskCompletedEvent(ms definition.MutableState, scheduledEventID, startedEventID int64, result *commonpb.Payloads, identity string) *historypb.HistoryEvent { event, _ := ms.AddActivityTaskCompletedEvent(scheduledEventID, startedEventID, &workflowservice.RespondActivityTaskCompletedRequest{ Result: result, @@ -5221,12 +5222,12 @@ func addActivityTaskCompletedEvent(ms workflow.MutableState, scheduledEventID, s return event } -func addActivityTaskFailedEvent(ms workflow.MutableState, scheduledEventID, startedEventID int64, failure *failurepb.Failure, retryState enumspb.RetryState, identity string) *historypb.HistoryEvent { +func addActivityTaskFailedEvent(ms definition.MutableState, scheduledEventID, startedEventID int64, failure *failurepb.Failure, retryState enumspb.RetryState, identity string) *historypb.HistoryEvent { event, _ := ms.AddActivityTaskFailedEvent(scheduledEventID, startedEventID, failure, retryState, identity) return event } -func addTimerStartedEvent(ms workflow.MutableState, workflowTaskCompletedEventID int64, timerID string, +func addTimerStartedEvent(ms definition.MutableState, workflowTaskCompletedEventID int64, timerID string, timeout time.Duration) (*historypb.HistoryEvent, *persistencespb.TimerInfo) { event, ti, _ := ms.AddTimerStartedEvent(workflowTaskCompletedEventID, &commandpb.StartTimerCommandAttributes{ @@ -5236,12 +5237,12 @@ func addTimerStartedEvent(ms workflow.MutableState, workflowTaskCompletedEventID return event, ti } -func addTimerFiredEvent(ms workflow.MutableState, timerID string) *historypb.HistoryEvent { +func addTimerFiredEvent(ms definition.MutableState, timerID string) *historypb.HistoryEvent { event, _ := ms.AddTimerFiredEvent(timerID) return event } -func addRequestCancelInitiatedEvent(ms workflow.MutableState, workflowTaskCompletedEventID int64, +func addRequestCancelInitiatedEvent(ms definition.MutableState, workflowTaskCompletedEventID int64, cancelRequestID string, namespace namespace.Name, namespaceID namespace.ID, workflowID, runID string) (*historypb.HistoryEvent, *persistencespb.RequestCancelInfo) { event, rci, _ := ms.AddRequestCancelExternalWorkflowExecutionInitiatedEvent(workflowTaskCompletedEventID, cancelRequestID, &commandpb.RequestCancelExternalWorkflowExecutionCommandAttributes{ @@ -5255,12 +5256,12 @@ func addRequestCancelInitiatedEvent(ms workflow.MutableState, workflowTaskComple return event, rci } -func addCancelRequestedEvent(ms workflow.MutableState, initiatedID int64, namespace namespace.Name, namespaceID namespace.ID, workflowID, runID string) *historypb.HistoryEvent { +func addCancelRequestedEvent(ms definition.MutableState, initiatedID int64, namespace namespace.Name, namespaceID namespace.ID, workflowID, runID string) *historypb.HistoryEvent { event, _ := ms.AddExternalWorkflowExecutionCancelRequested(initiatedID, namespace, namespaceID, workflowID, runID) return event } -func addRequestSignalInitiatedEvent(ms workflow.MutableState, workflowTaskCompletedEventID int64, +func addRequestSignalInitiatedEvent(ms definition.MutableState, workflowTaskCompletedEventID int64, signalRequestID string, namespace namespace.Name, namespaceID namespace.ID, workflowID, runID, signalName string, input *commonpb.Payloads, control string, header *commonpb.Header) (*historypb.HistoryEvent, *persistencespb.SignalInfo) { event, si, _ := ms.AddSignalExternalWorkflowExecutionInitiatedEvent(workflowTaskCompletedEventID, signalRequestID, @@ -5279,13 +5280,13 @@ func addRequestSignalInitiatedEvent(ms workflow.MutableState, workflowTaskComple return event, si } -func addSignaledEvent(ms workflow.MutableState, initiatedID int64, namespace namespace.Name, namespaceID namespace.ID, workflowID, runID string, control string) *historypb.HistoryEvent { +func addSignaledEvent(ms definition.MutableState, initiatedID int64, namespace namespace.Name, namespaceID namespace.ID, workflowID, runID string, control string) *historypb.HistoryEvent { event, _ := ms.AddExternalWorkflowExecutionSignaled(initiatedID, namespace, namespaceID, workflowID, runID, control) return event } func addStartChildWorkflowExecutionInitiatedEvent( - ms workflow.MutableState, + ms definition.MutableState, workflowTaskCompletedID int64, createRequestID string, namespace namespace.Name, @@ -5312,7 +5313,7 @@ func addStartChildWorkflowExecutionInitiatedEvent( return event, cei } -func addChildWorkflowExecutionStartedEvent(ms workflow.MutableState, initiatedID int64, workflowID, runID string, +func addChildWorkflowExecutionStartedEvent(ms definition.MutableState, initiatedID int64, workflowID, runID string, workflowType string, clock *clockspb.VectorClock) *historypb.HistoryEvent { event, _ := ms.AddChildWorkflowExecutionStartedEvent( &commonpb.WorkflowExecution{ @@ -5327,13 +5328,13 @@ func addChildWorkflowExecutionStartedEvent(ms workflow.MutableState, initiatedID return event } -func addChildWorkflowExecutionCompletedEvent(ms workflow.MutableState, initiatedID int64, childExecution *commonpb.WorkflowExecution, +func addChildWorkflowExecutionCompletedEvent(ms definition.MutableState, initiatedID int64, childExecution *commonpb.WorkflowExecution, attributes *historypb.WorkflowExecutionCompletedEventAttributes) *historypb.HistoryEvent { event, _ := ms.AddChildWorkflowExecutionCompletedEvent(initiatedID, childExecution, attributes) return event } -func addCompleteWorkflowEvent(ms workflow.MutableState, workflowTaskCompletedEventID int64, +func addCompleteWorkflowEvent(ms definition.MutableState, workflowTaskCompletedEventID int64, result *commonpb.Payloads) *historypb.HistoryEvent { event, _ := ms.AddCompletedWorkflowEvent( workflowTaskCompletedEventID, @@ -5345,7 +5346,7 @@ func addCompleteWorkflowEvent(ms workflow.MutableState, workflowTaskCompletedEve } func addFailWorkflowEvent( - ms workflow.MutableState, + ms definition.MutableState, workflowTaskCompletedEventID int64, failure *failurepb.Failure, retryState enumspb.RetryState, diff --git a/service/history/nDCStandbyTaskUtil.go b/service/history/nDCStandbyTaskUtil.go index 89040f47b09..ca467e53930 100644 --- a/service/history/nDCStandbyTaskUtil.go +++ b/service/history/nDCStandbyTaskUtil.go @@ -38,12 +38,12 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" ) type ( - standbyActionFn func(context.Context, workflow.Context, workflow.MutableState) (interface{}, error) + standbyActionFn func(context.Context, definition.WorkflowContext, definition.MutableState) (interface{}, error) standbyPostActionFn func(context.Context, tasks.Task, interface{}, log.Logger) error standbyCurrentTimeFn func() time.Time @@ -140,7 +140,7 @@ func newHistoryResendInfo( } func newActivityTaskPostActionInfo( - mutableState workflow.MutableState, + mutableState definition.MutableState, activityScheduleToStartTimeout time.Duration, ) (*activityTaskPostActionInfo, error) { resendInfo, err := getHistoryResendInfo(mutableState) @@ -155,7 +155,7 @@ func newActivityTaskPostActionInfo( } func newActivityRetryTimePostActionInfo( - mutableState workflow.MutableState, + mutableState definition.MutableState, taskQueue string, activityScheduleToStartTimeout time.Duration, ) (*activityTaskPostActionInfo, error) { @@ -172,7 +172,7 @@ func newActivityRetryTimePostActionInfo( } func newWorkflowTaskPostActionInfo( - mutableState workflow.MutableState, + mutableState definition.MutableState, workflowTaskScheduleToStartTimeout int64, taskqueue taskqueuepb.TaskQueue, ) (*workflowTaskPostActionInfo, error) { @@ -189,7 +189,7 @@ func newWorkflowTaskPostActionInfo( } func getHistoryResendInfo( - mutableState workflow.MutableState, + mutableState definition.MutableState, ) (*historyResendInfo, error) { currentBranch, err := versionhistory.GetCurrentVersionHistory(mutableState.GetExecutionInfo().GetVersionHistories()) diff --git a/service/history/nDCTaskUtil.go b/service/history/nDCTaskUtil.go index d240744d1e0..46ba05b1d9b 100644 --- a/service/history/nDCTaskUtil.go +++ b/service/history/nDCTaskUtil.go @@ -36,14 +36,13 @@ import ( "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" ) // CheckTaskVersion will return an error if task version check fails func CheckTaskVersion( - shard shard.Context, + shard definition.ShardContext, logger log.Logger, namespace *namespace.Namespace, version int64, @@ -71,11 +70,11 @@ func CheckTaskVersion( // if still mutable state's next event ID <= task ID, will return nil, nil func loadMutableStateForTransferTask( ctx context.Context, - wfContext workflow.Context, + wfContext definition.WorkflowContext, transferTask tasks.Task, metricsHandler metrics.MetricsHandler, logger log.Logger, -) (workflow.MutableState, error) { +) (definition.MutableState, error) { logger = tasks.InitializeLogger(transferTask, logger) mutableState, err := LoadMutableStateForTask( ctx, @@ -115,11 +114,11 @@ func loadMutableStateForTransferTask( // if still mutable state's next event ID <= task ID, will return nil, nil func loadMutableStateForTimerTask( ctx context.Context, - wfContext workflow.Context, + wfContext definition.WorkflowContext, timerTask tasks.Task, metricsHandler metrics.MetricsHandler, logger log.Logger, -) (workflow.MutableState, error) { +) (definition.MutableState, error) { logger = tasks.InitializeLogger(timerTask, logger) return LoadMutableStateForTask( ctx, @@ -133,12 +132,12 @@ func loadMutableStateForTimerTask( func LoadMutableStateForTask( ctx context.Context, - wfContext workflow.Context, + wfContext definition.WorkflowContext, task tasks.Task, taskEventIDAndRetryable func(task tasks.Task, executionInfo *persistencespb.WorkflowExecutionInfo) (int64, bool), metricsHandler metrics.MetricsHandler, logger log.Logger, -) (workflow.MutableState, error) { +) (definition.MutableState, error) { mutableState, err := wfContext.LoadMutableState(ctx) if err != nil { diff --git a/service/history/ndc/activity_replicator.go b/service/history/ndc/activity_replicator.go index 1a11426898f..bf56c0e836e 100644 --- a/service/history/ndc/activity_replicator.go +++ b/service/history/ndc/activity_replicator.go @@ -30,7 +30,7 @@ import ( "context" "time" - "go.temporal.io/server/common/definition" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" commonpb "go.temporal.io/api/common/v1" @@ -50,7 +50,6 @@ import ( "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" serviceerrors "go.temporal.io/server/common/serviceerror" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/workflow" ) @@ -68,15 +67,15 @@ type ( } ActivityReplicatorImpl struct { - historyCache workflow.Cache + historyCache definition.WorkflowCache clusterMetadata cluster.Metadata logger log.Logger } ) func NewActivityReplicator( - shard shard.Context, - historyCache workflow.Cache, + shard definition.ShardContext, + historyCache definition.WorkflowCache, logger log.Logger, ) *ActivityReplicatorImpl { @@ -107,7 +106,7 @@ func (r *ActivityReplicatorImpl) SyncActivity( ctx, namespaceID, execution, - workflow.CallerTypeAPI, + definition.CallerTypeTask, ) if err != nil { // for get workflow execution context, with valid run id @@ -211,7 +210,7 @@ func (r *ActivityReplicatorImpl) SyncActivity( updateMode, nil, // no new workflow nil, // no new workflow - workflow.TransactionPolicyPassive, + definition.TransactionPolicyPassive, nil, ) } @@ -279,7 +278,7 @@ func (r *ActivityReplicatorImpl) testVersionHistory( workflowID string, runID string, scheduledEventID int64, - mutableState workflow.MutableState, + mutableState definition.MutableState, incomingVersionHistory *historyspb.VersionHistory, ) (bool, error) { diff --git a/service/history/ndc/activity_replicator_test.go b/service/history/ndc/activity_replicator_test.go index 4812043f95a..35b6105e75b 100644 --- a/service/history/ndc/activity_replicator_test.go +++ b/service/history/ndc/activity_replicator_test.go @@ -42,12 +42,12 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/primitives/timestamp" serviceerrors "go.temporal.io/server/common/serviceerror" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" @@ -66,7 +66,7 @@ type ( mockTimerProcessor *queues.MockQueue mockNamespaceCache *namespace.MockRegistry mockClusterMetadata *cluster.MockMetadata - mockMutableState *workflow.MockMutableState + mockMutableState *definition.MockMutableState mockExecutionMgr *persistence.MockExecutionManager @@ -94,7 +94,7 @@ func (s *activityReplicatorSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockMutableState = workflow.NewMockMutableState(s.controller) + s.mockMutableState = definition.NewMockMutableState(s.controller) s.mockTxProcessor = queues.NewMockQueue(s.controller) s.mockTimerProcessor = queues.NewMockQueue(s.controller) s.mockTxProcessor.EXPECT().Category().Return(tasks.CategoryTransfer).AnyTimes() @@ -110,7 +110,7 @@ func (s *activityReplicatorSuite) SetupTest() { }}, tests.NewDynamicConfig(), ) - s.workflowCache = workflow.NewCache(s.mockShard).(*workflow.CacheImpl) + s.workflowCache = workflow.NewCache(s.mockShard) s.mockNamespaceCache = s.mockShard.Resource.NamespaceCache s.mockExecutionMgr = s.mockShard.Resource.ExecutionMgr @@ -640,10 +640,10 @@ func (s *activityReplicatorSuite) TestSyncActivity_WorkflowClosed() { } key := definition.NewWorkflowKey(namespaceID.String(), workflowID, runID) - weContext := workflow.NewMockContext(s.controller) + weContext := definition.NewMockWorkflowContext(s.controller) weContext.EXPECT().LoadMutableState(gomock.Any()).Return(s.mockMutableState, nil) - weContext.EXPECT().Lock(gomock.Any(), workflow.CallerTypeAPI).Return(nil) - weContext.EXPECT().Unlock(workflow.CallerTypeAPI) + weContext.EXPECT().Lock(gomock.Any(), definition.CallerTypeTask).Return(nil) + weContext.EXPECT().Unlock(definition.CallerTypeTask) _, err := s.workflowCache.PutIfNotExist(key, weContext) s.NoError(err) @@ -714,10 +714,10 @@ func (s *activityReplicatorSuite) TestSyncActivity_ActivityNotFound() { } key := definition.NewWorkflowKey(namespaceID.String(), workflowID, runID) - weContext := workflow.NewMockContext(s.controller) + weContext := definition.NewMockWorkflowContext(s.controller) weContext.EXPECT().LoadMutableState(gomock.Any()).Return(s.mockMutableState, nil) - weContext.EXPECT().Lock(gomock.Any(), workflow.CallerTypeAPI).Return(nil) - weContext.EXPECT().Unlock(workflow.CallerTypeAPI) + weContext.EXPECT().Lock(gomock.Any(), definition.CallerTypeTask).Return(nil) + weContext.EXPECT().Unlock(definition.CallerTypeTask) _, err := s.workflowCache.PutIfNotExist(key, weContext) s.NoError(err) @@ -789,10 +789,10 @@ func (s *activityReplicatorSuite) TestSyncActivity_ActivityFound_Zombie() { } key := definition.NewWorkflowKey(namespaceID.String(), workflowID, runID) - weContext := workflow.NewMockContext(s.controller) + weContext := definition.NewMockWorkflowContext(s.controller) weContext.EXPECT().LoadMutableState(gomock.Any()).Return(s.mockMutableState, nil) - weContext.EXPECT().Lock(gomock.Any(), workflow.CallerTypeAPI).Return(nil) - weContext.EXPECT().Unlock(workflow.CallerTypeAPI) + weContext.EXPECT().Lock(gomock.Any(), definition.CallerTypeTask).Return(nil) + weContext.EXPECT().Unlock(definition.CallerTypeTask) _, err := s.workflowCache.PutIfNotExist(key, weContext) s.NoError(err) @@ -825,10 +825,10 @@ func (s *activityReplicatorSuite) TestSyncActivity_ActivityFound_Zombie() { gomock.Any(), gomock.Any(), persistence.UpdateWorkflowModeBypassCurrent, - workflow.Context(nil), - workflow.MutableState(nil), - workflow.TransactionPolicyPassive, - (*workflow.TransactionPolicy)(nil), + definition.WorkflowContext(nil), + definition.MutableState(nil), + definition.TransactionPolicyPassive, + (*definition.TransactionPolicy)(nil), ).Return(nil) s.mockNamespaceCache.EXPECT().GetNamespaceByID(namespaceID).Return( @@ -882,10 +882,10 @@ func (s *activityReplicatorSuite) TestSyncActivity_ActivityFound_NonZombie() { } key := definition.NewWorkflowKey(namespaceID.String(), workflowID, runID) - weContext := workflow.NewMockContext(s.controller) + weContext := definition.NewMockWorkflowContext(s.controller) weContext.EXPECT().LoadMutableState(gomock.Any()).Return(s.mockMutableState, nil) - weContext.EXPECT().Lock(gomock.Any(), workflow.CallerTypeAPI).Return(nil) - weContext.EXPECT().Unlock(workflow.CallerTypeAPI) + weContext.EXPECT().Lock(gomock.Any(), definition.CallerTypeTask).Return(nil) + weContext.EXPECT().Unlock(definition.CallerTypeTask) _, err := s.workflowCache.PutIfNotExist(key, weContext) s.NoError(err) @@ -918,10 +918,10 @@ func (s *activityReplicatorSuite) TestSyncActivity_ActivityFound_NonZombie() { gomock.Any(), gomock.Any(), persistence.UpdateWorkflowModeUpdateCurrent, - workflow.Context(nil), - workflow.MutableState(nil), - workflow.TransactionPolicyPassive, - (*workflow.TransactionPolicy)(nil), + definition.WorkflowContext(nil), + definition.MutableState(nil), + definition.TransactionPolicyPassive, + (*definition.TransactionPolicy)(nil), ).Return(nil) s.mockNamespaceCache.EXPECT().GetNamespaceByID(namespaceID).Return( diff --git a/service/history/ndc/branch_manager.go b/service/history/ndc/branch_manager.go index 8d950b7d76e..0c55f650294 100644 --- a/service/history/ndc/branch_manager.go +++ b/service/history/ndc/branch_manager.go @@ -39,7 +39,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" serviceerrors "go.temporal.io/server/common/serviceerror" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) @@ -58,13 +58,13 @@ type ( } BranchMgrImpl struct { - shard shard.Context + shard definition.ShardContext namespaceRegistry namespace.Registry clusterMetadata cluster.Metadata executionMgr persistence.ExecutionManager - context workflow.Context - mutableState workflow.MutableState + context definition.WorkflowContext + mutableState definition.MutableState logger log.Logger } ) @@ -72,9 +72,9 @@ type ( var _ BranchMgr = (*BranchMgrImpl)(nil) func NewBranchMgr( - shard shard.Context, - context workflow.Context, - mutableState workflow.MutableState, + shard definition.ShardContext, + context definition.WorkflowContext, + mutableState definition.MutableState, logger log.Logger, ) *BranchMgrImpl { diff --git a/service/history/ndc/branch_manager_test.go b/service/history/ndc/branch_manager_test.go index 96f4dbc40d2..e893d0872a7 100644 --- a/service/history/ndc/branch_manager_test.go +++ b/service/history/ndc/branch_manager_test.go @@ -43,9 +43,9 @@ import ( "go.temporal.io/server/common/persistence/versionhistory" serviceerrors "go.temporal.io/server/common/serviceerror" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" - "go.temporal.io/server/service/history/workflow" ) type ( @@ -55,8 +55,8 @@ type ( controller *gomock.Controller mockShard *shard.ContextTest - mockContext *workflow.MockContext - mockMutableState *workflow.MockMutableState + mockContext *definition.MockWorkflowContext + mockMutableState *definition.MockMutableState mockClusterMetadata *cluster.MockMetadata mockExecutionManager *persistence.MockExecutionManager @@ -81,8 +81,8 @@ func (s *branchMgrSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockContext = workflow.NewMockContext(s.controller) - s.mockMutableState = workflow.NewMockMutableState(s.controller) + s.mockContext = definition.NewMockWorkflowContext(s.controller) + s.mockMutableState = definition.NewMockMutableState(s.controller) s.mockShard = shard.NewTestContext( s.controller, @@ -235,7 +235,7 @@ func (s *branchMgrSuite) TestFlushBufferedEvents() { s.mockMutableState.EXPECT().HasBufferedEvents().Return(true).AnyTimes() s.mockMutableState.EXPECT().IsWorkflowExecutionRunning().Return(true).AnyTimes() s.mockMutableState.EXPECT().UpdateCurrentVersion(lastWriteVersion, true).Return(nil) - workflowTask := &workflow.WorkflowTaskInfo{ + workflowTask := &definition.WorkflowTaskInfo{ ScheduledEventID: 1234, StartedEventID: 2345, } diff --git a/service/history/ndc/conflict_resolver.go b/service/history/ndc/conflict_resolver.go index 7656821574c..64f54b0a71b 100644 --- a/service/history/ndc/conflict_resolver.go +++ b/service/history/ndc/conflict_resolver.go @@ -33,12 +33,10 @@ import ( "go.temporal.io/api/serviceerror" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" - "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) type ( @@ -47,15 +45,15 @@ type ( ctx context.Context, branchIndex int32, incomingVersion int64, - ) (workflow.MutableState, bool, error) + ) (definition.MutableState, bool, error) } ConflictResolverImpl struct { - shard shard.Context + shard definition.ShardContext stateRebuilder StateRebuilder - context workflow.Context - mutableState workflow.MutableState + context definition.WorkflowContext + mutableState definition.MutableState logger log.Logger } ) @@ -63,9 +61,9 @@ type ( var _ ConflictResolver = (*ConflictResolverImpl)(nil) func NewConflictResolver( - shard shard.Context, - context workflow.Context, - mutableState workflow.MutableState, + shard definition.ShardContext, + context definition.WorkflowContext, + mutableState definition.MutableState, logger log.Logger, ) *ConflictResolverImpl { @@ -83,7 +81,7 @@ func (r *ConflictResolverImpl) prepareMutableState( ctx context.Context, branchIndex int32, incomingVersion int64, -) (workflow.MutableState, bool, error) { +) (definition.MutableState, bool, error) { versionHistories := r.mutableState.GetExecutionInfo().GetVersionHistories() currentVersionHistoryIndex := versionHistories.GetCurrentVersionHistoryIndex() @@ -125,7 +123,7 @@ func (r *ConflictResolverImpl) rebuild( ctx context.Context, branchIndex int32, requestID string, -) (workflow.MutableState, error) { +) (definition.MutableState, error) { versionHistories := r.mutableState.GetExecutionInfo().GetVersionHistories() replayVersionHistory, err := versionhistory.GetVersionHistory(versionHistories, branchIndex) diff --git a/service/history/ndc/conflict_resolver_mock.go b/service/history/ndc/conflict_resolver_mock.go index 6a5171f78f4..f0fe47d8ae7 100644 --- a/service/history/ndc/conflict_resolver_mock.go +++ b/service/history/ndc/conflict_resolver_mock.go @@ -33,7 +33,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - workflow "go.temporal.io/server/service/history/workflow" + definition "go.temporal.io/server/service/history/definition" ) // MockConflictResolver is a mock of ConflictResolver interface. @@ -60,10 +60,10 @@ func (m *MockConflictResolver) EXPECT() *MockConflictResolverMockRecorder { } // prepareMutableState mocks base method. -func (m *MockConflictResolver) prepareMutableState(ctx context.Context, branchIndex int32, incomingVersion int64) (workflow.MutableState, bool, error) { +func (m *MockConflictResolver) prepareMutableState(ctx context.Context, branchIndex int32, incomingVersion int64) (definition.MutableState, bool, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "prepareMutableState", ctx, branchIndex, incomingVersion) - ret0, _ := ret[0].(workflow.MutableState) + ret0, _ := ret[0].(definition.MutableState) ret1, _ := ret[1].(bool) ret2, _ := ret[2].(error) return ret0, ret1, ret2 diff --git a/service/history/ndc/conflict_resolver_test.go b/service/history/ndc/conflict_resolver_test.go index e586d1c90f3..4361a648733 100644 --- a/service/history/ndc/conflict_resolver_test.go +++ b/service/history/ndc/conflict_resolver_test.go @@ -36,13 +36,12 @@ import ( historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" - "go.temporal.io/server/service/history/workflow" ) type ( @@ -52,8 +51,8 @@ type ( controller *gomock.Controller mockShard *shard.ContextTest - mockContext *workflow.MockContext - mockMutableState *workflow.MockMutableState + mockContext *definition.MockWorkflowContext + mockMutableState *definition.MockMutableState mockStateBuilder *MockStateRebuilder logger log.Logger @@ -76,8 +75,8 @@ func (s *conflictResolverSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockContext = workflow.NewMockContext(s.controller) - s.mockMutableState = workflow.NewMockMutableState(s.controller) + s.mockContext = definition.NewMockWorkflowContext(s.controller) + s.mockMutableState = definition.NewMockMutableState(s.controller) s.mockStateBuilder = NewMockStateRebuilder(s.controller) s.mockShard = shard.NewTestContext( @@ -147,7 +146,7 @@ func (s *conflictResolverSuite) TestRebuild() { s.workflowID, s.runID, ) - mockRebuildMutableState := workflow.NewMockMutableState(s.controller) + mockRebuildMutableState := definition.NewMockMutableState(s.controller) mockRebuildMutableState.EXPECT().GetExecutionInfo().Return( &persistencespb.WorkflowExecutionInfo{ VersionHistories: versionhistory.NewVersionHistories( @@ -244,7 +243,7 @@ func (s *conflictResolverSuite) TestPrepareMutableState_Rebuild() { s.workflowID, s.runID, ) - mockRebuildMutableState := workflow.NewMockMutableState(s.controller) + mockRebuildMutableState := definition.NewMockMutableState(s.controller) mockRebuildMutableState.EXPECT().GetExecutionInfo().Return( &persistencespb.WorkflowExecutionInfo{ VersionHistories: versionhistory.NewVersionHistories( diff --git a/service/history/ndc/events_reapplier.go b/service/history/ndc/events_reapplier.go index 12d14b6dfd6..ec8e7f84660 100644 --- a/service/history/ndc/events_reapplier.go +++ b/service/history/ndc/events_reapplier.go @@ -33,17 +33,16 @@ import ( historypb "go.temporal.io/api/history/v1" "go.temporal.io/api/serviceerror" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) type ( EventsReapplier interface { ReapplyEvents( ctx context.Context, - ms workflow.MutableState, + ms definition.MutableState, historyEvents []*historypb.HistoryEvent, runID string, ) ([]*historypb.HistoryEvent, error) @@ -68,7 +67,7 @@ func NewEventsReapplier( func (r *EventsReapplierImpl) ReapplyEvents( ctx context.Context, - ms workflow.MutableState, + ms definition.MutableState, historyEvents []*historypb.HistoryEvent, runID string, ) ([]*historypb.HistoryEvent, error) { diff --git a/service/history/ndc/events_reapplier_mock.go b/service/history/ndc/events_reapplier_mock.go index 5fec6112058..eed50d16f65 100644 --- a/service/history/ndc/events_reapplier_mock.go +++ b/service/history/ndc/events_reapplier_mock.go @@ -34,7 +34,7 @@ import ( gomock "github.com/golang/mock/gomock" history "go.temporal.io/api/history/v1" - workflow "go.temporal.io/server/service/history/workflow" + definition "go.temporal.io/server/service/history/definition" ) // MockEventsReapplier is a mock of EventsReapplier interface. @@ -61,7 +61,7 @@ func (m *MockEventsReapplier) EXPECT() *MockEventsReapplierMockRecorder { } // ReapplyEvents mocks base method. -func (m *MockEventsReapplier) ReapplyEvents(ctx context.Context, ms workflow.MutableState, historyEvents []*history.HistoryEvent, runID string) ([]*history.HistoryEvent, error) { +func (m *MockEventsReapplier) ReapplyEvents(ctx context.Context, ms definition.MutableState, historyEvents []*history.HistoryEvent, runID string) ([]*history.HistoryEvent, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ReapplyEvents", ctx, ms, historyEvents, runID) ret0, _ := ret[0].([]*history.HistoryEvent) diff --git a/service/history/ndc/events_reapplier_test.go b/service/history/ndc/events_reapplier_test.go index fcd7675de57..c9cf4e70779 100644 --- a/service/history/ndc/events_reapplier_test.go +++ b/service/history/ndc/events_reapplier_test.go @@ -38,11 +38,10 @@ import ( historypb "go.temporal.io/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/payloads" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) type ( @@ -95,7 +94,7 @@ func (s *nDCEventReapplicationSuite) TestReapplyEvents_AppliedEvent() { } attr := event.GetWorkflowExecutionSignaledEventAttributes() - msCurrent := workflow.NewMockMutableState(s.controller) + msCurrent := definition.NewMockMutableState(s.controller) msCurrent.EXPECT().IsWorkflowExecutionRunning().Return(true) msCurrent.EXPECT().GetLastWriteVersion().Return(int64(1), nil).AnyTimes() msCurrent.EXPECT().GetExecutionInfo().Return(execution).AnyTimes() @@ -130,7 +129,7 @@ func (s *nDCEventReapplicationSuite) TestReapplyEvents_Noop() { }}, } - msCurrent := workflow.NewMockMutableState(s.controller) + msCurrent := definition.NewMockMutableState(s.controller) dedupResource := definition.NewEventReappliedID(runID, event.GetEventId(), event.GetVersion()) msCurrent.EXPECT().IsResourceDuplicated(dedupResource).Return(true) events := []*historypb.HistoryEvent{ @@ -169,7 +168,7 @@ func (s *nDCEventReapplicationSuite) TestReapplyEvents_PartialAppliedEvent() { } attr1 := event1.GetWorkflowExecutionSignaledEventAttributes() - msCurrent := workflow.NewMockMutableState(s.controller) + msCurrent := definition.NewMockMutableState(s.controller) msCurrent.EXPECT().IsWorkflowExecutionRunning().Return(true) msCurrent.EXPECT().GetLastWriteVersion().Return(int64(1), nil).AnyTimes() msCurrent.EXPECT().GetExecutionInfo().Return(execution).AnyTimes() @@ -212,7 +211,7 @@ func (s *nDCEventReapplicationSuite) TestReapplyEvents_Error() { } attr := event.GetWorkflowExecutionSignaledEventAttributes() - msCurrent := workflow.NewMockMutableState(s.controller) + msCurrent := definition.NewMockMutableState(s.controller) msCurrent.EXPECT().IsWorkflowExecutionRunning().Return(true) msCurrent.EXPECT().GetLastWriteVersion().Return(int64(1), nil).AnyTimes() msCurrent.EXPECT().GetExecutionInfo().Return(execution).AnyTimes() diff --git a/service/history/ndc/history_replicator.go b/service/history/ndc/history_replicator.go index 7567e494324..28076e3c50d 100644 --- a/service/history/ndc/history_replicator.go +++ b/service/history/ndc/history_replicator.go @@ -44,7 +44,6 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/collection" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" @@ -54,7 +53,7 @@ import ( "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" serviceerrors "go.temporal.io/server/common/serviceerror" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) @@ -64,7 +63,7 @@ const ( type ( stateBuilderProvider func( - mutableState workflow.MutableState, + mutableState definition.MutableState, logger log.Logger, ) workflow.MutableStateRebuilder @@ -72,17 +71,17 @@ type ( namespaceEntry *namespace.Namespace, startTime time.Time, logger log.Logger, - ) workflow.MutableState + ) definition.MutableState branchMgrProvider func( - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, logger log.Logger, ) BranchMgr conflictResolverProvider func( - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, logger log.Logger, ) ConflictResolver @@ -90,7 +89,7 @@ type ( namespaceID namespace.ID, workflowID string, baseRunID string, - newContext workflow.Context, + newContext definition.WorkflowContext, newRunID string, logger log.Logger, ) resetter @@ -107,13 +106,13 @@ type ( } HistoryReplicatorImpl struct { - shard shard.Context + shard definition.ShardContext clusterMetadata cluster.Metadata executionMgr persistence.ExecutionManager historySerializer serialization.Serializer metricsHandler metrics.MetricsHandler namespaceRegistry namespace.Registry - historyCache workflow.Cache + historyCache definition.WorkflowCache eventsReapplier EventsReapplier transactionMgr transactionMgr logger log.Logger @@ -134,8 +133,8 @@ type ( var errPanic = serviceerror.NewInternal("encountered panic") func NewHistoryReplicator( - shard shard.Context, - historyCache workflow.Cache, + shard definition.ShardContext, + historyCache definition.WorkflowCache, eventsReapplier EventsReapplier, logger log.Logger, eventSerializer serialization.Serializer, @@ -155,15 +154,15 @@ func NewHistoryReplicator( logger: log.With(logger, tag.ComponentHistoryReplicator), newBranchMgr: func( - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, logger log.Logger, ) BranchMgr { return NewBranchMgr(shard, context, mutableState, logger) }, newConflictResolver: func( - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, logger log.Logger, ) ConflictResolver { return NewConflictResolver(shard, context, mutableState, logger) @@ -172,14 +171,14 @@ func NewHistoryReplicator( namespaceID namespace.ID, workflowID string, baseRunID string, - newContext workflow.Context, + newContext definition.WorkflowContext, newRunID string, logger log.Logger, ) resetter { return NewResetter(shard, transactionMgr, namespaceID, workflowID, baseRunID, newContext, newRunID, logger) }, newStateBuilder: func( - state workflow.MutableState, + state definition.MutableState, logger log.Logger, ) workflow.MutableStateRebuilder { @@ -193,7 +192,7 @@ func NewHistoryReplicator( namespaceEntry *namespace.Namespace, startTime time.Time, logger log.Logger, - ) workflow.MutableState { + ) definition.MutableState { return workflow.NewMutableState( shard, shard.GetEventsCache(), @@ -247,7 +246,7 @@ func (r *HistoryReplicatorImpl) ApplyWorkflowState( WorkflowId: wid, RunId: rid, }, - workflow.CallerTypeTask, + definition.CallerTypeTask, ) if err != nil { return err @@ -323,7 +322,7 @@ func (r *HistoryReplicatorImpl) applyEvents( ctx, task.getNamespaceID(), *task.getExecution(), - workflow.CallerTypeAPI, + definition.CallerTypeTask, ) if err != nil { // for get workflow execution context, with valid run id @@ -392,8 +391,8 @@ func (r *HistoryReplicatorImpl) applyEvents( func (r *HistoryReplicatorImpl) applyStartEvents( ctx context.Context, - context workflow.Context, - releaseFn workflow.ReleaseCacheFunc, + context definition.WorkflowContext, + releaseFn definition.ReleaseFunc, task replicationTask, ) error { @@ -447,8 +446,8 @@ func (r *HistoryReplicatorImpl) applyStartEvents( func (r *HistoryReplicatorImpl) applyNonStartEventsPrepareBranch( ctx context.Context, - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, task replicationTask, ) (bool, int32, error) { @@ -478,11 +477,11 @@ func (r *HistoryReplicatorImpl) applyNonStartEventsPrepareBranch( func (r *HistoryReplicatorImpl) applyNonStartEventsPrepareMutableState( ctx context.Context, - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, branchIndex int32, task replicationTask, -) (workflow.MutableState, bool, error) { +) (definition.MutableState, bool, error) { incomingVersion := task.getVersion() conflictResolver := r.newConflictResolver(context, mutableState, task.getLogger()) @@ -502,10 +501,10 @@ func (r *HistoryReplicatorImpl) applyNonStartEventsPrepareMutableState( func (r *HistoryReplicatorImpl) applyNonStartEventsToCurrentBranch( ctx context.Context, - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, isRebuilt bool, - releaseFn workflow.ReleaseCacheFunc, + releaseFn definition.ReleaseFunc, task replicationTask, ) error { @@ -580,10 +579,10 @@ func (r *HistoryReplicatorImpl) applyNonStartEventsToCurrentBranch( func (r *HistoryReplicatorImpl) applyNonStartEventsToNoneCurrentBranch( ctx context.Context, - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, branchIndex int32, - releaseFn workflow.ReleaseCacheFunc, + releaseFn definition.ReleaseFunc, task replicationTask, ) error { @@ -608,10 +607,10 @@ func (r *HistoryReplicatorImpl) applyNonStartEventsToNoneCurrentBranch( func (r *HistoryReplicatorImpl) applyNonStartEventsToNoneCurrentBranchWithoutContinueAsNew( ctx context.Context, - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, branchIndex int32, - releaseFn workflow.ReleaseCacheFunc, + releaseFn definition.ReleaseFunc, task replicationTask, ) error { @@ -665,8 +664,8 @@ func (r *HistoryReplicatorImpl) applyNonStartEventsToNoneCurrentBranchWithoutCon func (r *HistoryReplicatorImpl) applyNonStartEventsToNoneCurrentBranchWithContinueAsNew( ctx context.Context, - context workflow.Context, - releaseFn workflow.ReleaseCacheFunc, + context definition.WorkflowContext, + releaseFn definition.ReleaseFunc, task replicationTask, ) error { @@ -710,9 +709,9 @@ func (r *HistoryReplicatorImpl) applyNonStartEventsToNoneCurrentBranchWithContin func (r *HistoryReplicatorImpl) applyNonStartEventsMissingMutableState( ctx context.Context, - newContext workflow.Context, + newContext definition.WorkflowContext, task replicationTask, -) (workflow.MutableState, error) { +) (definition.MutableState, error) { // for non reset workflow execution replication task, just do re-replication if !task.isWorkflowReset() { @@ -765,8 +764,8 @@ func (r *HistoryReplicatorImpl) applyNonStartEventsMissingMutableState( func (r *HistoryReplicatorImpl) applyNonStartEventsResetWorkflow( ctx context.Context, - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, task replicationTask, ) error { diff --git a/service/history/ndc/history_replicator_test.go b/service/history/ndc/history_replicator_test.go index e133eddf460..b3e5dd2458c 100644 --- a/service/history/ndc/history_replicator_test.go +++ b/service/history/ndc/history_replicator_test.go @@ -32,7 +32,7 @@ import ( historypb "go.temporal.io/api/history/v1" "go.temporal.io/server/common" - "go.temporal.io/server/service/history/events" + "go.temporal.io/server/service/history/definition" "github.com/golang/mock/gomock" "github.com/pborman/uuid" @@ -65,8 +65,8 @@ type ( controller *gomock.Controller mockShard *shard.ContextTest - mockEventCache *events.MockCache - mockHistoryCache *workflow.MockCache + mockEventCache *definition.MockEventCache + mockHistoryCache *definition.MockWorkflowCache mockNamespaceCache *namespace.MockRegistry mockRemoteAdminClient *adminservicemock.MockAdminServiceClient mockExecutionManager *persistence.MockExecutionManager @@ -103,7 +103,7 @@ func (s *historyReplicatorSuite) SetupTest() { s.mockExecutionManager = s.mockShard.Resource.ExecutionMgr s.mockNamespaceCache = s.mockShard.Resource.NamespaceCache - s.mockHistoryCache = workflow.NewMockCache(s.controller) + s.mockHistoryCache = definition.NewMockWorkflowCache(s.controller) s.mockEventCache = s.mockShard.MockEventsCache s.mockRemoteAdminClient = s.mockShard.Resource.RemoteAdminClient eventReapplier := NewMockEventsReapplier(s.controller) @@ -172,12 +172,12 @@ func (s *historyReplicatorSuite) Test_ApplyWorkflowState_BrandNew() { WorkflowId: s.workflowID, RunId: s.runID, } - mockWeCtx := workflow.NewMockContext(s.controller) + mockWeCtx := definition.NewMockWorkflowContext(s.controller) s.mockHistoryCache.EXPECT().GetOrCreateWorkflowExecution( gomock.Any(), namespace.ID(namespaceID), we, - workflow.CallerTypeTask, + definition.CallerTypeTask, ).Return(mockWeCtx, workflow.NoopReleaseFn, nil) mockWeCtx.EXPECT().CreateWorkflowExecution( gomock.Any(), @@ -281,12 +281,12 @@ func (s *historyReplicatorSuite) Test_ApplyWorkflowState_Ancestors() { WorkflowId: s.workflowID, RunId: s.runID, } - mockWeCtx := workflow.NewMockContext(s.controller) + mockWeCtx := definition.NewMockWorkflowContext(s.controller) s.mockHistoryCache.EXPECT().GetOrCreateWorkflowExecution( gomock.Any(), namespace.ID(namespaceID), we, - workflow.CallerTypeTask, + definition.CallerTypeTask, ).Return(mockWeCtx, workflow.NoopReleaseFn, nil) mockWeCtx.EXPECT().CreateWorkflowExecution( gomock.Any(), diff --git a/service/history/ndc/resetter.go b/service/history/ndc/resetter.go index a5d9090ed53..0f1b2d98ef9 100644 --- a/service/history/ndc/resetter.go +++ b/service/history/ndc/resetter.go @@ -34,14 +34,12 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" serviceerrors "go.temporal.io/server/common/serviceerror" - "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) const ( @@ -57,11 +55,11 @@ type ( baseLastEventVersion int64, incomingFirstEventID int64, incomingFirstEventVersion int64, - ) (workflow.MutableState, error) + ) (definition.MutableState, error) } resetterImpl struct { - shard shard.Context + shard definition.ShardContext transactionMgr transactionMgr executionMgr persistence.ExecutionManager stateRebuilder StateRebuilder @@ -69,7 +67,7 @@ type ( namespaceID namespace.ID workflowID string baseRunID string - newContext workflow.Context + newContext definition.WorkflowContext newRunID string logger log.Logger @@ -79,12 +77,12 @@ type ( var _ resetter = (*resetterImpl)(nil) func NewResetter( - shard shard.Context, + shard definition.ShardContext, transactionMgr transactionMgr, namespaceID namespace.ID, workflowID string, baseRunID string, - newContext workflow.Context, + newContext definition.WorkflowContext, newRunID string, logger log.Logger, ) *resetterImpl { @@ -111,7 +109,7 @@ func (r *resetterImpl) resetWorkflow( baseLastEventVersion int64, incomingFirstEventID int64, incomingFirstEventVersion int64, -) (workflow.MutableState, error) { +) (definition.MutableState, error) { baseBranchToken, err := r.getBaseBranchToken( ctx, diff --git a/service/history/ndc/resetter_test.go b/service/history/ndc/resetter_test.go index ebd25184de6..7b53c41a619 100644 --- a/service/history/ndc/resetter_test.go +++ b/service/history/ndc/resetter_test.go @@ -38,12 +38,12 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" serviceerrors "go.temporal.io/server/common/serviceerror" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" "go.temporal.io/server/service/history/workflow" @@ -56,8 +56,8 @@ type ( controller *gomock.Controller mockShard *shard.ContextTest - mockBaseMutableState *workflow.MockMutableState - mockRebuiltMutableState *workflow.MockMutableState + mockBaseMutableState *definition.MockMutableState + mockRebuiltMutableState *definition.MockMutableState mockTransactionMgr *MocktransactionMgr mockStateBuilder *MockStateRebuilder @@ -68,7 +68,7 @@ type ( namespace namespace.Name workflowID string baseRunID string - newContext workflow.Context + newContext definition.WorkflowContext newRunID string workflowResetter *resetterImpl @@ -84,8 +84,8 @@ func (s *resetterSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockBaseMutableState = workflow.NewMockMutableState(s.controller) - s.mockRebuiltMutableState = workflow.NewMockMutableState(s.controller) + s.mockBaseMutableState = definition.NewMockMutableState(s.controller) + s.mockRebuiltMutableState = definition.NewMockMutableState(s.controller) s.mockTransactionMgr = NewMocktransactionMgr(s.controller) s.mockStateBuilder = NewMockStateRebuilder(s.controller) diff --git a/service/history/ndc/state_rebuilder.go b/service/history/ndc/state_rebuilder.go index d564e23a5b8..16d5553a0c3 100644 --- a/service/history/ndc/state_rebuilder.go +++ b/service/history/ndc/state_rebuilder.go @@ -38,14 +38,12 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/collection" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" - "go.temporal.io/server/service/history/events" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) @@ -61,13 +59,13 @@ type ( targetWorkflowIdentifier definition.WorkflowKey, targetBranchToken []byte, requestID string, - ) (workflow.MutableState, int64, error) + ) (definition.MutableState, int64, error) } StateRebuilderImpl struct { - shard shard.Context + shard definition.ShardContext namespaceRegistry namespace.Registry - eventsCache events.Cache + eventsCache definition.EventCache clusterMetadata cluster.Metadata executionMgr persistence.ExecutionManager taskRefresher workflow.TaskRefresher @@ -85,7 +83,7 @@ type ( var _ StateRebuilder = (*StateRebuilderImpl)(nil) func NewStateRebuilder( - shard shard.Context, + shard definition.ShardContext, logger log.Logger, ) *StateRebuilderImpl { @@ -117,7 +115,7 @@ func (r *StateRebuilderImpl) Rebuild( targetWorkflowIdentifier definition.WorkflowKey, targetBranchToken []byte, requestID string, -) (workflow.MutableState, int64, error) { +) (definition.MutableState, int64, error) { iter := collection.NewPagingIterator(r.getPaginationFn( ctx, common.FirstEventID, @@ -186,7 +184,7 @@ func (r *StateRebuilderImpl) Rebuild( } // close rebuilt mutable state transaction clearing all generated tasks, etc. - _, _, err = rebuiltMutableState.CloseTransactionAsSnapshot(now, workflow.TransactionPolicyPassive) + _, _, err = rebuiltMutableState.CloseTransactionAsSnapshot(now, definition.TransactionPolicyPassive) if err != nil { return nil, 0, err } @@ -204,7 +202,7 @@ func (r *StateRebuilderImpl) Rebuild( func (r *StateRebuilderImpl) initializeBuilders( namespaceEntry *namespace.Namespace, now time.Time, -) (workflow.MutableState, workflow.MutableStateRebuilder) { +) (definition.MutableState, workflow.MutableStateRebuilder) { resetMutableState := workflow.NewMutableState( r.shard, r.shard.GetEventsCache(), diff --git a/service/history/ndc/state_rebuilder_mock.go b/service/history/ndc/state_rebuilder_mock.go index 117f494df12..a95ecb6860d 100644 --- a/service/history/ndc/state_rebuilder_mock.go +++ b/service/history/ndc/state_rebuilder_mock.go @@ -34,8 +34,7 @@ import ( time "time" gomock "github.com/golang/mock/gomock" - definition "go.temporal.io/server/common/definition" - workflow "go.temporal.io/server/service/history/workflow" + definition "go.temporal.io/server/service/history/definition" ) // MockStateRebuilder is a mock of StateRebuilder interface. @@ -62,10 +61,10 @@ func (m *MockStateRebuilder) EXPECT() *MockStateRebuilderMockRecorder { } // Rebuild mocks base method. -func (m *MockStateRebuilder) Rebuild(ctx context.Context, now time.Time, baseWorkflowIdentifier definition.WorkflowKey, baseBranchToken []byte, baseLastEventID int64, baseLastEventVersion *int64, targetWorkflowIdentifier definition.WorkflowKey, targetBranchToken []byte, requestID string) (workflow.MutableState, int64, error) { +func (m *MockStateRebuilder) Rebuild(ctx context.Context, now time.Time, baseWorkflowIdentifier definition.WorkflowKey, baseBranchToken []byte, baseLastEventID int64, baseLastEventVersion *int64, targetWorkflowIdentifier definition.WorkflowKey, targetBranchToken []byte, requestID string) (definition.MutableState, int64, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Rebuild", ctx, now, baseWorkflowIdentifier, baseBranchToken, baseLastEventID, baseLastEventVersion, targetWorkflowIdentifier, targetBranchToken, requestID) - ret0, _ := ret[0].(workflow.MutableState) + ret0, _ := ret[0].(definition.MutableState) ret1, _ := ret[1].(int64) ret2, _ := ret[2].(error) return ret0, ret1, ret2 diff --git a/service/history/ndc/state_rebuilder_test.go b/service/history/ndc/state_rebuilder_test.go index 90f2259d89a..52aeb1e14d1 100644 --- a/service/history/ndc/state_rebuilder_test.go +++ b/service/history/ndc/state_rebuilder_test.go @@ -44,14 +44,13 @@ import ( "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/collection" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/payloads" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" - "go.temporal.io/server/service/history/events" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" "go.temporal.io/server/service/history/workflow" @@ -64,7 +63,7 @@ type ( controller *gomock.Controller mockShard *shard.ContextTest - mockEventsCache *events.MockCache + mockEventsCache *definition.MockEventCache mockTaskRefresher *workflow.MockTaskRefresher mockNamespaceCache *namespace.MockRegistry mockClusterMetadata *cluster.MockMetadata diff --git a/service/history/ndc/transaction_manager.go b/service/history/ndc/transaction_manager.go index 5de7451868b..e4d08fc658d 100644 --- a/service/history/ndc/transaction_manager.go +++ b/service/history/ndc/transaction_manager.go @@ -43,8 +43,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/serialization" "go.temporal.io/server/common/persistence/versionhistory" - "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) // NOTE: terminology @@ -152,9 +151,9 @@ type ( } transactionMgrImpl struct { - shard shard.Context + shard definition.ShardContext namespaceRegistry namespace.Registry - historyCache workflow.Cache + historyCache definition.WorkflowCache clusterMetadata cluster.Metadata executionManager persistence.ExecutionManager serializer serialization.Serializer @@ -171,8 +170,8 @@ type ( var _ transactionMgr = (*transactionMgrImpl)(nil) func newTransactionMgr( - shard shard.Context, - historyCache workflow.Cache, + shard definition.ShardContext, + historyCache definition.WorkflowCache, eventsReapplier EventsReapplier, logger log.Logger, ) *transactionMgrImpl { @@ -278,11 +277,11 @@ func (r *transactionMgrImpl) backfillWorkflowEventsReapply( ctx context.Context, targetWorkflow Workflow, targetWorkflowEvents *persistence.WorkflowEvents, -) (persistence.UpdateWorkflowMode, workflow.TransactionPolicy, error) { +) (persistence.UpdateWorkflowMode, definition.TransactionPolicy, error) { isCurrentWorkflow, err := r.isWorkflowCurrent(ctx, targetWorkflow) if err != nil { - return 0, workflow.TransactionPolicyActive, err + return 0, definition.TransactionPolicyActive, err } isWorkflowRunning := targetWorkflow.GetMutableState().IsWorkflowExecutionRunning() targetWorkflowActiveCluster := targetWorkflow.GetMutableState().GetNamespaceEntry().ActiveClusterName() @@ -306,9 +305,9 @@ func (r *transactionMgrImpl) backfillWorkflowEventsReapply( targetWorkflowEvents.Events, targetWorkflow.GetMutableState().GetExecutionState().GetRunId(), ); err != nil { - return 0, workflow.TransactionPolicyActive, err + return 0, definition.TransactionPolicyActive, err } - return persistence.UpdateWorkflowModeUpdateCurrent, workflow.TransactionPolicyActive, nil + return persistence.UpdateWorkflowModeUpdateCurrent, definition.TransactionPolicyActive, nil } // case 1.b @@ -323,11 +322,11 @@ func (r *transactionMgrImpl) backfillWorkflowEventsReapply( baseVersionHistories := baseMutableState.GetExecutionInfo().GetVersionHistories() baseCurrentVersionHistory, err := versionhistory.GetCurrentVersionHistory(baseVersionHistories) if err != nil { - return 0, workflow.TransactionPolicyActive, err + return 0, definition.TransactionPolicyActive, err } baseRebuildLastEventVersion, err := versionhistory.GetVersionHistoryEventVersion(baseCurrentVersionHistory, baseRebuildLastEventID) if err != nil { - return 0, workflow.TransactionPolicyActive, err + return 0, definition.TransactionPolicyActive, err } baseCurrentBranchToken := baseCurrentVersionHistory.GetBranchToken() baseNextEventID := baseMutableState.GetNextEventID() @@ -353,13 +352,13 @@ func (r *transactionMgrImpl) backfillWorkflowEventsReapply( // no-op. Usually this is due to reset workflow with pending child workflows r.logger.Warn("Cannot reset workflow. Ignoring reapply events.", tag.Error(err)) // the target workflow is not reset so it is still the current workflow. It need to persist updated version histories. - return persistence.UpdateWorkflowModeUpdateCurrent, workflow.TransactionPolicyPassive, nil + return persistence.UpdateWorkflowModeUpdateCurrent, definition.TransactionPolicyPassive, nil case nil: // after the reset of target workflow (current workflow) with additional events to be reapplied // target workflow is no longer the current workflow - return persistence.UpdateWorkflowModeBypassCurrent, workflow.TransactionPolicyPassive, nil + return persistence.UpdateWorkflowModeBypassCurrent, definition.TransactionPolicyPassive, nil default: - return 0, workflow.TransactionPolicyActive, err + return 0, definition.TransactionPolicyActive, err } } @@ -368,13 +367,13 @@ func (r *transactionMgrImpl) backfillWorkflowEventsReapply( if err := targetWorkflow.GetContext().ReapplyEvents( []*persistence.WorkflowEvents{targetWorkflowEvents}, ); err != nil { - return 0, workflow.TransactionPolicyActive, err + return 0, definition.TransactionPolicyActive, err } if isCurrentWorkflow { - return persistence.UpdateWorkflowModeUpdateCurrent, workflow.TransactionPolicyPassive, nil + return persistence.UpdateWorkflowModeUpdateCurrent, definition.TransactionPolicyPassive, nil } - return persistence.UpdateWorkflowModeBypassCurrent, workflow.TransactionPolicyPassive, nil + return persistence.UpdateWorkflowModeBypassCurrent, definition.TransactionPolicyPassive, nil } func (r *transactionMgrImpl) checkWorkflowExists( @@ -444,7 +443,7 @@ func (r *transactionMgrImpl) loadWorkflow( WorkflowId: workflowID, RunId: runID, }, - workflow.CallerTypeAPI, + definition.CallerTypeTask, ) if err != nil { return nil, err diff --git a/service/history/ndc/transaction_manager_existing_workflow.go b/service/history/ndc/transaction_manager_existing_workflow.go index 6f1be6a5e43..422200b4207 100644 --- a/service/history/ndc/transaction_manager_existing_workflow.go +++ b/service/history/ndc/transaction_manager_existing_workflow.go @@ -35,7 +35,7 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) type ( @@ -259,13 +259,13 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) updateAsZombie( if err != nil { return err } - if targetPolicy != workflow.TransactionPolicyPassive { + if targetPolicy != definition.TransactionPolicyPassive { return serviceerror.NewInternal("transactionMgrForExistingWorkflow updateAsZombie encountered target workflow policy not being passive") } - var newContext workflow.Context - var newMutableState workflow.MutableState - var newTransactionPolicy *workflow.TransactionPolicy + var newContext definition.WorkflowContext + var newMutableState definition.MutableState + var newTransactionPolicy *definition.TransactionPolicy if newWorkflow != nil { newWorkflowPolicy, err := newWorkflow.SuppressBy( currentWorkflow, @@ -273,7 +273,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) updateAsZombie( if err != nil { return err } - if newWorkflowPolicy != workflow.TransactionPolicyPassive { + if newWorkflowPolicy != definition.TransactionPolicyPassive { return serviceerror.NewInternal("transactionMgrForExistingWorkflow updateAsZombie encountered new workflow policy not being passive") } @@ -299,7 +299,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) updateAsZombie( // new workflow does not exists, continue newContext = newWorkflow.GetContext() newMutableState = newWorkflow.GetMutableState() - newTransactionPolicy = workflow.TransactionPolicyPassive.Ptr() + newTransactionPolicy = definition.TransactionPolicyPassive.Ptr() } } @@ -314,7 +314,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) updateAsZombie( persistence.UpdateWorkflowModeBypassCurrent, newContext, newMutableState, - workflow.TransactionPolicyPassive, + definition.TransactionPolicyPassive, newTransactionPolicy, ) } @@ -329,7 +329,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) suppressCurrentAndUpdateAsCur var err error - currentWorkflowPolicy := workflow.TransactionPolicyPassive + currentWorkflowPolicy := definition.TransactionPolicyPassive if currentWorkflow.GetMutableState().IsWorkflowExecutionRunning() { currentWorkflowPolicy, err = currentWorkflow.SuppressBy( targetWorkflow, @@ -342,8 +342,8 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) suppressCurrentAndUpdateAsCur return err } - var newContext workflow.Context - var newMutableState workflow.MutableState + var newContext definition.WorkflowContext + var newMutableState definition.MutableState if newWorkflow != nil { newContext = newWorkflow.GetContext() newMutableState = newWorkflow.GetMutableState() @@ -372,8 +372,8 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) conflictResolveAsCurrent( newWorkflow Workflow, ) error { - var newContext workflow.Context - var newMutableState workflow.MutableState + var newContext definition.WorkflowContext + var newMutableState definition.MutableState if newWorkflow != nil { newContext = newWorkflow.GetContext() newMutableState = newWorkflow.GetMutableState() @@ -406,12 +406,12 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) conflictResolveAsZombie( if err != nil { return err } - if targetWorkflowPolicy != workflow.TransactionPolicyPassive { + if targetWorkflowPolicy != definition.TransactionPolicyPassive { return serviceerror.NewInternal("transactionMgrForExistingWorkflow conflictResolveAsZombie encountered target workflow policy not being passive") } - var newContext workflow.Context - var newMutableState workflow.MutableState + var newContext definition.WorkflowContext + var newMutableState definition.MutableState if newWorkflow != nil { newWorkflowPolicy, err := newWorkflow.SuppressBy( currentWorkflow, @@ -419,7 +419,7 @@ func (r *nDCTransactionMgrForExistingWorkflowImpl) conflictResolveAsZombie( if err != nil { return err } - if newWorkflowPolicy != workflow.TransactionPolicyPassive { + if newWorkflowPolicy != definition.TransactionPolicyPassive { return serviceerror.NewInternal("transactionMgrForExistingWorkflow conflictResolveAsZombie encountered new workflow policy not being passive") } diff --git a/service/history/ndc/transaction_manager_existing_workflow_test.go b/service/history/ndc/transaction_manager_existing_workflow_test.go index f9eed7b7034..700c1f6e8f2 100644 --- a/service/history/ndc/transaction_manager_existing_workflow_test.go +++ b/service/history/ndc/transaction_manager_existing_workflow_test.go @@ -36,7 +36,7 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) type ( @@ -79,17 +79,17 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow newReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() newWorkflow := NewMockWorkflow(s.controller) - newContext := workflow.NewMockContext(s.controller) - newMutableState := workflow.NewMockMutableState(s.controller) - var newReleaseFn workflow.ReleaseCacheFunc = func(error) { newReleaseCalled = true } + newContext := definition.NewMockWorkflowContext(s.controller) + newMutableState := definition.NewMockMutableState(s.controller) + var newReleaseFn definition.ReleaseFunc = func(error) { newReleaseCalled = true } newWorkflow.EXPECT().GetContext().Return(newContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(newMutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(newReleaseFn).AnyTimes() @@ -120,7 +120,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow isWorkflowRebuilt := false targetWorkflow := NewMockWorkflow(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() newWorkflow := NewMockWorkflow(s.controller) @@ -155,26 +155,26 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() newWorkflow := NewMockWorkflow(s.controller) - newContext := workflow.NewMockContext(s.controller) - newMutableState := workflow.NewMockMutableState(s.controller) - var newReleaseFn workflow.ReleaseCacheFunc = func(error) { newReleaseCalled = true } + newContext := definition.NewMockWorkflowContext(s.controller) + newMutableState := definition.NewMockMutableState(s.controller) + var newReleaseFn definition.ReleaseFunc = func(error) { newReleaseCalled = true } newWorkflow.EXPECT().GetContext().Return(newContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(newMutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(newReleaseFn).AnyTimes() newWorkflow.EXPECT().Revive().Return(nil) currentWorkflow := NewMockWorkflow(s.controller) - currentContext := workflow.NewMockContext(s.controller) - currentMutableState := workflow.NewMockMutableState(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + currentContext := definition.NewMockWorkflowContext(s.controller) + currentMutableState := definition.NewMockMutableState(s.controller) + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetContext().Return(currentContext).AnyTimes() currentWorkflow.EXPECT().GetMutableState().Return(currentMutableState).AnyTimes() currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() @@ -191,7 +191,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow s.mockTransactionMgr.EXPECT().loadWorkflow(ctx, namespaceID, workflowID, currentRunID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(true, nil) - currentWorkflowPolicy := workflow.TransactionPolicyPassive + currentWorkflowPolicy := definition.TransactionPolicyPassive currentMutableState.EXPECT().IsWorkflowExecutionRunning().Return(true).AnyTimes() currentWorkflow.EXPECT().SuppressBy(targetWorkflow).Return(currentWorkflowPolicy, nil) targetWorkflow.EXPECT().Revive().Return(nil) @@ -231,26 +231,26 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() newWorkflow := NewMockWorkflow(s.controller) - newContext := workflow.NewMockContext(s.controller) - newMutableState := workflow.NewMockMutableState(s.controller) - var newReleaseFn workflow.ReleaseCacheFunc = func(error) { newReleaseCalled = true } + newContext := definition.NewMockWorkflowContext(s.controller) + newMutableState := definition.NewMockMutableState(s.controller) + var newReleaseFn definition.ReleaseFunc = func(error) { newReleaseCalled = true } newWorkflow.EXPECT().GetContext().Return(newContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(newMutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(newReleaseFn).AnyTimes() newWorkflow.EXPECT().Revive().Return(nil) currentWorkflow := NewMockWorkflow(s.controller) - currentContext := workflow.NewMockContext(s.controller) - currentMutableState := workflow.NewMockMutableState(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + currentContext := definition.NewMockWorkflowContext(s.controller) + currentMutableState := definition.NewMockMutableState(s.controller) + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetContext().Return(currentContext).AnyTimes() currentWorkflow.EXPECT().GetMutableState().Return(currentMutableState).AnyTimes() currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() @@ -267,7 +267,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow s.mockTransactionMgr.EXPECT().loadWorkflow(ctx, namespaceID, workflowID, currentRunID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(true, nil) - currentWorkflowPolicy := workflow.TransactionPolicyPassive + currentWorkflowPolicy := definition.TransactionPolicyPassive currentMutableState.EXPECT().IsWorkflowExecutionRunning().Return(false).AnyTimes() currentWorkflow.EXPECT().SuppressBy(targetWorkflow).Return(currentWorkflowPolicy, nil).Times(0) targetWorkflow.EXPECT().Revive().Return(nil) @@ -308,23 +308,23 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() newWorkflow := NewMockWorkflow(s.controller) - newContext := workflow.NewMockContext(s.controller) - newMutableState := workflow.NewMockMutableState(s.controller) - var newReleaseFn workflow.ReleaseCacheFunc = func(error) { newReleaseCalled = true } + newContext := definition.NewMockWorkflowContext(s.controller) + newMutableState := definition.NewMockMutableState(s.controller) + var newReleaseFn definition.ReleaseFunc = func(error) { newReleaseCalled = true } newWorkflow.EXPECT().GetContext().Return(newContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(newMutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(newReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() targetMutableState.EXPECT().IsCurrentWorkflowGuaranteed().Return(false).AnyTimes() @@ -347,8 +347,8 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow s.mockTransactionMgr.EXPECT().checkWorkflowExists(ctx, namespaceID, workflowID, newRunID).Return(false, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) - targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) - newWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) + targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) + newWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) targetContext.EXPECT().UpdateWorkflowExecutionWithNew( gomock.Any(), @@ -356,8 +356,8 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow persistence.UpdateWorkflowModeBypassCurrent, newContext, newMutableState, - workflow.TransactionPolicyPassive, - workflow.TransactionPolicyPassive.Ptr(), + definition.TransactionPolicyPassive, + definition.TransactionPolicyPassive.Ptr(), ).Return(nil) err := s.updateMgr.dispatchForExistingWorkflow(ctx, now, isWorkflowRebuilt, targetWorkflow, newWorkflow) @@ -384,23 +384,23 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() newWorkflow := NewMockWorkflow(s.controller) - newContext := workflow.NewMockContext(s.controller) - newMutableState := workflow.NewMockMutableState(s.controller) - var newReleaseFn workflow.ReleaseCacheFunc = func(error) { newReleaseCalled = true } + newContext := definition.NewMockWorkflowContext(s.controller) + newMutableState := definition.NewMockMutableState(s.controller) + var newReleaseFn definition.ReleaseFunc = func(error) { newReleaseCalled = true } newWorkflow.EXPECT().GetContext().Return(newContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(newMutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(newReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() targetMutableState.EXPECT().IsCurrentWorkflowGuaranteed().Return(false).AnyTimes() @@ -423,17 +423,17 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow s.mockTransactionMgr.EXPECT().checkWorkflowExists(ctx, namespaceID, workflowID, newRunID).Return(true, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) - targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) - newWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) + targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) + newWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) targetContext.EXPECT().UpdateWorkflowExecutionWithNew( gomock.Any(), now, persistence.UpdateWorkflowModeBypassCurrent, - (workflow.Context)(nil), - (workflow.MutableState)(nil), - workflow.TransactionPolicyPassive, - (*workflow.TransactionPolicy)(nil), + (definition.WorkflowContext)(nil), + (definition.MutableState)(nil), + definition.TransactionPolicyPassive, + (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.updateMgr.dispatchForExistingWorkflow(ctx, now, isWorkflowRebuilt, targetWorkflow, newWorkflow) @@ -457,17 +457,17 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow newReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() newWorkflow := NewMockWorkflow(s.controller) - newContext := workflow.NewMockContext(s.controller) - newMutableState := workflow.NewMockMutableState(s.controller) - var newReleaseFn workflow.ReleaseCacheFunc = func(error) { newReleaseCalled = true } + newContext := definition.NewMockWorkflowContext(s.controller) + newMutableState := definition.NewMockMutableState(s.controller) + var newReleaseFn definition.ReleaseFunc = func(error) { newReleaseCalled = true } newWorkflow.EXPECT().GetContext().Return(newContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(newMutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(newReleaseFn).AnyTimes() @@ -488,9 +488,9 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow targetMutableState, newContext, newMutableState, - (workflow.Context)(nil), - (workflow.MutableState)(nil), - (*workflow.TransactionPolicy)(nil), + (definition.WorkflowContext)(nil), + (definition.MutableState)(nil), + (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.updateMgr.dispatchForExistingWorkflow(ctx, now, isWorkflowRebuilt, targetWorkflow, newWorkflow) @@ -515,26 +515,26 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() newWorkflow := NewMockWorkflow(s.controller) - newContext := workflow.NewMockContext(s.controller) - newMutableState := workflow.NewMockMutableState(s.controller) - var newReleaseFn workflow.ReleaseCacheFunc = func(error) { newReleaseCalled = true } + newContext := definition.NewMockWorkflowContext(s.controller) + newMutableState := definition.NewMockMutableState(s.controller) + var newReleaseFn definition.ReleaseFunc = func(error) { newReleaseCalled = true } newWorkflow.EXPECT().GetContext().Return(newContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(newMutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(newReleaseFn).AnyTimes() newWorkflow.EXPECT().Revive().Return(nil) currentWorkflow := NewMockWorkflow(s.controller) - currentContext := workflow.NewMockContext(s.controller) - currentMutableState := workflow.NewMockMutableState(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + currentContext := definition.NewMockWorkflowContext(s.controller) + currentMutableState := definition.NewMockMutableState(s.controller) + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetContext().Return(currentContext).AnyTimes() currentWorkflow.EXPECT().GetMutableState().Return(currentMutableState).AnyTimes() currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() @@ -550,7 +550,7 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow s.mockTransactionMgr.EXPECT().loadWorkflow(ctx, namespaceID, workflowID, currentRunID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(true, nil) - currentWorkflowPolicy := workflow.TransactionPolicyActive + currentWorkflowPolicy := definition.TransactionPolicyActive currentMutableState.EXPECT().IsWorkflowExecutionRunning().Return(true).AnyTimes() currentWorkflow.EXPECT().SuppressBy(targetWorkflow).Return(currentWorkflowPolicy, nil) targetWorkflow.EXPECT().Revive().Return(nil) @@ -591,23 +591,23 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() newWorkflow := NewMockWorkflow(s.controller) - newContext := workflow.NewMockContext(s.controller) - newMutableState := workflow.NewMockMutableState(s.controller) - var newReleaseFn workflow.ReleaseCacheFunc = func(error) { newReleaseCalled = true } + newContext := definition.NewMockWorkflowContext(s.controller) + newMutableState := definition.NewMockMutableState(s.controller) + var newReleaseFn definition.ReleaseFunc = func(error) { newReleaseCalled = true } newWorkflow.EXPECT().GetContext().Return(newContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(newMutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(newReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() targetMutableState.EXPECT().GetExecutionInfo().Return(&persistencespb.WorkflowExecutionInfo{ @@ -629,8 +629,8 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow s.mockTransactionMgr.EXPECT().checkWorkflowExists(ctx, namespaceID, workflowID, newRunID).Return(false, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) - targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) - newWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) + targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) + newWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) targetContext.EXPECT().ConflictResolveWorkflowExecution( gomock.Any(), @@ -639,9 +639,9 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow targetMutableState, newContext, newMutableState, - (workflow.Context)(nil), - (workflow.MutableState)(nil), - (*workflow.TransactionPolicy)(nil), + (definition.WorkflowContext)(nil), + (definition.MutableState)(nil), + (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.updateMgr.dispatchForExistingWorkflow(ctx, now, isWorkflowRebuilt, targetWorkflow, newWorkflow) @@ -668,23 +668,23 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() newWorkflow := NewMockWorkflow(s.controller) - newContext := workflow.NewMockContext(s.controller) - newMutableState := workflow.NewMockMutableState(s.controller) - var newReleaseFn workflow.ReleaseCacheFunc = func(error) { newReleaseCalled = true } + newContext := definition.NewMockWorkflowContext(s.controller) + newMutableState := definition.NewMockMutableState(s.controller) + var newReleaseFn definition.ReleaseFunc = func(error) { newReleaseCalled = true } newWorkflow.EXPECT().GetContext().Return(newContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(newMutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(newReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() targetMutableState.EXPECT().GetExecutionInfo().Return(&persistencespb.WorkflowExecutionInfo{ @@ -706,19 +706,19 @@ func (s *transactionMgrForExistingWorkflowSuite) TestDispatchForExistingWorkflow s.mockTransactionMgr.EXPECT().checkWorkflowExists(ctx, namespaceID, workflowID, newRunID).Return(true, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) - targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) - newWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) + targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) + newWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) targetContext.EXPECT().ConflictResolveWorkflowExecution( gomock.Any(), now, persistence.ConflictResolveWorkflowModeBypassCurrent, targetMutableState, - (workflow.Context)(nil), - (workflow.MutableState)(nil), - (workflow.Context)(nil), - (workflow.MutableState)(nil), - (*workflow.TransactionPolicy)(nil), + (definition.WorkflowContext)(nil), + (definition.MutableState)(nil), + (definition.WorkflowContext)(nil), + (definition.MutableState)(nil), + (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.updateMgr.dispatchForExistingWorkflow(ctx, now, isWorkflowRebuilt, targetWorkflow, newWorkflow) diff --git a/service/history/ndc/transaction_manager_new_workflow.go b/service/history/ndc/transaction_manager_new_workflow.go index 5dd83a3c589..701045fe3f6 100644 --- a/service/history/ndc/transaction_manager_new_workflow.go +++ b/service/history/ndc/transaction_manager_new_workflow.go @@ -35,7 +35,7 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) type ( @@ -158,7 +158,7 @@ func (r *nDCTransactionMgrForNewWorkflowImpl) createAsCurrent( targetWorkflowSnapshot, targetWorkflowEventsSeq, err := targetWorkflow.GetMutableState().CloseTransactionAsSnapshot( now, - workflow.TransactionPolicyPassive, + definition.TransactionPolicyPassive, ) if err != nil { return err @@ -214,7 +214,7 @@ func (r *nDCTransactionMgrForNewWorkflowImpl) createAsZombie( if err != nil { return err } - if targetWorkflowPolicy != workflow.TransactionPolicyPassive { + if targetWorkflowPolicy != definition.TransactionPolicyPassive { return serviceerror.NewInternal("transactionMgrForNewWorkflow createAsZombie encountered target workflow policy not being passive") } @@ -286,7 +286,7 @@ func (r *nDCTransactionMgrForNewWorkflowImpl) suppressCurrentAndCreateAsCurrent( targetWorkflow.GetContext(), targetWorkflow.GetMutableState(), currentWorkflowPolicy, - workflow.TransactionPolicyPassive.Ptr(), + definition.TransactionPolicyPassive.Ptr(), ) } diff --git a/service/history/ndc/transaction_manager_new_workflow_test.go b/service/history/ndc/transaction_manager_new_workflow_test.go index 19486b21f9c..22505b6c4b1 100644 --- a/service/history/ndc/transaction_manager_new_workflow_test.go +++ b/service/history/ndc/transaction_manager_new_workflow_test.go @@ -38,7 +38,7 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) type ( @@ -80,7 +80,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_Dup() { runID := "some random run ID" newWorkflow := NewMockWorkflow(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) + mutableState := definition.NewMockMutableState(s.controller) newWorkflow.EXPECT().GetMutableState().Return(mutableState).AnyTimes() mutableState.EXPECT().GetExecutionInfo().Return(&persistencespb.WorkflowExecutionInfo{ @@ -108,9 +108,9 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_BrandNew_ releaseCalled := false newWorkflow := NewMockWorkflow(s.controller) - weContext := workflow.NewMockContext(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) - var releaseFn workflow.ReleaseCacheFunc = func(error) { releaseCalled = true } + weContext := definition.NewMockWorkflowContext(s.controller) + mutableState := definition.NewMockMutableState(s.controller) + var releaseFn definition.ReleaseFunc = func(error) { releaseCalled = true } newWorkflow.EXPECT().GetContext().Return(weContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(mutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(releaseFn).AnyTimes() @@ -128,7 +128,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_BrandNew_ mutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: runID, }).AnyTimes() - mutableState.EXPECT().CloseTransactionAsSnapshot(now, workflow.TransactionPolicyPassive).Return( + mutableState.EXPECT().CloseTransactionAsSnapshot(now, definition.TransactionPolicyPassive).Return( workflowSnapshot, workflowEventsSeq, nil, ) @@ -163,9 +163,9 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_BrandNew_ releaseCalled := false newWorkflow := NewMockWorkflow(s.controller) - weContext := workflow.NewMockContext(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) - var releaseFn workflow.ReleaseCacheFunc = func(error) { releaseCalled = true } + weContext := definition.NewMockWorkflowContext(s.controller) + mutableState := definition.NewMockMutableState(s.controller) + var releaseFn definition.ReleaseFunc = func(error) { releaseCalled = true } newWorkflow.EXPECT().GetContext().Return(weContext).AnyTimes() newWorkflow.EXPECT().GetMutableState().Return(mutableState).AnyTimes() newWorkflow.EXPECT().GetReleaseFn().Return(releaseFn).AnyTimes() @@ -183,7 +183,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_BrandNew_ mutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: runID, }).AnyTimes() - mutableState.EXPECT().CloseTransactionAsSnapshot(now, workflow.TransactionPolicyPassive).Return( + mutableState.EXPECT().CloseTransactionAsSnapshot(now, definition.TransactionPolicyPassive).Return( workflowSnapshot, workflowEventsSeq, nil, ) @@ -221,16 +221,16 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsC currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - currentMutableState := workflow.NewMockMutableState(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + currentMutableState := definition.NewMockMutableState(s.controller) + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetMutableState().Return(currentMutableState).AnyTimes() currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() @@ -247,7 +247,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsC targetMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: targetRunID, }).AnyTimes() - targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, workflow.TransactionPolicyPassive).Return( + targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, definition.TransactionPolicyPassive).Return( targetWorkflowSnapshot, targetWorkflowEventsSeq, nil, ) @@ -296,16 +296,16 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsC currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - currentMutableState := workflow.NewMockMutableState(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + currentMutableState := definition.NewMockMutableState(s.controller) + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetMutableState().Return(currentMutableState).AnyTimes() currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() @@ -322,7 +322,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsC targetMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: targetRunID, }).AnyTimes() - targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, workflow.TransactionPolicyPassive).Return( + targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, definition.TransactionPolicyPassive).Return( targetWorkflowSnapshot, targetWorkflowEventsSeq, nil, ) @@ -370,15 +370,15 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() targetWorkflowSnapshot := &persistence.WorkflowSnapshot{ @@ -399,7 +399,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ targetMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: targetRunID, }).AnyTimes() - targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, workflow.TransactionPolicyPassive).Return( + targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, definition.TransactionPolicyPassive).Return( targetWorkflowSnapshot, targetWorkflowEventsSeq, nil, ) @@ -407,7 +407,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ s.mockTransactionMgr.EXPECT().loadWorkflow(ctx, namespaceID, workflowID, currentRunID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) - targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) + targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) targetContext.EXPECT().CreateWorkflowExecution( gomock.Any(), @@ -440,15 +440,15 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() targetWorkflowSnapshot := &persistence.WorkflowSnapshot{ @@ -469,7 +469,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ targetMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: targetRunID, }).AnyTimes() - targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, workflow.TransactionPolicyPassive).Return( + targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, definition.TransactionPolicyPassive).Return( targetWorkflowSnapshot, targetWorkflowEventsSeq, nil, ) @@ -477,7 +477,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ s.mockTransactionMgr.EXPECT().loadWorkflow(ctx, namespaceID, workflowID, currentRunID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) - targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) + targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) targetContext.EXPECT().CreateWorkflowExecution( gomock.Any(), @@ -510,15 +510,15 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() targetWorkflowSnapshot := &persistence.WorkflowSnapshot{ @@ -539,7 +539,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ targetMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: targetRunID, }).AnyTimes() - targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, workflow.TransactionPolicyPassive).Return( + targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, definition.TransactionPolicyPassive).Return( targetWorkflowSnapshot, targetWorkflowEventsSeq, nil, ) @@ -547,7 +547,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ s.mockTransactionMgr.EXPECT().loadWorkflow(ctx, namespaceID, workflowID, currentRunID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) - targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) + targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) targetContext.EXPECT().CreateWorkflowExecution( gomock.Any(), @@ -580,15 +580,15 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() targetWorkflowSnapshot := &persistence.WorkflowSnapshot{ @@ -609,7 +609,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ targetMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{ RunId: targetRunID, }).AnyTimes() - targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, workflow.TransactionPolicyPassive).Return( + targetMutableState.EXPECT().CloseTransactionAsSnapshot(now, definition.TransactionPolicyPassive).Return( targetWorkflowSnapshot, targetWorkflowEventsSeq, nil, ) @@ -617,7 +617,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_CreateAsZ s.mockTransactionMgr.EXPECT().loadWorkflow(ctx, namespaceID, workflowID, currentRunID).Return(currentWorkflow, nil) targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(false, nil) - targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(workflow.TransactionPolicyPassive, nil) + targetWorkflow.EXPECT().SuppressBy(currentWorkflow).Return(definition.TransactionPolicyPassive, nil) targetContext.EXPECT().CreateWorkflowExecution( gomock.Any(), @@ -650,17 +650,17 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_SuppressC currentReleaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - targetContext := workflow.NewMockContext(s.controller) - targetMutableState := workflow.NewMockMutableState(s.controller) - var targetReleaseFn workflow.ReleaseCacheFunc = func(error) { targetReleaseCalled = true } + targetContext := definition.NewMockWorkflowContext(s.controller) + targetMutableState := definition.NewMockMutableState(s.controller) + var targetReleaseFn definition.ReleaseFunc = func(error) { targetReleaseCalled = true } targetWorkflow.EXPECT().GetContext().Return(targetContext).AnyTimes() targetWorkflow.EXPECT().GetMutableState().Return(targetMutableState).AnyTimes() targetWorkflow.EXPECT().GetReleaseFn().Return(targetReleaseFn).AnyTimes() currentWorkflow := NewMockWorkflow(s.controller) - currentContext := workflow.NewMockContext(s.controller) - currentMutableState := workflow.NewMockMutableState(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + currentContext := definition.NewMockWorkflowContext(s.controller) + currentMutableState := definition.NewMockMutableState(s.controller) + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetContext().Return(currentContext).AnyTimes() currentWorkflow.EXPECT().GetMutableState().Return(currentMutableState).AnyTimes() currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() @@ -678,7 +678,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_SuppressC targetWorkflow.EXPECT().HappensAfter(currentWorkflow).Return(true, nil) currentMutableState.EXPECT().IsWorkflowExecutionRunning().Return(true).AnyTimes() - currentWorkflowPolicy := workflow.TransactionPolicyActive + currentWorkflowPolicy := definition.TransactionPolicyActive currentWorkflow.EXPECT().SuppressBy(targetWorkflow).Return(currentWorkflowPolicy, nil) targetWorkflow.EXPECT().Revive().Return(nil) @@ -689,7 +689,7 @@ func (s *transactionMgrForNewWorkflowSuite) TestDispatchForNewWorkflow_SuppressC targetContext, targetMutableState, currentWorkflowPolicy, - workflow.TransactionPolicyPassive.Ptr(), + definition.TransactionPolicyPassive.Ptr(), ).Return(nil) err := s.createMgr.dispatchForNewWorkflow(ctx, now, targetWorkflow) diff --git a/service/history/ndc/transaction_manager_test.go b/service/history/ndc/transaction_manager_test.go index 84417509980..d83de9ca885 100644 --- a/service/history/ndc/transaction_manager_test.go +++ b/service/history/ndc/transaction_manager_test.go @@ -44,6 +44,7 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" "go.temporal.io/server/service/history/workflow" @@ -147,9 +148,9 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Active_Open() runID := uuid.New() targetWorkflow := NewMockWorkflow(s.controller) - weContext := workflow.NewMockContext(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) - var releaseFn workflow.ReleaseCacheFunc = func(error) { releaseCalled = true } + weContext := definition.NewMockWorkflowContext(s.controller) + mutableState := definition.NewMockMutableState(s.controller) + var releaseFn definition.ReleaseFunc = func(error) { releaseCalled = true } workflowEvents := &persistence.WorkflowEvents{ Events: []*historypb.HistoryEvent{{EventId: 1}}, @@ -170,7 +171,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Active_Open() mutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{RunId: runID}) weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), workflowEvents).Return(int64(0), nil) weContext.EXPECT().UpdateWorkflowExecutionWithNew( - gomock.Any(), now, persistence.UpdateWorkflowModeUpdateCurrent, nil, nil, workflow.TransactionPolicyActive, (*workflow.TransactionPolicy)(nil), + gomock.Any(), now, persistence.UpdateWorkflowModeUpdateCurrent, nil, nil, definition.TransactionPolicyActive, (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.transactionMgr.backfillWorkflow(ctx, now, targetWorkflow, workflowEvents) s.NoError(err) @@ -195,9 +196,9 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Active_Closed releaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - weContext := workflow.NewMockContext(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) - var releaseFn workflow.ReleaseCacheFunc = func(error) { releaseCalled = true } + weContext := definition.NewMockWorkflowContext(s.controller) + mutableState := definition.NewMockMutableState(s.controller) + var releaseFn definition.ReleaseFunc = func(error) { releaseCalled = true } workflowEvents := &persistence.WorkflowEvents{} @@ -247,7 +248,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Active_Closed weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), workflowEvents).Return(int64(0), nil) weContext.EXPECT().UpdateWorkflowExecutionWithNew( - gomock.Any(), now, persistence.UpdateWorkflowModeBypassCurrent, nil, nil, workflow.TransactionPolicyPassive, (*workflow.TransactionPolicy)(nil), + gomock.Any(), now, persistence.UpdateWorkflowModeBypassCurrent, nil, nil, definition.TransactionPolicyPassive, (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.transactionMgr.backfillWorkflow(ctx, now, targetWorkflow, workflowEvents) @@ -273,9 +274,9 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Closed_ResetF releaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - weContext := workflow.NewMockContext(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) - var releaseFn workflow.ReleaseCacheFunc = func(error) { releaseCalled = true } + weContext := definition.NewMockWorkflowContext(s.controller) + mutableState := definition.NewMockMutableState(s.controller) + var releaseFn definition.ReleaseFunc = func(error) { releaseCalled = true } workflowEvents := &persistence.WorkflowEvents{} @@ -325,7 +326,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Closed_ResetF weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), workflowEvents).Return(int64(0), nil) weContext.EXPECT().UpdateWorkflowExecutionWithNew( - gomock.Any(), now, persistence.UpdateWorkflowModeUpdateCurrent, nil, nil, workflow.TransactionPolicyPassive, (*workflow.TransactionPolicy)(nil), + gomock.Any(), now, persistence.UpdateWorkflowModeUpdateCurrent, nil, nil, definition.TransactionPolicyPassive, (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.transactionMgr.backfillWorkflow(ctx, now, targetWorkflow, workflowEvents) @@ -339,9 +340,9 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Passive_Open( releaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - weContext := workflow.NewMockContext(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) - var releaseFn workflow.ReleaseCacheFunc = func(error) { releaseCalled = true } + weContext := definition.NewMockWorkflowContext(s.controller) + mutableState := definition.NewMockMutableState(s.controller) + var releaseFn definition.ReleaseFunc = func(error) { releaseCalled = true } workflowEvents := &persistence.WorkflowEvents{ Events: []*historypb.HistoryEvent{{EventId: 1}}, @@ -360,7 +361,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Passive_Open( weContext.EXPECT().ReapplyEvents([]*persistence.WorkflowEvents{workflowEvents}) weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), workflowEvents).Return(int64(0), nil) weContext.EXPECT().UpdateWorkflowExecutionWithNew( - gomock.Any(), now, persistence.UpdateWorkflowModeUpdateCurrent, nil, nil, workflow.TransactionPolicyPassive, (*workflow.TransactionPolicy)(nil), + gomock.Any(), now, persistence.UpdateWorkflowModeUpdateCurrent, nil, nil, definition.TransactionPolicyPassive, (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.transactionMgr.backfillWorkflow(ctx, now, targetWorkflow, workflowEvents) s.NoError(err) @@ -378,9 +379,9 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Passive_Close releaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - weContext := workflow.NewMockContext(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) - var releaseFn workflow.ReleaseCacheFunc = func(error) { releaseCalled = true } + weContext := definition.NewMockWorkflowContext(s.controller) + mutableState := definition.NewMockMutableState(s.controller) + var releaseFn definition.ReleaseFunc = func(error) { releaseCalled = true } workflowEvents := &persistence.WorkflowEvents{} @@ -410,7 +411,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_CurrentWorkflow_Passive_Close weContext.EXPECT().ReapplyEvents([]*persistence.WorkflowEvents{workflowEvents}) weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), workflowEvents).Return(int64(0), nil) weContext.EXPECT().UpdateWorkflowExecutionWithNew( - gomock.Any(), now, persistence.UpdateWorkflowModeUpdateCurrent, nil, nil, workflow.TransactionPolicyPassive, (*workflow.TransactionPolicy)(nil), + gomock.Any(), now, persistence.UpdateWorkflowModeUpdateCurrent, nil, nil, definition.TransactionPolicyPassive, (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.transactionMgr.backfillWorkflow(ctx, now, targetWorkflow, workflowEvents) @@ -430,9 +431,9 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_NotCurrentWorkflow_Active() { releaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - weContext := workflow.NewMockContext(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) - var releaseFn workflow.ReleaseCacheFunc = func(error) { releaseCalled = true } + weContext := definition.NewMockWorkflowContext(s.controller) + mutableState := definition.NewMockMutableState(s.controller) + var releaseFn definition.ReleaseFunc = func(error) { releaseCalled = true } workflowEvents := &persistence.WorkflowEvents{ Events: []*historypb.HistoryEvent{{ @@ -468,7 +469,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_NotCurrentWorkflow_Active() { weContext.EXPECT().ReapplyEvents([]*persistence.WorkflowEvents{workflowEvents}) weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), workflowEvents).Return(int64(0), nil) weContext.EXPECT().UpdateWorkflowExecutionWithNew( - gomock.Any(), now, persistence.UpdateWorkflowModeBypassCurrent, nil, nil, workflow.TransactionPolicyPassive, (*workflow.TransactionPolicy)(nil), + gomock.Any(), now, persistence.UpdateWorkflowModeBypassCurrent, nil, nil, definition.TransactionPolicyPassive, (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.transactionMgr.backfillWorkflow(ctx, now, targetWorkflow, workflowEvents) s.NoError(err) @@ -487,9 +488,9 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_NotCurrentWorkflow_Passive() releaseCalled := false targetWorkflow := NewMockWorkflow(s.controller) - weContext := workflow.NewMockContext(s.controller) - mutableState := workflow.NewMockMutableState(s.controller) - var releaseFn workflow.ReleaseCacheFunc = func(error) { releaseCalled = true } + weContext := definition.NewMockWorkflowContext(s.controller) + mutableState := definition.NewMockMutableState(s.controller) + var releaseFn definition.ReleaseFunc = func(error) { releaseCalled = true } workflowEvents := &persistence.WorkflowEvents{ Events: []*historypb.HistoryEvent{{ @@ -525,7 +526,7 @@ func (s *transactionMgrSuite) TestBackfillWorkflow_NotCurrentWorkflow_Passive() weContext.EXPECT().ReapplyEvents([]*persistence.WorkflowEvents{workflowEvents}) weContext.EXPECT().PersistWorkflowEvents(gomock.Any(), workflowEvents).Return(int64(0), nil) weContext.EXPECT().UpdateWorkflowExecutionWithNew( - gomock.Any(), now, persistence.UpdateWorkflowModeBypassCurrent, nil, nil, workflow.TransactionPolicyPassive, (*workflow.TransactionPolicy)(nil), + gomock.Any(), now, persistence.UpdateWorkflowModeBypassCurrent, nil, nil, definition.TransactionPolicyPassive, (*definition.TransactionPolicy)(nil), ).Return(nil) err := s.transactionMgr.backfillWorkflow(ctx, now, targetWorkflow, workflowEvents) s.NoError(err) diff --git a/service/history/ndc/workflow.go b/service/history/ndc/workflow.go index e411d44fe96..7b280932c6a 100644 --- a/service/history/ndc/workflow.go +++ b/service/history/ndc/workflow.go @@ -38,7 +38,7 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/payloads" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/workflow" + "go.temporal.io/server/service/history/definition" ) var ( @@ -48,13 +48,13 @@ var ( type ( Workflow interface { - GetContext() workflow.Context - GetMutableState() workflow.MutableState - GetReleaseFn() workflow.ReleaseCacheFunc + GetContext() definition.WorkflowContext + GetMutableState() definition.MutableState + GetReleaseFn() definition.ReleaseFunc GetVectorClock() (int64, int64, error) HappensAfter(that Workflow) (bool, error) Revive() error - SuppressBy(incomingWorkflow Workflow) (workflow.TransactionPolicy, error) + SuppressBy(incomingWorkflow Workflow) (definition.TransactionPolicy, error) FlushBufferedEvents() error } @@ -63,9 +63,9 @@ type ( clusterMetadata cluster.Metadata ctx context.Context - context workflow.Context - mutableState workflow.MutableState - releaseFn workflow.ReleaseCacheFunc + context definition.WorkflowContext + mutableState definition.MutableState + releaseFn definition.ReleaseFunc } ) @@ -73,9 +73,9 @@ func NewWorkflow( ctx context.Context, namespaceRegistry namespace.Registry, clusterMetadata cluster.Metadata, - context workflow.Context, - mutableState workflow.MutableState, - releaseFn workflow.ReleaseCacheFunc, + context definition.WorkflowContext, + mutableState definition.MutableState, + releaseFn definition.ReleaseFunc, ) *WorkflowImpl { return &WorkflowImpl{ @@ -89,15 +89,15 @@ func NewWorkflow( } } -func (r *WorkflowImpl) GetContext() workflow.Context { +func (r *WorkflowImpl) GetContext() definition.WorkflowContext { return r.context } -func (r *WorkflowImpl) GetMutableState() workflow.MutableState { +func (r *WorkflowImpl) GetMutableState() definition.MutableState { return r.mutableState } -func (r *WorkflowImpl) GetReleaseFn() workflow.ReleaseCacheFunc { +func (r *WorkflowImpl) GetReleaseFn() definition.ReleaseFunc { return r.releaseFn } @@ -156,7 +156,7 @@ func (r *WorkflowImpl) Revive() error { func (r *WorkflowImpl) SuppressBy( incomingWorkflow Workflow, -) (workflow.TransactionPolicy, error) { +) (definition.TransactionPolicy, error) { // NOTE: READ BEFORE MODIFICATION // @@ -167,11 +167,11 @@ func (r *WorkflowImpl) SuppressBy( lastWriteVersion, lastEventTaskID, err := r.GetVectorClock() if err != nil { - return workflow.TransactionPolicyActive, err + return definition.TransactionPolicyActive, err } incomingLastWriteVersion, incomingLastEventTaskID, err := incomingWorkflow.GetVectorClock() if err != nil { - return workflow.TransactionPolicyActive, err + return definition.TransactionPolicyActive, err } if WorkflowHappensAfter( @@ -180,21 +180,21 @@ func (r *WorkflowImpl) SuppressBy( incomingLastWriteVersion, incomingLastEventTaskID, ) { - return workflow.TransactionPolicyActive, serviceerror.NewInternal("Workflow cannot suppress workflow by older workflow") + return definition.TransactionPolicyActive, serviceerror.NewInternal("Workflow cannot suppress workflow by older workflow") } // if workflow is in zombie or finished state, keep as is if !r.mutableState.IsWorkflowExecutionRunning() { - return workflow.TransactionPolicyPassive, nil + return definition.TransactionPolicyPassive, nil } lastWriteCluster := r.clusterMetadata.ClusterNameForFailoverVersion(true, lastWriteVersion) currentCluster := r.clusterMetadata.GetCurrentClusterName() if currentCluster == lastWriteCluster { - return workflow.TransactionPolicyActive, r.terminateWorkflow(lastWriteVersion, incomingLastWriteVersion) + return definition.TransactionPolicyActive, r.terminateWorkflow(lastWriteVersion, incomingLastWriteVersion) } - return workflow.TransactionPolicyPassive, r.zombiefyWorkflow() + return definition.TransactionPolicyPassive, r.zombiefyWorkflow() } func (r *WorkflowImpl) FlushBufferedEvents() error { diff --git a/service/history/ndc/workflow_mock.go b/service/history/ndc/workflow_mock.go index 82d87b86985..4cf6c3c5b2e 100644 --- a/service/history/ndc/workflow_mock.go +++ b/service/history/ndc/workflow_mock.go @@ -32,7 +32,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - workflow "go.temporal.io/server/service/history/workflow" + definition "go.temporal.io/server/service/history/definition" ) // MockWorkflow is a mock of Workflow interface. @@ -73,10 +73,10 @@ func (mr *MockWorkflowMockRecorder) FlushBufferedEvents() *gomock.Call { } // GetContext mocks base method. -func (m *MockWorkflow) GetContext() workflow.Context { +func (m *MockWorkflow) GetContext() definition.WorkflowContext { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetContext") - ret0, _ := ret[0].(workflow.Context) + ret0, _ := ret[0].(definition.WorkflowContext) return ret0 } @@ -87,10 +87,10 @@ func (mr *MockWorkflowMockRecorder) GetContext() *gomock.Call { } // GetMutableState mocks base method. -func (m *MockWorkflow) GetMutableState() workflow.MutableState { +func (m *MockWorkflow) GetMutableState() definition.MutableState { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetMutableState") - ret0, _ := ret[0].(workflow.MutableState) + ret0, _ := ret[0].(definition.MutableState) return ret0 } @@ -101,10 +101,10 @@ func (mr *MockWorkflowMockRecorder) GetMutableState() *gomock.Call { } // GetReleaseFn mocks base method. -func (m *MockWorkflow) GetReleaseFn() workflow.ReleaseCacheFunc { +func (m *MockWorkflow) GetReleaseFn() definition.ReleaseFunc { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetReleaseFn") - ret0, _ := ret[0].(workflow.ReleaseCacheFunc) + ret0, _ := ret[0].(definition.ReleaseFunc) return ret0 } @@ -160,10 +160,10 @@ func (mr *MockWorkflowMockRecorder) Revive() *gomock.Call { } // SuppressBy mocks base method. -func (m *MockWorkflow) SuppressBy(incomingWorkflow Workflow) (workflow.TransactionPolicy, error) { +func (m *MockWorkflow) SuppressBy(incomingWorkflow Workflow) (definition.TransactionPolicy, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SuppressBy", incomingWorkflow) - ret0, _ := ret[0].(workflow.TransactionPolicy) + ret0, _ := ret[0].(definition.TransactionPolicy) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/service/history/ndc/workflow_resetter.go b/service/history/ndc/workflow_resetter.go index e5291987119..9476e583208 100644 --- a/service/history/ndc/workflow_resetter.go +++ b/service/history/ndc/workflow_resetter.go @@ -41,7 +41,6 @@ import ( "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/collection" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/failure" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" @@ -49,12 +48,12 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) type ( - workflowResetReapplyEventsFn func(ctx context.Context, resetMutableState workflow.MutableState) error + workflowResetReapplyEventsFn func(ctx context.Context, resetMutableState definition.MutableState) error WorkflowResetter interface { ResetWorkflow( @@ -78,11 +77,11 @@ type ( stateRebuilderProvider func() StateRebuilder workflowResetterImpl struct { - shard shard.Context + shard definition.ShardContext namespaceRegistry namespace.Registry clusterMetadata cluster.Metadata executionMgr persistence.ExecutionManager - historyCache workflow.Cache + historyCache definition.WorkflowCache newStateRebuilder stateRebuilderProvider transaction workflow.Transaction logger log.Logger @@ -92,8 +91,8 @@ type ( var _ WorkflowResetter = (*workflowResetterImpl)(nil) func NewWorkflowResetter( - shard shard.Context, - historyCache workflow.Cache, + shard definition.ShardContext, + historyCache definition.WorkflowCache, logger log.Logger, ) *workflowResetterImpl { return &workflowResetterImpl{ @@ -148,7 +147,7 @@ func (r *workflowResetterImpl) ResetWorkflow( currentWorkflowMutation, currentWorkflowEventsSeq, err = currentMutableState.CloseTransactionAsMutation( r.shard.GetTimeSource().Now(), - workflow.TransactionPolicyActive, + definition.TransactionPolicyActive, ) if err != nil { return err @@ -157,7 +156,7 @@ func (r *workflowResetterImpl) ResetWorkflow( HistorySize: currentWorkflow.GetContext().GetHistorySize(), } - reapplyEventsFn = func(ctx context.Context, resetMutableState workflow.MutableState) error { + reapplyEventsFn = func(ctx context.Context, resetMutableState definition.MutableState) error { lastVisitedRunID, err := r.reapplyContinueAsNewWorkflowEvents( ctx, resetMutableState, @@ -182,7 +181,7 @@ func (r *workflowResetterImpl) ResetWorkflow( return nil } } else { - reapplyEventsFn = func(ctx context.Context, resetMutableState workflow.MutableState) error { + reapplyEventsFn = func(ctx context.Context, resetMutableState definition.MutableState) error { _, err := r.reapplyContinueAsNewWorkflowEvents( ctx, resetMutableState, @@ -314,7 +313,7 @@ func (r *workflowResetterImpl) prepareResetWorkflow( func (r *workflowResetterImpl) reapplyEventsToResetWorkflow( ctx context.Context, - resetMutableState workflow.MutableState, + resetMutableState definition.MutableState, resetReapplyType enumspb.ResetReapplyType, reapplyEventsApplier workflowResetReapplyEventsFn, additionalReapplyEvents []*historypb.HistoryEvent, @@ -351,7 +350,7 @@ func (r *workflowResetterImpl) persistToDB( now := r.shard.GetTimeSource().Now() resetWorkflowSnapshot, resetWorkflowEventsSeq, err := resetWorkflow.GetMutableState().CloseTransactionAsSnapshot( now, - workflow.TransactionPolicyActive, + definition.TransactionPolicyActive, ) if err != nil { return err @@ -465,7 +464,7 @@ func (r *workflowResetterImpl) replayResetWorkflow( } func (r *workflowResetterImpl) failWorkflowTask( - resetMutableState workflow.MutableState, + resetMutableState definition.MutableState, baseRunID string, baseRebuildLastEventID int64, baseRebuildLastEventVersion int64, @@ -514,7 +513,7 @@ func (r *workflowResetterImpl) failWorkflowTask( func (r *workflowResetterImpl) failInflightActivity( now time.Time, - mutableState workflow.MutableState, + mutableState definition.MutableState, terminateReason string, ) error { @@ -572,7 +571,7 @@ func (r *workflowResetterImpl) forkAndGenerateBranchToken( } func (r *workflowResetterImpl) terminateWorkflow( - mutableState workflow.MutableState, + mutableState definition.MutableState, terminateReason string, ) error { @@ -589,7 +588,7 @@ func (r *workflowResetterImpl) terminateWorkflow( func (r *workflowResetterImpl) reapplyContinueAsNewWorkflowEvents( ctx context.Context, - resetMutableState workflow.MutableState, + resetMutableState definition.MutableState, namespaceID namespace.ID, workflowID string, baseRunID string, @@ -630,7 +629,7 @@ func (r *workflowResetterImpl) reapplyContinueAsNewWorkflowEvents( WorkflowId: workflowID, RunId: runID, }, - workflow.CallerTypeAPI, + definition.CallerTypeTask, ) if err != nil { return 0, nil, err @@ -682,7 +681,7 @@ func (r *workflowResetterImpl) reapplyContinueAsNewWorkflowEvents( func (r *workflowResetterImpl) reapplyWorkflowEvents( ctx context.Context, - mutableState workflow.MutableState, + mutableState definition.MutableState, firstEventID int64, nextEventID int64, branchToken []byte, @@ -723,7 +722,7 @@ func (r *workflowResetterImpl) reapplyWorkflowEvents( } func (r *workflowResetterImpl) reapplyEvents( - mutableState workflow.MutableState, + mutableState definition.MutableState, events []*historypb.HistoryEvent, ) error { diff --git a/service/history/ndc/workflow_resetter_test.go b/service/history/ndc/workflow_resetter_test.go index 29e00370d93..eca9ceef553 100644 --- a/service/history/ndc/workflow_resetter_test.go +++ b/service/history/ndc/workflow_resetter_test.go @@ -42,7 +42,6 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/collection" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/failure" "go.temporal.io/server/common/log" "go.temporal.io/server/common/namespace" @@ -50,6 +49,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" "go.temporal.io/server/service/history/workflow" @@ -133,9 +133,9 @@ func (s *workflowResetterSuite) TearDownTest() { func (s *workflowResetterSuite) TestPersistToDB_CurrentTerminated() { currentWorkflow := NewMockWorkflow(s.controller) currentReleaseCalled := false - currentContext := workflow.NewMockContext(s.controller) - currentMutableState := workflow.NewMockMutableState(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + currentContext := definition.NewMockWorkflowContext(s.controller) + currentMutableState := definition.NewMockMutableState(s.controller) + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetContext().Return(currentContext).AnyTimes() currentWorkflow.EXPECT().GetMutableState().Return(currentMutableState).AnyTimes() currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() @@ -159,9 +159,9 @@ func (s *workflowResetterSuite) TestPersistToDB_CurrentTerminated() { resetWorkflow := NewMockWorkflow(s.controller) resetReleaseCalled := false - resetContext := workflow.NewMockContext(s.controller) - resetMutableState := workflow.NewMockMutableState(s.controller) - var tarGetReleaseFn workflow.ReleaseCacheFunc = func(error) { resetReleaseCalled = true } + resetContext := definition.NewMockWorkflowContext(s.controller) + resetMutableState := definition.NewMockMutableState(s.controller) + var tarGetReleaseFn definition.ReleaseFunc = func(error) { resetReleaseCalled = true } resetWorkflow.EXPECT().GetContext().Return(resetContext).AnyTimes() resetWorkflow.EXPECT().GetMutableState().Return(resetMutableState).AnyTimes() resetWorkflow.EXPECT().GetReleaseFn().Return(tarGetReleaseFn).AnyTimes() @@ -182,7 +182,7 @@ func (s *workflowResetterSuite) TestPersistToDB_CurrentTerminated() { }} resetMutableState.EXPECT().CloseTransactionAsSnapshot( gomock.Any(), - workflow.TransactionPolicyActive, + definition.TransactionPolicyActive, ).Return(resetSnapshot, resetEventsSeq, nil) resetMutableState.EXPECT().GetNamespaceEntry().Return(namespace.FromPersistentState(&persistence.GetNamespaceResponse{ Namespace: &persistencespb.NamespaceDetail{ @@ -219,9 +219,9 @@ func (s *workflowResetterSuite) TestPersistToDB_CurrentNotTerminated() { currentWorkflow := NewMockWorkflow(s.controller) currentReleaseCalled := false - currentContext := workflow.NewMockContext(s.controller) - currentMutableState := workflow.NewMockMutableState(s.controller) - var currentReleaseFn workflow.ReleaseCacheFunc = func(error) { currentReleaseCalled = true } + currentContext := definition.NewMockWorkflowContext(s.controller) + currentMutableState := definition.NewMockMutableState(s.controller) + var currentReleaseFn definition.ReleaseFunc = func(error) { currentReleaseCalled = true } currentWorkflow.EXPECT().GetContext().Return(currentContext).AnyTimes() currentWorkflow.EXPECT().GetMutableState().Return(currentMutableState).AnyTimes() currentWorkflow.EXPECT().GetReleaseFn().Return(currentReleaseFn).AnyTimes() @@ -233,9 +233,9 @@ func (s *workflowResetterSuite) TestPersistToDB_CurrentNotTerminated() { resetWorkflow := NewMockWorkflow(s.controller) resetReleaseCalled := false - resetContext := workflow.NewMockContext(s.controller) - resetMutableState := workflow.NewMockMutableState(s.controller) - var tarGetReleaseFn workflow.ReleaseCacheFunc = func(error) { resetReleaseCalled = true } + resetContext := definition.NewMockWorkflowContext(s.controller) + resetMutableState := definition.NewMockMutableState(s.controller) + var tarGetReleaseFn definition.ReleaseFunc = func(error) { resetReleaseCalled = true } resetWorkflow.EXPECT().GetContext().Return(resetContext).AnyTimes() resetWorkflow.EXPECT().GetMutableState().Return(resetMutableState).AnyTimes() resetWorkflow.EXPECT().GetReleaseFn().Return(tarGetReleaseFn).AnyTimes() @@ -254,7 +254,7 @@ func (s *workflowResetterSuite) TestPersistToDB_CurrentNotTerminated() { }} resetMutableState.EXPECT().CloseTransactionAsSnapshot( gomock.Any(), - workflow.TransactionPolicyActive, + definition.TransactionPolicyActive, ).Return(resetSnapshot, resetEventsSeq, nil) resetContext.EXPECT().GetHistorySize().Return(int64(123)).AnyTimes() resetContext.EXPECT().CreateWorkflowExecution( @@ -285,7 +285,7 @@ func (s *workflowResetterSuite) TestReplayResetWorkflow() { resetBranchToken := []byte("some random reset branch token") resetRequestID := uuid.New() resetHistorySize := int64(4411) - resetMutableState := workflow.NewMockMutableState(s.controller) + resetMutableState := definition.NewMockMutableState(s.controller) shardID := s.mockShard.GetShardID() s.mockExecutionMgr.EXPECT().ForkHistoryBranch(gomock.Any(), &persistence.ForkHistoryBranchRequest{ @@ -338,7 +338,7 @@ func (s *workflowResetterSuite) TestFailWorkflowTask_NoWorkflowTask() { resetRunID := uuid.New() resetReason := "some random reset reason" - mutableState := workflow.NewMockMutableState(s.controller) + mutableState := definition.NewMockMutableState(s.controller) mutableState.EXPECT().GetPendingWorkflowTask().Return(nil, false).AnyTimes() err := s.workflowResetter.failWorkflowTask( @@ -359,8 +359,8 @@ func (s *workflowResetterSuite) TestFailWorkflowTask_WorkflowTaskScheduled() { resetRunID := uuid.New() resetReason := "some random reset reason" - mutableState := workflow.NewMockMutableState(s.controller) - workflowTaskSchedule := &workflow.WorkflowTaskInfo{ + mutableState := definition.NewMockMutableState(s.controller) + workflowTaskSchedule := &definition.WorkflowTaskInfo{ ScheduledEventID: baseRebuildLastEventID - 12, StartedEventID: common.EmptyEventID, RequestID: uuid.New(), @@ -369,7 +369,7 @@ func (s *workflowResetterSuite) TestFailWorkflowTask_WorkflowTaskScheduled() { Kind: enumspb.TASK_QUEUE_KIND_NORMAL, }, } - workflowTaskStart := &workflow.WorkflowTaskInfo{ + workflowTaskStart := &definition.WorkflowTaskInfo{ ScheduledEventID: workflowTaskSchedule.ScheduledEventID, StartedEventID: workflowTaskSchedule.ScheduledEventID + 1, RequestID: workflowTaskSchedule.RequestID, @@ -412,8 +412,8 @@ func (s *workflowResetterSuite) TestFailWorkflowTask_WorkflowTaskStarted() { resetRunID := uuid.New() resetReason := "some random reset reason" - mutableState := workflow.NewMockMutableState(s.controller) - workflowTask := &workflow.WorkflowTaskInfo{ + mutableState := definition.NewMockMutableState(s.controller) + workflowTask := &definition.WorkflowTaskInfo{ ScheduledEventID: baseRebuildLastEventID - 12, StartedEventID: baseRebuildLastEventID - 10, RequestID: uuid.New(), @@ -450,7 +450,7 @@ func (s *workflowResetterSuite) TestFailInflightActivity() { now := time.Now().UTC() terminateReason := "some random termination reason" - mutableState := workflow.NewMockMutableState(s.controller) + mutableState := definition.NewMockMutableState(s.controller) activity1 := &persistencespb.ActivityInfo{ Version: 12, @@ -512,7 +512,7 @@ func (s *workflowResetterSuite) TestGenerateBranchToken() { } func (s *workflowResetterSuite) TestTerminateWorkflow() { - workflowTask := &workflow.WorkflowTaskInfo{ + workflowTask := &definition.WorkflowTaskInfo{ Version: 123, ScheduledEventID: 1234, StartedEventID: 5678, @@ -520,7 +520,7 @@ func (s *workflowResetterSuite) TestTerminateWorkflow() { nextEventID := int64(666) terminateReason := "some random terminate reason" - mutableState := workflow.NewMockMutableState(s.controller) + mutableState := definition.NewMockMutableState(s.controller) mutableState.EXPECT().GetNextEventID().Return(nextEventID).AnyTimes() mutableState.EXPECT().GetInFlightWorkflowTask().Return(workflowTask, true) @@ -589,7 +589,7 @@ func (s *workflowResetterSuite) TestReapplyContinueAsNewWorkflowEvents_WithOutCo NextPageToken: nil, }, nil) - mutableState := workflow.NewMockMutableState(s.controller) + mutableState := definition.NewMockMutableState(s.controller) lastVisitedRunID, err := s.workflowResetter.reapplyContinueAsNewWorkflowEvents( ctx, @@ -692,17 +692,17 @@ func (s *workflowResetterSuite) TestReapplyContinueAsNewWorkflowEvents_WithConti NextPageToken: nil, }, nil) - resetContext := workflow.NewMockContext(s.controller) - resetContext.EXPECT().Lock(gomock.Any(), workflow.CallerTypeAPI).Return(nil) - resetContext.EXPECT().Unlock(workflow.CallerTypeAPI) - resetMutableState := workflow.NewMockMutableState(s.controller) + resetContext := definition.NewMockWorkflowContext(s.controller) + resetContext.EXPECT().Lock(gomock.Any(), definition.CallerTypeTask).Return(nil) + resetContext.EXPECT().Unlock(definition.CallerTypeTask) + resetMutableState := definition.NewMockMutableState(s.controller) resetContext.EXPECT().LoadMutableState(gomock.Any()).Return(resetMutableState, nil) resetMutableState.EXPECT().GetNextEventID().Return(newNextEventID).AnyTimes() resetMutableState.EXPECT().GetCurrentBranchToken().Return(newBranchToken, nil).AnyTimes() resetContextCacheKey := definition.NewWorkflowKey(s.namespaceID.String(), s.workflowID, newRunID) _, _ = s.workflowResetter.historyCache.(*workflow.CacheImpl).PutIfNotExist(resetContextCacheKey, resetContext) - mutableState := workflow.NewMockMutableState(s.controller) + mutableState := definition.NewMockMutableState(s.controller) lastVisitedRunID, err := s.workflowResetter.reapplyContinueAsNewWorkflowEvents( ctx, @@ -765,7 +765,7 @@ func (s *workflowResetterSuite) TestReapplyWorkflowEvents() { NextPageToken: nil, }, nil) - mutableState := workflow.NewMockMutableState(s.controller) + mutableState := definition.NewMockMutableState(s.controller) nextRunID, err := s.workflowResetter.reapplyWorkflowEvents( context.Background(), @@ -806,7 +806,7 @@ func (s *workflowResetterSuite) TestReapplyEvents() { } events := []*historypb.HistoryEvent{event1, event2, event3} - mutableState := workflow.NewMockMutableState(s.controller) + mutableState := definition.NewMockMutableState(s.controller) for _, event := range events { if event.GetEventType() == enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED { diff --git a/service/history/ndc/workflow_test.go b/service/history/ndc/workflow_test.go index 2d05744f5d2..076458331bc 100644 --- a/service/history/ndc/workflow_test.go +++ b/service/history/ndc/workflow_test.go @@ -42,6 +42,7 @@ import ( "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/namespace" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) @@ -52,8 +53,8 @@ type ( controller *gomock.Controller mockNamespaceCache *namespace.MockRegistry - mockContext *workflow.MockContext - mockMutableState *workflow.MockMutableState + mockContext *definition.MockWorkflowContext + mockMutableState *definition.MockMutableState mockClusterMetadata *cluster.MockMetadata namespaceID string @@ -72,8 +73,8 @@ func (s *workflowSuite) SetupTest() { s.controller = gomock.NewController(s.T()) s.mockNamespaceCache = namespace.NewMockRegistry(s.controller) - s.mockContext = workflow.NewMockContext(s.controller) - s.mockMutableState = workflow.NewMockMutableState(s.controller) + s.mockContext = definition.NewMockWorkflowContext(s.controller) + s.mockMutableState = definition.NewMockMutableState(s.controller) s.mockClusterMetadata = cluster.NewMockMetadata(s.controller) s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() @@ -188,8 +189,8 @@ func (s *workflowSuite) TestSuppressWorkflowBy_Error() { workflow.NoopReleaseFn, ) - incomingMockContext := workflow.NewMockContext(s.controller) - incomingMockMutableState := workflow.NewMockMutableState(s.controller) + incomingMockContext := definition.NewMockWorkflowContext(s.controller) + incomingMockMutableState := definition.NewMockMutableState(s.controller) incomingNDCWorkflow := NewWorkflow( context.Background(), s.mockNamespaceCache, @@ -255,8 +256,8 @@ func (s *workflowSuite) TestSuppressWorkflowBy_Terminate() { incomingRunID := uuid.New() incomingLastEventTaskID := int64(144) incomingLastEventVersion := lastEventVersion + 1 - incomingMockContext := workflow.NewMockContext(s.controller) - incomingMockMutableState := workflow.NewMockMutableState(s.controller) + incomingMockContext := definition.NewMockWorkflowContext(s.controller) + incomingMockMutableState := definition.NewMockMutableState(s.controller) incomingNDCWorkflow := NewWorkflow( context.Background(), s.mockNamespaceCache, @@ -278,7 +279,7 @@ func (s *workflowSuite) TestSuppressWorkflowBy_Terminate() { s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockMutableState.EXPECT().UpdateCurrentVersion(lastEventVersion, true).Return(nil).AnyTimes() - inFlightWorkflowTask := &workflow.WorkflowTaskInfo{ + inFlightWorkflowTask := &definition.WorkflowTaskInfo{ Version: 1234, ScheduledEventID: 5678, StartedEventID: 9012, @@ -305,12 +306,12 @@ func (s *workflowSuite) TestSuppressWorkflowBy_Terminate() { s.mockMutableState.EXPECT().IsWorkflowExecutionRunning().Return(false) policy, err := nDCWorkflow.SuppressBy(incomingNDCWorkflow) s.NoError(err) - s.Equal(workflow.TransactionPolicyPassive, policy) + s.Equal(definition.TransactionPolicyPassive, policy) s.mockMutableState.EXPECT().IsWorkflowExecutionRunning().Return(true) policy, err = nDCWorkflow.SuppressBy(incomingNDCWorkflow) s.NoError(err) - s.Equal(workflow.TransactionPolicyActive, policy) + s.Equal(definition.TransactionPolicyActive, policy) } func (s *workflowSuite) TestSuppressWorkflowBy_Zombiefy() { @@ -344,8 +345,8 @@ func (s *workflowSuite) TestSuppressWorkflowBy_Zombiefy() { incomingRunID := uuid.New() incomingLastEventTaskID := int64(144) incomingLastEventVersion := lastEventVersion + 1 - incomingMockContext := workflow.NewMockContext(s.controller) - incomingMockMutableState := workflow.NewMockMutableState(s.controller) + incomingMockContext := definition.NewMockWorkflowContext(s.controller) + incomingMockMutableState := definition.NewMockMutableState(s.controller) incomingNDCWorkflow := NewWorkflow( context.Background(), s.mockNamespaceCache, @@ -371,12 +372,12 @@ func (s *workflowSuite) TestSuppressWorkflowBy_Zombiefy() { s.mockMutableState.EXPECT().IsWorkflowExecutionRunning().Return(false) policy, err := nDCWorkflow.SuppressBy(incomingNDCWorkflow) s.NoError(err) - s.Equal(workflow.TransactionPolicyPassive, policy) + s.Equal(definition.TransactionPolicyPassive, policy) s.mockMutableState.EXPECT().IsWorkflowExecutionRunning().Return(true) policy, err = nDCWorkflow.SuppressBy(incomingNDCWorkflow) s.NoError(err) - s.Equal(workflow.TransactionPolicyPassive, policy) + s.Equal(definition.TransactionPolicyPassive, policy) s.Equal(enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE, executionState.State) s.EqualValues(enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING, executionState.Status) } diff --git a/service/history/queueAckMgr.go b/service/history/queueAckMgr.go index e6424e97547..5ce104e5aa5 100644 --- a/service/history/queueAckMgr.go +++ b/service/history/queueAckMgr.go @@ -34,8 +34,8 @@ import ( "go.temporal.io/server/common/metrics" ctasks "go.temporal.io/server/common/tasks" "go.temporal.io/server/common/util" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" ) type ( @@ -45,7 +45,7 @@ type ( // for the shard when all preceding tasks are acknowledged. queueAckMgrImpl struct { isFailover bool - shard shard.Context + shard definition.ShardContext options *QueueProcessorOptions processor processor logger log.Logger @@ -69,7 +69,7 @@ const ( var _ queueAckMgr = (*queueAckMgrImpl)(nil) func newQueueAckMgr( - shard shard.Context, + shard definition.ShardContext, options *QueueProcessorOptions, processor processor, ackLevel int64, @@ -93,7 +93,7 @@ func newQueueAckMgr( } func newQueueFailoverAckMgr( - shard shard.Context, + shard definition.ShardContext, options *QueueProcessorOptions, processor processor, ackLevel int64, diff --git a/service/history/queueAckMgr_test.go b/service/history/queueAckMgr_test.go index a2314c4fc0c..060f22e469a 100644 --- a/service/history/queueAckMgr_test.go +++ b/service/history/queueAckMgr_test.go @@ -35,13 +35,13 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" p "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/primitives/timestamp" ctasks "go.temporal.io/server/common/tasks" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" diff --git a/service/history/queueFactoryBase.go b/service/history/queueFactoryBase.go index 20a0aecd243..a7bd9a620a9 100644 --- a/service/history/queueFactoryBase.go +++ b/service/history/queueFactoryBase.go @@ -38,9 +38,8 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/quotas" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" ) const ( @@ -58,7 +57,7 @@ type ( // as that will lead to a cycle dependency issue between shard and workflow package. // 2. Move this interface to queues package after 1 is done so that there's no cycle dependency // between workflow and queues package. - CreateQueue(shard shard.Context, cache workflow.Cache) queues.Queue + CreateQueue(shard definition.ShardContext, cache definition.WorkflowCache) queues.Queue } QueueFactoryBaseParams struct { diff --git a/service/history/queueProcessorBase.go b/service/history/queueProcessorBase.go index a8c38ea13e5..9e9e648318e 100644 --- a/service/history/queueProcessorBase.go +++ b/service/history/queueProcessorBase.go @@ -37,9 +37,9 @@ import ( "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/quotas" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" - "go.temporal.io/server/service/history/workflow" ) type ( @@ -57,7 +57,7 @@ type ( queueProcessorBase struct { clusterName string - shard shard.Context + shard definition.ShardContext timeSource clock.TimeSource options *QueueProcessorOptions queueProcessor common.Daemon @@ -85,11 +85,11 @@ var ( func newQueueProcessorBase( clusterName string, - shard shard.Context, + shard definition.ShardContext, options *QueueProcessorOptions, queueProcessor common.Daemon, queueAckMgr queueAckMgr, - historyCache workflow.Cache, + historyCache definition.WorkflowCache, scheduler queues.Scheduler, rescheduler queues.Rescheduler, rateLimiter quotas.RateLimiter, diff --git a/service/history/queues/executable_test.go b/service/history/queues/executable_test.go index 209278b31bf..72227f53b9c 100644 --- a/service/history/queues/executable_test.go +++ b/service/history/queues/executable_test.go @@ -37,13 +37,13 @@ import ( "go.temporal.io/api/serviceerror" "go.temporal.io/server/common/clock" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" ctasks "go.temporal.io/server/common/tasks" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" ) diff --git a/service/history/queues/queue.go b/service/history/queues/queue.go index d0ecb85f728..3eb03fa8055 100644 --- a/service/history/queues/queue.go +++ b/service/history/queues/queue.go @@ -22,6 +22,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination queue_mock.go + package queues import ( @@ -29,8 +31,6 @@ import ( "go.temporal.io/server/service/history/tasks" ) -//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination queue_mock.go - type ( Queue interface { common.Daemon diff --git a/service/history/queues/queue_base.go b/service/history/queues/queue_base.go index 79007fdf00c..4ef483d4a79 100644 --- a/service/history/queues/queue_base.go +++ b/service/history/queues/queue_base.go @@ -40,7 +40,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/predicates" "go.temporal.io/server/common/quotas" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" ) @@ -74,7 +74,7 @@ type ( } queueBase struct { - shard shard.Context + shard definition.ShardContext status int32 shutdownCh chan struct{} @@ -119,7 +119,7 @@ type ( ) func newQueueBase( - shard shard.Context, + shard definition.ShardContext, category tasks.Category, paginationFnProvider PaginationFnProvider, scheduler Scheduler, diff --git a/service/history/queues/queue_immediate.go b/service/history/queues/queue_immediate.go index c359f916a9b..35de5495056 100644 --- a/service/history/queues/queue_immediate.go +++ b/service/history/queues/queue_immediate.go @@ -36,7 +36,7 @@ import ( "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/quotas" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" ) @@ -51,7 +51,7 @@ type ( ) func NewImmediateQueue( - shard shard.Context, + shard definition.ShardContext, category tasks.Category, scheduler Scheduler, priorityAssigner PriorityAssigner, diff --git a/service/history/queues/queue_scheduled.go b/service/history/queues/queue_scheduled.go index a391857ef4e..eb1f7fb9ee4 100644 --- a/service/history/queues/queue_scheduled.go +++ b/service/history/queues/queue_scheduled.go @@ -38,7 +38,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/quotas" "go.temporal.io/server/common/timer" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" ) @@ -60,7 +60,7 @@ const ( ) func NewScheduledQueue( - shard shard.Context, + shard definition.ShardContext, category tasks.Category, scheduler Scheduler, priorityAssigner PriorityAssigner, diff --git a/service/history/queues/util_test.go b/service/history/queues/util_test.go index a715449edb3..bb2ea644fe4 100644 --- a/service/history/queues/util_test.go +++ b/service/history/queues/util_test.go @@ -30,7 +30,7 @@ import ( "github.com/stretchr/testify/assert" - "go.temporal.io/server/common/definition" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" ) diff --git a/service/history/replication/ack_manager.go b/service/history/replication/ack_manager.go index fce5c2ac148..ae92b93242b 100644 --- a/service/history/replication/ack_manager.go +++ b/service/history/replication/ack_manager.go @@ -41,7 +41,6 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/backoff" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" @@ -50,9 +49,8 @@ import ( "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" ) type ( @@ -65,9 +63,9 @@ type ( ackMgrImpl struct { currentClusterName string - shard shard.Context + shard definition.ShardContext config *configs.Config - workflowCache workflow.Cache + workflowCache definition.WorkflowCache executionMgr persistence.ExecutionManager metricsHandler metrics.MetricsHandler logger log.Logger @@ -87,8 +85,8 @@ var ( ) func NewAckManager( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, executionMgr persistence.ExecutionManager, logger log.Logger, ) AckManager { @@ -362,7 +360,7 @@ func (p *ackMgrImpl) generateSyncActivityTask( namespaceID, workflowID, runID, - func(mutableState workflow.MutableState) (*replicationspb.ReplicationTask, error) { + func(mutableState definition.MutableState) (*replicationspb.ReplicationTask, error) { activityInfo, ok := mutableState.GetActivityInfo(taskInfo.ScheduledEventID) if !ok { return nil, nil @@ -421,7 +419,7 @@ func (p *ackMgrImpl) generateHistoryReplicationTask( namespaceID, workflowID, runID, - func(mutableState workflow.MutableState) (*replicationspb.ReplicationTask, error) { + func(mutableState definition.MutableState) (*replicationspb.ReplicationTask, error) { versionHistoryItems, branchToken, err := getVersionHistoryItems( mutableState, taskInfo.FirstEventID, @@ -487,7 +485,7 @@ func (p *ackMgrImpl) generateSyncWorkflowStateTask( namespaceID, workflowID, runID, - func(mutableState workflow.MutableState) (*replicationspb.ReplicationTask, error) { + func(mutableState definition.MutableState) (*replicationspb.ReplicationTask, error) { return &replicationspb.ReplicationTask{ TaskType: enumsspb.REPLICATION_TASK_TYPE_SYNC_WORKFLOW_STATE_TASK, SourceTaskId: taskID, @@ -547,7 +545,7 @@ func (p *ackMgrImpl) processReplication( namespaceID namespace.ID, workflowID string, runID string, - action func(workflow.MutableState) (*replicationspb.ReplicationTask, error), + action func(definition.MutableState) (*replicationspb.ReplicationTask, error), ) (retReplicationTask *replicationspb.ReplicationTask, retError error) { execution := commonpb.WorkflowExecution{ @@ -559,7 +557,7 @@ func (p *ackMgrImpl) processReplication( ctx, namespaceID, execution, - workflow.CallerTypeTask, + definition.CallerTypeTask, ) if err != nil { return nil, err @@ -608,7 +606,7 @@ func (p *ackMgrImpl) processNewRunReplication( WorkflowId: workflowID, RunId: newRunID, }, - workflow.CallerTypeTask, + definition.CallerTypeTask, ) if err != nil { return nil, err @@ -650,7 +648,7 @@ func (p *ackMgrImpl) processNewRunReplication( } func getVersionHistoryItems( - mutableState workflow.MutableState, + mutableState definition.MutableState, eventID int64, version int64, ) ([]*historyspb.VersionHistoryItem, []byte, error) { diff --git a/service/history/replication/ack_manager_test.go b/service/history/replication/ack_manager_test.go index a337c353b34..06cc5ef0628 100644 --- a/service/history/replication/ack_manager_test.go +++ b/service/history/replication/ack_manager_test.go @@ -43,13 +43,13 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/failure" "go.temporal.io/server/common/log" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/payloads" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" @@ -64,7 +64,7 @@ type ( controller *gomock.Controller mockShard *shard.ContextTest mockNamespaceCache *namespace.MockRegistry - mockMutableState *workflow.MockMutableState + mockMutableState *definition.MockMutableState mockClusterMetadata *cluster.MockMetadata mockExecutionMgr *persistence.MockExecutionManager @@ -92,7 +92,7 @@ func (s *ackManagerSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockMutableState = workflow.NewMockMutableState(s.controller) + s.mockMutableState = definition.NewMockMutableState(s.controller) s.mockShard = shard.NewTestContext( s.controller, @@ -278,7 +278,7 @@ func (s *ackManagerSuite) TestSyncActivity_WorkflowCompleted() { WorkflowId: workflowID, RunId: runID, }, - workflow.CallerTypeTask, + definition.CallerTypeTask, ) context.(*workflow.ContextImpl).MutableState = s.mockMutableState release(nil) @@ -330,7 +330,7 @@ func (s *ackManagerSuite) TestSyncActivity_ActivityCompleted() { WorkflowId: workflowID, RunId: runID, }, - workflow.CallerTypeTask, + definition.CallerTypeTask, ) context.(*workflow.ContextImpl).MutableState = s.mockMutableState @@ -385,7 +385,7 @@ func (s *ackManagerSuite) TestSyncActivity_ActivityRetry() { WorkflowId: workflowID, RunId: runID, }, - workflow.CallerTypeTask, + definition.CallerTypeTask, ) context.(*workflow.ContextImpl).MutableState = s.mockMutableState @@ -498,7 +498,7 @@ func (s *ackManagerSuite) TestSyncActivity_ActivityRunning() { WorkflowId: workflowID, RunId: runID, }, - workflow.CallerTypeTask, + definition.CallerTypeTask, ) context.(*workflow.ContextImpl).MutableState = s.mockMutableState diff --git a/service/history/replication/dlq_handler.go b/service/history/replication/dlq_handler.go index 9c9bbaa0642..6042650ae4e 100644 --- a/service/history/replication/dlq_handler.go +++ b/service/history/replication/dlq_handler.go @@ -40,7 +40,7 @@ import ( "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/xdc" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/workflow" ) @@ -72,9 +72,9 @@ type ( dlqHandlerImpl struct { taskExecutorsLock sync.Mutex taskExecutors map[string]TaskExecutor - shard shard.Context + shard definition.ShardContext deleteManager workflow.DeleteManager - workflowCache workflow.Cache + workflowCache definition.WorkflowCache resender xdc.NDCHistoryResender taskExecutorProvider TaskExecutorProvider logger log.Logger @@ -82,9 +82,9 @@ type ( ) func NewLazyDLQHandler( - shard shard.Context, + shard definition.ShardContext, deleteManager workflow.DeleteManager, - workflowCache workflow.Cache, + workflowCache definition.WorkflowCache, clientBean client.Bean, taskExecutorProvider TaskExecutorProvider, ) DLQHandler { @@ -99,9 +99,9 @@ func NewLazyDLQHandler( } func newDLQHandler( - shard shard.Context, + shard definition.ShardContext, deleteManager workflow.DeleteManager, - workflowCache workflow.Cache, + workflowCache definition.WorkflowCache, clientBean client.Bean, taskExecutors map[string]TaskExecutor, taskExecutorProvider TaskExecutorProvider, diff --git a/service/history/replication/dlq_handler_test.go b/service/history/replication/dlq_handler_test.go index 7fc543e8054..0ceeccde2ae 100644 --- a/service/history/replication/dlq_handler_test.go +++ b/service/history/replication/dlq_handler_test.go @@ -42,10 +42,10 @@ import ( replicationspb "go.temporal.io/server/api/replication/v1" "go.temporal.io/server/client" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/resourcetest" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" @@ -118,7 +118,7 @@ func (s *dlqHandlerSuite) SetupTest() { s.replicationMessageHandler = newDLQHandler( s.mockShard, workflow.NewMockDeleteManager(s.controller), - workflow.NewMockCache(s.controller), + definition.NewMockWorkflowCache(s.controller), s.mockClientBean, s.taskExecutors, func(params TaskExecutorParams) TaskExecutor { diff --git a/service/history/replication/task_executor.go b/service/history/replication/task_executor.go index 376744a33dc..cab331f5f0d 100644 --- a/service/history/replication/task_executor.go +++ b/service/history/replication/task_executor.go @@ -43,7 +43,7 @@ import ( "go.temporal.io/server/common/namespace" serviceerrors "go.temporal.io/server/common/serviceerror" "go.temporal.io/server/common/xdc" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) @@ -54,11 +54,11 @@ type ( TaskExecutorParams struct { RemoteCluster string // TODO: Remove this remote cluster from executor then it can use singleton. - Shard shard.Context + Shard definition.ShardContext HistoryResender xdc.NDCHistoryResender - HistoryEngine shard.Engine + HistoryEngine definition.Engine DeleteManager workflow.DeleteManager - WorkflowCache workflow.Cache + WorkflowCache definition.WorkflowCache } TaskExecutorProvider func(params TaskExecutorParams) TaskExecutor @@ -66,12 +66,12 @@ type ( taskExecutorImpl struct { currentCluster string remoteCluster string - shard shard.Context + shard definition.ShardContext namespaceRegistry namespace.Registry nDCHistoryResender xdc.NDCHistoryResender - historyEngine shard.Engine + historyEngine definition.Engine deleteManager workflow.DeleteManager - workflowCache workflow.Cache + workflowCache definition.WorkflowCache metricsHandler metrics.MetricsHandler logger log.Logger } @@ -81,11 +81,11 @@ type ( // The executor uses by 1) DLQ replication task handler 2) history replication task processor func NewTaskExecutor( remoteCluster string, - shard shard.Context, + shard definition.ShardContext, nDCHistoryResender xdc.NDCHistoryResender, - historyEngine shard.Engine, + historyEngine definition.Engine, deleteManager workflow.DeleteManager, - workflowCache workflow.Cache, + workflowCache definition.WorkflowCache, ) TaskExecutor { return &taskExecutorImpl{ currentCluster: shard.GetClusterMetadata().GetCurrentClusterName(), @@ -350,7 +350,7 @@ func (e *taskExecutorImpl) cleanupWorkflowExecution(ctx context.Context, namespa WorkflowId: workflowID, RunId: runID, } - wfCtx, releaseFn, err := e.workflowCache.GetOrCreateWorkflowExecution(ctx, nsID, ex, workflow.CallerTypeTask) + wfCtx, releaseFn, err := e.workflowCache.GetOrCreateWorkflowExecution(ctx, nsID, ex, definition.CallerTypeTask) if err != nil { return err } diff --git a/service/history/replication/task_executor_test.go b/service/history/replication/task_executor_test.go index cbffe6b98dd..ff4f7392e3b 100644 --- a/service/history/replication/task_executor_test.go +++ b/service/history/replication/task_executor_test.go @@ -49,6 +49,7 @@ import ( serviceerrors "go.temporal.io/server/common/serviceerror" "go.temporal.io/server/common/xdc" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" "go.temporal.io/server/service/history/workflow" @@ -63,12 +64,12 @@ type ( remoteCluster string mockResource *resourcetest.Test mockShard *shard.ContextTest - mockEngine *shard.MockEngine + mockEngine *definition.MockEngine config *configs.Config historyClient *historyservicemock.MockHistoryServiceClient mockNamespaceCache *namespace.MockRegistry clusterMetadata *cluster.MockMetadata - workflowCache *workflow.MockCache + workflowCache *definition.MockWorkflowCache nDCHistoryResender *xdc.MockNDCHistoryResender replicationTaskExecutor *taskExecutorImpl @@ -106,13 +107,13 @@ func (s *taskExecutorSuite) SetupTest() { }}, s.config, ) - s.mockEngine = shard.NewMockEngine(s.controller) + s.mockEngine = definition.NewMockEngine(s.controller) s.mockResource = s.mockShard.Resource s.mockNamespaceCache = s.mockResource.NamespaceCache s.clusterMetadata = s.mockResource.ClusterMetadata s.nDCHistoryResender = xdc.NewMockNDCHistoryResender(s.controller) s.historyClient = historyservicemock.NewMockHistoryServiceClient(s.controller) - s.workflowCache = workflow.NewMockCache(s.controller) + s.workflowCache = definition.NewMockWorkflowCache(s.controller) s.clusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockNamespaceCache.EXPECT().GetNamespaceName(gomock.Any()).Return(tests.Namespace, nil).AnyTimes() diff --git a/service/history/replication/task_processor.go b/service/history/replication/task_processor.go index 13c3bd553fa..ffec6775b50 100644 --- a/service/history/replication/task_processor.go +++ b/service/history/replication/task_processor.go @@ -53,6 +53,7 @@ import ( "go.temporal.io/server/common/quotas" serviceerrors "go.temporal.io/server/common/serviceerror" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" ) @@ -77,8 +78,8 @@ type ( currentCluster string sourceCluster string status int32 - shard shard.Context - historyEngine shard.Engine + shard definition.ShardContext + historyEngine definition.Engine historySerializer serialization.Serializer config *configs.Config metricsHandler metrics.MetricsHandler @@ -109,8 +110,8 @@ type ( // NewTaskProcessor creates a new replication task processor. func NewTaskProcessor( - shard shard.Context, - historyEngine shard.Engine, + shard definition.ShardContext, + historyEngine definition.Engine, config *configs.Config, metricsHandler metrics.MetricsHandler, replicationTaskFetcher taskFetcher, diff --git a/service/history/replication/task_processor_manager.go b/service/history/replication/task_processor_manager.go index 92b26ab2576..8ef263162ba 100644 --- a/service/history/replication/task_processor_manager.go +++ b/service/history/replication/task_processor_manager.go @@ -43,7 +43,7 @@ import ( "go.temporal.io/server/common/persistence/serialization" "go.temporal.io/server/common/xdc" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/workflow" ) @@ -53,12 +53,12 @@ type ( taskProcessorManagerImpl struct { config *configs.Config deleteMgr workflow.DeleteManager - engine shard.Engine + engine definition.Engine eventSerializer serialization.Serializer - shard shard.Context + shard definition.ShardContext status int32 replicationTaskFetcherFactory TaskFetcherFactory - workflowCache workflow.Cache + workflowCache definition.WorkflowCache resender xdc.NDCHistoryResender taskExecutorProvider TaskExecutorProvider metricsHandler metrics.MetricsHandler @@ -75,9 +75,9 @@ var _ common.Daemon = (*taskProcessorManagerImpl)(nil) func NewTaskProcessorManager( config *configs.Config, - shard shard.Context, - engine shard.Engine, - workflowCache workflow.Cache, + shard definition.ShardContext, + engine definition.Engine, + workflowCache definition.WorkflowCache, workflowDeleteManager workflow.DeleteManager, clientBean client.Bean, eventSerializer serialization.Serializer, diff --git a/service/history/replication/task_processor_manager_test.go b/service/history/replication/task_processor_manager_test.go index 2cdcd35719b..3bc76ad004e 100644 --- a/service/history/replication/task_processor_manager_test.go +++ b/service/history/replication/task_processor_manager_test.go @@ -42,7 +42,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/serialization" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" ) @@ -53,8 +53,8 @@ type ( *require.Assertions controller *gomock.Controller - mockShard *shard.MockContext - mockEngine *shard.MockEngine + mockShard *definition.MockShardContext + mockEngine *definition.MockEngine mockClientBean *client.MockBean mockClusterMetadata *cluster.MockMetadata mockHistoryClient *historyservicemock.MockHistoryServiceClient @@ -92,8 +92,8 @@ func (s *taskProcessorManagerSuite) SetupTest() { s.requestChan = make(chan *replicationTaskRequest, 10) s.shardID = rand.Int31() - s.mockShard = shard.NewMockContext(s.controller) - s.mockEngine = shard.NewMockEngine(s.controller) + s.mockShard = definition.NewMockShardContext(s.controller) + s.mockEngine = definition.NewMockEngine(s.controller) s.mockClientBean = client.NewMockBean(s.controller) s.mockReplicationTaskExecutor = NewMockTaskExecutor(s.controller) diff --git a/service/history/replication/task_processor_test.go b/service/history/replication/task_processor_test.go index c24a84f3b0e..bea207168d0 100644 --- a/service/history/replication/task_processor_test.go +++ b/service/history/replication/task_processor_test.go @@ -56,6 +56,7 @@ import ( "go.temporal.io/server/common/quotas" "go.temporal.io/server/common/resourcetest" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" @@ -69,7 +70,7 @@ type ( controller *gomock.Controller mockResource *resourcetest.Test mockShard *shard.ContextTest - mockEngine *shard.MockEngine + mockEngine *definition.MockEngine mockNamespaceCache *namespace.MockRegistry mockClientBean *client.MockBean mockAdminClient *adminservicemock.MockAdminServiceClient @@ -126,7 +127,7 @@ func (s *taskProcessorSuite) SetupTest() { }, s.config, ) - s.mockEngine = shard.NewMockEngine(s.controller) + s.mockEngine = definition.NewMockEngine(s.controller) s.mockResource = s.mockShard.Resource s.mockNamespaceCache = s.mockResource.NamespaceCache s.mockClientBean = s.mockResource.ClientBean diff --git a/service/history/shard/context_impl.go b/service/history/shard/context_impl.go index dca80c07f2f..d2deb68c2b5 100644 --- a/service/history/shard/context_impl.go +++ b/service/history/shard/context_impl.go @@ -48,7 +48,6 @@ import ( "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/future" "go.temporal.io/server/common/headers" "go.temporal.io/server/common/log" @@ -63,6 +62,7 @@ import ( "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/common/util" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/vclock" @@ -91,13 +91,13 @@ type ( stringRepr string executionManager persistence.ExecutionManager metricsHandler metrics.MetricsHandler - eventsCache events.Cache + eventsCache definition.EventCache closeCallback func(*ContextImpl) config *configs.Config contextTaggedLogger log.Logger throttledLogger log.Logger engineFactory EngineFactory - engineFuture *future.FutureImpl[Engine] + engineFuture *future.FutureImpl[definition.Engine] persistenceShardManager persistence.ShardManager clientBean client.Bean @@ -111,7 +111,7 @@ type ( archivalMetadata archiver.ArchivalMetadata hostInfoProvider membership.HostInfoProvider - // Context that lives for the lifetime of the shard context + // ShardContext that lives for the lifetime of the shard context lifecycleCtx context.Context lifecycleCancel context.CancelFunc @@ -148,13 +148,13 @@ type ( contextRequest interface{} contextRequestAcquire struct{} - contextRequestAcquired struct{ engine Engine } + contextRequestAcquired struct{ engine definition.Engine } contextRequestLost struct{} contextRequestStop struct{} contextRequestFinishStop struct{} ) -var _ Context = (*ContextImpl)(nil) +var _ definition.ShardContext = (*ContextImpl)(nil) var ( // ErrShardStatusUnknown means we're not sure if we have the shard lock or not. This may be returned @@ -206,7 +206,7 @@ func (s *ContextImpl) GetPingChecks() []common.PingCheck { func (s *ContextImpl) GetEngine( ctx context.Context, -) (Engine, error) { +) (definition.Engine, error) { return s.engineFuture.Get(ctx) } @@ -1130,7 +1130,7 @@ func (s *ContextImpl) GetConfig() *configs.Config { return s.config } -func (s *ContextImpl) GetEventsCache() events.Cache { +func (s *ContextImpl) GetEventsCache() definition.EventCache { // constant from initialization (except for tests), no need for locks return s.eventsCache } @@ -1487,7 +1487,7 @@ func (s *ContextImpl) maybeRecordShardAcquisitionLatency(ownershipChanged bool) } } -func (s *ContextImpl) createEngine() Engine { +func (s *ContextImpl) createEngine() definition.Engine { s.contextTaggedLogger.Info("", tag.LifeCycleStarting, tag.ComponentShardEngine) engine := s.engineFactory.CreateEngine(s) engine.Start() @@ -1521,7 +1521,7 @@ func (s *ContextImpl) finishStop() { } } -func (s *ContextImpl) isValid() bool { +func (s *ContextImpl) IsValid() bool { s.stateLock.Lock() defer s.stateLock.Unlock() return s.state < contextStateStopping @@ -1884,7 +1884,7 @@ func (s *ContextImpl) acquireShard() { ownershipChanged := false op := func() error { - if !s.isValid() { + if !s.IsValid() { return s.newShardClosedErrorWithShardID() } @@ -1910,7 +1910,7 @@ func (s *ContextImpl) acquireShard() { s.contextTaggedLogger.Info("Acquired shard") // The first time we get the shard, we have to create the engine - var engine Engine + var engine definition.Engine if !s.engineFuture.Ready() { s.maybeRecordShardAcquisitionLatency(ownershipChanged) engine = s.createEngine() @@ -1994,7 +1994,7 @@ func newContext( handoverNamespaces: make(map[string]*namespaceHandOverInfo), lifecycleCtx: lifecycleCtx, lifecycleCancel: lifecycleCancel, - engineFuture: future.NewFuture[Engine](), + engineFuture: future.NewFuture[definition.Engine](), } shardContext.eventsCache = events.NewEventsCache( shardContext.GetShardID(), diff --git a/service/history/shard/context_test.go b/service/history/shard/context_test.go index 7d2744c2ceb..173c1975b94 100644 --- a/service/history/shard/context_test.go +++ b/service/history/shard/context_test.go @@ -41,6 +41,7 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" ) @@ -51,12 +52,12 @@ type ( *require.Assertions controller *gomock.Controller - mockShard Context + mockShard definition.ShardContext mockClusterMetadata *cluster.MockMetadata mockShardManager *persistence.MockShardManager mockExecutionManager *persistence.MockExecutionManager mockNamespaceCache *namespace.MockRegistry - mockHistoryEngine *MockEngine + mockHistoryEngine *definition.MockEngine timeSource *clock.EventTimeSource } @@ -97,7 +98,7 @@ func (s *contextSuite) SetupTest() { s.mockExecutionManager = shardContext.Resource.ExecutionMgr s.mockShardManager = shardContext.Resource.ShardMgr - s.mockHistoryEngine = NewMockEngine(s.controller) + s.mockHistoryEngine = definition.NewMockEngine(s.controller) shardContext.engineFuture.Set(s.mockHistoryEngine, nil) } diff --git a/service/history/shard/context_testutil.go b/service/history/shard/context_testutil.go index f434d287148..cf0a455b56d 100644 --- a/service/history/shard/context_testutil.go +++ b/service/history/shard/context_testutil.go @@ -39,7 +39,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/resourcetest" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/events" + "go.temporal.io/server/service/history/definition" ) type ContextTest struct { @@ -47,11 +47,11 @@ type ContextTest struct { Resource *resourcetest.Test - MockEventsCache *events.MockCache + MockEventsCache *definition.MockEventCache MockHostInfoProvider *membership.MockHostInfoProvider } -var _ Context = (*ContextTest)(nil) +var _ definition.ShardContext = (*ContextTest)(nil) func NewTestContextWithTimeSource( ctrl *gomock.Controller, @@ -71,7 +71,7 @@ func NewTestContext( config *configs.Config, ) *ContextTest { resourceTest := resourcetest.NewTest(ctrl, metrics.History) - eventsCache := events.NewMockCache(ctrl) + eventsCache := definition.NewMockEventCache(ctrl) hostInfoProvider := membership.NewMockHostInfoProvider(ctrl) lifecycleCtx, lifecycleCancel := context.WithCancel(context.Background()) if shardInfo.QueueAckLevels == nil { @@ -93,7 +93,7 @@ func NewTestContext( lifecycleCancel: lifecycleCancel, state: contextStateAcquired, - engineFuture: future.NewFuture[Engine](), + engineFuture: future.NewFuture[definition.Engine](), shardInfo: shardInfo, taskSequenceNumber: shardInfo.RangeId << int64(config.RangeSizeBits), immediateTaskExclusiveMaxReadLevel: shardInfo.RangeId << int64(config.RangeSizeBits), @@ -122,12 +122,12 @@ func NewTestContext( } // SetEngineForTest sets s.engine. Only used by tests. -func (s *ContextTest) SetEngineForTesting(engine Engine) { +func (s *ContextTest) SetEngineForTesting(engine definition.Engine) { s.engineFuture.Set(engine, nil) } // SetEventsCacheForTesting sets s.eventsCache. Only used by tests. -func (s *ContextTest) SetEventsCacheForTesting(c events.Cache) { +func (s *ContextTest) SetEventsCacheForTesting(c definition.EventCache) { // for testing only, will only be called immediately after initialization s.eventsCache = c } diff --git a/service/history/shard/controller_impl.go b/service/history/shard/controller_impl.go index 82ccf1d8ed0..da6f3aca727 100644 --- a/service/history/shard/controller_impl.go +++ b/service/history/shard/controller_impl.go @@ -52,6 +52,7 @@ import ( serviceerrors "go.temporal.io/server/common/serviceerror" "go.temporal.io/server/common/util" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" ) const ( @@ -91,7 +92,7 @@ type ( } ) -var _ Controller = (*ControllerImpl)(nil) +var _ definition.ShardController = (*ControllerImpl)(nil) func (c *ControllerImpl) Start() { if !atomic.CompareAndSwapInt32( @@ -176,7 +177,7 @@ func (c *ControllerImpl) Status() int32 { func (c *ControllerImpl) GetShardByNamespaceWorkflow( namespaceID namespace.ID, workflowID string, -) (Context, error) { +) (definition.ShardContext, error) { shardID := c.config.GetShardID(namespaceID, workflowID) return c.GetShardByID(shardID) } @@ -186,7 +187,7 @@ func (c *ControllerImpl) GetShardByNamespaceWorkflow( // Callers can use GetEngine on the shard to block on rangeid lease acquisition. func (c *ControllerImpl) GetShardByID( shardID int32, -) (Context, error) { +) (definition.ShardContext, error) { startTime := time.Now().UTC() defer c.taggedMetricsHandler.Timer(metrics.GetEngineForShardLatency.GetMetricName()).Record(time.Since(startTime)) @@ -227,7 +228,7 @@ func (c *ControllerImpl) shardClosedCallback(shard *ContextImpl) { func (c *ControllerImpl) getOrCreateShardContext(shardID int32) (*ContextImpl, error) { c.RLock() if shard, ok := c.historyShards[shardID]; ok { - if shard.isValid() { + if shard.IsValid() { c.RUnlock() return shard, nil } @@ -250,7 +251,7 @@ func (c *ControllerImpl) getOrCreateShardContext(shardID int32) (*ContextImpl, e // Check again with exclusive lock if shard, ok := c.historyShards[shardID]; ok { - if shard.isValid() { + if shard.IsValid() { return shard, nil } diff --git a/service/history/shard/controller_test.go b/service/history/shard/controller_test.go index eae0087b77e..d0beef35f1a 100644 --- a/service/history/shard/controller_test.go +++ b/service/history/shard/controller_test.go @@ -37,6 +37,7 @@ import ( "go.temporal.io/server/api/enums/v1" persistencespb "go.temporal.io/server/api/persistence/v1" + "go.temporal.io/server/service/history/definition" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" @@ -65,7 +66,7 @@ type ( controller *gomock.Controller mockResource *resourcetest.Test - mockHistoryEngine *MockEngine + mockHistoryEngine *definition.MockEngine mockClusterMetadata *cluster.MockMetadata mockServiceResolver *membership.MockServiceResolver @@ -125,7 +126,7 @@ func (s *controllerSuite) SetupTest() { s.controller = gomock.NewController(s.T()) s.mockResource = resourcetest.NewTest(s.controller, metrics.History) - s.mockHistoryEngine = NewMockEngine(s.controller) + s.mockHistoryEngine = definition.NewMockEngine(s.controller) s.mockEngineFactory = NewMockEngineFactory(s.controller) s.mockShardManager = s.mockResource.ShardMgr @@ -436,9 +437,9 @@ func (s *controllerSuite) TestHistoryEngineClosed() { s.mockResource, s.mockHostInfoProvider, ) - historyEngines := make(map[int32]*MockEngine) + historyEngines := make(map[int32]*definition.MockEngine) for shardID := int32(1); shardID <= numShards; shardID++ { - mockEngine := NewMockEngine(s.controller) + mockEngine := definition.NewMockEngine(s.controller) historyEngines[shardID] = mockEngine s.setupMocksForAcquireShard(shardID, mockEngine, 5, 6, true) } @@ -539,9 +540,9 @@ func (s *controllerSuite) TestShardControllerClosed() { s.mockHostInfoProvider, ) - historyEngines := make(map[int32]*MockEngine) + historyEngines := make(map[int32]*definition.MockEngine) for shardID := int32(1); shardID <= numShards; shardID++ { - mockEngine := NewMockEngine(s.controller) + mockEngine := definition.NewMockEngine(s.controller) historyEngines[shardID] = mockEngine s.setupMocksForAcquireShard(shardID, mockEngine, 5, 6, true) } @@ -588,7 +589,7 @@ func (s *controllerSuite) TestShardExplicitUnload() { s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestSingleDCClusterInfo).AnyTimes() - mockEngine := NewMockEngine(s.controller) + mockEngine := definition.NewMockEngine(s.controller) mockEngine.EXPECT().Stop().AnyTimes() s.setupMocksForAcquireShard(0, mockEngine, 5, 6, false) @@ -603,7 +604,7 @@ func (s *controllerSuite) TestShardExplicitUnload() { time.Sleep(1 * time.Millisecond) } s.Equal(0, len(s.shardController.ShardIDs())) - s.False(shard.isValid()) + s.False(shard.IsValid()) } func (s *controllerSuite) TestShardExplicitUnloadCancelGetOrCreate() { @@ -611,7 +612,7 @@ func (s *controllerSuite) TestShardExplicitUnloadCancelGetOrCreate() { s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestSingleDCClusterInfo).AnyTimes() - mockEngine := NewMockEngine(s.controller) + mockEngine := definition.NewMockEngine(s.controller) mockEngine.EXPECT().Stop().AnyTimes() shardID := int32(0) @@ -652,7 +653,7 @@ func (s *controllerSuite) TestShardExplicitUnloadCancelAcquire() { s.mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes() s.mockClusterMetadata.EXPECT().GetAllClusterInfo().Return(cluster.TestSingleDCClusterInfo).AnyTimes() - mockEngine := NewMockEngine(s.controller) + mockEngine := definition.NewMockEngine(s.controller) mockEngine.EXPECT().Stop().AnyTimes() shardID := int32(0) @@ -722,8 +723,8 @@ func (s *controllerSuite) TestShardControllerFuzz() { queueStates := s.queueStates() s.mockServiceResolver.EXPECT().Lookup(convert.Int32ToString(shardID)).Return(s.hostInfo, nil).AnyTimes() - s.mockEngineFactory.EXPECT().CreateEngine(contextMatcher(shardID)).DoAndReturn(func(shard Context) Engine { - mockEngine := NewMockEngine(disconnectedMockController) + s.mockEngineFactory.EXPECT().CreateEngine(contextMatcher(shardID)).DoAndReturn(func(shard definition.ShardContext) definition.Engine { + mockEngine := definition.NewMockEngine(disconnectedMockController) status := new(int32) mockEngine.EXPECT().NotifyNewTasks(gomock.Any(), gomock.Any()).AnyTimes() mockEngine.EXPECT().Start().Do(func() { @@ -764,7 +765,7 @@ func (s *controllerSuite) TestShardControllerFuzz() { s.mockShardManager.EXPECT().AssertShardOwnership(gomock.Any(), gomock.Any()).Return(nil).AnyTimes() } - randomLoadedShard := func() (int32, Context) { + randomLoadedShard := func() (int32, definition.ShardContext) { s.shardController.Lock() defer s.shardController.Unlock() if len(s.shardController.historyShards) == 0 { @@ -829,7 +830,7 @@ func (s *controllerSuite) TestShardControllerFuzz() { func (s *controllerSuite) setupMocksForAcquireShard( shardID int32, - mockEngine *MockEngine, + mockEngine *definition.MockEngine, currentRangeID, newRangeID int64, required bool, ) { @@ -962,7 +963,7 @@ var _ fmt.Stringer = (*ContextImpl)(nil) type contextMatcher int32 func (s contextMatcher) Matches(x interface{}) bool { - context, ok := x.(Context) + context, ok := x.(definition.ShardContext) return ok && context.GetShardID() == int32(s) } diff --git a/service/history/shard/engine_factory.go b/service/history/shard/engine_factory.go index 249d5850b56..777c3ca16b3 100644 --- a/service/history/shard/engine_factory.go +++ b/service/history/shard/engine_factory.go @@ -26,9 +26,13 @@ package shard +import ( + "go.temporal.io/server/service/history/definition" +) + type ( // EngineFactory is used to create an instance of sharded history engine EngineFactory interface { - CreateEngine(context Context) Engine + CreateEngine(context definition.ShardContext) definition.Engine } ) diff --git a/service/history/shard/engine_factory_mock.go b/service/history/shard/engine_factory_mock.go index 1d147c9e68e..27bb2250daf 100644 --- a/service/history/shard/engine_factory_mock.go +++ b/service/history/shard/engine_factory_mock.go @@ -32,6 +32,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" + definition "go.temporal.io/server/service/history/definition" ) // MockEngineFactory is a mock of EngineFactory interface. @@ -58,10 +59,10 @@ func (m *MockEngineFactory) EXPECT() *MockEngineFactoryMockRecorder { } // CreateEngine mocks base method. -func (m *MockEngineFactory) CreateEngine(context Context) Engine { +func (m *MockEngineFactory) CreateEngine(context definition.ShardContext) definition.Engine { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateEngine", context) - ret0, _ := ret[0].(Engine) + ret0, _ := ret[0].(definition.Engine) return ret0 } diff --git a/service/history/shard/fx.go b/service/history/shard/fx.go index 76734d3f4bf..f724b2d129a 100644 --- a/service/history/shard/fx.go +++ b/service/history/shard/fx.go @@ -43,6 +43,7 @@ import ( "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" ) var Module = fx.Options( @@ -69,7 +70,7 @@ func ControllerProvider( hostInfoProvider membership.HostInfoProvider, engineFactory EngineFactory, tracerProvider trace.TracerProvider, -) Controller { +) definition.ShardController { return &ControllerImpl{ status: common.DaemonStatusInitialized, membershipUpdateCh: make(chan *membership.ChangedEvent, 10), diff --git a/service/history/taskAllocator.go b/service/history/taskAllocator.go index 75cd7219c9f..913e8825d84 100644 --- a/service/history/taskAllocator.go +++ b/service/history/taskAllocator.go @@ -30,7 +30,7 @@ import ( "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/namespace" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" ) type ( @@ -44,7 +44,7 @@ type ( taskAllocatorImpl struct { currentClusterName string - shard shard.Context + shard definition.ShardContext namespaceRegistry namespace.Registry logger log.Logger @@ -53,7 +53,7 @@ type ( ) // newTaskAllocator create a new task allocator -func newTaskAllocator(shard shard.Context) taskAllocator { +func newTaskAllocator(shard definition.ShardContext) taskAllocator { return &taskAllocatorImpl{ currentClusterName: shard.GetClusterMetadata().GetCurrentClusterName(), shard: shard, diff --git a/service/history/timerQueueAckMgr.go b/service/history/timerQueueAckMgr.go index 78020a10bca..360aa228b06 100644 --- a/service/history/timerQueueAckMgr.go +++ b/service/history/timerQueueAckMgr.go @@ -40,8 +40,8 @@ import ( ctasks "go.temporal.io/server/common/tasks" "go.temporal.io/server/common/util" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" ) @@ -53,7 +53,7 @@ type ( timerQueueAckMgrImpl struct { operation string isFailover bool - shard shard.Context + shard definition.ShardContext executionMgr persistence.ExecutionManager logger log.Logger metricHandler metrics.MetricsHandler @@ -98,7 +98,7 @@ var _ timerQueueAckMgr = (*timerQueueAckMgrImpl)(nil) func newTimerQueueAckMgr( operation string, - shard shard.Context, + shard definition.ShardContext, minLevel time.Time, timeNow timeNow, updateTimerAckLevel updateTimerAckLevel, @@ -137,7 +137,7 @@ func newTimerQueueAckMgr( } func newTimerQueueFailoverAckMgr( - shard shard.Context, + shard definition.ShardContext, minLevel time.Time, maxLevel time.Time, timeNow timeNow, diff --git a/service/history/timerQueueAckMgr_test.go b/service/history/timerQueueAckMgr_test.go index a4267f23ae3..a3fa8dd0b34 100644 --- a/service/history/timerQueueAckMgr_test.go +++ b/service/history/timerQueueAckMgr_test.go @@ -36,7 +36,6 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" @@ -44,6 +43,7 @@ import ( "go.temporal.io/server/common/primitives" "go.temporal.io/server/common/primitives/timestamp" ctasks "go.temporal.io/server/common/tasks" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" diff --git a/service/history/timerQueueActiveProcessor.go b/service/history/timerQueueActiveProcessor.go index 479cedd46b1..0f6cf2548e9 100644 --- a/service/history/timerQueueActiveProcessor.go +++ b/service/history/timerQueueActiveProcessor.go @@ -41,8 +41,8 @@ import ( "go.temporal.io/server/common/quotas" "go.temporal.io/server/common/timer" "go.temporal.io/server/common/xdc" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/workflow" ) @@ -57,8 +57,8 @@ type ( ) func newTimerQueueActiveProcessor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, scheduler queues.Scheduler, priorityAssigner queues.PriorityAssigner, workflowDeleteManager workflow.DeleteManager, @@ -203,8 +203,8 @@ func newTimerQueueActiveProcessor( } func newTimerQueueFailoverProcessor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, scheduler queues.Scheduler, priorityAssigner queues.PriorityAssigner, workflowDeleteManager workflow.DeleteManager, diff --git a/service/history/timerQueueActiveTaskExecutor.go b/service/history/timerQueueActiveTaskExecutor.go index ca491c93451..18d2f0c53f6 100644 --- a/service/history/timerQueueActiveTaskExecutor.go +++ b/service/history/timerQueueActiveTaskExecutor.go @@ -40,7 +40,6 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/backoff" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/failure" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" @@ -48,6 +47,7 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" @@ -64,8 +64,8 @@ type ( ) func newTimerQueueActiveTaskExecutor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, workflowDeleteManager workflow.DeleteManager, queueProcessor *timerQueueActiveProcessorImpl, logger log.Logger, @@ -583,15 +583,15 @@ func (t *timerQueueActiveTaskExecutor) executeWorkflowTimeoutTask( } func (t *timerQueueActiveTaskExecutor) getTimerSequence( - mutableState workflow.MutableState, + mutableState definition.MutableState, ) workflow.TimerSequence { return workflow.NewTimerSequence(mutableState) } func (t *timerQueueActiveTaskExecutor) updateWorkflowExecution( ctx context.Context, - context workflow.Context, - mutableState workflow.MutableState, + context definition.WorkflowContext, + mutableState definition.MutableState, scheduleNewWorkflowTask bool, ) error { var err error diff --git a/service/history/timerQueueActiveTaskExecutor_test.go b/service/history/timerQueueActiveTaskExecutor_test.go index a843ec640b2..9d9a62e67ef 100644 --- a/service/history/timerQueueActiveTaskExecutor_test.go +++ b/service/history/timerQueueActiveTaskExecutor_test.go @@ -47,7 +47,6 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" @@ -55,6 +54,7 @@ import ( "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/common/quotas" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" @@ -82,7 +82,7 @@ type ( mockDeleteManager *workflow.MockDeleteManager mockExecutionMgr *persistence.MockExecutionManager - workflowCache workflow.Cache + workflowCache definition.WorkflowCache logger log.Logger namespaceID namespace.ID namespaceEntry *namespace.Namespace @@ -1460,7 +1460,7 @@ func (s *timerQueueActiveTaskExecutorSuite) TestWorkflowTimeout_WorkflowExpired( } func (s *timerQueueActiveTaskExecutorSuite) createPersistenceMutableState( - ms workflow.MutableState, + ms definition.MutableState, lastEventID int64, lastEventVersion int64, ) *persistencespb.WorkflowMutableState { @@ -1477,7 +1477,7 @@ func (s *timerQueueActiveTaskExecutorSuite) getMutableStateFromCache( namespaceID namespace.ID, workflowID string, runID string, -) workflow.MutableState { +) definition.MutableState { return s.workflowCache.(*workflow.CacheImpl).Get( definition.NewWorkflowKey(namespaceID.String(), workflowID, runID), ).(*workflow.ContextImpl).MutableState diff --git a/service/history/timerQueueFactory.go b/service/history/timerQueueFactory.go index 9da60cf255a..dd4885fa25e 100644 --- a/service/history/timerQueueFactory.go +++ b/service/history/timerQueueFactory.go @@ -36,8 +36,8 @@ import ( "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/resource" "go.temporal.io/server/common/xdc" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/workflow" "go.temporal.io/server/service/worker/archiver" @@ -105,8 +105,8 @@ func NewTimerQueueFactory( } func (f *timerQueueFactory) CreateQueue( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, ) queues.Queue { if f.HostScheduler != nil && f.Config.TimerProcessorEnableMultiCursor() { logger := log.With(shard.GetLogger(), tag.ComponentTimerQueue) diff --git a/service/history/timerQueueProcessor.go b/service/history/timerQueueProcessor.go index aff87f60fa3..0fe1c837ec3 100644 --- a/service/history/timerQueueProcessor.go +++ b/service/history/timerQueueProcessor.go @@ -44,6 +44,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/quotas" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" @@ -60,11 +61,11 @@ type ( timerQueueProcessorImpl struct { singleProcessor bool currentClusterName string - shard shard.Context + shard definition.ShardContext taskAllocator taskAllocator config *configs.Config metricHandler metrics.MetricsHandler - workflowCache workflow.Cache + workflowCache definition.WorkflowCache scheduler queues.Scheduler priorityAssigner queues.PriorityAssigner workflowDeleteManager workflow.DeleteManager @@ -83,8 +84,8 @@ type ( ) func newTimerQueueProcessor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, scheduler queues.Scheduler, priorityAssigner queues.PriorityAssigner, clientBean client.Bean, diff --git a/service/history/timerQueueProcessorBase.go b/service/history/timerQueueProcessorBase.go index ba3a43e1e28..25134ac92f4 100644 --- a/service/history/timerQueueProcessorBase.go +++ b/service/history/timerQueueProcessorBase.go @@ -32,10 +32,10 @@ import ( "go.temporal.io/server/common/timer" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" "go.temporal.io/server/common" "go.temporal.io/server/common/backoff" @@ -56,8 +56,8 @@ var ( type ( timerQueueProcessorBase struct { operation string - shard shard.Context - cache workflow.Cache + shard definition.ShardContext + cache definition.WorkflowCache executionManager persistence.ExecutionManager status int32 shutdownWG sync.WaitGroup @@ -84,8 +84,8 @@ type ( func newTimerQueueProcessorBase( operation string, - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, timerProcessor common.Daemon, timerQueueAckMgr timerQueueAckMgr, timerGate timer.Gate, @@ -367,7 +367,7 @@ func (t *timerQueueProcessorBase) submitTask( } func newTimerTaskShardScheduler( - shard shard.Context, + shard definition.ShardContext, logger log.Logger, ) queues.Scheduler { config := shard.GetConfig() diff --git a/service/history/timerQueueStandbyProcessor.go b/service/history/timerQueueStandbyProcessor.go index 5eeb67b9b9d..c5c4bf92329 100644 --- a/service/history/timerQueueStandbyProcessor.go +++ b/service/history/timerQueueStandbyProcessor.go @@ -40,8 +40,8 @@ import ( "go.temporal.io/server/common/quotas" "go.temporal.io/server/common/timer" "go.temporal.io/server/common/xdc" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/workflow" ) @@ -57,8 +57,8 @@ type ( ) func newTimerQueueStandbyProcessor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, scheduler queues.Scheduler, priorityAssigner queues.PriorityAssigner, workflowDeleteManager workflow.DeleteManager, diff --git a/service/history/timerQueueStandbyTaskExecutor.go b/service/history/timerQueueStandbyTaskExecutor.go index 10e6cb5d4ea..30392101315 100644 --- a/service/history/timerQueueStandbyTaskExecutor.go +++ b/service/history/timerQueueStandbyTaskExecutor.go @@ -43,8 +43,8 @@ import ( "go.temporal.io/server/common/xdc" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/vclock" "go.temporal.io/server/service/history/workflow" @@ -60,8 +60,8 @@ type ( ) func newTimerQueueStandbyTaskExecutor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, workflowDeleteManager workflow.DeleteManager, nDCHistoryResender xdc.NDCHistoryResender, matchingClient matchingservice.MatchingServiceClient, @@ -124,7 +124,7 @@ func (t *timerQueueStandbyTaskExecutor) executeUserTimerTimeoutTask( ctx context.Context, timerTask *tasks.UserTimerTask, ) error { - actionFn := func(_ context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(_ context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { timerSequence := t.getTimerSequence(mutableState) timerSequenceIDs := timerSequence.LoadAndSortUserTimers() if len(timerSequenceIDs) > 0 { @@ -179,7 +179,7 @@ func (t *timerQueueStandbyTaskExecutor) executeActivityTimeoutTask( // // the overall solution is to attempt to generate a new activity timer task whenever the // task passed in is safe to be throw away. - actionFn := func(ctx context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(ctx context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { timerSequence := t.getTimerSequence(mutableState) updateMutableState := false timerSequenceIDs := timerSequence.LoadAndSortActivityTimers() @@ -268,7 +268,7 @@ func (t *timerQueueStandbyTaskExecutor) executeActivityRetryTimerTask( ctx context.Context, task *tasks.ActivityRetryTimerTask, ) (retError error) { - actionFn := func(_ context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(_ context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { activityInfo, ok := mutableState.GetActivityInfo(task.EventID) // activity schedule ID if !ok { return nil, nil @@ -316,7 +316,7 @@ func (t *timerQueueStandbyTaskExecutor) executeWorkflowTaskTimeoutTask( return nil } - actionFn := func(_ context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(_ context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { workflowTask, isPending := mutableState.GetWorkflowTaskInfo(timerTask.EventID) if !isPending { return nil, nil @@ -349,7 +349,7 @@ func (t *timerQueueStandbyTaskExecutor) executeWorkflowBackoffTimerTask( ctx context.Context, timerTask *tasks.WorkflowBackoffTimerTask, ) error { - actionFn := func(_ context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(_ context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { if mutableState.HasProcessedOrPendingWorkflowTask() { // if there is one workflow task already been processed // or has pending workflow task, meaning workflow has already running @@ -388,7 +388,7 @@ func (t *timerQueueStandbyTaskExecutor) executeWorkflowTimeoutTask( ctx context.Context, timerTask *tasks.WorkflowTimeoutTask, ) error { - actionFn := func(_ context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(_ context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { // we do not need to notify new timer to base, since if there is no new event being replicated // checking again if the timer can be completed is meaningless @@ -431,7 +431,7 @@ func (t *timerQueueStandbyTaskExecutor) getStandbyClusterTime() time.Time { } func (t *timerQueueStandbyTaskExecutor) getTimerSequence( - mutableState workflow.MutableState, + mutableState definition.MutableState, ) workflow.TimerSequence { return workflow.NewTimerSequence(mutableState) } diff --git a/service/history/timerQueueStandbyTaskExecutor_test.go b/service/history/timerQueueStandbyTaskExecutor_test.go index 27930f9c8c0..61c4b6143e5 100644 --- a/service/history/timerQueueStandbyTaskExecutor_test.go +++ b/service/history/timerQueueStandbyTaskExecutor_test.go @@ -49,7 +49,6 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" @@ -58,6 +57,7 @@ import ( "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/common/xdc" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" @@ -84,7 +84,7 @@ type ( mockDeleteManager *workflow.MockDeleteManager mockMatchingClient *matchingservicemock.MockMatchingServiceClient - workflowCache workflow.Cache + workflowCache definition.WorkflowCache logger log.Logger namespaceID namespace.ID namespaceEntry *namespace.Namespace @@ -1516,7 +1516,7 @@ func (s *timerQueueStandbyTaskExecutorSuite) TestProcessActivityRetryTimer_Pendi } func (s *timerQueueStandbyTaskExecutorSuite) createPersistenceMutableState( - ms workflow.MutableState, + ms definition.MutableState, lastEventID int64, lastEventVersion int64, ) *persistencespb.WorkflowMutableState { diff --git a/service/history/timerQueueTaskExecutorBase.go b/service/history/timerQueueTaskExecutorBase.go index 0dc952489be..20b3fdeedbf 100644 --- a/service/history/timerQueueTaskExecutorBase.go +++ b/service/history/timerQueueTaskExecutorBase.go @@ -39,7 +39,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/workflow" ) @@ -47,10 +47,10 @@ import ( type ( timerQueueTaskExecutorBase struct { currentClusterName string - shard shard.Context + shard definition.ShardContext registry namespace.Registry deleteManager workflow.DeleteManager - cache workflow.Cache + cache definition.WorkflowCache logger log.Logger matchingClient matchingservice.MatchingServiceClient metricHandler metrics.MetricsHandler @@ -59,8 +59,8 @@ type ( ) func newTimerQueueTaskExecutorBase( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, deleteManager workflow.DeleteManager, matchingClient matchingservice.MatchingServiceClient, logger log.Logger, @@ -96,7 +96,7 @@ func (t *timerQueueTaskExecutorBase) executeDeleteHistoryEventTask( ctx, namespace.ID(task.GetNamespaceID()), workflowExecution, - workflow.CallerTypeTask, + definition.CallerTypeTask, ) if err != nil { return err @@ -147,9 +147,9 @@ func (t *timerQueueTaskExecutorBase) executeDeleteHistoryEventTask( func getWorkflowExecutionContextForTask( ctx context.Context, - workflowCache workflow.Cache, + workflowCache definition.WorkflowCache, task tasks.Task, -) (workflow.Context, workflow.ReleaseCacheFunc, error) { +) (definition.WorkflowContext, definition.ReleaseFunc, error) { namespaceID, execution := getTaskNamespaceIDAndWorkflowExecution(task) return getWorkflowExecutionContext( ctx, @@ -161,10 +161,10 @@ func getWorkflowExecutionContextForTask( func getWorkflowExecutionContext( ctx context.Context, - workflowCache workflow.Cache, + workflowCache definition.WorkflowCache, namespaceID namespace.ID, execution commonpb.WorkflowExecution, -) (workflow.Context, workflow.ReleaseCacheFunc, error) { +) (definition.WorkflowContext, definition.ReleaseFunc, error) { ctx, cancel := context.WithTimeout(ctx, taskGetExecutionTimeout) defer cancel() @@ -172,7 +172,7 @@ func getWorkflowExecutionContext( ctx, namespaceID, execution, - workflow.CallerTypeTask, + definition.CallerTypeTask, ) if common.IsContextDeadlineExceededErr(err) { err = consts.ErrWorkflowBusy diff --git a/service/history/timerQueueTaskExecutorBase_test.go b/service/history/timerQueueTaskExecutorBase_test.go index 802d7de62f8..b85a993fffd 100644 --- a/service/history/timerQueueTaskExecutorBase_test.go +++ b/service/history/timerQueueTaskExecutorBase_test.go @@ -40,9 +40,9 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/persistence" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" @@ -56,7 +56,7 @@ type ( controller *gomock.Controller mockDeleteManager *workflow.MockDeleteManager - mockCache *workflow.MockCache + mockCache *definition.MockWorkflowCache testShardContext *shard.ContextTest timerQueueTaskExecutorBase *timerQueueTaskExecutorBase @@ -79,7 +79,7 @@ func (s *timerQueueTaskExecutorBaseSuite) SetupTest() { s.controller = gomock.NewController(s.T()) s.mockDeleteManager = workflow.NewMockDeleteManager(s.controller) - s.mockCache = workflow.NewMockCache(s.controller) + s.mockCache = definition.NewMockWorkflowCache(s.controller) config := tests.NewDynamicConfig() s.testShardContext = shard.NewTestContext( @@ -128,10 +128,10 @@ func (s *timerQueueTaskExecutorBaseSuite) Test_executeDeleteHistoryEventTask_NoE RunId: tests.RunID, } - mockWeCtx := workflow.NewMockContext(s.controller) - mockMutableState := workflow.NewMockMutableState(s.controller) + mockWeCtx := definition.NewMockWorkflowContext(s.controller) + mockMutableState := definition.NewMockMutableState(s.controller) - s.mockCache.EXPECT().GetOrCreateWorkflowExecution(gomock.Any(), tests.NamespaceID, we, workflow.CallerTypeTask).Return(mockWeCtx, workflow.NoopReleaseFn, nil) + s.mockCache.EXPECT().GetOrCreateWorkflowExecution(gomock.Any(), tests.NamespaceID, we, definition.CallerTypeTask).Return(mockWeCtx, workflow.NoopReleaseFn, nil) mockWeCtx.EXPECT().LoadMutableState(gomock.Any()).Return(mockMutableState, nil) mockMutableState.EXPECT().GetLastWriteVersion().Return(int64(1), nil) @@ -178,10 +178,10 @@ func (s *timerQueueTaskExecutorBaseSuite) TestArchiveHistory_DeleteFailed() { RunId: tests.RunID, } - mockWeCtx := workflow.NewMockContext(s.controller) - mockMutableState := workflow.NewMockMutableState(s.controller) + mockWeCtx := definition.NewMockWorkflowContext(s.controller) + mockMutableState := definition.NewMockMutableState(s.controller) - s.mockCache.EXPECT().GetOrCreateWorkflowExecution(gomock.Any(), tests.NamespaceID, we, workflow.CallerTypeTask).Return(mockWeCtx, workflow.NoopReleaseFn, nil) + s.mockCache.EXPECT().GetOrCreateWorkflowExecution(gomock.Any(), tests.NamespaceID, we, definition.CallerTypeTask).Return(mockWeCtx, workflow.NoopReleaseFn, nil) mockWeCtx.EXPECT().LoadMutableState(gomock.Any()).Return(mockMutableState, nil) mockMutableState.EXPECT().GetLastWriteVersion().Return(int64(1), nil) diff --git a/service/history/transferQueueActiveProcessor.go b/service/history/transferQueueActiveProcessor.go index d7119ab3ed6..1a0f6d88c1f 100644 --- a/service/history/transferQueueActiveProcessor.go +++ b/service/history/transferQueueActiveProcessor.go @@ -40,10 +40,9 @@ import ( "go.temporal.io/server/common/quotas" "go.temporal.io/server/common/sdk" "go.temporal.io/server/common/xdc" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" "go.temporal.io/server/service/worker/archiver" ) @@ -59,8 +58,8 @@ type ( ) func newTransferQueueActiveProcessor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, scheduler queues.Scheduler, priorityAssigner queues.PriorityAssigner, archivalClient archiver.Client, @@ -230,8 +229,8 @@ func newTransferQueueActiveProcessor( } func newTransferQueueFailoverProcessor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, scheduler queues.Scheduler, priorityAssigner queues.PriorityAssigner, archivalClient archiver.Client, diff --git a/service/history/transferQueueActiveTaskExecutor.go b/service/history/transferQueueActiveTaskExecutor.go index 5b3f6743739..0964ce381ea 100644 --- a/service/history/transferQueueActiveTaskExecutor.go +++ b/service/history/transferQueueActiveTaskExecutor.go @@ -55,9 +55,9 @@ import ( serviceerrors "go.temporal.io/server/common/serviceerror" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/ndc" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/vclock" "go.temporal.io/server/service/history/workflow" @@ -75,8 +75,8 @@ type ( ) func newTransferQueueActiveTaskExecutor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, archivalClient archiver.Client, sdkClientFactory sdk.ClientFactory, logger log.Logger, @@ -937,9 +937,9 @@ func (t *transferQueueActiveTaskExecutor) processResetWorkflow( tag.WorkflowEventID(resetPoint.GetFirstWorkflowTaskCompletedId()), ) - var baseContext workflow.Context - var baseMutableState workflow.MutableState - var baseRelease workflow.ReleaseCacheFunc + var baseContext definition.WorkflowContext + var baseMutableState definition.MutableState + var baseRelease definition.ReleaseFunc if resetPoint.GetRunId() == executionState.RunId { baseContext = currentContext baseMutableState = currentMutableState @@ -986,13 +986,13 @@ func (t *transferQueueActiveTaskExecutor) processResetWorkflow( func (t *transferQueueActiveTaskExecutor) recordChildExecutionStarted( ctx context.Context, task *tasks.StartChildExecutionTask, - context workflow.Context, + context definition.WorkflowContext, initiatedAttributes *historypb.StartChildWorkflowExecutionInitiatedEventAttributes, runID string, clock *clockspb.VectorClock, ) error { return t.updateWorkflowExecution(ctx, context, true, - func(mutableState workflow.MutableState) error { + func(mutableState definition.MutableState) error { if !mutableState.IsWorkflowExecutionRunning() { return serviceerror.NewNotFound("Workflow execution already completed.") } @@ -1020,12 +1020,12 @@ func (t *transferQueueActiveTaskExecutor) recordChildExecutionStarted( func (t *transferQueueActiveTaskExecutor) recordStartChildExecutionFailed( ctx context.Context, task *tasks.StartChildExecutionTask, - context workflow.Context, + context definition.WorkflowContext, initiatedAttributes *historypb.StartChildWorkflowExecutionInitiatedEventAttributes, failedCause enumspb.StartChildWorkflowExecutionFailedCause, ) error { return t.updateWorkflowExecution(ctx, context, true, - func(mutableState workflow.MutableState) error { + func(mutableState definition.MutableState) error { if !mutableState.IsWorkflowExecutionRunning() { return serviceerror.NewNotFound("Workflow execution already completed.") } @@ -1065,14 +1065,14 @@ func (t *transferQueueActiveTaskExecutor) createFirstWorkflowTask( func (t *transferQueueActiveTaskExecutor) requestCancelExternalExecutionCompleted( ctx context.Context, task *tasks.CancelExecutionTask, - context workflow.Context, + context definition.WorkflowContext, targetNamespace namespace.Name, targetNamespaceID namespace.ID, targetWorkflowID string, targetRunID string, ) error { err := t.updateWorkflowExecution(ctx, context, true, - func(mutableState workflow.MutableState) error { + func(mutableState definition.MutableState) error { if !mutableState.IsWorkflowExecutionRunning() { return serviceerror.NewNotFound("Workflow execution already completed.") } @@ -1098,7 +1098,7 @@ func (t *transferQueueActiveTaskExecutor) requestCancelExternalExecutionComplete func (t *transferQueueActiveTaskExecutor) signalExternalExecutionCompleted( ctx context.Context, task *tasks.SignalExecutionTask, - context workflow.Context, + context definition.WorkflowContext, targetNamespace namespace.Name, targetNamespaceID namespace.ID, targetWorkflowID string, @@ -1106,7 +1106,7 @@ func (t *transferQueueActiveTaskExecutor) signalExternalExecutionCompleted( control string, ) error { err := t.updateWorkflowExecution(ctx, context, true, - func(mutableState workflow.MutableState) error { + func(mutableState definition.MutableState) error { if !mutableState.IsWorkflowExecutionRunning() { return serviceerror.NewNotFound("Workflow execution already completed.") } @@ -1132,7 +1132,7 @@ func (t *transferQueueActiveTaskExecutor) signalExternalExecutionCompleted( func (t *transferQueueActiveTaskExecutor) requestCancelExternalExecutionFailed( ctx context.Context, task *tasks.CancelExecutionTask, - context workflow.Context, + context definition.WorkflowContext, targetNamespace namespace.Name, targetNamespaceID namespace.ID, targetWorkflowID string, @@ -1140,7 +1140,7 @@ func (t *transferQueueActiveTaskExecutor) requestCancelExternalExecutionFailed( failedCause enumspb.CancelExternalWorkflowExecutionFailedCause, ) error { err := t.updateWorkflowExecution(ctx, context, true, - func(mutableState workflow.MutableState) error { + func(mutableState definition.MutableState) error { if !mutableState.IsWorkflowExecutionRunning() { return serviceerror.NewNotFound("Workflow execution already completed.") } @@ -1167,7 +1167,7 @@ func (t *transferQueueActiveTaskExecutor) requestCancelExternalExecutionFailed( func (t *transferQueueActiveTaskExecutor) signalExternalExecutionFailed( ctx context.Context, task *tasks.SignalExecutionTask, - context workflow.Context, + context definition.WorkflowContext, targetNamespace namespace.Name, targetNamespaceID namespace.ID, targetWorkflowID string, @@ -1176,7 +1176,7 @@ func (t *transferQueueActiveTaskExecutor) signalExternalExecutionFailed( failedCause enumspb.SignalExternalWorkflowExecutionFailedCause, ) error { err := t.updateWorkflowExecution(ctx, context, true, - func(mutableState workflow.MutableState) error { + func(mutableState definition.MutableState) error { if !mutableState.IsWorkflowExecutionRunning() { return serviceerror.NewNotFound("Workflow is not running.") } @@ -1203,9 +1203,9 @@ func (t *transferQueueActiveTaskExecutor) signalExternalExecutionFailed( func (t *transferQueueActiveTaskExecutor) updateWorkflowExecution( ctx context.Context, - context workflow.Context, + context definition.WorkflowContext, createWorkflowTask bool, - action func(workflow.MutableState) error, + action func(definition.MutableState) error, ) error { mutableState, err := context.LoadMutableState(ctx) if err != nil { @@ -1347,9 +1347,9 @@ func (t *transferQueueActiveTaskExecutor) resetWorkflow( task *tasks.ResetWorkflowTask, reason string, resetPoint *workflowpb.ResetPointInfo, - baseMutableState workflow.MutableState, - currentContext workflow.Context, - currentMutableState workflow.MutableState, + baseMutableState definition.MutableState, + currentContext definition.WorkflowContext, + currentMutableState definition.MutableState, logger log.Logger, ) error { var err error diff --git a/service/history/transferQueueActiveTaskExecutor_test.go b/service/history/transferQueueActiveTaskExecutor_test.go index 110f2315859..b175b61f6b1 100644 --- a/service/history/transferQueueActiveTaskExecutor_test.go +++ b/service/history/transferQueueActiveTaskExecutor_test.go @@ -59,7 +59,6 @@ import ( "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" dc "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" @@ -72,6 +71,7 @@ import ( "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" @@ -104,7 +104,7 @@ type ( mockArchiverProvider *provider.MockArchiverProvider mockParentClosePolicyClient *parentclosepolicy.MockClient - workflowCache workflow.Cache + workflowCache definition.WorkflowCache logger log.Logger namespaceID namespace.ID namespace namespace.Name @@ -2537,7 +2537,7 @@ func (s *transferQueueActiveTaskExecutorSuite) TestPendingCloseExecutionTasks() s.Run(c.Name, func() { ctrl := gomock.NewController(s.T()) - mockMutableState := workflow.NewMockMutableState(ctrl) + mockMutableState := definition.NewMockMutableState(ctrl) var closeTransferTaskId int64 if c.CloseTransferTaskIdSet { closeTransferTaskId = 10 @@ -2553,14 +2553,14 @@ func (s *transferQueueActiveTaskExecutorSuite) TestPendingCloseExecutionTasks() namespaceEntry := tests.GlobalNamespaceEntry mockMutableState.EXPECT().GetNamespaceEntry().Return(namespaceEntry).AnyTimes() - mockWorkflowContext := workflow.NewMockContext(ctrl) + mockWorkflowContext := definition.NewMockWorkflowContext(ctrl) mockWorkflowContext.EXPECT().GetWorkflowKey().Return(workflowKey).AnyTimes() mockWorkflowContext.EXPECT().LoadMutableState(gomock.Any()).Return(mockMutableState, nil) - mockWorkflowCache := workflow.NewMockCache(ctrl) + mockWorkflowCache := definition.NewMockWorkflowCache(ctrl) mockWorkflowCache.EXPECT().GetOrCreateWorkflowExecution(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), - ).Return(mockWorkflowContext, workflow.ReleaseCacheFunc(func(err error) { + ).Return(mockWorkflowContext, definition.ReleaseFunc(func(err error) { }), nil) mockClusterMetadata := cluster.NewMockMetadata(ctrl) @@ -2568,7 +2568,7 @@ func (s *transferQueueActiveTaskExecutorSuite) TestPendingCloseExecutionTasks() mockClusterMetadata.EXPECT().GetCurrentClusterName().Return(clusterName).AnyTimes() mockClusterMetadata.EXPECT().IsGlobalNamespaceEnabled().Return(false).AnyTimes() - mockShard := shard.NewMockContext(ctrl) + mockShard := definition.NewMockShardContext(ctrl) mockShard.EXPECT().GetConfig().Return(&configs.Config{ TransferProcessorEnsureCloseBeforeDelete: func() bool { return c.EnsureCloseBeforeDelete @@ -2641,7 +2641,7 @@ func (s *transferQueueActiveTaskExecutorSuite) TestPendingCloseExecutionTasks() func (s *transferQueueActiveTaskExecutorSuite) createAddWorkflowTaskRequest( task *tasks.WorkflowTask, - mutableState workflow.MutableState, + mutableState definition.MutableState, ) *matchingservice.AddWorkflowTaskRequest { taskQueue := &taskqueuepb.TaskQueue{ Name: task.TaskQueue, @@ -2734,7 +2734,7 @@ func (s *transferQueueActiveTaskExecutorSuite) createChildWorkflowExecutionReque namespace namespace.Name, childNamespace namespace.Name, task *tasks.StartChildExecutionTask, - mutableState workflow.MutableState, + mutableState definition.MutableState, ci *persistencespb.ChildExecutionInfo, ) *historyservice.StartWorkflowExecutionRequest { event, err := mutableState.GetChildExecutionInitiatedEvent(context.Background(), task.InitiatedEventID) @@ -2776,7 +2776,7 @@ func (s *transferQueueActiveTaskExecutorSuite) createChildWorkflowExecutionReque } func (s *transferQueueActiveTaskExecutorSuite) createPersistenceMutableState( - ms workflow.MutableState, + ms definition.MutableState, lastEventID int64, lastEventVersion int64, ) *persistencespb.WorkflowMutableState { diff --git a/service/history/transferQueueFactory.go b/service/history/transferQueueFactory.go index 6a92dd220f3..7780262c831 100644 --- a/service/history/transferQueueFactory.go +++ b/service/history/transferQueueFactory.go @@ -37,10 +37,9 @@ import ( "go.temporal.io/server/common/resource" "go.temporal.io/server/common/sdk" "go.temporal.io/server/common/xdc" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" "go.temporal.io/server/service/worker/archiver" ) @@ -108,8 +107,8 @@ func NewTransferQueueFactory( } func (f *transferQueueFactory) CreateQueue( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, ) queues.Queue { if f.HostScheduler != nil && f.Config.TransferProcessorEnableMultiCursor() { logger := log.With(shard.GetLogger(), tag.ComponentTransferQueue) diff --git a/service/history/transferQueueProcessor.go b/service/history/transferQueueProcessor.go index e46a5f2b6dd..531534dadb7 100644 --- a/service/history/transferQueueProcessor.go +++ b/service/history/transferQueueProcessor.go @@ -45,10 +45,10 @@ import ( "go.temporal.io/server/common/quotas" "go.temporal.io/server/common/sdk" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" "go.temporal.io/server/service/worker/archiver" ) @@ -60,8 +60,8 @@ type ( transferQueueProcessorImpl struct { singleProcessor bool currentClusterName string - shard shard.Context - workflowCache workflow.Cache + shard definition.ShardContext + workflowCache definition.WorkflowCache archivalClient archiver.Client sdkClientFactory sdk.ClientFactory taskAllocator taskAllocator @@ -85,8 +85,8 @@ type ( ) func newTransferQueueProcessor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, scheduler queues.Scheduler, priorityAssigner queues.PriorityAssigner, clientBean client.Bean, diff --git a/service/history/transferQueueProcessorBase.go b/service/history/transferQueueProcessorBase.go index b4e12ff4548..74c1b42bf53 100644 --- a/service/history/transferQueueProcessorBase.go +++ b/service/history/transferQueueProcessorBase.go @@ -31,8 +31,8 @@ import ( "go.temporal.io/server/common/headers" "go.temporal.io/server/common/log" "go.temporal.io/server/common/persistence" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" ) @@ -47,7 +47,7 @@ type ( transferQueueShutdown func() error transferQueueProcessorBase struct { - shard shard.Context + shard definition.ShardContext options *QueueProcessorOptions executionManager persistence.ExecutionManager maxReadLevel maxReadLevel @@ -58,7 +58,7 @@ type ( ) func newTransferQueueProcessorBase( - shard shard.Context, + shard definition.ShardContext, options *QueueProcessorOptions, maxReadLevel maxReadLevel, updateTransferAckLevel updateTransferAckLevel, @@ -106,7 +106,7 @@ func (t *transferQueueProcessorBase) queueShutdown() error { } func newTransferTaskShardScheduler( - shard shard.Context, + shard definition.ShardContext, logger log.Logger, ) queues.Scheduler { config := shard.GetConfig() diff --git a/service/history/transferQueueStandbyProcessor.go b/service/history/transferQueueStandbyProcessor.go index 8f1987ea74e..196194a8cdd 100644 --- a/service/history/transferQueueStandbyProcessor.go +++ b/service/history/transferQueueStandbyProcessor.go @@ -37,10 +37,9 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/quotas" "go.temporal.io/server/common/xdc" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" "go.temporal.io/server/service/worker/archiver" ) @@ -57,10 +56,10 @@ type ( func newTransferQueueStandbyProcessor( clusterName string, - shard shard.Context, + shard definition.ShardContext, scheduler queues.Scheduler, priorityAssigner queues.PriorityAssigner, - workflowCache workflow.Cache, + workflowCache definition.WorkflowCache, archivalClient archiver.Client, taskAllocator taskAllocator, clientBean client.Bean, diff --git a/service/history/transferQueueStandbyTaskExecutor.go b/service/history/transferQueueStandbyTaskExecutor.go index 5c3cfc8348b..e52cf14dccc 100644 --- a/service/history/transferQueueStandbyTaskExecutor.go +++ b/service/history/transferQueueStandbyTaskExecutor.go @@ -44,11 +44,10 @@ import ( "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/common/xdc" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/ndc" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" "go.temporal.io/server/service/worker/archiver" ) @@ -66,8 +65,8 @@ var ( ) func newTransferQueueStandbyTaskExecutor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, archivalClient archiver.Client, nDCHistoryResender xdc.NDCHistoryResender, logger log.Logger, @@ -133,7 +132,7 @@ func (t *transferQueueStandbyTaskExecutor) processActivityTask( transferTask *tasks.ActivityTask, ) error { processTaskIfClosed := false - actionFn := func(_ context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(_ context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { activityInfo, ok := mutableState.GetActivityInfo(transferTask.ScheduledEventID) if !ok { return nil, nil @@ -172,7 +171,7 @@ func (t *transferQueueStandbyTaskExecutor) processWorkflowTask( transferTask *tasks.WorkflowTask, ) error { processTaskIfClosed := false - actionFn := func(_ context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(_ context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { wtInfo, ok := mutableState.GetWorkflowTaskInfo(transferTask.ScheduledEventID) if !ok { return nil, nil @@ -230,7 +229,7 @@ func (t *transferQueueStandbyTaskExecutor) processCloseExecution( transferTask *tasks.CloseExecutionTask, ) error { processTaskIfClosed := true - actionFn := func(ctx context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(ctx context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { if mutableState.IsWorkflowExecutionRunning() { // this can happen if workflow is reset. return nil, nil @@ -347,7 +346,7 @@ func (t *transferQueueStandbyTaskExecutor) processCancelExecution( transferTask *tasks.CancelExecutionTask, ) error { processTaskIfClosed := false - actionFn := func(_ context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(_ context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { requestCancelInfo, ok := mutableState.GetRequestCancelInfo(transferTask.InitiatedEventID) if !ok { return nil, nil @@ -382,7 +381,7 @@ func (t *transferQueueStandbyTaskExecutor) processSignalExecution( transferTask *tasks.SignalExecutionTask, ) error { processTaskIfClosed := false - actionFn := func(_ context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(_ context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { signalInfo, ok := mutableState.GetSignalInfo(transferTask.InitiatedEventID) if !ok { return nil, nil @@ -417,7 +416,7 @@ func (t *transferQueueStandbyTaskExecutor) processStartChildExecution( transferTask *tasks.StartChildExecutionTask, ) error { processTaskIfClosed := true - actionFn := func(ctx context.Context, wfContext workflow.Context, mutableState workflow.MutableState) (interface{}, error) { + actionFn := func(ctx context.Context, wfContext definition.WorkflowContext, mutableState definition.MutableState) (interface{}, error) { childWorkflowInfo, ok := mutableState.GetChildExecutionInfo(transferTask.InitiatedEventID) if !ok { return nil, nil diff --git a/service/history/transferQueueStandbyTaskExecutor_test.go b/service/history/transferQueueStandbyTaskExecutor_test.go index 14b61445941..1f4cb4102e6 100644 --- a/service/history/transferQueueStandbyTaskExecutor_test.go +++ b/service/history/transferQueueStandbyTaskExecutor_test.go @@ -59,7 +59,6 @@ import ( "go.temporal.io/server/common/archiver/provider" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" @@ -68,6 +67,7 @@ import ( "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/common/xdc" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" @@ -97,7 +97,7 @@ type ( mockArchivalMetadata *archiver.MockArchivalMetadata mockArchiverProvider *provider.MockArchiverProvider - workflowCache workflow.Cache + workflowCache definition.WorkflowCache logger log.Logger namespaceID namespace.ID namespaceEntry *namespace.Namespace @@ -1275,7 +1275,7 @@ func (s *transferQueueStandbyTaskExecutorSuite) TestProcessStartChildExecution_S } func (s *transferQueueStandbyTaskExecutorSuite) createPersistenceMutableState( - ms workflow.MutableState, + ms definition.MutableState, lastEventID int64, lastEventVersion int64, ) *persistencespb.WorkflowMutableState { diff --git a/service/history/transferQueueTaskExecutorBase.go b/service/history/transferQueueTaskExecutorBase.go index 88c83a70657..0ec6d24f360 100644 --- a/service/history/transferQueueTaskExecutorBase.go +++ b/service/history/transferQueueTaskExecutorBase.go @@ -41,8 +41,8 @@ import ( "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/vclock" "go.temporal.io/server/service/history/workflow" @@ -61,9 +61,9 @@ const ( type ( transferQueueTaskExecutorBase struct { currentClusterName string - shard shard.Context + shard definition.ShardContext registry namespace.Registry - cache workflow.Cache + cache definition.WorkflowCache archivalClient archiver.Client logger log.Logger metricHandler metrics.MetricsHandler @@ -76,8 +76,8 @@ type ( ) func newTransferQueueTaskExecutorBase( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, archivalClient archiver.Client, logger log.Logger, metricHandler metrics.MetricsHandler, @@ -246,7 +246,7 @@ func (t *transferQueueTaskExecutorBase) deleteExecution(ctx context.Context, tas ctx, namespace.ID(task.GetNamespaceID()), workflowExecution, - workflow.CallerTypeTask, + definition.CallerTypeTask, ) if err != nil { return err @@ -298,7 +298,7 @@ func (t *transferQueueTaskExecutorBase) deleteExecution(ctx context.Context, tas ) } -func (t *transferQueueTaskExecutorBase) isCloseExecutionTaskPending(ms workflow.MutableState, weCtx workflow.Context) bool { +func (t *transferQueueTaskExecutorBase) isCloseExecutionTaskPending(ms definition.MutableState, weCtx definition.WorkflowContext) bool { closeTransferTaskId := ms.GetExecutionInfo().CloseTransferTaskId // taskID == 0 if workflow closed before this field was added (v1.17). if closeTransferTaskId == 0 { diff --git a/service/history/visibilityQueueFactory.go b/service/history/visibilityQueueFactory.go index 965e60908da..af1125ed902 100644 --- a/service/history/visibilityQueueFactory.go +++ b/service/history/visibilityQueueFactory.go @@ -31,10 +31,9 @@ import ( "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/persistence/visibility/manager" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" ) const ( @@ -97,8 +96,8 @@ func NewVisibilityQueueFactory( } func (f *visibilityQueueFactory) CreateQueue( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, ) queues.Queue { if f.HostScheduler != nil && f.Config.VisibilityProcessorEnableMultiCursor() { logger := log.With(shard.GetLogger(), tag.ComponentVisibilityQueue) diff --git a/service/history/visibilityQueueProcessor.go b/service/history/visibilityQueueProcessor.go index afa5f51441e..97e54797e01 100644 --- a/service/history/visibilityQueueProcessor.go +++ b/service/history/visibilityQueueProcessor.go @@ -37,10 +37,10 @@ import ( "go.temporal.io/server/common/persistence/visibility/manager" "go.temporal.io/server/common/quotas" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" ) type ( @@ -51,7 +51,7 @@ type ( // from transferQueueActiveProcessorImpl (transferQueueProcessorImpl.activeTaskProcessor) *queueProcessorBase queueAckMgr - shard shard.Context + shard definition.ShardContext options *QueueProcessorOptions executionManager persistence.ExecutionManager maxReadLevel maxReadLevel @@ -73,8 +73,8 @@ type ( ) func newVisibilityQueueProcessor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, scheduler queues.Scheduler, priorityAssigner queues.PriorityAssigner, visibilityMgr manager.VisibilityManager, @@ -360,7 +360,7 @@ func (t *visibilityQueueProcessorImpl) queueShutdown() error { } func newVisibilityTaskShardScheduler( - shard shard.Context, + shard definition.ShardContext, logger log.Logger, ) queues.Scheduler { config := shard.GetConfig() diff --git a/service/history/visibilityQueueTaskExecutor.go b/service/history/visibilityQueueTaskExecutor.go index 16de51225db..8448fbdacea 100644 --- a/service/history/visibilityQueueTaskExecutor.go +++ b/service/history/visibilityQueueTaskExecutor.go @@ -33,23 +33,21 @@ import ( "go.temporal.io/api/serviceerror" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence/visibility/manager" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/queues" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tasks" - "go.temporal.io/server/service/history/workflow" ) type ( visibilityQueueTaskExecutor struct { - shard shard.Context - cache workflow.Cache + shard definition.ShardContext + cache definition.WorkflowCache logger log.Logger metricProvider metrics.MetricsHandler visibilityMgr manager.VisibilityManager @@ -59,8 +57,8 @@ type ( var errUnknownVisibilityTask = serviceerror.NewInternal("unknown visibility task") func newVisibilityQueueTaskExecutor( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, visibilityMgr manager.VisibilityManager, logger log.Logger, metricProvider metrics.MetricsHandler, diff --git a/service/history/visibilityQueueTaskExecutor_test.go b/service/history/visibilityQueueTaskExecutor_test.go index 05b2262e0ef..3ab6491a4cc 100644 --- a/service/history/visibilityQueueTaskExecutor_test.go +++ b/service/history/visibilityQueueTaskExecutor_test.go @@ -46,7 +46,6 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" @@ -55,6 +54,7 @@ import ( "go.temporal.io/server/common/persistence/visibility/manager" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/queues" "go.temporal.io/server/service/history/shard" @@ -74,7 +74,7 @@ type ( mockVisibilityMgr *manager.MockVisibilityManager mockExecutionMgr *persistence.MockExecutionManager - workflowCache workflow.Cache + workflowCache definition.WorkflowCache logger log.Logger namespaceID namespace.ID namespace namespace.Name @@ -485,7 +485,7 @@ func (s *visibilityQueueTaskExecutorSuite) createRecordWorkflowExecutionStartedR namespaceName namespace.Name, startEvent *historypb.HistoryEvent, task *tasks.StartExecutionVisibilityTask, - mutableState workflow.MutableState, + mutableState definition.MutableState, backoff time.Duration, taskQueueName string, ) *manager.RecordWorkflowExecutionStartedRequest { @@ -515,7 +515,7 @@ func (s *visibilityQueueTaskExecutorSuite) createRecordWorkflowExecutionStartedR func (s *visibilityQueueTaskExecutorSuite) createUpsertWorkflowRequest( namespaceName namespace.Name, task *tasks.UpsertExecutionVisibilityTask, - mutableState workflow.MutableState, + mutableState definition.MutableState, taskQueueName string, ) *manager.UpsertWorkflowExecutionRequest { execution := &commonpb.WorkflowExecution{ @@ -541,7 +541,7 @@ func (s *visibilityQueueTaskExecutorSuite) createUpsertWorkflowRequest( } func (s *visibilityQueueTaskExecutorSuite) createPersistenceMutableState( - ms workflow.MutableState, + ms definition.MutableState, lastEventID int64, lastEventVersion int64, ) *persistencespb.WorkflowMutableState { diff --git a/service/history/workflow/cache.go b/service/history/workflow/cache.go index f90ec1230b1..7ffbbe99ea7 100644 --- a/service/history/workflow/cache.go +++ b/service/history/workflow/cache.go @@ -37,47 +37,33 @@ import ( "go.temporal.io/api/serviceerror" "go.temporal.io/server/common/cache" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" ) type ( - ReleaseCacheFunc func(err error) - - Cache interface { - GetOrCreateWorkflowExecution( - ctx context.Context, - namespaceID namespace.ID, - execution commonpb.WorkflowExecution, - caller CallerType, - ) (Context, ReleaseCacheFunc, error) - } - CacheImpl struct { cache.Cache - shard shard.Context + shard definition.ShardContext logger log.Logger metricsHandler metrics.MetricsHandler config *configs.Config } - - NewCacheFn func(shard shard.Context) Cache ) -var NoopReleaseFn ReleaseCacheFunc = func(err error) {} +var NoopReleaseFn definition.ReleaseFunc = func(err error) {} const ( cacheNotReleased int32 = 0 cacheReleased int32 = 1 ) -func NewCache(shard shard.Context) Cache { +func NewCache(shard definition.ShardContext) *CacheImpl { opts := &cache.Options{} config := shard.GetConfig() opts.InitialCapacity = config.HistoryCacheInitialSize() @@ -97,8 +83,8 @@ func (c *CacheImpl) GetOrCreateWorkflowExecution( ctx context.Context, namespaceID namespace.ID, execution commonpb.WorkflowExecution, - caller CallerType, -) (Context, ReleaseCacheFunc, error) { + caller definition.CallerType, +) (definition.WorkflowContext, definition.ReleaseFunc, error) { if err := c.validateWorkflowExecutionInfo(ctx, namespaceID, &execution); err != nil { return nil, nil, err @@ -129,11 +115,11 @@ func (c *CacheImpl) getOrCreateWorkflowExecutionInternal( execution commonpb.WorkflowExecution, handler metrics.MetricsHandler, forceClearContext bool, - caller CallerType, -) (Context, ReleaseCacheFunc, error) { + caller definition.CallerType, +) (definition.WorkflowContext, definition.ReleaseFunc, error) { key := definition.NewWorkflowKey(namespaceID.String(), execution.GetWorkflowId(), execution.GetRunId()) - workflowCtx, cacheHit := c.Get(key).(Context) + workflowCtx, cacheHit := c.Get(key).(definition.WorkflowContext) if !cacheHit { handler.Counter(metrics.CacheMissCounter.GetMetricName()).Record(1) // Let's create the workflow execution workflowCtx @@ -143,7 +129,7 @@ func (c *CacheImpl) getOrCreateWorkflowExecutionInternal( handler.Counter(metrics.CacheFailures.GetMetricName()).Record(1) return nil, nil, err } - workflowCtx = elem.(Context) + workflowCtx = elem.(definition.WorkflowContext) } // TODO This will create a closure on every request. @@ -162,9 +148,9 @@ func (c *CacheImpl) getOrCreateWorkflowExecutionInternal( func (c *CacheImpl) makeReleaseFunc( key definition.WorkflowKey, - context Context, + context definition.WorkflowContext, forceClearContext bool, - caller CallerType, + caller definition.CallerType, ) func(error) { status := cacheNotReleased diff --git a/service/history/workflow/cache_mock.go b/service/history/workflow/cache_mock.go index 9d016b02f5c..abf3a28b018 100644 --- a/service/history/workflow/cache_mock.go +++ b/service/history/workflow/cache_mock.go @@ -27,51 +27,3 @@ // Package workflow is a generated GoMock package. package workflow - -import ( - context "context" - reflect "reflect" - - gomock "github.com/golang/mock/gomock" - v1 "go.temporal.io/api/common/v1" - namespace "go.temporal.io/server/common/namespace" -) - -// MockCache is a mock of Cache interface. -type MockCache struct { - ctrl *gomock.Controller - recorder *MockCacheMockRecorder -} - -// MockCacheMockRecorder is the mock recorder for MockCache. -type MockCacheMockRecorder struct { - mock *MockCache -} - -// NewMockCache creates a new mock instance. -func NewMockCache(ctrl *gomock.Controller) *MockCache { - mock := &MockCache{ctrl: ctrl} - mock.recorder = &MockCacheMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockCache) EXPECT() *MockCacheMockRecorder { - return m.recorder -} - -// GetOrCreateWorkflowExecution mocks base method. -func (m *MockCache) GetOrCreateWorkflowExecution(ctx context.Context, namespaceID namespace.ID, execution v1.WorkflowExecution, caller CallerType) (Context, ReleaseCacheFunc, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetOrCreateWorkflowExecution", ctx, namespaceID, execution, caller) - ret0, _ := ret[0].(Context) - ret1, _ := ret[1].(ReleaseCacheFunc) - ret2, _ := ret[2].(error) - return ret0, ret1, ret2 -} - -// GetOrCreateWorkflowExecution indicates an expected call of GetOrCreateWorkflowExecution. -func (mr *MockCacheMockRecorder) GetOrCreateWorkflowExecution(ctx, namespaceID, execution, caller interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrCreateWorkflowExecution", reflect.TypeOf((*MockCache)(nil).GetOrCreateWorkflowExecution), ctx, namespaceID, execution, caller) -} diff --git a/service/history/workflow/cache_test.go b/service/history/workflow/cache_test.go index 761e14ee564..423013c99b7 100644 --- a/service/history/workflow/cache_test.go +++ b/service/history/workflow/cache_test.go @@ -43,6 +43,7 @@ import ( "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" ) @@ -55,7 +56,7 @@ type ( controller *gomock.Controller mockShard *shard.ContextTest - cache Cache + cache *CacheImpl } ) @@ -101,12 +102,12 @@ func (s *historyCacheSuite) TestHistoryCacheBasic() { WorkflowId: "some random workflow ID", RunId: uuid.New(), } - mockMS1 := NewMockMutableState(s.controller) + mockMS1 := definition.NewMockMutableState(s.controller) ctx, release, err := s.cache.GetOrCreateWorkflowExecution( context.Background(), namespaceID, execution1, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err) ctx.(*ContextImpl).MutableState = mockMS1 @@ -115,7 +116,7 @@ func (s *historyCacheSuite) TestHistoryCacheBasic() { context.Background(), namespaceID, execution1, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err) s.Equal(mockMS1, ctx.(*ContextImpl).MutableState) @@ -129,7 +130,7 @@ func (s *historyCacheSuite) TestHistoryCacheBasic() { context.Background(), namespaceID, execution2, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err) s.NotEqual(mockMS1, ctx.(*ContextImpl).MutableState) @@ -149,7 +150,7 @@ func (s *historyCacheSuite) TestHistoryCachePinning() { context.Background(), namespaceID, we, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err) @@ -158,12 +159,12 @@ func (s *historyCacheSuite) TestHistoryCachePinning() { RunId: uuid.New(), } - // Cache is full because context is pinned, should get an error now + // WorkflowCache is full because context is pinned, should get an error now _, _, err2 := s.cache.GetOrCreateWorkflowExecution( context.Background(), namespaceID, we2, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.NotNil(err2) @@ -174,7 +175,7 @@ func (s *historyCacheSuite) TestHistoryCachePinning() { context.Background(), namespaceID, we2, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err3) release2(err3) @@ -184,7 +185,7 @@ func (s *historyCacheSuite) TestHistoryCachePinning() { context.Background(), namespaceID, we, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err4) s.False(ctx == newContext) @@ -204,12 +205,12 @@ func (s *historyCacheSuite) TestHistoryCacheClear() { context.Background(), namespaceID, we, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err) // since we are just testing whether the release function will clear the cache // all we need is a fake MutableState - mock := NewMockMutableState(s.controller) + mock := definition.NewMockMutableState(s.controller) ctx.(*ContextImpl).MutableState = mock release(nil) @@ -220,7 +221,7 @@ func (s *historyCacheSuite) TestHistoryCacheClear() { context.Background(), namespaceID, we, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err) @@ -234,7 +235,7 @@ func (s *historyCacheSuite) TestHistoryCacheClear() { context.Background(), namespaceID, we, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err) s.Nil(ctx.(*ContextImpl).MutableState) @@ -269,14 +270,14 @@ func (s *historyCacheSuite) TestHistoryCacheConcurrentAccess_Release() { WorkflowId: workflowId, RunId: runID, }, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err) // since each time the is reset to nil s.Nil(ctx.(*ContextImpl).MutableState) // since we are just testing whether the release function will clear the cache // all we need is a fake MutableState - mock := NewMockMutableState(s.controller) + mock := definition.NewMockMutableState(s.controller) mock.EXPECT().GetQueryRegistry().Return(NewQueryRegistry()) ctx.(*ContextImpl).MutableState = mock release(errors.New("some random error message")) @@ -294,7 +295,7 @@ func (s *historyCacheSuite) TestHistoryCacheConcurrentAccess_Release() { WorkflowId: workflowId, RunId: runID, }, - CallerTypeAPI, + definition.CallerTypeAPI, ) s.Nil(err) // since we are just testing whether the release function will clear the cache @@ -331,7 +332,7 @@ func (s *historyCacheSuite) TestHistoryCacheConcurrentAccess_Pin() { startGroup.Done() startGroup.Wait() - var releaseFn ReleaseCacheFunc + var releaseFn definition.ReleaseFunc var err error for { _, releaseFn, err = s.cache.GetOrCreateWorkflowExecution( @@ -341,7 +342,7 @@ func (s *historyCacheSuite) TestHistoryCacheConcurrentAccess_Pin() { WorkflowId: workflowID, RunId: runID, }, - CallerTypeAPI, + definition.CallerTypeAPI, ) if err == nil { break diff --git a/service/history/workflow/checksum.go b/service/history/workflow/checksum.go index 9a55c296058..8e1a20bacee 100644 --- a/service/history/workflow/checksum.go +++ b/service/history/workflow/checksum.go @@ -31,6 +31,8 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common/checksum" "go.temporal.io/server/common/util" + "go.temporal.io/server/service/history/definition" + "golang.org/x/exp/maps" ) @@ -38,7 +40,7 @@ const ( mutableStateChecksumPayloadV1 = int32(1) ) -func generateMutableStateChecksum(ms MutableState) (*persistencespb.Checksum, error) { +func generateMutableStateChecksum(ms definition.MutableState) (*persistencespb.Checksum, error) { payload := newMutableStateChecksumPayload(ms) csum, err := checksum.GenerateCRC32(payload, mutableStateChecksumPayloadV1) if err != nil { @@ -48,7 +50,7 @@ func generateMutableStateChecksum(ms MutableState) (*persistencespb.Checksum, er } func verifyMutableStateChecksum( - ms MutableState, + ms definition.MutableState, csum *persistencespb.Checksum, ) error { if csum.Version != mutableStateChecksumPayloadV1 { @@ -58,7 +60,7 @@ func verifyMutableStateChecksum( return checksum.Verify(payload, csum) } -func newMutableStateChecksumPayload(ms MutableState) *checksumspb.MutableStateChecksumPayload { +func newMutableStateChecksumPayload(ms definition.MutableState) *checksumspb.MutableStateChecksumPayload { executionInfo := ms.GetExecutionInfo() executionState := ms.GetExecutionState() payload := &checksumspb.MutableStateChecksumPayload{ diff --git a/service/history/workflow/context.go b/service/history/workflow/context.go index 158e50c4473..106f8823d5c 100644 --- a/service/history/workflow/context.go +++ b/service/history/workflow/context.go @@ -22,8 +22,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination context_mock.go - package workflow import ( @@ -40,7 +38,6 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/clock" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/locks" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" @@ -50,7 +47,7 @@ import ( "go.temporal.io/server/common/rpc" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" ) @@ -58,96 +55,9 @@ const ( defaultRemoteCallTimeout = 30 * time.Second ) -const ( - CallerTypeAPI CallerType = 0 - CallerTypeTask CallerType = 1 -) - -type ( - CallerType int - - Context interface { - GetWorkflowKey() definition.WorkflowKey - - LoadMutableState(ctx context.Context) (MutableState, error) - LoadExecutionStats(ctx context.Context) (*persistencespb.ExecutionStats, error) - Clear() - - Lock(ctx context.Context, caller CallerType) error - Unlock(caller CallerType) - - GetHistorySize() int64 - SetHistorySize(size int64) - - ReapplyEvents( - eventBatches []*persistence.WorkflowEvents, - ) error - - PersistWorkflowEvents( - ctx context.Context, - workflowEvents *persistence.WorkflowEvents, - ) (int64, error) - - CreateWorkflowExecution( - ctx context.Context, - now time.Time, - createMode persistence.CreateWorkflowMode, - prevRunID string, - prevLastWriteVersion int64, - newMutableState MutableState, - newWorkflow *persistence.WorkflowSnapshot, - newWorkflowEvents []*persistence.WorkflowEvents, - ) error - ConflictResolveWorkflowExecution( - ctx context.Context, - now time.Time, - conflictResolveMode persistence.ConflictResolveWorkflowMode, - resetMutableState MutableState, - newContext Context, - newMutableState MutableState, - currentContext Context, - currentMutableState MutableState, - currentTransactionPolicy *TransactionPolicy, - ) error - UpdateWorkflowExecutionAsActive( - ctx context.Context, - now time.Time, - ) error - UpdateWorkflowExecutionWithNewAsActive( - ctx context.Context, - now time.Time, - newContext Context, - newMutableState MutableState, - ) error - UpdateWorkflowExecutionAsPassive( - ctx context.Context, - now time.Time, - ) error - UpdateWorkflowExecutionWithNewAsPassive( - ctx context.Context, - now time.Time, - newContext Context, - newMutableState MutableState, - ) error - UpdateWorkflowExecutionWithNew( - ctx context.Context, - now time.Time, - updateMode persistence.UpdateWorkflowMode, - newContext Context, - newMutableState MutableState, - currentWorkflowTransactionPolicy TransactionPolicy, - newWorkflowTransactionPolicy *TransactionPolicy, - ) error - SetWorkflowExecution( - ctx context.Context, - now time.Time, - ) error - } -) - type ( ContextImpl struct { - shard shard.Context + shard definition.ShardContext workflowKey definition.WorkflowKey logger log.Logger metricsHandler metrics.MetricsHandler @@ -156,15 +66,15 @@ type ( transaction Transaction mutex locks.PriorityMutex - MutableState MutableState + MutableState definition.MutableState stats *persistencespb.ExecutionStats } ) -var _ Context = (*ContextImpl)(nil) +var _ definition.WorkflowContext = (*ContextImpl)(nil) func NewContext( - shard shard.Context, + shard definition.ShardContext, workflowKey definition.WorkflowKey, logger log.Logger, ) *ContextImpl { @@ -185,12 +95,12 @@ func NewContext( func (c *ContextImpl) Lock( ctx context.Context, - caller CallerType, + caller definition.CallerType, ) error { switch caller { - case CallerTypeAPI: + case definition.CallerTypeAPI: return c.mutex.LockHigh(ctx) - case CallerTypeTask: + case definition.CallerTypeTask: return c.mutex.LockLow(ctx) default: panic(fmt.Sprintf("unknown caller type: %v", caller)) @@ -198,12 +108,12 @@ func (c *ContextImpl) Lock( } func (c *ContextImpl) Unlock( - caller CallerType, + caller definition.CallerType, ) { switch caller { - case CallerTypeAPI: + case definition.CallerTypeAPI: c.mutex.UnlockHigh() - case CallerTypeTask: + case definition.CallerTypeTask: c.mutex.UnlockLow() default: panic(fmt.Sprintf("unknown caller type: %v", caller)) @@ -251,7 +161,7 @@ func (c *ContextImpl) LoadExecutionStats(ctx context.Context) (*persistencespb.E return c.stats, nil } -func (c *ContextImpl) LoadMutableState(ctx context.Context) (MutableState, error) { +func (c *ContextImpl) LoadMutableState(ctx context.Context) (definition.MutableState, error) { namespaceEntry, err := c.shard.GetNamespaceRegistry().GetNamespaceByID( namespace.ID(c.workflowKey.NamespaceID), ) @@ -305,7 +215,7 @@ func (c *ContextImpl) LoadMutableState(ctx context.Context) (MutableState, error return nil, err } if flushBeforeReady { - return nil, serviceerror.NewInternal("Context counter flushBeforeReady status after loading mutable state from DB") + return nil, serviceerror.NewInternal("WorkflowContext counter flushBeforeReady status after loading mutable state from DB") } return c.MutableState, nil @@ -324,7 +234,7 @@ func (c *ContextImpl) CreateWorkflowExecution( createMode persistence.CreateWorkflowMode, prevRunID string, prevLastWriteVersion int64, - newMutableState MutableState, + newMutableState definition.MutableState, newWorkflow *persistence.WorkflowSnapshot, newWorkflowEvents []*persistence.WorkflowEvents, ) (retError error) { @@ -370,12 +280,12 @@ func (c *ContextImpl) ConflictResolveWorkflowExecution( ctx context.Context, now time.Time, conflictResolveMode persistence.ConflictResolveWorkflowMode, - resetMutableState MutableState, - newContext Context, - newMutableState MutableState, - currentContext Context, - currentMutableState MutableState, - currentTransactionPolicy *TransactionPolicy, + resetMutableState definition.MutableState, + newContext definition.WorkflowContext, + newMutableState definition.MutableState, + currentContext definition.WorkflowContext, + currentMutableState definition.MutableState, + currentTransactionPolicy *definition.TransactionPolicy, ) (retError error) { defer func() { @@ -386,7 +296,7 @@ func (c *ContextImpl) ConflictResolveWorkflowExecution( resetWorkflow, resetWorkflowEventsSeq, err := resetMutableState.CloseTransactionAsSnapshot( now, - TransactionPolicyPassive, + definition.TransactionPolicyPassive, ) if err != nil { return err @@ -407,7 +317,7 @@ func (c *ContextImpl) ConflictResolveWorkflowExecution( newWorkflow, newWorkflowEventsSeq, err = newMutableState.CloseTransactionAsSnapshot( now, - TransactionPolicyPassive, + definition.TransactionPolicyPassive, ) if err != nil { return err @@ -494,7 +404,7 @@ func (c *ContextImpl) UpdateWorkflowExecutionAsActive( persistence.UpdateWorkflowModeUpdateCurrent, nil, nil, - TransactionPolicyActive, + definition.TransactionPolicyActive, nil, ); err != nil { return err @@ -513,8 +423,8 @@ func (c *ContextImpl) UpdateWorkflowExecutionAsActive( func (c *ContextImpl) UpdateWorkflowExecutionWithNewAsActive( ctx context.Context, now time.Time, - newContext Context, - newMutableState MutableState, + newContext definition.WorkflowContext, + newMutableState definition.MutableState, ) error { return c.UpdateWorkflowExecutionWithNew( @@ -523,8 +433,8 @@ func (c *ContextImpl) UpdateWorkflowExecutionWithNewAsActive( persistence.UpdateWorkflowModeUpdateCurrent, newContext, newMutableState, - TransactionPolicyActive, - TransactionPolicyActive.Ptr(), + definition.TransactionPolicyActive, + definition.TransactionPolicyActive.Ptr(), ) } @@ -539,7 +449,7 @@ func (c *ContextImpl) UpdateWorkflowExecutionAsPassive( persistence.UpdateWorkflowModeUpdateCurrent, nil, nil, - TransactionPolicyPassive, + definition.TransactionPolicyPassive, nil, ) } @@ -547,8 +457,8 @@ func (c *ContextImpl) UpdateWorkflowExecutionAsPassive( func (c *ContextImpl) UpdateWorkflowExecutionWithNewAsPassive( ctx context.Context, now time.Time, - newContext Context, - newMutableState MutableState, + newContext definition.WorkflowContext, + newMutableState definition.MutableState, ) error { return c.UpdateWorkflowExecutionWithNew( @@ -557,8 +467,8 @@ func (c *ContextImpl) UpdateWorkflowExecutionWithNewAsPassive( persistence.UpdateWorkflowModeUpdateCurrent, newContext, newMutableState, - TransactionPolicyPassive, - TransactionPolicyPassive.Ptr(), + definition.TransactionPolicyPassive, + definition.TransactionPolicyPassive.Ptr(), ) } @@ -566,10 +476,10 @@ func (c *ContextImpl) UpdateWorkflowExecutionWithNew( ctx context.Context, now time.Time, updateMode persistence.UpdateWorkflowMode, - newContext Context, - newMutableState MutableState, - currentWorkflowTransactionPolicy TransactionPolicy, - newWorkflowTransactionPolicy *TransactionPolicy, + newContext definition.WorkflowContext, + newMutableState definition.MutableState, + currentWorkflowTransactionPolicy definition.TransactionPolicy, + newWorkflowTransactionPolicy *definition.TransactionPolicy, ) (retError error) { defer func() { @@ -667,7 +577,7 @@ func (c *ContextImpl) SetWorkflowExecution(ctx context.Context, now time.Time) ( resetWorkflowSnapshot, resetWorkflowEventsSeq, err := c.MutableState.CloseTransactionAsSnapshot( now, - TransactionPolicyPassive, + definition.TransactionPolicyPassive, ) if err != nil { return err @@ -784,7 +694,7 @@ func (c *ContextImpl) ReapplyEvents( for _, events := range eventBatches { if namespace.ID(events.NamespaceID) != namespaceID || events.WorkflowID != workflowID { - return serviceerror.NewInternal("Context encountered mismatch namespaceID / workflowID in events reapplication.") + return serviceerror.NewInternal("WorkflowContext encountered mismatch namespaceID / workflowID in events reapplication.") } for _, e := range events.Events { @@ -925,7 +835,7 @@ func (c *ContextImpl) enforceSizeCheck( func emitStateTransitionCount( metricsHandler metrics.MetricsHandler, - mutableState MutableState, + mutableState definition.MutableState, ) { if mutableState == nil { return diff --git a/service/history/workflow/delete_manager.go b/service/history/workflow/delete_manager.go index 72ad051b4bb..0f032c76459 100644 --- a/service/history/workflow/delete_manager.go +++ b/service/history/workflow/delete_manager.go @@ -36,13 +36,12 @@ import ( enumsspb "go.temporal.io/server/api/enums/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/clock" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/worker/archiver" ) @@ -53,30 +52,30 @@ type ( ctx context.Context, nsID namespace.ID, we commonpb.WorkflowExecution, - ms MutableState, + ms definition.MutableState, workflowClosedVersion int64, ) error DeleteWorkflowExecution( ctx context.Context, nsID namespace.ID, we commonpb.WorkflowExecution, - weCtx Context, - ms MutableState, + weCtx definition.WorkflowContext, + ms definition.MutableState, forceDeleteFromOpenVisibility bool, ) error DeleteWorkflowExecutionByRetention( ctx context.Context, nsID namespace.ID, we commonpb.WorkflowExecution, - weCtx Context, - ms MutableState, + weCtx definition.WorkflowContext, + ms definition.MutableState, archiveIfEnabled bool, ) error } DeleteManagerImpl struct { - shard shard.Context - historyCache Cache + shard definition.ShardContext + historyCache definition.WorkflowCache config *configs.Config metricsHandler metrics.MetricsHandler archivalClient archiver.Client @@ -87,8 +86,8 @@ type ( var _ DeleteManager = (*DeleteManagerImpl)(nil) func NewDeleteManager( - shard shard.Context, - cache Cache, + shard definition.ShardContext, + cache definition.WorkflowCache, config *configs.Config, archiverClient archiver.Client, timeSource clock.TimeSource, @@ -109,7 +108,7 @@ func (m *DeleteManagerImpl) AddDeleteWorkflowExecutionTask( ctx context.Context, nsID namespace.ID, we commonpb.WorkflowExecution, - ms MutableState, + ms definition.MutableState, workflowClosedVersion int64, ) error { @@ -139,8 +138,8 @@ func (m *DeleteManagerImpl) DeleteWorkflowExecution( ctx context.Context, nsID namespace.ID, we commonpb.WorkflowExecution, - weCtx Context, - ms MutableState, + weCtx definition.WorkflowContext, + ms definition.MutableState, forceDeleteFromOpenVisibility bool, ) error { @@ -160,8 +159,8 @@ func (m *DeleteManagerImpl) DeleteWorkflowExecutionByRetention( ctx context.Context, nsID namespace.ID, we commonpb.WorkflowExecution, - weCtx Context, - ms MutableState, + weCtx definition.WorkflowContext, + ms definition.MutableState, archiveIfEnabled bool, ) error { @@ -181,8 +180,8 @@ func (m *DeleteManagerImpl) deleteWorkflowExecutionInternal( ctx context.Context, namespaceID namespace.ID, we commonpb.WorkflowExecution, - weCtx Context, - ms MutableState, + weCtx definition.WorkflowContext, + ms definition.MutableState, archiveIfEnabled bool, forceDeleteFromOpenVisibility bool, metricsHandler metrics.MetricsHandler, @@ -256,8 +255,8 @@ func (m *DeleteManagerImpl) archiveWorkflowIfEnabled( namespaceID namespace.ID, workflowExecution commonpb.WorkflowExecution, currentBranchToken []byte, - weCtx Context, - ms MutableState, + weCtx definition.WorkflowContext, + ms definition.MutableState, metricsHandler metrics.MetricsHandler, ) (deletionPromised bool, err error) { diff --git a/service/history/workflow/delete_manager_mock.go b/service/history/workflow/delete_manager_mock.go index f8ed3f73f71..9153380dccd 100644 --- a/service/history/workflow/delete_manager_mock.go +++ b/service/history/workflow/delete_manager_mock.go @@ -33,8 +33,9 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - v1 "go.temporal.io/api/common/v1" + common "go.temporal.io/api/common/v1" namespace "go.temporal.io/server/common/namespace" + definition "go.temporal.io/server/service/history/definition" ) // MockDeleteManager is a mock of DeleteManager interface. @@ -61,7 +62,7 @@ func (m *MockDeleteManager) EXPECT() *MockDeleteManagerMockRecorder { } // AddDeleteWorkflowExecutionTask mocks base method. -func (m *MockDeleteManager) AddDeleteWorkflowExecutionTask(ctx context.Context, nsID namespace.ID, we v1.WorkflowExecution, ms MutableState, workflowClosedVersion int64) error { +func (m *MockDeleteManager) AddDeleteWorkflowExecutionTask(ctx context.Context, nsID namespace.ID, we common.WorkflowExecution, ms definition.MutableState, workflowClosedVersion int64) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddDeleteWorkflowExecutionTask", ctx, nsID, we, ms, workflowClosedVersion) ret0, _ := ret[0].(error) @@ -75,7 +76,7 @@ func (mr *MockDeleteManagerMockRecorder) AddDeleteWorkflowExecutionTask(ctx, nsI } // DeleteWorkflowExecution mocks base method. -func (m *MockDeleteManager) DeleteWorkflowExecution(ctx context.Context, nsID namespace.ID, we v1.WorkflowExecution, weCtx Context, ms MutableState, forceDeleteFromOpenVisibility bool) error { +func (m *MockDeleteManager) DeleteWorkflowExecution(ctx context.Context, nsID namespace.ID, we common.WorkflowExecution, weCtx definition.WorkflowContext, ms definition.MutableState, forceDeleteFromOpenVisibility bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeleteWorkflowExecution", ctx, nsID, we, weCtx, ms, forceDeleteFromOpenVisibility) ret0, _ := ret[0].(error) @@ -89,7 +90,7 @@ func (mr *MockDeleteManagerMockRecorder) DeleteWorkflowExecution(ctx, nsID, we, } // DeleteWorkflowExecutionByRetention mocks base method. -func (m *MockDeleteManager) DeleteWorkflowExecutionByRetention(ctx context.Context, nsID namespace.ID, we v1.WorkflowExecution, weCtx Context, ms MutableState, archiveIfEnabled bool) error { +func (m *MockDeleteManager) DeleteWorkflowExecutionByRetention(ctx context.Context, nsID namespace.ID, we common.WorkflowExecution, weCtx definition.WorkflowContext, ms definition.MutableState, archiveIfEnabled bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeleteWorkflowExecutionByRetention", ctx, nsID, we, weCtx, ms, archiveIfEnabled) ret0, _ := ret[0].(error) diff --git a/service/history/workflow/delete_manager_test.go b/service/history/workflow/delete_manager_test.go index 369c6d65415..bf88436575a 100644 --- a/service/history/workflow/delete_manager_test.go +++ b/service/history/workflow/delete_manager_test.go @@ -44,11 +44,10 @@ import ( carchiver "go.temporal.io/server/common/archiver" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/searchattribute" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tests" "go.temporal.io/server/service/worker/archiver" ) @@ -59,9 +58,9 @@ type ( *require.Assertions controller *gomock.Controller - mockCache *MockCache + mockCache *definition.MockWorkflowCache mockArchivalClient *archiver.MockClient - mockShardContext *shard.MockContext + mockShardContext *definition.MockShardContext mockClock *clock.EventTimeSource mockNamespaceRegistry *namespace.MockRegistry mockMetadata *cluster.MockMetadata @@ -87,14 +86,14 @@ func (s *deleteManagerWorkflowSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockCache = NewMockCache(s.controller) + s.mockCache = definition.NewMockWorkflowCache(s.controller) s.mockArchivalClient = archiver.NewMockClient(s.controller) s.mockClock = clock.NewEventTimeSource() s.mockNamespaceRegistry = namespace.NewMockRegistry(s.controller) s.mockMetadata = cluster.NewMockMetadata(s.controller) config := tests.NewDynamicConfig() - s.mockShardContext = shard.NewMockContext(s.controller) + s.mockShardContext = definition.NewMockShardContext(s.controller) s.mockShardContext.EXPECT().GetMetricsHandler().Return(metrics.NoopMetricsHandler).AnyTimes() s.mockShardContext.EXPECT().GetNamespaceRegistry().Return(s.mockNamespaceRegistry).AnyTimes() s.mockShardContext.EXPECT().GetClusterMetadata().Return(s.mockMetadata).AnyTimes() @@ -114,8 +113,8 @@ func (s *deleteManagerWorkflowSuite) TestDeleteDeletedWorkflowExecution() { RunId: tests.RunID, } - mockWeCtx := NewMockContext(s.controller) - mockMutableState := NewMockMutableState(s.controller) + mockWeCtx := definition.NewMockWorkflowContext(s.controller) + mockMutableState := definition.NewMockMutableState(s.controller) mockMutableState.EXPECT().GetCurrentBranchToken().Return([]byte{22, 8, 78}, nil) mockMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{State: enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED}) closeTime := time.Date(1978, 8, 22, 1, 2, 3, 4, time.UTC) @@ -156,8 +155,8 @@ func (s *deleteManagerWorkflowSuite) TestDeleteDeletedWorkflowExecution_Error() RunId: tests.RunID, } - mockWeCtx := NewMockContext(s.controller) - mockMutableState := NewMockMutableState(s.controller) + mockWeCtx := definition.NewMockWorkflowContext(s.controller) + mockMutableState := definition.NewMockMutableState(s.controller) mockMutableState.EXPECT().GetCurrentBranchToken().Return([]byte{22, 8, 78}, nil) mockMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{State: enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED}) closeTime := time.Date(1978, 8, 22, 1, 2, 3, 4, time.UTC) @@ -198,8 +197,8 @@ func (s *deleteManagerWorkflowSuite) TestDeleteWorkflowExecution_OpenWorkflow() } now := time.Now() - mockWeCtx := NewMockContext(s.controller) - mockMutableState := NewMockMutableState(s.controller) + mockWeCtx := definition.NewMockWorkflowContext(s.controller) + mockMutableState := definition.NewMockMutableState(s.controller) closeExecutionVisibilityTaskID := int64(39) mockMutableState.EXPECT().GetCurrentBranchToken().Return([]byte{22, 8, 78}, nil) mockMutableState.EXPECT().GetExecutionInfo().MinTimes(1).Return(&persistencespb.WorkflowExecutionInfo{ @@ -239,8 +238,8 @@ func (s *deleteManagerWorkflowSuite) TestDeleteWorkflowExecutionRetention_Archiv RunId: tests.RunID, } - mockWeCtx := NewMockContext(s.controller) - mockMutableState := NewMockMutableState(s.controller) + mockWeCtx := definition.NewMockWorkflowContext(s.controller) + mockMutableState := definition.NewMockMutableState(s.controller) mockMutableState.EXPECT().GetCurrentBranchToken().Return([]byte{22, 8, 78}, nil) mockMutableState.EXPECT().GetExecutionState().Return(&persistencespb.WorkflowExecutionState{State: enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED}) @@ -310,8 +309,8 @@ func (s *deleteManagerWorkflowSuite) TestDeleteWorkflowExecutionRetention_Archiv RunId: tests.RunID, } - mockWeCtx := NewMockContext(s.controller) - mockMutableState := NewMockMutableState(s.controller) + mockWeCtx := definition.NewMockWorkflowContext(s.controller) + mockMutableState := definition.NewMockMutableState(s.controller) branchToken := []byte{22, 8, 78} mockMutableState.EXPECT().GetCurrentBranchToken().Return(branchToken, nil) mockMutableState.EXPECT().GetExecutionState(). diff --git a/service/history/workflow/fx.go b/service/history/workflow/fx.go index 890a2e3a738..3af6f0ce37a 100644 --- a/service/history/workflow/fx.go +++ b/service/history/workflow/fx.go @@ -26,18 +26,8 @@ package workflow import ( "go.uber.org/fx" - - "go.temporal.io/server/service/history/shard" ) var Module = fx.Options( - fx.Provide(NewCacheFnProvider), fx.Populate(&taskGeneratorProvider), ) - -// NewCacheFnProvider provide a NewCacheFn that can be used to create new workflow cache. -func NewCacheFnProvider() NewCacheFn { - return func(shard shard.Context) Cache { - return NewCache(shard) - } -} diff --git a/service/history/workflow/history_builder.go b/service/history/workflow/history_builder.go index 8d3f504f9df..835428af923 100644 --- a/service/history/workflow/history_builder.go +++ b/service/history/workflow/history_builder.go @@ -40,6 +40,7 @@ import ( "go.temporal.io/server/common/clock" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/service/history/definition" ) const ( @@ -52,19 +53,6 @@ const ( type ( HistoryBuilderState int - HistoryMutation struct { - // events to be persist to events table - DBEventsBatches [][]*historypb.HistoryEvent - // events to be buffer in execution table - DBBufferBatch []*historypb.HistoryEvent - // whether to clear buffer events on DB - DBClearBuffer bool - // accumulated buffered events, equal to all buffer events from execution table - MemBufferBatch []*historypb.HistoryEvent - // scheduled to started event ID mapping for flushed buffered event - ScheduledIDToStartedID map[int64]int64 - } - TaskIDGenerator func(number int) ([]int64, error) HistoryBuilder struct { @@ -1117,7 +1105,7 @@ func (b *HistoryBuilder) FlushAndCreateNewBatch() { func (b *HistoryBuilder) Finish( flushBufferEvent bool, -) (*HistoryMutation, error) { +) (*definition.HistoryMutation, error) { defer func() { b.state = HistoryBuilderStateSealed }() @@ -1145,7 +1133,7 @@ func (b *HistoryBuilder) Finish( return nil, err } - return &HistoryMutation{ + return &definition.HistoryMutation{ DBEventsBatches: dbEventsBatches, DBClearBuffer: dbClearBuffer, DBBufferBatch: dbBufferBatch, diff --git a/service/history/workflow/history_builder_test.go b/service/history/workflow/history_builder_test.go index 1b7ab4270b5..12a055c27e0 100644 --- a/service/history/workflow/history_builder_test.go +++ b/service/history/workflow/history_builder_test.go @@ -47,6 +47,7 @@ import ( "go.temporal.io/server/common/clock" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tests" ) @@ -1658,7 +1659,7 @@ func (s *historyBuilderSuite) testAppendFlushFinishEventWithoutBufferSingleBatch s.NoError(err) s.assertEventIDTaskID(historyMutation) - s.Equal(&HistoryMutation{ + s.Equal(&definition.HistoryMutation{ DBEventsBatches: [][]*historypb.HistoryEvent{{event1, event2}}, DBClearBuffer: false, DBBufferBatch: nil, @@ -1733,7 +1734,7 @@ func (s *historyBuilderSuite) testAppendFlushFinishEventWithoutBufferMultiBatch( s.NoError(err) s.assertEventIDTaskID(historyMutation) - s.Equal(&HistoryMutation{ + s.Equal(&definition.HistoryMutation{ DBEventsBatches: [][]*historypb.HistoryEvent{ {event11, event12}, {event21, event22}, @@ -1769,7 +1770,7 @@ func (s *historyBuilderSuite) TestAppendFlushFinishEvent_WithBuffer_WithoutDBBuf s.NoError(err) s.assertEventIDTaskID(historyMutation) - s.Equal(&HistoryMutation{ + s.Equal(&definition.HistoryMutation{ DBEventsBatches: nil, DBClearBuffer: false, DBBufferBatch: []*historypb.HistoryEvent{event1, event2}, @@ -1801,7 +1802,7 @@ func (s *historyBuilderSuite) TestAppendFlushFinishEvent_WithBuffer_WithoutDBBuf s.NoError(err) s.assertEventIDTaskID(historyMutation) - s.Equal(&HistoryMutation{ + s.Equal(&definition.HistoryMutation{ DBEventsBatches: [][]*historypb.HistoryEvent{{event1, event2}}, DBClearBuffer: false, DBBufferBatch: nil, @@ -1831,7 +1832,7 @@ func (s *historyBuilderSuite) TestAppendFlushFinishEvent_WithoutBuffer_WithDBBuf s.NoError(err) s.assertEventIDTaskID(historyMutation) - s.Equal(&HistoryMutation{ + s.Equal(&definition.HistoryMutation{ DBEventsBatches: nil, DBClearBuffer: false, DBBufferBatch: nil, @@ -1861,7 +1862,7 @@ func (s *historyBuilderSuite) TestAppendFlushFinishEvent_WithoutBuffer_WithDBBuf s.NoError(err) s.assertEventIDTaskID(historyMutation) - s.Equal(&HistoryMutation{ + s.Equal(&definition.HistoryMutation{ DBEventsBatches: [][]*historypb.HistoryEvent{{event1, event2}}, DBClearBuffer: true, DBBufferBatch: nil, @@ -1898,7 +1899,7 @@ func (s *historyBuilderSuite) TestAppendFlushFinishEvent_WithBuffer_WithDBBuffer s.NoError(err) s.assertEventIDTaskID(historyMutation) - s.Equal(&HistoryMutation{ + s.Equal(&definition.HistoryMutation{ DBEventsBatches: nil, DBClearBuffer: false, DBBufferBatch: []*historypb.HistoryEvent{event1, event2}, @@ -1935,7 +1936,7 @@ func (s *historyBuilderSuite) TestAppendFlushFinishEvent_WithBuffer_WithDBBuffer s.NoError(err) s.assertEventIDTaskID(historyMutation) - s.Equal(&HistoryMutation{ + s.Equal(&definition.HistoryMutation{ DBEventsBatches: [][]*historypb.HistoryEvent{{event0, event1, event2}}, DBClearBuffer: true, DBBufferBatch: nil, @@ -2283,7 +2284,7 @@ func (s *historyBuilderSuite) TestReorder() { } func (s *historyBuilderSuite) assertEventIDTaskID( - historyMutation *HistoryMutation, + historyMutation *definition.HistoryMutation, ) { for _, event := range historyMutation.DBBufferBatch { diff --git a/service/history/workflow/mutable_state_impl.go b/service/history/workflow/mutable_state_impl.go index 56699565826..e7c20fcbbe2 100644 --- a/service/history/workflow/mutable_state_impl.go +++ b/service/history/workflow/mutable_state_impl.go @@ -47,13 +47,11 @@ import ( "go.temporal.io/server/api/historyservice/v1" persistencespb "go.temporal.io/server/api/persistence/v1" workflowspb "go.temporal.io/server/api/workflow/v1" - "go.temporal.io/server/common" "go.temporal.io/server/common/backoff" "go.temporal.io/server/common/clock" "go.temporal.io/server/common/cluster" "go.temporal.io/server/common/convert" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/enums" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" @@ -67,8 +65,7 @@ import ( "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/events" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" ) @@ -104,6 +101,8 @@ var ( ErrMissingSignalInitiatedEvent = serviceerror.NewInternal("unable to get signal initiated event") ) +var emptyTasks = []tasks.Task{} + type ( MutableStateImpl struct { pendingActivityTimerHeartbeats map[int64]time.Time // Scheduled Event ID -> LastHeartbeatTimeoutVisibilityInSeconds. @@ -137,7 +136,7 @@ type ( executionInfo *persistencespb.WorkflowExecutionInfo // Workflow mutable state info. executionState *persistencespb.WorkflowExecutionState - hBuilder *HistoryBuilder + hBuilder definition.HistoryBuilder // in memory only attributes // indicate the current version @@ -169,11 +168,11 @@ type ( taskGenerator TaskGenerator workflowTaskManager *workflowTaskStateMachine - QueryRegistry QueryRegistry + QueryRegistry definition.QueryRegistry - shard shard.Context + shard definition.ShardContext clusterMetadata cluster.Metadata - eventsCache events.Cache + eventsCache definition.EventCache config *configs.Config timeSource clock.TimeSource logger log.Logger @@ -181,11 +180,11 @@ type ( } ) -var _ MutableState = (*MutableStateImpl)(nil) +var _ definition.MutableState = (*MutableStateImpl)(nil) func NewMutableState( - shard shard.Context, - eventsCache events.Cache, + shard definition.ShardContext, + eventsCache definition.EventCache, logger log.Logger, namespaceEntry *namespace.Namespace, startTime time.Time, @@ -270,8 +269,8 @@ func NewMutableState( } func newMutableStateFromDB( - shard shard.Context, - eventsCache events.Cache, + shard definition.ShardContext, + eventsCache definition.EventCache, logger log.Logger, namespaceEntry *namespace.Namespace, dbRecord *persistencespb.WorkflowMutableState, @@ -352,8 +351,8 @@ func newMutableStateFromDB( } func NewSanitizedMutableState( - shard shard.Context, - eventsCache events.Cache, + shard definition.ShardContext, + eventsCache definition.EventCache, logger log.Logger, namespaceEntry *namespace.Namespace, mutableStateRecord *persistencespb.WorkflowMutableState, @@ -466,7 +465,7 @@ func (e *MutableStateImpl) SetCurrentBranchToken( return nil } -func (e *MutableStateImpl) SetHistoryBuilder(hBuilder *HistoryBuilder) { +func (e *MutableStateImpl) SetHistoryBuilder(hBuilder definition.HistoryBuilder) { e.hBuilder = hBuilder } @@ -614,7 +613,7 @@ func (e *MutableStateImpl) GetWorkflowType() *commonpb.WorkflowType { return wType } -func (e *MutableStateImpl) GetQueryRegistry() QueryRegistry { +func (e *MutableStateImpl) GetQueryRegistry() definition.QueryRegistry { return e.QueryRegistry } @@ -634,7 +633,7 @@ func (e *MutableStateImpl) GetActivityScheduledEvent( } event, err := e.eventsCache.GetEvent( ctx, - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(e.executionInfo.NamespaceId), WorkflowID: e.executionInfo.WorkflowId, RunID: e.executionState.RunId, @@ -714,7 +713,7 @@ func (e *MutableStateImpl) GetChildExecutionInitiatedEvent( } event, err := e.eventsCache.GetEvent( ctx, - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(e.executionInfo.NamespaceId), WorkflowID: e.executionInfo.WorkflowId, RunID: e.executionState.RunId, @@ -757,7 +756,7 @@ func (e *MutableStateImpl) GetRequesteCancelExternalInitiatedEvent( } event, err := e.eventsCache.GetEvent( ctx, - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(e.executionInfo.NamespaceId), WorkflowID: e.executionInfo.WorkflowId, RunID: e.executionState.RunId, @@ -831,7 +830,7 @@ func (e *MutableStateImpl) GetSignalExternalInitiatedEvent( } event, err := e.eventsCache.GetEvent( ctx, - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(e.executionInfo.NamespaceId), WorkflowID: e.executionInfo.WorkflowId, RunID: e.executionState.RunId, @@ -869,7 +868,7 @@ func (e *MutableStateImpl) GetCompletionEvent( event, err := e.eventsCache.GetEvent( ctx, - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(e.executionInfo.NamespaceId), WorkflowID: e.executionInfo.WorkflowId, RunID: e.executionState.RunId, @@ -919,7 +918,7 @@ func (e *MutableStateImpl) GetStartEvent( event, err := e.eventsCache.GetEvent( ctx, - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(e.executionInfo.NamespaceId), WorkflowID: e.executionInfo.WorkflowId, RunID: e.executionState.RunId, @@ -1024,7 +1023,7 @@ func (e *MutableStateImpl) writeEventToCache( // For completion event: store it within events cache so we can communicate the result to parent execution // during the processing of DeleteTransferTask without loading this event from database e.eventsCache.PutEvent( - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(e.executionInfo.NamespaceId), WorkflowID: e.executionInfo.WorkflowId, RunID: e.executionState.RunId, @@ -1237,7 +1236,7 @@ func (e *MutableStateImpl) DeleteUserTimer( // GetWorkflowTaskInfo returns details about the in-progress workflow task func (e *MutableStateImpl) GetWorkflowTaskInfo( scheduledEventID int64, -) (*WorkflowTaskInfo, bool) { +) (*definition.WorkflowTaskInfo, bool) { return e.workflowTaskManager.GetWorkflowTaskInfo(scheduledEventID) } @@ -1269,7 +1268,7 @@ func (e *MutableStateImpl) HasPendingWorkflowTask() bool { return e.workflowTaskManager.HasPendingWorkflowTask() } -func (e *MutableStateImpl) GetPendingWorkflowTask() (*WorkflowTaskInfo, bool) { +func (e *MutableStateImpl) GetPendingWorkflowTask() (*definition.WorkflowTaskInfo, bool) { return e.workflowTaskManager.GetPendingWorkflowTask() } @@ -1277,7 +1276,7 @@ func (e *MutableStateImpl) HasInFlightWorkflowTask() bool { return e.workflowTaskManager.HasInFlightWorkflowTask() } -func (e *MutableStateImpl) GetInFlightWorkflowTask() (*WorkflowTaskInfo, bool) { +func (e *MutableStateImpl) GetInFlightWorkflowTask() (*definition.WorkflowTaskInfo, bool) { return e.workflowTaskManager.GetInFlightWorkflowTask() } @@ -1304,7 +1303,7 @@ func (e *MutableStateImpl) ClearTransientWorkflowTask() error { return serviceerror.NewInternal("cannot clear transient workflow task when there are buffered events") } // no buffered event - resetWorkflowTaskInfo := &WorkflowTaskInfo{ + resetWorkflowTaskInfo := &definition.WorkflowTaskInfo{ Version: common.EmptyVersion, ScheduledEventID: common.EmptyEventID, StartedEventID: common.EmptyEventID, @@ -1417,7 +1416,7 @@ func (e *MutableStateImpl) DeleteSignalRequested( func (e *MutableStateImpl) addWorkflowExecutionStartedEventForContinueAsNew( parentExecutionInfo *workflowspb.ParentExecutionInfo, execution commonpb.WorkflowExecution, - previousExecutionState MutableState, + previousExecutionState definition.MutableState, command *commandpb.ContinueAsNewWorkflowExecutionCommandAttributes, firstRunID string, ) (*historypb.HistoryEvent, error) { @@ -1690,7 +1689,7 @@ func (e *MutableStateImpl) AddFirstWorkflowTaskScheduled( func (e *MutableStateImpl) AddWorkflowTaskScheduledEvent( bypassTaskGeneration bool, -) (*WorkflowTaskInfo, error) { +) (*definition.WorkflowTaskInfo, error) { opTag := tag.WorkflowActionWorkflowTaskScheduled if err := e.checkMutability(opTag); err != nil { return nil, err @@ -1702,7 +1701,7 @@ func (e *MutableStateImpl) AddWorkflowTaskScheduledEvent( func (e *MutableStateImpl) AddWorkflowTaskScheduledEventAsHeartbeat( bypassTaskGeneration bool, originalScheduledTimestamp *time.Time, -) (*WorkflowTaskInfo, error) { +) (*definition.WorkflowTaskInfo, error) { opTag := tag.WorkflowActionWorkflowTaskScheduled if err := e.checkMutability(opTag); err != nil { return nil, err @@ -1710,7 +1709,7 @@ func (e *MutableStateImpl) AddWorkflowTaskScheduledEventAsHeartbeat( return e.workflowTaskManager.AddWorkflowTaskScheduledEventAsHeartbeat(bypassTaskGeneration, originalScheduledTimestamp) } -func (e *MutableStateImpl) ReplicateTransientWorkflowTaskScheduled() (*WorkflowTaskInfo, error) { +func (e *MutableStateImpl) ReplicateTransientWorkflowTaskScheduled() (*definition.WorkflowTaskInfo, error) { return e.workflowTaskManager.ReplicateTransientWorkflowTaskScheduled() } @@ -1722,7 +1721,7 @@ func (e *MutableStateImpl) ReplicateWorkflowTaskScheduledEvent( attempt int32, scheduleTimestamp *time.Time, originalScheduledTimestamp *time.Time, -) (*WorkflowTaskInfo, error) { +) (*definition.WorkflowTaskInfo, error) { return e.workflowTaskManager.ReplicateWorkflowTaskScheduledEvent(version, scheduledEventID, taskQueue, startToCloseTimeout, attempt, scheduleTimestamp, originalScheduledTimestamp) } @@ -1731,7 +1730,7 @@ func (e *MutableStateImpl) AddWorkflowTaskStartedEvent( requestID string, taskQueue *taskqueuepb.TaskQueue, identity string, -) (*historypb.HistoryEvent, *WorkflowTaskInfo, error) { +) (*historypb.HistoryEvent, *definition.WorkflowTaskInfo, error) { opTag := tag.WorkflowActionWorkflowTaskStarted if err := e.checkMutability(opTag); err != nil { return nil, nil, err @@ -1740,19 +1739,19 @@ func (e *MutableStateImpl) AddWorkflowTaskStartedEvent( } func (e *MutableStateImpl) ReplicateWorkflowTaskStartedEvent( - workflowTask *WorkflowTaskInfo, + workflowTask *definition.WorkflowTaskInfo, version int64, scheduledEventID int64, startedEventID int64, requestID string, timestamp time.Time, -) (*WorkflowTaskInfo, error) { +) (*definition.WorkflowTaskInfo, error) { return e.workflowTaskManager.ReplicateWorkflowTaskStartedEvent(workflowTask, version, scheduledEventID, startedEventID, requestID, timestamp) } func (e *MutableStateImpl) CreateTransientWorkflowTask( - workflowTask *WorkflowTaskInfo, + workflowTask *definition.WorkflowTaskInfo, identity string, ) *historyspb.TransientWorkflowTaskInfo { return e.workflowTaskManager.CreateTransientWorkflowTaskEvents(workflowTask, identity) @@ -3163,7 +3162,7 @@ func (e *MutableStateImpl) AddContinueAsNewEvent( workflowTaskCompletedEventID int64, parentNamespace namespace.Name, command *commandpb.ContinueAsNewWorkflowExecutionCommandAttributes, -) (*historypb.HistoryEvent, MutableState, error) { +) (*historypb.HistoryEvent, definition.MutableState, error) { opTag := tag.WorkflowActionWorkflowContinueAsNew if err := e.checkMutability(opTag); err != nil { @@ -3829,7 +3828,7 @@ func (e *MutableStateImpl) StartTransaction( func (e *MutableStateImpl) CloseTransactionAsMutation( now time.Time, - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, ) (*persistence.WorkflowMutation, []*persistence.WorkflowEvents, error) { if err := e.prepareCloseTransaction( @@ -3860,8 +3859,8 @@ func (e *MutableStateImpl) CloseTransactionAsMutation( // we generate checksum here based on the assumption that the returned // snapshot object is considered immutable. As of this writing, the only - // code that modifies the returned object lives inside Context.resetWorkflowExecution - // currently, the updates done inside Context.resetWorkflowExecution doesn't + // code that modifies the returned object lives inside WorkflowContext.resetWorkflowExecution + // currently, the updates done inside WorkflowContext.resetWorkflowExecution doesn't // impact the checksum calculation checksum := e.generateChecksum() @@ -3907,7 +3906,7 @@ func (e *MutableStateImpl) CloseTransactionAsMutation( func (e *MutableStateImpl) CloseTransactionAsSnapshot( now time.Time, - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, ) (*persistence.WorkflowSnapshot, []*persistence.WorkflowEvents, error) { if err := e.prepareCloseTransaction( @@ -3943,8 +3942,8 @@ func (e *MutableStateImpl) CloseTransactionAsSnapshot( // we generate checksum here based on the assumption that the returned // snapshot object is considered immutable. As of this writing, the only - // code that modifies the returned object lives inside Context.resetWorkflowExecution - // currently, the updates done inside Context.resetWorkflowExecution doesn't + // code that modifies the returned object lives inside WorkflowContext.resetWorkflowExecution + // currently, the updates done inside WorkflowContext.resetWorkflowExecution doesn't // impact the checksum calculation checksum := e.generateChecksum() @@ -4000,7 +3999,7 @@ func (e *MutableStateImpl) GenerateMigrationTasks() (tasks.Task, error) { } func (e *MutableStateImpl) prepareCloseTransaction( - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, ) error { if err := e.closeTransactionWithPolicyCheck( @@ -4032,7 +4031,7 @@ func (e *MutableStateImpl) prepareCloseTransaction( } func (e *MutableStateImpl) cleanupTransaction( - _ TransactionPolicy, + _ definition.TransactionPolicy, ) error { e.updateActivityInfos = make(map[int64]*persistencespb.ActivityInfo) @@ -4073,7 +4072,7 @@ func (e *MutableStateImpl) cleanupTransaction( func (e *MutableStateImpl) prepareEventsAndReplicationTasks( now time.Time, - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, ) ([]*persistence.WorkflowEvents, []*historypb.HistoryEvent, bool, error) { currentBranchToken, err := e.GetCurrentBranchToken() @@ -4130,7 +4129,7 @@ func (e *MutableStateImpl) prepareEventsAndReplicationTasks( e.syncActivityToReplicationTask(now, transactionPolicy)..., ) - if transactionPolicy == TransactionPolicyPassive && + if transactionPolicy == definition.TransactionPolicyPassive && len(e.InsertTasks[tasks.CategoryReplication]) > 0 { return nil, nil, false, serviceerror.NewInternal("should not generate replication task when close transaction as passive") } @@ -4139,11 +4138,11 @@ func (e *MutableStateImpl) prepareEventsAndReplicationTasks( } func (e *MutableStateImpl) eventsToReplicationTask( - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, events []*historypb.HistoryEvent, ) error { - if transactionPolicy == TransactionPolicyPassive || + if transactionPolicy == definition.TransactionPolicyPassive || !e.canReplicateEvents() || len(events) == 0 { return nil @@ -4161,10 +4160,10 @@ func (e *MutableStateImpl) eventsToReplicationTask( func (e *MutableStateImpl) syncActivityToReplicationTask( now time.Time, - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, ) []tasks.Task { - if transactionPolicy == TransactionPolicyPassive || + if transactionPolicy == definition.TransactionPolicyPassive || !e.canReplicateEvents() { return emptyTasks } @@ -4200,10 +4199,10 @@ func (e *MutableStateImpl) updatePendingEventIDs( func (e *MutableStateImpl) updateWithLastWriteEvent( lastEvent *historypb.HistoryEvent, - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, ) error { - if transactionPolicy == TransactionPolicyPassive { + if transactionPolicy == definition.TransactionPolicyPassive { // already handled in mutable state. return nil } @@ -4230,11 +4229,11 @@ func (e *MutableStateImpl) canReplicateEvents() bool { // NOTE: do not apply this check on every batch, since transient // workflow task && workflow finish will be broken (the first batch) func (e *MutableStateImpl) validateNoEventsAfterWorkflowFinish( - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, workflowEventSeq []*persistence.WorkflowEvents, ) error { - if transactionPolicy == TransactionPolicyPassive || + if transactionPolicy == definition.TransactionPolicyPassive || len(workflowEventSeq) == 0 { return nil } @@ -4380,10 +4379,10 @@ func (e *MutableStateImpl) startTransactionHandleWorkflowTaskFailover() (bool, e } func (e *MutableStateImpl) closeTransactionWithPolicyCheck( - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, ) error { - if transactionPolicy == TransactionPolicyPassive || + if transactionPolicy == definition.TransactionPolicyPassive || !e.canReplicateEvents() { return nil } @@ -4402,10 +4401,10 @@ func (e *MutableStateImpl) closeTransactionWithPolicyCheck( } func (e *MutableStateImpl) closeTransactionHandleBufferedEventsLimit( - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, ) error { - if transactionPolicy == TransactionPolicyPassive || + if transactionPolicy == definition.TransactionPolicyPassive || !e.IsWorkflowExecutionRunning() { return nil } @@ -4434,10 +4433,10 @@ func (e *MutableStateImpl) closeTransactionHandleBufferedEventsLimit( } func (e *MutableStateImpl) closeTransactionHandleWorkflowReset( - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, ) error { - if transactionPolicy == TransactionPolicyPassive || + if transactionPolicy == definition.TransactionPolicyPassive || !e.IsWorkflowExecutionRunning() { return nil } @@ -4475,10 +4474,10 @@ func (e *MutableStateImpl) closeTransactionHandleWorkflowReset( } func (e *MutableStateImpl) closeTransactionHandleActivityUserTimerTasks( - transactionPolicy TransactionPolicy, + transactionPolicy definition.TransactionPolicy, ) error { - if transactionPolicy == TransactionPolicyPassive || + if transactionPolicy == definition.TransactionPolicyPassive || !e.IsWorkflowExecutionRunning() { return nil } diff --git a/service/history/workflow/mutable_state_impl_test.go b/service/history/workflow/mutable_state_impl_test.go index b81a474416c..f020c58d1fe 100644 --- a/service/history/workflow/mutable_state_impl_test.go +++ b/service/history/workflow/mutable_state_impl_test.go @@ -43,7 +43,6 @@ import ( historyspb "go.temporal.io/server/api/history/v1" persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/failure" "go.temporal.io/server/common/log" "go.temporal.io/server/common/namespace" @@ -52,7 +51,7 @@ import ( "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/events" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" ) @@ -65,7 +64,7 @@ type ( controller *gomock.Controller mockConfig *configs.Config mockShard *shard.ContextTest - mockEventsCache *events.MockCache + mockEventsCache *definition.MockEventCache mutableState *MutableStateImpl logger log.Logger @@ -90,7 +89,7 @@ func (s *mutableStateSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockEventsCache = events.NewMockCache(s.controller) + s.mockEventsCache = definition.NewMockEventCache(s.controller) s.mockConfig = tests.NewDynamicConfig() s.mockShard = shard.NewTestContext( @@ -204,7 +203,7 @@ func (s *mutableStateSuite) TestChecksum() { { name: "closeTransactionAsSnapshot", closeTxFunc: func(ms *MutableStateImpl) (*persistencespb.Checksum, error) { - snapshot, _, err := ms.CloseTransactionAsSnapshot(time.Now().UTC(), TransactionPolicyPassive) + snapshot, _, err := ms.CloseTransactionAsSnapshot(time.Now().UTC(), definition.TransactionPolicyPassive) if err != nil { return nil, err } @@ -215,7 +214,7 @@ func (s *mutableStateSuite) TestChecksum() { name: "closeTransactionAsMutation", enableBufferedEvents: true, closeTxFunc: func(ms *MutableStateImpl) (*persistencespb.Checksum, error) { - mutation, _, err := ms.CloseTransactionAsMutation(time.Now().UTC(), TransactionPolicyPassive) + mutation, _, err := ms.CloseTransactionAsMutation(time.Now().UTC(), definition.TransactionPolicyPassive) if err != nil { return nil, err } @@ -508,7 +507,7 @@ func (s *mutableStateSuite) prepareTransientWorkflowTaskCompletionFirstBatchRepl eventID++ s.mockEventsCache.EXPECT().PutEvent( - events.EventKey{ + definition.EventKey{ NamespaceID: namespaceID, WorkflowID: execution.GetWorkflowId(), RunID: execution.GetRunId(), @@ -603,7 +602,7 @@ func (s *mutableStateSuite) prepareTransientWorkflowTaskCompletionFirstBatchRepl newWorkflowTaskScheduleEvent, newWorkflowTaskStartedEvent, })) - _, _, err = s.mutableState.CloseTransactionAsMutation(time.Now().UTC(), TransactionPolicyPassive) + _, _, err = s.mutableState.CloseTransactionAsMutation(time.Now().UTC(), definition.TransactionPolicyPassive) s.NoError(err) return newWorkflowTaskScheduleEvent, newWorkflowTaskStartedEvent diff --git a/service/history/workflow/mutable_state_rebuilder.go b/service/history/workflow/mutable_state_rebuilder.go index e226adc1f42..ca9aef1edc6 100644 --- a/service/history/workflow/mutable_state_rebuilder.go +++ b/service/history/workflow/mutable_state_rebuilder.go @@ -41,7 +41,7 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" ) type ( @@ -53,16 +53,16 @@ type ( execution commonpb.WorkflowExecution, history []*historypb.HistoryEvent, newRunHistory []*historypb.HistoryEvent, - ) (MutableState, error) + ) (definition.MutableState, error) } MutableStateRebuilderImpl struct { - shard shard.Context + shard definition.ShardContext clusterMetadata cluster.Metadata namespaceRegistry namespace.Registry logger log.Logger - mutableState MutableState + mutableState definition.MutableState } ) @@ -74,9 +74,9 @@ const ( var _ MutableStateRebuilder = (*MutableStateRebuilderImpl)(nil) func NewMutableStateRebuilder( - shard shard.Context, + shard definition.ShardContext, logger log.Logger, - mutableState MutableState, + mutableState definition.MutableState, ) *MutableStateRebuilderImpl { return &MutableStateRebuilderImpl{ @@ -95,13 +95,13 @@ func (b *MutableStateRebuilderImpl) ApplyEvents( execution commonpb.WorkflowExecution, history []*historypb.HistoryEvent, newRunHistory []*historypb.HistoryEvent, -) (MutableState, error) { +) (definition.MutableState, error) { if len(history) == 0 { return nil, serviceerror.NewInternal(ErrMessageHistorySizeZero) } firstEvent := history[0] - var newRunMutableState MutableState + var newRunMutableState definition.MutableState taskGenerator := taskGeneratorProvider.NewTaskGenerator(b.shard, b.mutableState) diff --git a/service/history/workflow/mutable_state_rebuilder_mock.go b/service/history/workflow/mutable_state_rebuilder_mock.go index b7e83a4dc48..e8b6e31f161 100644 --- a/service/history/workflow/mutable_state_rebuilder_mock.go +++ b/service/history/workflow/mutable_state_rebuilder_mock.go @@ -33,9 +33,10 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - v1 "go.temporal.io/api/common/v1" - v10 "go.temporal.io/api/history/v1" + common "go.temporal.io/api/common/v1" + history "go.temporal.io/api/history/v1" namespace "go.temporal.io/server/common/namespace" + definition "go.temporal.io/server/service/history/definition" ) // MockMutableStateRebuilder is a mock of MutableStateRebuilder interface. @@ -62,10 +63,10 @@ func (m *MockMutableStateRebuilder) EXPECT() *MockMutableStateRebuilderMockRecor } // ApplyEvents mocks base method. -func (m *MockMutableStateRebuilder) ApplyEvents(ctx context.Context, namespaceID namespace.ID, requestID string, execution v1.WorkflowExecution, history, newRunHistory []*v10.HistoryEvent) (MutableState, error) { +func (m *MockMutableStateRebuilder) ApplyEvents(ctx context.Context, namespaceID namespace.ID, requestID string, execution common.WorkflowExecution, history, newRunHistory []*history.HistoryEvent) (definition.MutableState, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ApplyEvents", ctx, namespaceID, requestID, execution, history, newRunHistory) - ret0, _ := ret[0].(MutableState) + ret0, _ := ret[0].(definition.MutableState) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/service/history/workflow/mutable_state_rebuilder_test.go b/service/history/workflow/mutable_state_rebuilder_test.go index cb40f4e7f27..b8d93cc16fd 100644 --- a/service/history/workflow/mutable_state_rebuilder_test.go +++ b/service/history/workflow/mutable_state_rebuilder_test.go @@ -51,7 +51,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" - "go.temporal.io/server/service/history/events" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" ) @@ -63,10 +63,10 @@ type ( controller *gomock.Controller mockShard *shard.ContextTest - mockEventsCache *events.MockCache + mockEventsCache *definition.MockEventCache mockNamespaceCache *namespace.MockRegistry mockTaskGenerator *MockTaskGenerator - mockMutableState *MockMutableState + mockMutableState *definition.MockMutableState mockClusterMetadata *cluster.MockMetadata mockTaskGeneratorForNew *MockTaskGenerator @@ -79,7 +79,7 @@ type ( } testTaskGeneratorProvider struct { - mockMutableState *MockMutableState + mockMutableState *definition.MockMutableState mockTaskGenerator *MockTaskGenerator mockTaskGeneratorForNew *MockTaskGenerator @@ -104,7 +104,7 @@ func (s *stateBuilderSuite) SetupTest() { s.controller = gomock.NewController(s.T()) s.mockTaskGenerator = NewMockTaskGenerator(s.controller) - s.mockMutableState = NewMockMutableState(s.controller) + s.mockMutableState = definition.NewMockMutableState(s.controller) s.mockTaskGeneratorForNew = NewMockTaskGenerator(s.controller) s.mockShard = shard.NewTestContext( @@ -748,7 +748,7 @@ func (s *stateBuilderSuite) TestApplyEvents_EventTypeWorkflowTaskScheduled() { Attempt: workflowTaskAttempt, }}, } - wt := &WorkflowTaskInfo{ + wt := &definition.WorkflowTaskInfo{ Version: event.GetVersion(), ScheduledEventID: event.GetEventId(), StartedEventID: common.EmptyEventID, @@ -797,7 +797,7 @@ func (s *stateBuilderSuite) TestApplyEvents_EventTypeWorkflowTaskStarted() { RequestId: workflowTaskRequestID, }}, } - wt := &WorkflowTaskInfo{ + wt := &definition.WorkflowTaskInfo{ Version: event.GetVersion(), ScheduledEventID: scheduledEventID, StartedEventID: event.GetEventId(), @@ -807,7 +807,7 @@ func (s *stateBuilderSuite) TestApplyEvents_EventTypeWorkflowTaskStarted() { Attempt: 1, } s.mockMutableState.EXPECT().ReplicateWorkflowTaskStartedEvent( - (*WorkflowTaskInfo)(nil), event.GetVersion(), scheduledEventID, event.GetEventId(), workflowTaskRequestID, timestamp.TimeValue(event.GetEventTime()), + (*definition.WorkflowTaskInfo)(nil), event.GetVersion(), scheduledEventID, event.GetEventId(), workflowTaskRequestID, timestamp.TimeValue(event.GetEventTime()), ).Return(wt, nil) s.mockUpdateVersion(event) s.mockTaskGenerator.EXPECT().GenerateStartWorkflowTaskTasks( @@ -849,7 +849,7 @@ func (s *stateBuilderSuite) TestApplyEvents_EventTypeWorkflowTaskTimedOut() { taskqueue := &taskqueuepb.TaskQueue{Kind: enumspb.TASK_QUEUE_KIND_NORMAL, Name: "some random taskqueue"} newScheduledEventID := int64(233) s.executionInfo.TaskQueue = taskqueue.GetName() - s.mockMutableState.EXPECT().ReplicateTransientWorkflowTaskScheduled().Return(&WorkflowTaskInfo{ + s.mockMutableState.EXPECT().ReplicateTransientWorkflowTaskScheduled().Return(&definition.WorkflowTaskInfo{ Version: version, ScheduledEventID: newScheduledEventID, TaskQueue: taskqueue, @@ -893,7 +893,7 @@ func (s *stateBuilderSuite) TestApplyEvents_EventTypeWorkflowTaskFailed() { taskqueue := &taskqueuepb.TaskQueue{Kind: enumspb.TASK_QUEUE_KIND_NORMAL, Name: "some random taskqueue"} newScheduledEventID := int64(233) s.executionInfo.TaskQueue = taskqueue.GetName() - s.mockMutableState.EXPECT().ReplicateTransientWorkflowTaskScheduled().Return(&WorkflowTaskInfo{ + s.mockMutableState.EXPECT().ReplicateTransientWorkflowTaskScheduled().Return(&definition.WorkflowTaskInfo{ Version: version, ScheduledEventID: newScheduledEventID, TaskQueue: taskqueue, @@ -1797,8 +1797,8 @@ func (s *stateBuilderSuite) TestApplyEventsNewEventsNotHandled() { } func (p *testTaskGeneratorProvider) NewTaskGenerator( - _ shard.Context, - mutableState MutableState, + _ definition.ShardContext, + mutableState definition.MutableState, ) TaskGenerator { if mutableState == p.mockMutableState { return p.mockTaskGenerator diff --git a/service/history/workflow/mutable_state_util.go b/service/history/workflow/mutable_state_util.go index af02877bb06..8de3267f3c1 100644 --- a/service/history/workflow/mutable_state_util.go +++ b/service/history/workflow/mutable_state_util.go @@ -28,7 +28,7 @@ import ( "time" persistencespb "go.temporal.io/server/api/persistence/v1" - "go.temporal.io/server/common/definition" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" ) diff --git a/service/history/workflow/query.go b/service/history/workflow/query.go index da5f770cf35..ee7eafa4c5a 100644 --- a/service/history/workflow/query.go +++ b/service/history/workflow/query.go @@ -31,10 +31,12 @@ import ( enumspb "go.temporal.io/api/enums/v1" querypb "go.temporal.io/api/query/v1" "go.temporal.io/api/serviceerror" + + "go.temporal.io/server/service/history/definition" ) const ( - QueryCompletionTypeSucceeded QueryCompletionType = iota + QueryCompletionTypeSucceeded definition.QueryCompletionType = iota QueryCompletionTypeUnblocked QueryCompletionTypeFailed ) @@ -46,16 +48,6 @@ var ( ) type ( - QueryCompletionType int - - query interface { - getID() string - getCompletionCh() <-chan struct{} - getQueryInput() *querypb.WorkflowQuery - GetCompletionState() (*QueryCompletionState, error) - setCompletionState(*QueryCompletionState) error - } - queryImpl struct { id string queryInput *querypb.WorkflowQuery @@ -63,15 +55,9 @@ type ( completionState atomic.Value } - - QueryCompletionState struct { - Type QueryCompletionType - Result *querypb.WorkflowQueryResult - Err error - } ) -func newQuery(queryInput *querypb.WorkflowQuery) query { +func newQuery(queryInput *querypb.WorkflowQuery) definition.Query { return &queryImpl{ id: uuid.New(), queryInput: queryInput, @@ -79,27 +65,27 @@ func newQuery(queryInput *querypb.WorkflowQuery) query { } } -func (q *queryImpl) getID() string { +func (q *queryImpl) GetID() string { return q.id } -func (q *queryImpl) getCompletionCh() <-chan struct{} { +func (q *queryImpl) GetCompletionCh() <-chan struct{} { return q.completionCh } -func (q *queryImpl) getQueryInput() *querypb.WorkflowQuery { +func (q *queryImpl) GetQueryInput() *querypb.WorkflowQuery { return q.queryInput } -func (q *queryImpl) GetCompletionState() (*QueryCompletionState, error) { +func (q *queryImpl) GetCompletionState() (*definition.QueryCompletionState, error) { ts := q.completionState.Load() if ts == nil { return nil, errQueryNotInCompletionState } - return ts.(*QueryCompletionState), nil + return ts.(*definition.QueryCompletionState), nil } -func (q *queryImpl) setCompletionState(completionState *QueryCompletionState) error { +func (q *queryImpl) SetCompletionState(completionState *definition.QueryCompletionState) error { if err := q.validateCompletionState(completionState); err != nil { return err } @@ -113,7 +99,7 @@ func (q *queryImpl) setCompletionState(completionState *QueryCompletionState) er } func (q *queryImpl) validateCompletionState( - completionState *QueryCompletionState, + completionState *definition.QueryCompletionState, ) error { if completionState == nil { return errCompletionStateInvalid diff --git a/service/history/workflow/query_registry.go b/service/history/workflow/query_registry.go index d7d29a8ea25..13d31731e3a 100644 --- a/service/history/workflow/query_registry.go +++ b/service/history/workflow/query_registry.go @@ -31,6 +31,7 @@ import ( "go.temporal.io/api/serviceerror" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" ) var ( @@ -38,42 +39,22 @@ var ( ) type ( - QueryRegistry interface { - HasBufferedQuery() bool - GetBufferedIDs() []string - HasCompletedQuery() bool - GetCompletedIDs() []string - HasUnblockedQuery() bool - GetUnblockedIDs() []string - HasFailedQuery() bool - GetFailedIDs() []string - - GetQueryCompletionCh(string) (<-chan struct{}, error) - GetQueryInput(string) (*querypb.WorkflowQuery, error) - GetCompletionState(string) (*QueryCompletionState, error) - - BufferQuery(queryInput *querypb.WorkflowQuery) (string, <-chan struct{}) - SetCompletionState(string, *QueryCompletionState) error - RemoveQuery(id string) - Clear() - } - queryRegistryImpl struct { sync.RWMutex - buffered map[string]query - completed map[string]query - unblocked map[string]query - failed map[string]query + buffered map[string]definition.Query + completed map[string]definition.Query + unblocked map[string]definition.Query + failed map[string]definition.Query } ) -func NewQueryRegistry() QueryRegistry { +func NewQueryRegistry() definition.QueryRegistry { return &queryRegistryImpl{ - buffered: make(map[string]query), - completed: make(map[string]query), - unblocked: make(map[string]query), - failed: make(map[string]query), + buffered: make(map[string]definition.Query), + completed: make(map[string]definition.Query), + unblocked: make(map[string]definition.Query), + failed: make(map[string]definition.Query), } } @@ -132,7 +113,7 @@ func (r *queryRegistryImpl) GetQueryCompletionCh(id string) (<-chan struct{}, er if err != nil { return nil, err } - return q.getCompletionCh(), nil + return q.GetCompletionCh(), nil } func (r *queryRegistryImpl) GetQueryInput(id string) (*querypb.WorkflowQuery, error) { @@ -142,10 +123,10 @@ func (r *queryRegistryImpl) GetQueryInput(id string) (*querypb.WorkflowQuery, er if err != nil { return nil, err } - return q.getQueryInput(), nil + return q.GetQueryInput(), nil } -func (r *queryRegistryImpl) GetCompletionState(id string) (*QueryCompletionState, error) { +func (r *queryRegistryImpl) GetCompletionState(id string) (*definition.QueryCompletionState, error) { r.RLock() defer r.RUnlock() q, err := r.getQueryNoLock(id) @@ -159,19 +140,19 @@ func (r *queryRegistryImpl) BufferQuery(queryInput *querypb.WorkflowQuery) (stri r.Lock() defer r.Unlock() q := newQuery(queryInput) - id := q.getID() + id := q.GetID() r.buffered[id] = q - return id, q.getCompletionCh() + return id, q.GetCompletionCh() } -func (r *queryRegistryImpl) SetCompletionState(id string, completionState *QueryCompletionState) error { +func (r *queryRegistryImpl) SetCompletionState(id string, completionState *definition.QueryCompletionState) error { r.Lock() defer r.Unlock() q, ok := r.buffered[id] if !ok { return errQueryNotExists } - if err := q.setCompletionState(completionState); err != nil { + if err := q.SetCompletionState(completionState); err != nil { return err } delete(r.buffered, id) @@ -199,16 +180,16 @@ func (r *queryRegistryImpl) Clear() { r.Lock() defer r.Unlock() for id, q := range r.buffered { - _ = q.setCompletionState(&QueryCompletionState{ + _ = q.SetCompletionState(&definition.QueryCompletionState{ Type: QueryCompletionTypeFailed, Err: consts.ErrBufferedQueryCleared, }) r.failed[id] = q } - r.buffered = make(map[string]query) + r.buffered = make(map[string]definition.Query) } -func (r *queryRegistryImpl) getQueryNoLock(id string) (query, error) { +func (r *queryRegistryImpl) getQueryNoLock(id string) (definition.Query, error) { if q, ok := r.buffered[id]; ok { return q, nil } @@ -224,7 +205,7 @@ func (r *queryRegistryImpl) getQueryNoLock(id string) (query, error) { return nil, errQueryNotExists } -func (r *queryRegistryImpl) getIDs(m map[string]query) []string { +func (r *queryRegistryImpl) getIDs(m map[string]definition.Query) []string { result := make([]string, len(m)) index := 0 for id := range m { diff --git a/service/history/workflow/query_registry_test.go b/service/history/workflow/query_registry_test.go index 2c3e48156b6..f5ea570b5db 100644 --- a/service/history/workflow/query_registry_test.go +++ b/service/history/workflow/query_registry_test.go @@ -34,6 +34,7 @@ import ( querypb "go.temporal.io/api/query/v1" "go.temporal.io/server/common/payloads" + "go.temporal.io/server/service/history/definition" ) type QueryRegistrySuite struct { @@ -62,7 +63,7 @@ func (s *QueryRegistrySuite) TestQueryRegistry() { s.assertChanState(false, completionChs...) for i := 0; i < 25; i++ { - err := qr.SetCompletionState(ids[i], &QueryCompletionState{ + err := qr.SetCompletionState(ids[i], &definition.QueryCompletionState{ Type: QueryCompletionTypeSucceeded, Result: &querypb.WorkflowQueryResult{ ResultType: enumspb.QUERY_RESULT_TYPE_ANSWERED, @@ -79,7 +80,7 @@ func (s *QueryRegistrySuite) TestQueryRegistry() { s.assertChanState(false, completionChs[25:]...) for i := 25; i < 50; i++ { - err := qr.SetCompletionState(ids[i], &QueryCompletionState{ + err := qr.SetCompletionState(ids[i], &definition.QueryCompletionState{ Type: QueryCompletionTypeUnblocked, }) s.NoError(err) @@ -93,7 +94,7 @@ func (s *QueryRegistrySuite) TestQueryRegistry() { s.assertChanState(false, completionChs[50:]...) for i := 50; i < 75; i++ { - err := qr.SetCompletionState(ids[i], &QueryCompletionState{ + err := qr.SetCompletionState(ids[i], &definition.QueryCompletionState{ Type: QueryCompletionTypeFailed, Err: errors.New("err"), }) @@ -111,16 +112,16 @@ func (s *QueryRegistrySuite) TestQueryRegistry() { for i := 0; i < 75; i++ { switch i % 3 { case 0: - s.Equal(errQueryNotExists, qr.SetCompletionState(ids[i], &QueryCompletionState{ + s.Equal(errQueryNotExists, qr.SetCompletionState(ids[i], &definition.QueryCompletionState{ Type: QueryCompletionTypeSucceeded, Result: &querypb.WorkflowQueryResult{}, })) case 1: - s.Equal(errQueryNotExists, qr.SetCompletionState(ids[i], &QueryCompletionState{ + s.Equal(errQueryNotExists, qr.SetCompletionState(ids[i], &definition.QueryCompletionState{ Type: QueryCompletionTypeUnblocked, })) case 2: - s.Equal(errQueryNotExists, qr.SetCompletionState(ids[i], &QueryCompletionState{ + s.Equal(errQueryNotExists, qr.SetCompletionState(ids[i], &definition.QueryCompletionState{ Type: QueryCompletionTypeFailed, Err: errors.New("err"), })) @@ -159,7 +160,7 @@ func (s *QueryRegistrySuite) TestQueryRegistry() { s.assertChanState(false, completionChs[75:]...) } -func (s *QueryRegistrySuite) assertBufferedState(qr QueryRegistry, ids ...string) { +func (s *QueryRegistrySuite) assertBufferedState(qr definition.QueryRegistry, ids ...string) { for _, id := range ids { completionCh, err := qr.GetQueryCompletionCh(id) s.NoError(err) @@ -173,7 +174,7 @@ func (s *QueryRegistrySuite) assertBufferedState(qr QueryRegistry, ids ...string } } -func (s *QueryRegistrySuite) assertCompletedState(qr QueryRegistry, ids ...string) { +func (s *QueryRegistrySuite) assertCompletedState(qr definition.QueryRegistry, ids ...string) { for _, id := range ids { completionCh, err := qr.GetQueryCompletionCh(id) s.NoError(err) @@ -190,7 +191,7 @@ func (s *QueryRegistrySuite) assertCompletedState(qr QueryRegistry, ids ...strin } } -func (s *QueryRegistrySuite) assertUnblockedState(qr QueryRegistry, ids ...string) { +func (s *QueryRegistrySuite) assertUnblockedState(qr definition.QueryRegistry, ids ...string) { for _, id := range ids { completionCh, err := qr.GetQueryCompletionCh(id) s.NoError(err) @@ -207,7 +208,7 @@ func (s *QueryRegistrySuite) assertUnblockedState(qr QueryRegistry, ids ...strin } } -func (s *QueryRegistrySuite) assertFailedState(qr QueryRegistry, ids ...string) { +func (s *QueryRegistrySuite) assertFailedState(qr definition.QueryRegistry, ids ...string) { for _, id := range ids { completionCh, err := qr.GetQueryCompletionCh(id) s.NoError(err) @@ -224,14 +225,14 @@ func (s *QueryRegistrySuite) assertFailedState(qr QueryRegistry, ids ...string) } } -func (s *QueryRegistrySuite) assertHasQueries(qr QueryRegistry, buffered, completed, unblocked, failed bool) { +func (s *QueryRegistrySuite) assertHasQueries(qr definition.QueryRegistry, buffered, completed, unblocked, failed bool) { s.Equal(buffered, qr.HasBufferedQuery()) s.Equal(completed, qr.HasCompletedQuery()) s.Equal(unblocked, qr.HasUnblockedQuery()) s.Equal(failed, qr.HasFailedQuery()) } -func (s *QueryRegistrySuite) assertQuerySizes(qr QueryRegistry, buffered, completed, unblocked, failed int) { +func (s *QueryRegistrySuite) assertQuerySizes(qr definition.QueryRegistry, buffered, completed, unblocked, failed int) { s.Len(qr.GetBufferedIDs(), buffered) s.Len(qr.GetCompletedIDs(), completed) s.Len(qr.GetUnblockedIDs(), unblocked) diff --git a/service/history/workflow/query_test.go b/service/history/workflow/query_test.go index 65e8edb55b9..78f15569487 100644 --- a/service/history/workflow/query_test.go +++ b/service/history/workflow/query_test.go @@ -34,6 +34,7 @@ import ( querypb "go.temporal.io/api/query/v1" "go.temporal.io/server/common/payloads" + "go.temporal.io/server/service/history/definition" ) type QuerySuite struct { @@ -51,7 +52,7 @@ func (s *QuerySuite) SetupTest() { func (s *QuerySuite) TestValidateCompletionState() { testCases := []struct { - ts *QueryCompletionState + ts *definition.QueryCompletionState expectErr bool }{ { @@ -59,13 +60,13 @@ func (s *QuerySuite) TestValidateCompletionState() { expectErr: true, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeSucceeded, }, expectErr: true, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeSucceeded, Result: &querypb.WorkflowQueryResult{}, Err: errors.New("err"), @@ -73,7 +74,7 @@ func (s *QuerySuite) TestValidateCompletionState() { expectErr: true, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeSucceeded, Result: &querypb.WorkflowQueryResult{ ResultType: enumspb.QUERY_RESULT_TYPE_ANSWERED, @@ -82,7 +83,7 @@ func (s *QuerySuite) TestValidateCompletionState() { expectErr: true, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeSucceeded, Result: &querypb.WorkflowQueryResult{ ResultType: enumspb.QUERY_RESULT_TYPE_ANSWERED, @@ -93,7 +94,7 @@ func (s *QuerySuite) TestValidateCompletionState() { expectErr: true, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeSucceeded, Result: &querypb.WorkflowQueryResult{ ResultType: enumspb.QUERY_RESULT_TYPE_FAILED, @@ -103,7 +104,7 @@ func (s *QuerySuite) TestValidateCompletionState() { expectErr: true, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeSucceeded, Result: &querypb.WorkflowQueryResult{ ResultType: enumspb.QUERY_RESULT_TYPE_FAILED, @@ -113,7 +114,7 @@ func (s *QuerySuite) TestValidateCompletionState() { expectErr: false, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeSucceeded, Result: &querypb.WorkflowQueryResult{ ResultType: enumspb.QUERY_RESULT_TYPE_ANSWERED, @@ -123,40 +124,40 @@ func (s *QuerySuite) TestValidateCompletionState() { expectErr: false, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeUnblocked, Result: &querypb.WorkflowQueryResult{}, }, expectErr: true, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeUnblocked, Err: errors.New("err"), }, expectErr: true, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeUnblocked, }, expectErr: false, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeFailed, }, expectErr: true, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeFailed, Result: &querypb.WorkflowQueryResult{}, }, expectErr: true, }, { - ts: &QueryCompletionState{ + ts: &definition.QueryCompletionState{ Type: QueryCompletionTypeFailed, Err: errors.New("err"), }, @@ -175,7 +176,7 @@ func (s *QuerySuite) TestValidateCompletionState() { } func (s *QuerySuite) TestCompletionState_Failed() { - completionStateFailed := &QueryCompletionState{ + completionStateFailed := &definition.QueryCompletionState{ Type: QueryCompletionTypeFailed, Err: errors.New("err"), } @@ -183,7 +184,7 @@ func (s *QuerySuite) TestCompletionState_Failed() { } func (s *QuerySuite) TestCompletionState_Completed() { - answeredCompletionState := &QueryCompletionState{ + answeredCompletionState := &definition.QueryCompletionState{ Type: QueryCompletionTypeSucceeded, Result: &querypb.WorkflowQueryResult{ ResultType: enumspb.QUERY_RESULT_TYPE_ANSWERED, @@ -194,27 +195,27 @@ func (s *QuerySuite) TestCompletionState_Completed() { } func (s *QuerySuite) TestCompletionState_Unblocked() { - unblockedCompletionState := &QueryCompletionState{ + unblockedCompletionState := &definition.QueryCompletionState{ Type: QueryCompletionTypeUnblocked, } s.testSetCompletionState(unblockedCompletionState) } -func (s *QuerySuite) testSetCompletionState(completionState *QueryCompletionState) { +func (s *QuerySuite) testSetCompletionState(completionState *definition.QueryCompletionState) { query := newQuery(nil) ts, err := query.GetCompletionState() s.Equal(errQueryNotInCompletionState, err) s.Nil(ts) - s.False(closed(query.getCompletionCh())) - s.Equal(errCompletionStateInvalid, query.setCompletionState(nil)) - s.NoError(query.setCompletionState(completionState)) - s.True(closed(query.getCompletionCh())) + s.False(closed(query.GetCompletionCh())) + s.Equal(errCompletionStateInvalid, query.SetCompletionState(nil)) + s.NoError(query.SetCompletionState(completionState)) + s.True(closed(query.GetCompletionCh())) actualCompletionState, err := query.GetCompletionState() s.NoError(err) s.assertCompletionStateEqual(completionState, actualCompletionState) } -func (s *QuerySuite) assertCompletionStateEqual(expected *QueryCompletionState, actual *QueryCompletionState) { +func (s *QuerySuite) assertCompletionStateEqual(expected *definition.QueryCompletionState, actual *definition.QueryCompletionState) { s.Equal(expected.Type, actual.Type) if expected.Err != nil { s.Equal(expected.Err.Error(), actual.Err.Error()) diff --git a/service/history/workflow/retry.go b/service/history/workflow/retry.go index 843af8b6cc7..3d3dc0b9d4d 100644 --- a/service/history/workflow/retry.go +++ b/service/history/workflow/retry.go @@ -44,6 +44,7 @@ import ( "go.temporal.io/server/common" "go.temporal.io/server/common/backoff" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/service/history/definition" ) // TODO treat 0 as 0, not infinite @@ -153,8 +154,8 @@ func isRetryable(failure *failurepb.Failure, nonRetryableTypes []string) bool { func SetupNewWorkflowForRetryOrCron( ctx context.Context, - previousMutableState MutableState, - newMutableState MutableState, + previousMutableState definition.MutableState, + newMutableState definition.MutableState, newRunID string, startAttr *historypb.WorkflowExecutionStartedEventAttributes, lastCompletionResult *commonpb.Payloads, diff --git a/service/history/workflow/task_generator.go b/service/history/workflow/task_generator.go index 1eb8229dcff..3650409ebbc 100644 --- a/service/history/workflow/task_generator.go +++ b/service/history/workflow/task_generator.go @@ -40,6 +40,7 @@ import ( "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" ) @@ -100,7 +101,7 @@ type ( TaskGeneratorImpl struct { namespaceRegistry namespace.Registry - mutableState MutableState + mutableState definition.MutableState config *configs.Config } ) @@ -111,7 +112,7 @@ var _ TaskGenerator = (*TaskGeneratorImpl)(nil) func NewTaskGenerator( namespaceRegistry namespace.Registry, - mutableState MutableState, + mutableState definition.MutableState, config *configs.Config, ) *TaskGeneratorImpl { return &TaskGeneratorImpl{ diff --git a/service/history/workflow/task_generator_provider.go b/service/history/workflow/task_generator_provider.go index 2d3beb7a97f..cca51d9c65f 100644 --- a/service/history/workflow/task_generator_provider.go +++ b/service/history/workflow/task_generator_provider.go @@ -25,7 +25,7 @@ package workflow import ( - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" ) var ( @@ -38,7 +38,7 @@ var ( type ( TaskGeneratorProvider interface { - NewTaskGenerator(shard.Context, MutableState) TaskGenerator + NewTaskGenerator(definition.ShardContext, definition.MutableState) TaskGenerator } taskGeneratorProviderImpl struct{} @@ -49,8 +49,8 @@ func NewTaskGeneratorProvider() TaskGeneratorProvider { } func (p *taskGeneratorProviderImpl) NewTaskGenerator( - shard shard.Context, - mutableState MutableState, + shard definition.ShardContext, + mutableState definition.MutableState, ) TaskGenerator { return NewTaskGenerator( shard.GetNamespaceRegistry(), diff --git a/service/history/workflow/task_generator_test.go b/service/history/workflow/task_generator_test.go index 7801871d491..8af653eebba 100644 --- a/service/history/workflow/task_generator_test.go +++ b/service/history/workflow/task_generator_test.go @@ -58,10 +58,10 @@ import ( historypb "go.temporal.io/api/history/v1" "go.temporal.io/server/api/persistence/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/configs" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" ) @@ -122,7 +122,7 @@ func TestTaskGeneratorImpl_GenerateWorkflowCloseTasks(t *testing.T) { namespaceRegistry.EXPECT().GetNamespaceID(gomock.Any()).Return(namespaceEntry.ID(), nil).AnyTimes() namespaceRegistry.EXPECT().GetNamespaceByID(namespaceEntry.ID()).Return(namespaceEntry, nil).AnyTimes() - mutableState := NewMockMutableState(ctrl) + mutableState := definition.NewMockMutableState(ctrl) mutableState.EXPECT().GetCurrentVersion().Return(int64(0)).AnyTimes() mutableState.EXPECT().GetExecutionInfo().Return(&persistence.WorkflowExecutionInfo{ NamespaceId: namespaceEntry.ID().String(), diff --git a/service/history/workflow/task_refresher.go b/service/history/workflow/task_refresher.go index 1273e4f18cf..aae01c50c34 100644 --- a/service/history/workflow/task_refresher.go +++ b/service/history/workflow/task_refresher.go @@ -38,29 +38,28 @@ import ( "go.temporal.io/server/common/persistence/visibility" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/events" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" ) type ( TaskRefresher interface { - RefreshTasks(ctx context.Context, mutableState MutableState) error + RefreshTasks(ctx context.Context, mutableState definition.MutableState) error } TaskRefresherImpl struct { - shard shard.Context + shard definition.ShardContext config *configs.Config namespaceRegistry namespace.Registry - eventsCache events.Cache + eventsCache definition.EventCache logger log.Logger } ) func NewTaskRefresher( - shard shard.Context, + shard definition.ShardContext, config *configs.Config, namespaceRegistry namespace.Registry, - eventsCache events.Cache, + eventsCache definition.EventCache, logger log.Logger, ) *TaskRefresherImpl { @@ -75,7 +74,7 @@ func NewTaskRefresher( func (r *TaskRefresherImpl) RefreshTasks( ctx context.Context, - mutableState MutableState, + mutableState definition.MutableState, ) error { taskGenerator := taskGeneratorProvider.NewTaskGenerator( @@ -165,7 +164,7 @@ func (r *TaskRefresherImpl) RefreshTasks( func (r *TaskRefresherImpl) refreshTasksForWorkflowStart( ctx context.Context, - mutableState MutableState, + mutableState definition.MutableState, taskGenerator TaskGenerator, ) error { @@ -194,7 +193,7 @@ func (r *TaskRefresherImpl) refreshTasksForWorkflowStart( func (r *TaskRefresherImpl) refreshTasksForWorkflowClose( ctx context.Context, - mutableState MutableState, + mutableState definition.MutableState, taskGenerator TaskGenerator, ) error { @@ -217,7 +216,7 @@ func (r *TaskRefresherImpl) refreshTasksForWorkflowClose( func (r *TaskRefresherImpl) refreshTasksForRecordWorkflowStarted( ctx context.Context, - mutableState MutableState, + mutableState definition.MutableState, taskGenerator TaskGenerator, ) error { @@ -238,7 +237,7 @@ func (r *TaskRefresherImpl) refreshTasksForRecordWorkflowStarted( } func (r *TaskRefresherImpl) refreshWorkflowTaskTasks( - mutableState MutableState, + mutableState definition.MutableState, taskGenerator TaskGenerator, ) error { @@ -267,7 +266,7 @@ func (r *TaskRefresherImpl) refreshWorkflowTaskTasks( func (r *TaskRefresherImpl) refreshTasksForActivity( ctx context.Context, - mutableState MutableState, + mutableState definition.MutableState, taskGenerator TaskGenerator, ) error { @@ -298,7 +297,7 @@ Loop: scheduleEvent, err := r.eventsCache.GetEvent( ctx, - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(executionInfo.NamespaceId), WorkflowID: executionInfo.WorkflowId, RunID: executionState.RunId, @@ -329,7 +328,7 @@ Loop: } func (r *TaskRefresherImpl) refreshTasksForTimer( - mutableState MutableState, + mutableState definition.MutableState, ) error { pendingTimerInfos := mutableState.GetPendingTimerInfos() @@ -357,7 +356,7 @@ func (r *TaskRefresherImpl) refreshTasksForTimer( func (r *TaskRefresherImpl) refreshTasksForChildWorkflow( ctx context.Context, - mutableState MutableState, + mutableState definition.MutableState, taskGenerator TaskGenerator, ) error { @@ -378,7 +377,7 @@ Loop: scheduleEvent, err := r.eventsCache.GetEvent( ctx, - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(executionInfo.NamespaceId), WorkflowID: executionInfo.WorkflowId, RunID: executionState.RunId, @@ -404,7 +403,7 @@ Loop: func (r *TaskRefresherImpl) refreshTasksForRequestCancelExternalWorkflow( ctx context.Context, - mutableState MutableState, + mutableState definition.MutableState, taskGenerator TaskGenerator, ) error { @@ -420,7 +419,7 @@ func (r *TaskRefresherImpl) refreshTasksForRequestCancelExternalWorkflow( for _, requestCancelInfo := range pendingRequestCancelInfos { initiateEvent, err := r.eventsCache.GetEvent( ctx, - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(executionInfo.NamespaceId), WorkflowID: executionInfo.WorkflowId, RunID: executionState.RunId, @@ -446,7 +445,7 @@ func (r *TaskRefresherImpl) refreshTasksForRequestCancelExternalWorkflow( func (r *TaskRefresherImpl) refreshTasksForSignalExternalWorkflow( ctx context.Context, - mutableState MutableState, + mutableState definition.MutableState, taskGenerator TaskGenerator, ) error { @@ -462,7 +461,7 @@ func (r *TaskRefresherImpl) refreshTasksForSignalExternalWorkflow( for _, signalInfo := range pendingSignalInfos { initiateEvent, err := r.eventsCache.GetEvent( ctx, - events.EventKey{ + definition.EventKey{ NamespaceID: namespace.ID(executionInfo.NamespaceId), WorkflowID: executionInfo.WorkflowId, RunID: executionState.RunId, diff --git a/service/history/workflow/task_refresher_mock.go b/service/history/workflow/task_refresher_mock.go index 7a8a02828ef..ea51ea19b3f 100644 --- a/service/history/workflow/task_refresher_mock.go +++ b/service/history/workflow/task_refresher_mock.go @@ -33,6 +33,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" + definition "go.temporal.io/server/service/history/definition" ) // MockTaskRefresher is a mock of TaskRefresher interface. @@ -59,7 +60,7 @@ func (m *MockTaskRefresher) EXPECT() *MockTaskRefresherMockRecorder { } // RefreshTasks mocks base method. -func (m *MockTaskRefresher) RefreshTasks(ctx context.Context, mutableState MutableState) error { +func (m *MockTaskRefresher) RefreshTasks(ctx context.Context, mutableState definition.MutableState) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RefreshTasks", ctx, mutableState) ret0, _ := ret[0].(error) diff --git a/service/history/workflow/test_util.go b/service/history/workflow/test_util.go index c75e1480be7..b88241c10e3 100644 --- a/service/history/workflow/test_util.go +++ b/service/history/workflow/test_util.go @@ -31,14 +31,13 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common/log" "go.temporal.io/server/common/namespace" - "go.temporal.io/server/service/history/events" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tests" ) func TestLocalMutableState( - shard shard.Context, - eventsCache events.Cache, + shard definition.ShardContext, + eventsCache definition.EventCache, ns *namespace.Namespace, logger log.Logger, runID string, @@ -52,8 +51,8 @@ func TestLocalMutableState( } func TestGlobalMutableState( - shard shard.Context, - eventsCache events.Cache, + shard definition.ShardContext, + eventsCache definition.EventCache, logger log.Logger, version int64, runID string, @@ -68,12 +67,12 @@ func TestGlobalMutableState( } func TestCloneToProto( - mutableState MutableState, + mutableState definition.MutableState, ) *persistencespb.WorkflowMutableState { if mutableState.HasBufferedEvents() { - _, _, _ = mutableState.CloseTransactionAsMutation(time.Now().UTC(), TransactionPolicyActive) + _, _, _ = mutableState.CloseTransactionAsMutation(time.Now().UTC(), definition.TransactionPolicyActive) } else { - _, _, _ = mutableState.CloseTransactionAsSnapshot(time.Now().UTC(), TransactionPolicyActive) + _, _, _ = mutableState.CloseTransactionAsSnapshot(time.Now().UTC(), definition.TransactionPolicyActive) } return mutableState.CloneToProto() } diff --git a/service/history/workflow/timer_sequence.go b/service/history/workflow/timer_sequence.go index e6d6d6470fd..75d0fccee03 100644 --- a/service/history/workflow/timer_sequence.go +++ b/service/history/workflow/timer_sequence.go @@ -37,6 +37,7 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" ) @@ -77,14 +78,14 @@ type ( } timerSequenceImpl struct { - mutableState MutableState + mutableState definition.MutableState } ) var _ TimerSequence = (*timerSequenceImpl)(nil) func NewTimerSequence( - mutableState MutableState, + mutableState definition.MutableState, ) *timerSequenceImpl { return &timerSequenceImpl{ mutableState: mutableState, diff --git a/service/history/workflow/timer_sequence_test.go b/service/history/workflow/timer_sequence_test.go index fff0966ee65..f0e93cd5f15 100644 --- a/service/history/workflow/timer_sequence_test.go +++ b/service/history/workflow/timer_sequence_test.go @@ -35,8 +35,8 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/tasks" "go.temporal.io/server/service/history/tests" ) @@ -47,7 +47,7 @@ type ( *require.Assertions controller *gomock.Controller - mockMutableState *MockMutableState + mockMutableState *definition.MockMutableState workflowKey definition.WorkflowKey timerSequence *timerSequenceImpl @@ -71,7 +71,7 @@ func (s *timerSequenceSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockMutableState = NewMockMutableState(s.controller) + s.mockMutableState = definition.NewMockMutableState(s.controller) s.workflowKey = definition.NewWorkflowKey( tests.NamespaceID.String(), diff --git a/service/history/workflow/transaction.go b/service/history/workflow/transaction.go index e160bf6a999..4022c57d104 100644 --- a/service/history/workflow/transaction.go +++ b/service/history/workflow/transaction.go @@ -22,6 +22,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination transaction_mock.go + package workflow import ( @@ -30,7 +32,6 @@ import ( "go.temporal.io/server/common/persistence" ) -//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination transaction_mock.go type ( Transaction interface { CreateWorkflowExecution( diff --git a/service/history/workflow/transaction_impl.go b/service/history/workflow/transaction_impl.go index deff9035466..80cc40f3a35 100644 --- a/service/history/workflow/transaction_impl.go +++ b/service/history/workflow/transaction_impl.go @@ -38,7 +38,7 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/versionhistory" - "go.temporal.io/server/service/history/events" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" ) @@ -49,7 +49,7 @@ type ( status enumspb.WorkflowExecutionStatus } TransactionImpl struct { - shard shard.Context + shard definition.ShardContext logger log.Logger } ) @@ -57,7 +57,7 @@ type ( var _ Transaction = (*TransactionImpl)(nil) func NewTransaction( - shard shard.Context, + shard definition.ShardContext, ) *TransactionImpl { return &TransactionImpl{ shard: shard, @@ -229,7 +229,7 @@ func (t *TransactionImpl) SetWorkflowExecution( func PersistWorkflowEvents( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, workflowEvents *persistence.WorkflowEvents, ) (int64, error) { @@ -246,7 +246,7 @@ func PersistWorkflowEvents( func persistFirstWorkflowEvents( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, workflowEvents *persistence.WorkflowEvents, ) (int64, error) { @@ -281,7 +281,7 @@ func persistFirstWorkflowEvents( func persistNonFirstWorkflowEvents( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, workflowEvents *persistence.WorkflowEvents, ) (int64, error) { @@ -317,7 +317,7 @@ func persistNonFirstWorkflowEvents( func appendHistoryEvents( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, namespaceID namespace.ID, execution commonpb.WorkflowExecution, request *persistence.AppendHistoryNodesRequest, @@ -329,7 +329,7 @@ func appendHistoryEvents( func createWorkflowExecution( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, request *persistence.CreateWorkflowExecutionRequest, ) (*persistence.CreateWorkflowExecutionResponse, error) { @@ -369,7 +369,7 @@ func createWorkflowExecution( func conflictResolveWorkflowExecution( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, request *persistence.ConflictResolveWorkflowExecutionRequest, ) (*persistence.ConflictResolveWorkflowExecutionResponse, error) { @@ -409,7 +409,7 @@ func conflictResolveWorkflowExecution( func getWorkflowExecution( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, request *persistence.GetWorkflowExecutionRequest, ) (*persistence.GetWorkflowExecutionResponse, error) { @@ -446,7 +446,7 @@ func getWorkflowExecution( func updateWorkflowExecution( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, request *persistence.UpdateWorkflowExecutionRequest, ) (*persistence.UpdateWorkflowExecutionResponse, error) { @@ -485,7 +485,7 @@ func updateWorkflowExecution( func setWorkflowExecution( ctx context.Context, - shard shard.Context, + shard definition.ShardContext, request *persistence.SetWorkflowExecutionRequest, ) (*persistence.SetWorkflowExecutionResponse, error) { @@ -505,7 +505,7 @@ func setWorkflowExecution( } func NotifyWorkflowSnapshotTasks( - engine shard.Engine, + engine definition.Engine, workflowSnapshot *persistence.WorkflowSnapshot, clusterName string, ) { @@ -516,7 +516,7 @@ func NotifyWorkflowSnapshotTasks( } func NotifyWorkflowMutationTasks( - engine shard.Engine, + engine definition.Engine, workflowMutation *persistence.WorkflowMutation, clusterName string, ) { @@ -527,7 +527,7 @@ func NotifyWorkflowMutationTasks( } func NotifyNewHistorySnapshotEvent( - engine shard.Engine, + engine definition.Engine, workflowSnapshot *persistence.WorkflowSnapshot, ) error { @@ -553,7 +553,7 @@ func NotifyNewHistorySnapshotEvent( lastWorkflowTaskStartEventID := executionInfo.LastWorkflowTaskStartedEventId nextEventID := workflowSnapshot.NextEventID - engine.NotifyNewHistoryEvent(events.NewNotification( + engine.NotifyNewHistoryEvent(definition.NewNotification( namespaceID, &commonpb.WorkflowExecution{ WorkflowId: workflowID, @@ -571,7 +571,7 @@ func NotifyNewHistorySnapshotEvent( } func NotifyNewHistoryMutationEvent( - engine shard.Engine, + engine definition.Engine, workflowMutation *persistence.WorkflowMutation, ) error { @@ -597,7 +597,7 @@ func NotifyNewHistoryMutationEvent( lastWorkflowTaskStartEventID := executionInfo.LastWorkflowTaskStartedEventId nextEventID := workflowMutation.NextEventID - engine.NotifyNewHistoryEvent(events.NewNotification( + engine.NotifyNewHistoryEvent(definition.NewNotification( namespaceID, &commonpb.WorkflowExecution{ WorkflowId: workflowID, @@ -615,7 +615,7 @@ func NotifyNewHistoryMutationEvent( } func emitMutationMetrics( - shard shard.Context, + shard definition.ShardContext, namespace *namespace.Namespace, stats ...*persistence.MutableStateStatistics, ) { @@ -630,7 +630,7 @@ func emitMutationMetrics( } func emitGetMetrics( - shard shard.Context, + shard definition.ShardContext, namespace *namespace.Namespace, stats ...*persistence.MutableStateStatistics, ) { @@ -671,7 +671,7 @@ func mutationToCompletionMetric( } func emitCompletionMetrics( - shard shard.Context, + shard definition.ShardContext, namespace *namespace.Namespace, completionMetrics ...completionMetric, ) { diff --git a/service/history/workflow/transaction_test.go b/service/history/workflow/transaction_test.go index e0a346097cf..75954c7da5f 100644 --- a/service/history/workflow/transaction_test.go +++ b/service/history/workflow/transaction_test.go @@ -38,6 +38,7 @@ import ( "go.temporal.io/server/common/log" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" ) @@ -48,8 +49,8 @@ type ( *require.Assertions controller *gomock.Controller - mockShard *shard.MockContext - mockEngine *shard.MockEngine + mockShard *definition.MockShardContext + mockEngine *definition.MockEngine mockNamespaceCache *namespace.MockRegistry logger log.Logger @@ -67,8 +68,8 @@ func (s *transactionSuite) SetupTest() { s.Assertions = require.New(s.T()) s.controller = gomock.NewController(s.T()) - s.mockShard = shard.NewMockContext(s.controller) - s.mockEngine = shard.NewMockEngine(s.controller) + s.mockShard = definition.NewMockShardContext(s.controller) + s.mockEngine = definition.NewMockEngine(s.controller) s.mockNamespaceCache = namespace.NewMockRegistry(s.controller) s.logger = log.NewTestLogger() diff --git a/service/history/workflow/util.go b/service/history/workflow/util.go index d4c7c99ae2f..c3a5ae09ef1 100644 --- a/service/history/workflow/util.go +++ b/service/history/workflow/util.go @@ -38,11 +38,12 @@ import ( "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/service/history/consts" + "go.temporal.io/server/service/history/definition" ) func failWorkflowTask( - mutableState MutableState, - workflowTask *WorkflowTaskInfo, + mutableState definition.MutableState, + workflowTask *definition.WorkflowTaskInfo, workflowTaskFailureCause enumspb.WorkflowTaskFailedCause, ) error { @@ -65,7 +66,7 @@ func failWorkflowTask( } func ScheduleWorkflowTask( - mutableState MutableState, + mutableState definition.MutableState, ) error { if mutableState.HasPendingWorkflowTask() { @@ -81,11 +82,11 @@ func ScheduleWorkflowTask( func RetryWorkflow( ctx context.Context, - mutableState MutableState, + mutableState definition.MutableState, eventBatchFirstEventID int64, parentNamespace namespace.Name, continueAsNewAttributes *commandpb.ContinueAsNewWorkflowExecutionCommandAttributes, -) (MutableState, error) { +) (definition.MutableState, error) { if workflowTask, ok := mutableState.GetInFlightWorkflowTask(); ok { if err := failWorkflowTask( @@ -111,7 +112,7 @@ func RetryWorkflow( } func TimeoutWorkflow( - mutableState MutableState, + mutableState definition.MutableState, eventBatchFirstEventID int64, retryState enumspb.RetryState, continuedRunID string, @@ -136,7 +137,7 @@ func TimeoutWorkflow( } func TerminateWorkflow( - mutableState MutableState, + mutableState definition.MutableState, eventBatchFirstEventID int64, terminateReason string, terminateDetails *commonpb.Payloads, diff --git a/service/history/workflow/workflow_task_state_machine.go b/service/history/workflow/workflow_task_state_machine.go index dad92613f5a..a2ce8944b0f 100644 --- a/service/history/workflow/workflow_task_state_machine.go +++ b/service/history/workflow/workflow_task_state_machine.go @@ -45,6 +45,7 @@ import ( "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/primitives/timestamp" + "go.temporal.io/server/service/history/definition" ) type ( @@ -74,7 +75,7 @@ func (m *workflowTaskStateMachine) ReplicateWorkflowTaskScheduledEvent( attempt int32, scheduledTime *time.Time, originalScheduledTimestamp *time.Time, -) (*WorkflowTaskInfo, error) { +) (*definition.WorkflowTaskInfo, error) { // set workflow state to running, since workflow task is scheduled // NOTE: for zombie workflow, should not change the state @@ -88,7 +89,7 @@ func (m *workflowTaskStateMachine) ReplicateWorkflowTaskScheduledEvent( } } - workflowTask := &WorkflowTaskInfo{ + workflowTask := &definition.WorkflowTaskInfo{ Version: version, ScheduledEventID: scheduledEventID, StartedEventID: common.EmptyEventID, @@ -105,7 +106,7 @@ func (m *workflowTaskStateMachine) ReplicateWorkflowTaskScheduledEvent( return workflowTask, nil } -func (m *workflowTaskStateMachine) ReplicateTransientWorkflowTaskScheduled() (*WorkflowTaskInfo, error) { +func (m *workflowTaskStateMachine) ReplicateTransientWorkflowTaskScheduled() (*definition.WorkflowTaskInfo, error) { if m.HasPendingWorkflowTask() || m.ms.GetExecutionInfo().WorkflowTaskAttempt == 1 { return nil, nil } @@ -124,7 +125,7 @@ func (m *workflowTaskStateMachine) ReplicateTransientWorkflowTaskScheduled() (*W // regarding workflow task timeout calculation: // 1. the attempt will be set to 1, so we still use default worflow task timeout // 2. ReplicateWorkflowTaskScheduledEvent will overwrite everything including workflowTaskTimeout - workflowTask := &WorkflowTaskInfo{ + workflowTask := &definition.WorkflowTaskInfo{ Version: m.ms.GetCurrentVersion(), ScheduledEventID: m.ms.GetNextEventID(), StartedEventID: common.EmptyEventID, @@ -141,13 +142,13 @@ func (m *workflowTaskStateMachine) ReplicateTransientWorkflowTaskScheduled() (*W } func (m *workflowTaskStateMachine) ReplicateWorkflowTaskStartedEvent( - workflowTask *WorkflowTaskInfo, + workflowTask *definition.WorkflowTaskInfo, version int64, scheduledEventID int64, startedEventID int64, requestID string, timestamp time.Time, -) (*WorkflowTaskInfo, error) { +) (*definition.WorkflowTaskInfo, error) { // Replicator calls it with a nil workflow task info, and it is safe to always lookup the workflow task in this case as it // does not have to deal with transient workflow task case. var ok bool @@ -168,7 +169,7 @@ func (m *workflowTaskStateMachine) ReplicateWorkflowTaskStartedEvent( } // Update mutable workflow task state - workflowTask = &WorkflowTaskInfo{ + workflowTask = &definition.WorkflowTaskInfo{ Version: version, ScheduledEventID: scheduledEventID, StartedEventID: startedEventID, @@ -240,7 +241,7 @@ func (m *workflowTaskStateMachine) AddWorkflowTaskScheduleToStartTimeoutEvent( func (m *workflowTaskStateMachine) AddWorkflowTaskScheduledEventAsHeartbeat( bypassTaskGeneration bool, originalScheduledTimestamp *time.Time, -) (*WorkflowTaskInfo, error) { +) (*definition.WorkflowTaskInfo, error) { opTag := tag.WorkflowActionWorkflowTaskScheduled if m.HasPendingWorkflowTask() { m.ms.logger.Warn(mutableStateInvalidHistoryActionMsg, opTag, @@ -324,7 +325,7 @@ func (m *workflowTaskStateMachine) AddWorkflowTaskScheduledEventAsHeartbeat( func (m *workflowTaskStateMachine) AddWorkflowTaskScheduledEvent( bypassTaskGeneration bool, -) (*WorkflowTaskInfo, error) { +) (*definition.WorkflowTaskInfo, error) { return m.AddWorkflowTaskScheduledEventAsHeartbeat(bypassTaskGeneration, timestamp.TimePtr(m.ms.timeSource.Now())) } @@ -370,7 +371,7 @@ func (m *workflowTaskStateMachine) AddWorkflowTaskStartedEvent( requestID string, taskQueue *taskqueuepb.TaskQueue, identity string, -) (*historypb.HistoryEvent, *WorkflowTaskInfo, error) { +) (*historypb.HistoryEvent, *definition.WorkflowTaskInfo, error) { opTag := tag.WorkflowActionWorkflowTaskStarted workflowTask, ok := m.GetWorkflowTaskInfo(scheduledEventID) if !ok || workflowTask.StartedEventID != common.EmptyEventID { @@ -580,7 +581,7 @@ func (m *workflowTaskStateMachine) FailWorkflowTask( incrementAttempt = incrementAttempt && !m.ms.IsStickyTaskQueueEnabled() m.ms.ClearStickyness() - failWorkflowTaskInfo := &WorkflowTaskInfo{ + failWorkflowTaskInfo := &definition.WorkflowTaskInfo{ Version: common.EmptyVersion, ScheduledEventID: common.EmptyEventID, StartedEventID: common.EmptyEventID, @@ -600,7 +601,7 @@ func (m *workflowTaskStateMachine) FailWorkflowTask( // DeleteWorkflowTask deletes a workflow task. func (m *workflowTaskStateMachine) DeleteWorkflowTask() { - resetWorkflowTaskInfo := &WorkflowTaskInfo{ + resetWorkflowTaskInfo := &definition.WorkflowTaskInfo{ Version: common.EmptyVersion, ScheduledEventID: common.EmptyEventID, StartedEventID: common.EmptyEventID, @@ -619,7 +620,7 @@ func (m *workflowTaskStateMachine) DeleteWorkflowTask() { // UpdateWorkflowTask updates a workflow task. func (m *workflowTaskStateMachine) UpdateWorkflowTask( - workflowTask *WorkflowTaskInfo, + workflowTask *definition.WorkflowTaskInfo, ) { m.ms.executionInfo.WorkflowTaskVersion = workflowTask.Version m.ms.executionInfo.WorkflowTaskScheduledEventId = workflowTask.ScheduledEventID @@ -646,7 +647,7 @@ func (m *workflowTaskStateMachine) HasPendingWorkflowTask() bool { return m.ms.executionInfo.WorkflowTaskScheduledEventId != common.EmptyEventID } -func (m *workflowTaskStateMachine) GetPendingWorkflowTask() (*WorkflowTaskInfo, bool) { +func (m *workflowTaskStateMachine) GetPendingWorkflowTask() (*definition.WorkflowTaskInfo, bool) { if m.ms.executionInfo.WorkflowTaskScheduledEventId == common.EmptyEventID { return nil, false } @@ -659,7 +660,7 @@ func (m *workflowTaskStateMachine) HasInFlightWorkflowTask() bool { return m.ms.executionInfo.WorkflowTaskStartedEventId > 0 } -func (m *workflowTaskStateMachine) GetInFlightWorkflowTask() (*WorkflowTaskInfo, bool) { +func (m *workflowTaskStateMachine) GetInFlightWorkflowTask() (*definition.WorkflowTaskInfo, bool) { if m.ms.executionInfo.WorkflowTaskScheduledEventId == common.EmptyEventID || m.ms.executionInfo.WorkflowTaskStartedEventId == common.EmptyEventID { return nil, false @@ -676,7 +677,7 @@ func (m *workflowTaskStateMachine) HasProcessedOrPendingWorkflowTask() bool { // GetWorkflowTaskInfo returns details about the in-progress workflow task func (m *workflowTaskStateMachine) GetWorkflowTaskInfo( scheduledEventID int64, -) (*WorkflowTaskInfo, bool) { +) (*definition.WorkflowTaskInfo, bool) { workflowTask := m.getWorkflowTaskInfo() if scheduledEventID == workflowTask.ScheduledEventID { return workflowTask, true @@ -685,7 +686,7 @@ func (m *workflowTaskStateMachine) GetWorkflowTaskInfo( } func (m *workflowTaskStateMachine) CreateTransientWorkflowTaskEvents( - workflowTask *WorkflowTaskInfo, + workflowTask *definition.WorkflowTaskInfo, identity string, ) *historyspb.TransientWorkflowTaskInfo { @@ -738,7 +739,7 @@ func (m *workflowTaskStateMachine) CreateTransientWorkflowTaskEvents( return transientWorkflowTask } -func (m *workflowTaskStateMachine) getWorkflowTaskInfo() *WorkflowTaskInfo { +func (m *workflowTaskStateMachine) getWorkflowTaskInfo() *definition.WorkflowTaskInfo { taskQueue := &taskqueuepb.TaskQueue{} if m.ms.IsStickyTaskQueueEnabled() { taskQueue.Name = m.ms.executionInfo.StickyTaskQueue @@ -748,7 +749,7 @@ func (m *workflowTaskStateMachine) getWorkflowTaskInfo() *WorkflowTaskInfo { taskQueue.Kind = enumspb.TASK_QUEUE_KIND_NORMAL } - return &WorkflowTaskInfo{ + return &definition.WorkflowTaskInfo{ Version: m.ms.executionInfo.WorkflowTaskVersion, ScheduledEventID: m.ms.executionInfo.WorkflowTaskScheduledEventId, StartedEventID: m.ms.executionInfo.WorkflowTaskStartedEventId, diff --git a/service/history/workflowRebuilder.go b/service/history/workflowRebuilder.go index ce4deef1ee5..6bfce12cd53 100644 --- a/service/history/workflowRebuilder.go +++ b/service/history/workflowRebuilder.go @@ -33,12 +33,11 @@ import ( "go.temporal.io/api/serviceerror" persistencespb "go.temporal.io/server/api/persistence/v1" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/log" "go.temporal.io/server/common/persistence/versionhistory" "go.temporal.io/server/service/history/api" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/ndc" - "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/workflow" ) @@ -52,7 +51,7 @@ type ( } workflowRebuilderImpl struct { - shard shard.Context + shard definition.ShardContext workflowConsistencyChecker api.WorkflowConsistencyChecker transaction workflow.Transaction logger log.Logger @@ -62,8 +61,8 @@ type ( var _ workflowRebuilder = (*workflowRebuilderImpl)(nil) func NewWorkflowRebuilder( - shard shard.Context, - workflowCache workflow.Cache, + shard definition.ShardContext, + workflowCache definition.WorkflowCache, logger log.Logger, ) *workflowRebuilderImpl { return &workflowRebuilderImpl{ @@ -126,7 +125,7 @@ func (r *workflowRebuilderImpl) replayResetWorkflow( stateTransitionCount int64, dbRecordVersion int64, requestID string, -) (workflow.MutableState, int64, error) { +) (definition.MutableState, int64, error) { rebuildMutableState, rebuildHistorySize, err := ndc.NewStateRebuilder(r.shard, r.logger).Rebuild( ctx, @@ -152,13 +151,13 @@ func (r *workflowRebuilderImpl) replayResetWorkflow( func (r *workflowRebuilderImpl) persistToDB( ctx context.Context, - mutableState workflow.MutableState, + mutableState definition.MutableState, historySize int64, ) error { now := r.shard.GetTimeSource().Now() resetWorkflowSnapshot, resetWorkflowEventsSeq, err := mutableState.CloseTransactionAsSnapshot( now, - workflow.TransactionPolicyPassive, + definition.TransactionPolicyPassive, ) if err != nil { return err diff --git a/service/history/workflowResetter_mock.go b/service/history/workflowResetter_mock.go index ee9ef927e36..c46d03992d3 100644 --- a/service/history/workflowResetter_mock.go +++ b/service/history/workflowResetter_mock.go @@ -33,7 +33,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - definition "go.temporal.io/server/common/definition" + definition "go.temporal.io/server/service/history/definition" ) // MockworkflowRebuilder is a mock of workflowRebuilder interface. diff --git a/service/history/workflowTaskHandler.go b/service/history/workflowTaskHandler.go index ea467310057..80fc9335a38 100644 --- a/service/history/workflowTaskHandler.go +++ b/service/history/workflowTaskHandler.go @@ -52,7 +52,7 @@ import ( "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/service/history/configs" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) @@ -67,9 +67,9 @@ type ( hasBufferedEvents bool workflowTaskFailedCause *workflowTaskFailedCause activityNotStartedCancelled bool - newMutableState workflow.MutableState + newMutableState definition.MutableState stopProcessing bool // should stop processing any more commands - mutableState workflow.MutableState + mutableState definition.MutableState initiatedChildExecutionsInBatch map[string]struct{} // Set of initiated child executions in the workflow task // validation @@ -81,7 +81,7 @@ type ( namespaceRegistry namespace.Registry metricsHandler metrics.MetricsHandler config *configs.Config - shard shard.Context + shard definition.ShardContext tokenSerializer common.TaskTokenSerializer } @@ -108,14 +108,14 @@ type ( func newWorkflowTaskHandler( identity string, workflowTaskCompletedID int64, - mutableState workflow.MutableState, + mutableState definition.MutableState, attrValidator *commandAttrValidator, sizeLimitChecker *workflowSizeChecker, logger log.Logger, namespaceRegistry namespace.Registry, metricsHandler metrics.MetricsHandler, config *configs.Config, - shard shard.Context, + shard definition.ShardContext, searchAttributesMapper searchattribute.Mapper, ) *workflowTaskHandlerImpl { diff --git a/service/history/workflowTaskHandlerCallbacks.go b/service/history/workflowTaskHandlerCallbacks.go index 0071b28efd0..56e794e20b0 100644 --- a/service/history/workflowTaskHandlerCallbacks.go +++ b/service/history/workflowTaskHandlerCallbacks.go @@ -40,7 +40,6 @@ import ( "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/clock" - "go.temporal.io/server/common/definition" "go.temporal.io/server/common/failure" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" @@ -54,7 +53,7 @@ import ( "go.temporal.io/server/service/history/api" "go.temporal.io/server/service/history/configs" "go.temporal.io/server/service/history/consts" - "go.temporal.io/server/service/history/shard" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/workflow" ) @@ -75,7 +74,7 @@ type ( workflowTaskHandlerCallbacksImpl struct { currentClusterName string config *configs.Config - shard shard.Context + shard definition.ShardContext workflowConsistencyChecker api.WorkflowConsistencyChecker timeSource clock.TimeSource namespaceRegistry namespace.Registry @@ -342,7 +341,7 @@ func (handler *workflowTaskHandlerCallbacksImpl) handleWorkflowTaskCompleted( workflowContext, err := handler.workflowConsistencyChecker.GetWorkflowContext( ctx, token.Clock, - func(mutableState workflow.MutableState) bool { + func(mutableState definition.MutableState) bool { _, ok := mutableState.GetWorkflowTaskInfo(scheduledEventID) if !ok && scheduledEventID >= mutableState.GetNextEventID() { handler.metricsHandler.Counter(metrics.StaleMutableStateCounter.GetMetricName()).Record( @@ -422,7 +421,7 @@ func (handler *workflowTaskHandlerCallbacksImpl) handleWorkflowTaskCompleted( var ( wtFailedCause *workflowTaskFailedCause activityNotStartedCancelled bool - newMutableState workflow.MutableState + newMutableState definition.MutableState hasUnhandledEvents bool responseMutations []workflowTaskResponseMutation @@ -538,7 +537,7 @@ func (handler *workflowTaskHandlerCallbacksImpl) handleWorkflowTaskCompleted( var newWorkflowTaskScheduledEventID int64 if createNewWorkflowTask { bypassTaskGeneration := request.GetReturnNewWorkflowTask() && wtFailedCause == nil - var newWorkflowTask *workflow.WorkflowTaskInfo + var newWorkflowTask *definition.WorkflowTaskInfo var err error if workflowTaskHeartbeating && !workflowTaskHeartbeatTimeout { newWorkflowTask, err = ms.AddWorkflowTaskScheduledEventAsHeartbeat( @@ -699,8 +698,8 @@ func (handler *workflowTaskHandlerCallbacksImpl) verifyFirstWorkflowTaskSchedule } func (handler *workflowTaskHandlerCallbacksImpl) createRecordWorkflowTaskStartedResponse( - ms workflow.MutableState, - workflowTask *workflow.WorkflowTaskInfo, + ms definition.MutableState, + workflowTask *definition.WorkflowTaskInfo, identity string, ) (*historyservice.RecordWorkflowTaskStartedResponse, error) { @@ -749,7 +748,7 @@ func (handler *workflowTaskHandlerCallbacksImpl) createRecordWorkflowTaskStarted return response, nil } -func (handler *workflowTaskHandlerCallbacksImpl) handleBufferedQueries(ms workflow.MutableState, queryResults map[string]*querypb.WorkflowQueryResult, createNewWorkflowTask bool, namespaceEntry *namespace.Namespace, workflowTaskHeartbeating bool) { +func (handler *workflowTaskHandlerCallbacksImpl) handleBufferedQueries(ms definition.MutableState, queryResults map[string]*querypb.WorkflowQueryResult, createNewWorkflowTask bool, namespaceEntry *namespace.Namespace, workflowTaskHeartbeating bool) { queryRegistry := ms.GetQueryRegistry() if !queryRegistry.HasBufferedQuery() { return @@ -792,7 +791,7 @@ func (handler *workflowTaskHandlerCallbacksImpl) handleBufferedQueries(ms workfl tag.WorkflowRunID(runID), tag.QueryID(id), tag.Error(err)) - failedCompletionState := &workflow.QueryCompletionState{ + failedCompletionState := &definition.QueryCompletionState{ Type: workflow.QueryCompletionTypeFailed, Err: err, } @@ -807,7 +806,7 @@ func (handler *workflowTaskHandlerCallbacksImpl) handleBufferedQueries(ms workfl scope.Counter(metrics.QueryRegistryInvalidStateCount.GetMetricName()).Record(1) } } else { - succeededCompletionState := &workflow.QueryCompletionState{ + succeededCompletionState := &definition.QueryCompletionState{ Type: workflow.QueryCompletionTypeSucceeded, Result: result, } @@ -829,7 +828,7 @@ func (handler *workflowTaskHandlerCallbacksImpl) handleBufferedQueries(ms workfl if !createNewWorkflowTask { buffered := queryRegistry.GetBufferedIDs() for _, id := range buffered { - unblockCompletionState := &workflow.QueryCompletionState{ + unblockCompletionState := &definition.QueryCompletionState{ Type: workflow.QueryCompletionTypeUnblocked, } if err := queryRegistry.SetCompletionState(id, unblockCompletionState); err != nil { @@ -848,12 +847,12 @@ func (handler *workflowTaskHandlerCallbacksImpl) handleBufferedQueries(ms workfl func failWorkflowTask( ctx context.Context, - wfContext workflow.Context, + wfContext definition.WorkflowContext, scheduledEventID int64, startedEventID int64, wtFailedCause *workflowTaskFailedCause, request *workflowservice.RespondWorkflowTaskCompletedRequest, -) (workflow.MutableState, error) { +) (definition.MutableState, error) { // clear any updates we have accumulated so far wfContext.Clear() diff --git a/service/history/workflowTaskHandlerCallbacks_test.go b/service/history/workflowTaskHandlerCallbacks_test.go index dd8559e7ff4..e39b315e67f 100644 --- a/service/history/workflowTaskHandlerCallbacks_test.go +++ b/service/history/workflowTaskHandlerCallbacks_test.go @@ -52,6 +52,7 @@ import ( "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/service/history/api" + "go.temporal.io/server/service/history/definition" "go.temporal.io/server/service/history/events" "go.temporal.io/server/service/history/shard" "go.temporal.io/server/service/history/tests" @@ -64,7 +65,7 @@ type ( suite.Suite controller *gomock.Controller - mockEventsCache *events.MockCache + mockEventsCache *definition.MockEventCache mockExecutionMgr *persistence.MockExecutionManager logger log.Logger @@ -294,9 +295,9 @@ func (s *WorkflowTaskHandlerCallbackSuite) TestHandleBufferedQueries_QueryTooLar s.assertQueryCounts(queryRegistry, 0, 5, 0, 5) } -func (s *WorkflowTaskHandlerCallbackSuite) setupBufferedQueriesMocks() (workflow.QueryRegistry, *workflow.MockMutableState) { +func (s *WorkflowTaskHandlerCallbackSuite) setupBufferedQueriesMocks() (definition.QueryRegistry, *definition.MockMutableState) { queryRegistry := s.constructQueryRegistry(10) - mockMutableState := workflow.NewMockMutableState(s.controller) + mockMutableState := definition.NewMockMutableState(s.controller) mockMutableState.EXPECT().GetQueryRegistry().Return(queryRegistry) mockMutableState.EXPECT().GetExecutionInfo().Return(&persistencespb.WorkflowExecutionInfo{ WorkflowId: tests.WorkflowID, @@ -318,7 +319,7 @@ func (s *WorkflowTaskHandlerCallbackSuite) constructQueryResults(ids []string, r return results } -func (s *WorkflowTaskHandlerCallbackSuite) constructQueryRegistry(numQueries int) workflow.QueryRegistry { +func (s *WorkflowTaskHandlerCallbackSuite) constructQueryRegistry(numQueries int) definition.QueryRegistry { queryRegistry := workflow.NewQueryRegistry() for i := 0; i < numQueries; i++ { queryRegistry.BufferQuery(&querypb.WorkflowQuery{}) @@ -326,7 +327,7 @@ func (s *WorkflowTaskHandlerCallbackSuite) constructQueryRegistry(numQueries int return queryRegistry } -func (s *WorkflowTaskHandlerCallbackSuite) assertQueryCounts(queryRegistry workflow.QueryRegistry, buffered, completed, unblocked, failed int) { +func (s *WorkflowTaskHandlerCallbackSuite) assertQueryCounts(queryRegistry definition.QueryRegistry, buffered, completed, unblocked, failed int) { s.Len(queryRegistry.GetBufferedIDs(), buffered) s.Len(queryRegistry.GetCompletedIDs(), completed) s.Len(queryRegistry.GetUnblockedIDs(), unblocked)