Skip to content

Commit

Permalink
adding a fix (#5074)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidporter-id-au authored Feb 4, 2023
1 parent 361a107 commit 7670ab2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions service/history/execution/state_rebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func (r *stateRebuilderImpl) Rebuild(
return nil, 0, err
}

// Corrupt data handling
if !iter.HasNext() {
return nil, 0, fmt.Errorf("Attempting to build history state but the iterator has found no history")
}
// need to specially handling the first batch, to initialize mutable state & state builder
batch, err := iter.Next()
if err != nil {
Expand Down
42 changes: 42 additions & 0 deletions service/history/execution/state_rebuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,45 @@ func (s *stateRebuilderSuite) TestRebuild() {
), rebuildMutableState.GetVersionHistories())
s.Equal(rebuildMutableState.GetExecutionInfo().StartTimestamp, now)
}

func (s *stateRebuilderSuite) TestInvalidStateHandling() {
requestID := uuid.New()
version := int64(12)
lastEventID := int64(2)
branchToken := []byte("other random branch token")
targetBranchToken := []byte("some other random branch token")
now := time.Now()

targetDomainID := uuid.New()
targetDomainName := "other random domain name"
targetWorkflowID := "other random workflow ID"
targetRunID := uuid.New()

s.mockDomainCache.EXPECT().GetDomainName(gomock.Any()).Return(targetDomainName, nil).AnyTimes()
s.mockHistoryV2Mgr.On("ReadHistoryBranchByBatch", mock.Anything, mock.Anything).Return(nil, &types.EntityNotExistsError{}).Once()

s.mockDomainCache.EXPECT().GetDomainByID(targetDomainID).Return(cache.NewGlobalDomainCacheEntryForTest(
&persistence.DomainInfo{ID: targetDomainID, Name: targetDomainName},
&persistence.DomainConfig{},
&persistence.DomainReplicationConfig{
ActiveClusterName: cluster.TestCurrentClusterName,
Clusters: []*persistence.ClusterReplicationConfig{
{ClusterName: cluster.TestCurrentClusterName},
{ClusterName: cluster.TestAlternativeClusterName},
},
},
1234,
), nil).AnyTimes()

s.nDCStateRebuilder.Rebuild(
context.Background(),
now,
definition.NewWorkflowIdentifier(s.domainID, s.workflowID, s.runID),
branchToken,
lastEventID,
version,
definition.NewWorkflowIdentifier(targetDomainID, targetWorkflowID, targetRunID),
targetBranchToken,
requestID,
)
}

0 comments on commit 7670ab2

Please sign in to comment.