Skip to content

Commit

Permalink
Refactor history packages (#5673)
Browse files Browse the repository at this point in the history
What changed?
Moving structs in the service/history package to their own packages

The handler is moved to it's own package with the interface (like in frontend)
The handler wrappers (grpc, and thrift) are moved to their own packages under wrapped (like in frontend)

The engine implementation is moved to it's own package as there was a circular dependency
history (service) -> handler -> history (engine)
and the engine implementation cannot be in the same package as the engine interface, as there is a dependency
engineimpl -> shard -> engine (Interface)

Moved all the error values in handler to a constants package as at least one of them (ErrRunIDNotValid) is referenced from two different packages (handler and engineimpl tests)

Why?
We should not have this much in the same package

Also when service and handler are in the same package we cannot introduce wrappers around handler in any other package than history as that will create a circular dependency:
history (service) -> wrapper -> history (handler)

How did you test it?
Ran unit tests

Potential risks
It just moves things around, so no real code changes

Release notes

Documentation Changes
  • Loading branch information
jakobht authored Feb 20, 2024
1 parent ff95842 commit 8f3e6bd
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 135 deletions.
6 changes: 3 additions & 3 deletions host/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
"github.com/uber/cadence/common"
"github.com/uber/cadence/common/log/tag"
"github.com/uber/cadence/common/types"
cadencehistory "github.com/uber/cadence/service/history"
"github.com/uber/cadence/service/history/engine/engineimpl"
"github.com/uber/cadence/service/history/execution"
"github.com/uber/cadence/service/matching"
)
Expand Down Expand Up @@ -309,8 +309,8 @@ GetHistoryLoop:
}

terminateEventAttributes := lastEvent.WorkflowExecutionTerminatedEventAttributes
s.Equal(cadencehistory.TerminateIfRunningReason, terminateEventAttributes.GetReason())
s.Equal(fmt.Sprintf(cadencehistory.TerminateIfRunningDetailsTemplate, we1.GetRunID()), string(terminateEventAttributes.Details))
s.Equal(engineimpl.TerminateIfRunningReason, terminateEventAttributes.GetReason())
s.Equal(fmt.Sprintf(engineimpl.TerminateIfRunningDetailsTemplate, we1.GetRunID()), string(terminateEventAttributes.Details))
s.Equal(execution.IdentityHistoryService, terminateEventAttributes.GetIdentity())
executionTerminated = true
break GetHistoryLoop
Expand Down
6 changes: 3 additions & 3 deletions host/signal_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/uber/cadence/common/client"
"github.com/uber/cadence/common/log/tag"
"github.com/uber/cadence/common/types"
cadencehistory "github.com/uber/cadence/service/history"
"github.com/uber/cadence/service/history/engine/engineimpl"
"github.com/uber/cadence/service/history/execution"
)

Expand Down Expand Up @@ -1655,8 +1655,8 @@ GetHistoryLoop:
}

terminateEventAttributes := lastEvent.WorkflowExecutionTerminatedEventAttributes
s.Equal(cadencehistory.TerminateIfRunningReason, terminateEventAttributes.GetReason())
s.Equal(fmt.Sprintf(cadencehistory.TerminateIfRunningDetailsTemplate, resp1.GetRunID()), string(terminateEventAttributes.Details))
s.Equal(engineimpl.TerminateIfRunningReason, terminateEventAttributes.GetReason())
s.Equal(fmt.Sprintf(engineimpl.TerminateIfRunningDetailsTemplate, resp1.GetRunID()), string(terminateEventAttributes.Details))
s.Equal(execution.IdentityHistoryService, terminateEventAttributes.GetIdentity())
executionTerminated = true
break GetHistoryLoop
Expand Down
38 changes: 38 additions & 0 deletions service/history/constants/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// The MIT License (MIT)

// Copyright (c) 2017-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 constants

import "github.com/uber/cadence/common/types"

var (
ErrDomainNotSet = &types.BadRequestError{Message: "Domain not set on request."}
ErrWorkflowExecutionNotSet = &types.BadRequestError{Message: "WorkflowExecution not set on request."}
ErrTaskListNotSet = &types.BadRequestError{Message: "Tasklist not set."}
ErrRunIDNotValid = &types.BadRequestError{Message: "RunID is not valid UUID."}
ErrWorkflowIDNotSet = &types.BadRequestError{Message: "WorkflowId is not set on request."}
ErrSourceClusterNotSet = &types.BadRequestError{Message: "Source Cluster not set on request."}
ErrTimestampNotSet = &types.BadRequestError{Message: "Timestamp not set on request."}
ErrInvalidTaskType = &types.BadRequestError{Message: "Invalid task type"}
ErrHistoryHostThrottle = &types.ServiceBusyError{Message: "History host rps exceeded"}
ErrShuttingDown = &types.InternalServiceError{Message: "Shutting down"}
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package history
package engineimpl

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package history
package engineimpl

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package history
package engineimpl

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package history
package engineimpl

import (
"context"
Expand Down Expand Up @@ -228,7 +228,7 @@ func (s *engineSuite) TestGetMutableState_IntestRunID() {
DomainUUID: constants.TestDomainID,
Execution: &execution,
})
s.Equal(errRunIDNotValid, err)
s.Equal(constants.ErrRunIDNotValid, err)
}

func (s *engineSuite) TestGetMutableState_EmptyRunID() {
Expand Down
Loading

0 comments on commit 8f3e6bd

Please sign in to comment.