Skip to content

Commit

Permalink
Check max taskID instead of max read level when process task (#2371)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminc authored Jan 12, 2022
1 parent 00a49ab commit ba30aa8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions service/history/shard/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type (
GetTransferMaxReadLevel() int64
UpdateTimerMaxReadLevel(cluster string) time.Time

GetMaxTaskIDForCurrentRangeID() int64

SetCurrentTime(cluster string, currentTime time.Time)
GetCurrentTime(cluster string) time.Time
GetLastUpdatedTime() time.Time
Expand Down
7 changes: 7 additions & 0 deletions service/history/shard/context_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ func (s *ContextImpl) GetEngine() (Engine, error) {
return s.engine, nil
}

func (s *ContextImpl) GetMaxTaskIDForCurrentRangeID() int64 {
s.rLock()
defer s.rUnlock()
// maxTransferSequenceNumber is the exclusive upper bound of task ID for current range.
return s.maxTransferSequenceNumber - 1
}

func (s *ContextImpl) GenerateTransferTaskID() (int64, error) {
s.wLock()
defer s.wUnlock()
Expand Down
14 changes: 14 additions & 0 deletions service/history/shard/context_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions service/history/taskProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ func (t *taskProcessor) taskWorker(
if !ok {
return
}
if task.GetTaskID() > t.shard.GetTransferMaxReadLevel() {
// this could happen if we lost ownership and was not aware of it.
if task.GetTaskID() > t.shard.GetMaxTaskIDForCurrentRangeID() {
// this could happen if we lost ownership and were not aware of it.
// unload shard
t.shard.Unload()
return
Expand Down

0 comments on commit ba30aa8

Please sign in to comment.