Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Strip workflow cache out of history engine #3594

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/deadlock/deadlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions service/history/api/activity_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -64,7 +64,7 @@ func SetActivityTaskRunID(

func GetActivityScheduledEventID(
activityID string,
mutableState workflow.MutableState,
mutableState definition.MutableState,
) (int64, error) {

if activityID == "" {
Expand Down
30 changes: 14 additions & 16 deletions service/history/api/consistency_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -62,22 +60,22 @@ 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,
workflowCache: workflowCache,
}
}

func (c *WorkflowConsistencyCheckerImpl) GetWorkflowCache() workflow.Cache {
func (c *WorkflowConsistencyCheckerImpl) GetWorkflowCache() definition.WorkflowCache {
return c.workflowCache
}

Expand Down Expand Up @@ -169,7 +167,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowContextValidatedByClock(
WorkflowId: workflowKey.WorkflowID,
RunId: workflowKey.RunID,
},
workflow.CallerTypeAPI,
definition.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -202,7 +200,7 @@ func (c *WorkflowConsistencyCheckerImpl) getWorkflowContextValidatedByCheck(
WorkflowId: workflowKey.WorkflowID,
RunId: workflowKey.RunID,
},
workflow.CallerTypeAPI,
definition.CallerTypeAPI,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -318,7 +316,7 @@ func (c *WorkflowConsistencyCheckerImpl) getCurrentRunID(

func assertShardOwnership(
ctx context.Context,
shardContext shard.Context,
shardContext definition.ShardContext,
shardOwnershipAsserted *bool,
) error {
if !*shardOwnershipAsserted {
Expand All @@ -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
}
Expand All @@ -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(),
Expand Down
40 changes: 19 additions & 21 deletions service/history/api/consistency_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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 }

Expand All @@ -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)

Expand All @@ -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 }

Expand All @@ -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),
Expand All @@ -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 }

Expand All @@ -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(""))

Expand All @@ -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 }

Expand All @@ -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(""))

Expand All @@ -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 }

Expand All @@ -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(""))

Expand Down Expand Up @@ -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,
})
Expand Down
21 changes: 10 additions & 11 deletions service/history/api/create_workflow_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -55,7 +54,7 @@ type (

func NewWorkflowWithSignal(
ctx context.Context,
shard shard.Context,
shard definition.ShardContext,
namespaceEntry *namespace.Namespace,
workflowID string,
runID string,
Expand Down Expand Up @@ -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(),
Expand All @@ -142,7 +141,7 @@ func CreateMutableState(
}

func GenerateFirstWorkflowTask(
mutableState workflow.MutableState,
mutableState definition.MutableState,
parentInfo *workflowspb.ParentExecutionInfo,
startEvent *historypb.HistoryEvent,
) error {
Expand All @@ -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
Expand All @@ -181,7 +180,7 @@ func NewWorkflowVersionCheck(

func ValidateStart(
ctx context.Context,
shard shard.Context,
shard definition.ShardContext,
namespaceEntry *namespace.Namespace,
workflowID string,
workflowInputSize int,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions service/history/api/deleteworkflow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading