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

Fix unable to reset workflow issue #1673

Merged
merged 3 commits into from Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions common/persistence/history_manager.go
Expand Up @@ -32,6 +32,7 @@ import (
enumspb "go.temporal.io/api/enums/v1"
historypb "go.temporal.io/api/history/v1"
"go.temporal.io/api/serviceerror"

wxing1292 marked this conversation as resolved.
Show resolved Hide resolved
"go.temporal.io/server/common/primitives/timestamp"

persistencespb "go.temporal.io/server/api/persistence/v1"
Expand Down Expand Up @@ -94,7 +95,10 @@ func (m *historyV2ManagerImpl) ForkHistoryBranch(
}
}

forkBranch, err := m.historySerializer.HistoryBranchFromBlob(&commonpb.DataBlob{Data: request.ForkBranchToken, EncodingType: enumspb.ENCODING_TYPE_PROTO3})
forkBranch, err := m.historySerializer.HistoryBranchFromBlob(&commonpb.DataBlob{
Data: request.ForkBranchToken,
EncodingType: enumspb.ENCODING_TYPE_PROTO3,
})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -566,7 +570,9 @@ func (m *historyV2ManagerImpl) readRawHistoryBranch(
currentBranch := branchAncestors[token.CurrentRangeIndex]
// minNodeID remains the same, since caller can read from the middle
// maxNodeID need to be shortened since this branch can contain additional history nodes
maxNodeID = currentBranch.GetEndNodeId()
if currentBranch.GetEndNodeId() < maxNodeID {
maxNodeID = currentBranch.GetEndNodeId()
}
branchID := currentBranch.GetBranchId()
resp, err := m.persistence.ReadHistoryBranch(&InternalReadHistoryBranchRequest{
ShardID: shardID,
Expand Down
43 changes: 43 additions & 0 deletions common/persistence/tests/history_store_test.go
Expand Up @@ -109,6 +109,7 @@ func (s *historyEventsSuite) TestAppendSelect_First() {
)
s.appendHistoryEvents(shardID, branchToken, eventsPacket)

s.Equal(eventsPacket.events, s.listHistoryEvents(shardID, branchToken, common.FirstEventID, 4))
s.Equal(eventsPacket.events, s.listAllHistoryEvents(shardID, branchToken))
}

Expand Down Expand Up @@ -136,6 +137,8 @@ func (s *historyEventsSuite) TestAppendSelect_NonShadowing() {
s.appendHistoryEvents(shardID, branchToken, eventsPacket1)
events = append(events, eventsPacket1.events...)

s.Equal(eventsPacket0.events, s.listHistoryEvents(shardID, branchToken, common.FirstEventID, 4))
s.Equal(eventsPacket1.events, s.listHistoryEvents(shardID, branchToken, 4, 6))
s.Equal(events, s.listAllHistoryEvents(shardID, branchToken))
}

Expand Down Expand Up @@ -175,6 +178,8 @@ func (s *historyEventsSuite) TestAppendSelect_Shadowing() {
s.appendHistoryEvents(shardID, branchToken, eventsPacket11)
events1 = append(events1, eventsPacket11.events...)

s.Equal(eventsPacket0.events, s.listHistoryEvents(shardID, branchToken, common.FirstEventID, 4))
s.Equal(eventsPacket11.events, s.listHistoryEvents(shardID, branchToken, 4, 6))
s.Equal(events1, s.listAllHistoryEvents(shardID, branchToken))
}

Expand Down Expand Up @@ -213,6 +218,10 @@ func (s *historyEventsSuite) TestAppendForkSelect_NoShadowing() {
s.appendHistoryEvents(shardID, newBranchToken, eventsPacket11)
events1 = append(events1, eventsPacket11.events...)

s.Equal(eventsPacket0.events, s.listHistoryEvents(shardID, branchToken, common.FirstEventID, 4))
s.Equal(eventsPacket0.events, s.listHistoryEvents(shardID, newBranchToken, common.FirstEventID, 4))
s.Equal(eventsPacket10.events, s.listHistoryEvents(shardID, branchToken, 4, 6))
s.Equal(eventsPacket11.events, s.listHistoryEvents(shardID, newBranchToken, 4, 6))
s.Equal(events0, s.listAllHistoryEvents(shardID, branchToken))
s.Equal(events1, s.listAllHistoryEvents(shardID, newBranchToken))
}
Expand Down Expand Up @@ -267,6 +276,12 @@ func (s *historyEventsSuite) TestAppendForkSelect_Shadowing_NonLastBranch() {
s.appendHistoryEvents(shardID, newBranchToken, eventsPacket21)
events1 = append(events1, eventsPacket21.events...)

s.Equal(eventsPacket0.events, s.listHistoryEvents(shardID, branchToken, common.FirstEventID, 4))
s.Equal(eventsPacket0.events, s.listHistoryEvents(shardID, newBranchToken, common.FirstEventID, 4))
s.Equal(eventsPacket1.events, s.listHistoryEvents(shardID, branchToken, 4, 6))
s.Equal(eventsPacket1.events, s.listHistoryEvents(shardID, newBranchToken, 4, 6))
s.Equal(eventsPacket20.events, s.listHistoryEvents(shardID, branchToken, 6, 7))
s.Equal(eventsPacket21.events, s.listHistoryEvents(shardID, newBranchToken, 6, 7))
s.Equal(events0, s.listAllHistoryEvents(shardID, branchToken))
s.Equal(events1, s.listAllHistoryEvents(shardID, newBranchToken))
}
Expand Down Expand Up @@ -304,6 +319,8 @@ func (s *historyEventsSuite) TestAppendForkSelect_Shadowing_LastBranch() {
s.appendHistoryEvents(shardID, newBranchToken, eventsPacket20)
events0 = append(events0, eventsPacket20.events...)

s.Equal(eventsPacket0.events, s.listHistoryEvents(shardID, newBranchToken, common.FirstEventID, 4))
s.Equal(eventsPacket20.events, s.listHistoryEvents(shardID, newBranchToken, 4, 6))
s.Equal(events0, s.listAllHistoryEvents(shardID, newBranchToken))

eventsPacket21 := s.newHistoryEvents(
Expand All @@ -314,6 +331,8 @@ func (s *historyEventsSuite) TestAppendForkSelect_Shadowing_LastBranch() {
s.appendHistoryEvents(shardID, newBranchToken, eventsPacket21)
events1 = append(events1, eventsPacket21.events...)

s.Equal(eventsPacket0.events, s.listHistoryEvents(shardID, newBranchToken, common.FirstEventID, 4))
s.Equal(eventsPacket21.events, s.listHistoryEvents(shardID, newBranchToken, 4, 6))
s.Equal(events1, s.listAllHistoryEvents(shardID, newBranchToken))
}

Expand Down Expand Up @@ -568,6 +587,30 @@ func (s *historyEventsSuite) trimHistoryBranch(
s.NoError(err)
}

func (s *historyEventsSuite) listHistoryEvents(
shardID int32,
branchToken []byte,
startEventID int64,
endEventID int64,
) []*historypb.HistoryEvent {
var token []byte
var events []*historypb.HistoryEvent
for doContinue := true; doContinue; doContinue = len(token) > 0 {
resp, err := s.store.ReadHistoryBranch(&p.ReadHistoryBranchRequest{
ShardID: shardID,
BranchToken: branchToken,
MinEventID: startEventID,
MaxEventID: endEventID,
PageSize: 1, // use 1 here for better testing exp
NextPageToken: token,
})
s.NoError(err)
token = resp.NextPageToken
events = append(events, resp.HistoryEvents...)
}
return events
}

func (s *historyEventsSuite) listAllHistoryEvents(
shardID int32,
branchToken []byte,
Expand Down