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

optimize queue ack manager, in case the task IDs are not sequencial. #875

Merged
merged 1 commit into from
Jun 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions service/history/queueAckMgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package history

import (
"sort"
"sync"

"github.com/uber-common/bark"
Expand Down Expand Up @@ -168,18 +169,24 @@ func (a *queueAckMgrImpl) updateQueueAckLevel() {
a.Lock()
ackLevel := a.ackLevel

// task ID is not sequancial, meaning there are a ton of missing chunks,
// so to optimize the performance, a sort is required
var taskIDs []int64
for k := range a.outstandingTasks {
taskIDs = append(taskIDs, k)
}
sort.Slice(taskIDs, func(i, j int) bool { return taskIDs[i] < taskIDs[j] })

MoveAckLevelLoop:
for current := a.ackLevel + 1; current <= a.readLevel; current++ {
// TODO: What happens if !ok?
if acked, ok := a.outstandingTasks[current]; ok {
if acked {
a.logger.Debugf("Updating ack level: %v", current)
ackLevel = current
a.finishedTaskCounter++
delete(a.outstandingTasks, current)
} else {
break MoveAckLevelLoop
}
for _, current := range taskIDs {
acked := a.outstandingTasks[current]
if acked {
a.logger.Debugf("Updating ack level: %v", current)
ackLevel = current
a.finishedTaskCounter++
delete(a.outstandingTasks, current)
} else {
break MoveAckLevelLoop
}
}
a.ackLevel = ackLevel
Expand Down