Skip to content

Commit

Permalink
Add dedupe logic for heartbeat timer creation (cadence-workflow#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
samarabbas authored and wxing1292 committed Jul 14, 2018
1 parent 19e4de2 commit cbbff60
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions common/persistence/dataInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ type (
ExpirationTime time.Time
MaximumAttempts int32
NonRetriableErrors []string
// Not written to database - This is used only for deduping heartbeat timer creation
LastTimeoutVisibility int64
}

// TimerInfo details - metadata about user timer info.
Expand Down
4 changes: 3 additions & 1 deletion service/history/timerQueueActiveProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Update_History_Loop:
// NOTE: When record activity HB comes in we only update last heartbeat timestamp, this is the place
// where we create next timer task based on that new updated timestamp.
isHeartBeatTask := timerTask.TimeoutType == int(workflow.TimeoutTypeHeartbeat)
if isHeartBeatTask {
if isHeartBeatTask && ai.LastTimeoutVisibility <= timerTask.VisibilityTimestamp.Unix() {
ai.TimerTaskStatus = ai.TimerTaskStatus &^ TimerTaskStatusCreatedHeartbeat
msBuilder.UpdateActivity(ai)
}
Expand Down Expand Up @@ -415,6 +415,8 @@ Update_History_Loop:
at := nextTask.(*persistence.ActivityTimeoutTask)

ai.TimerTaskStatus = ai.TimerTaskStatus | getActivityTimerStatus(workflow.TimeoutType(at.TimeoutType))
// Use second resolution for setting LastTimeoutVisibility, which is used for deduping heartbeat timer creation
ai.LastTimeoutVisibility = td.TimerSequenceID.VisibilityTimestamp.Unix()
msBuilder.UpdateActivity(ai)
createNewTimer = true

Expand Down

0 comments on commit cbbff60

Please sign in to comment.