Skip to content

Commit

Permalink
Fill domainID for backwards compatibility (cadence-workflow#4819)
Browse files Browse the repository at this point in the history
* Fill domainID for backwards compatibility

* Added unit test
  • Loading branch information
vytautas-karpavicius authored May 10, 2022
1 parent 361edb6 commit eede466
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions service/history/execution/mutable_state_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ func (e *mutableStateBuilder) Load(
e.replicationState = state.ReplicationState
e.checksum = state.Checksum

e.fillForBackwardsCompatibility()

if len(state.Checksum.Value) > 0 {
switch {
case e.shouldInvalidateChecksum():
Expand All @@ -348,6 +350,21 @@ func (e *mutableStateBuilder) Load(
}
}

func (e *mutableStateBuilder) fillForBackwardsCompatibility() {
// With https://github.com/uber/cadence/pull/4601 newly introduced DomainID may not be set for older workflows.
// Here we will fill its value based on previously used domain name.
for _, info := range e.pendingChildExecutionInfoIDs {
if info.DomainID == "" && info.DomainNameDEPRECATED != "" {
domainID, err := e.shard.GetDomainCache().GetDomainID(info.DomainNameDEPRECATED)
if err != nil {
e.logError("failed to fill domainId for pending child executions", tag.Error(err))
}

info.DomainID = domainID
}
}
}

func (e *mutableStateBuilder) GetCurrentBranchToken() ([]byte, error) {
if e.versionHistories != nil {
currentVersionHistory, err := e.versionHistories.GetCurrentVersionHistory()
Expand Down
20 changes: 20 additions & 0 deletions service/history/execution/mutable_state_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func (s *mutableStateSuite) SetupTest() {
s.testScope = s.mockShard.Resource.MetricsScope
s.logger = s.mockShard.GetLogger()

s.mockShard.Resource.DomainCache.EXPECT().GetDomainID(constants.TestDomainName).Return(constants.TestDomainID, nil).AnyTimes()

s.msBuilder = newMutableStateBuilder(s.mockShard, s.logger, constants.TestLocalDomainEntry)
}

Expand Down Expand Up @@ -787,6 +789,14 @@ func (s *mutableStateSuite) prepareTransientDecisionCompletionFirstBatchReplicat
return newDecisionScheduleEvent, newDecisionStartedEvent
}

func (s *mutableStateSuite) TestLoad_BackwardsCompatibility() {
mutableState := s.buildWorkflowMutableState()

s.msBuilder.Load(mutableState)

s.Equal(constants.TestDomainID, s.msBuilder.pendingChildExecutionInfoIDs[81].DomainID)
}

func (s *mutableStateSuite) TestUpdateCurrentVersion_WorkflowOpen() {
mutableState := s.buildWorkflowMutableState()

Expand Down Expand Up @@ -892,6 +902,16 @@ func (s *mutableStateSuite) buildWorkflowMutableState() *persistence.WorkflowMut
DomainID: constants.TestDomainID,
WorkflowTypeName: "code.uber.internal/test/foobar",
},
81: {
Version: failoverVersion,
InitiatedID: 80,
InitiatedEventBatchID: 20,
InitiatedEvent: &types.HistoryEvent{},
StartedID: common.EmptyEventID,
CreateRequestID: uuid.New(),
DomainNameDEPRECATED: constants.TestDomainName,
WorkflowTypeName: "code.uber.internal/test/foobar",
},
}

signalInfos := map[int64]*persistence.SignalInfo{
Expand Down

0 comments on commit eede466

Please sign in to comment.