Skip to content

Commit

Permalink
Rename TaskID in TimerInfo to TaskStatus for readability (cadence-wor…
Browse files Browse the repository at this point in the history
  • Loading branch information
wxing1292 authored Nov 7, 2019
1 parent e5b6bdb commit bc1ebff
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 47 deletions.
12 changes: 9 additions & 3 deletions common/persistence/cassandra/cassandraPersistenceUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ func updateTimerInfos(
a.TimerID,
a.StartedID,
a.ExpiryTime,
a.TaskID,
a.TaskStatus,
shardID,
rowTypeExecution,
domainID,
Expand Down Expand Up @@ -2150,7 +2150,10 @@ func createTimerInfo(
case "expiry_time":
info.ExpiryTime = v.(time.Time)
case "task_id":
info.TaskID = v.(int64)
// task_id is a misleading variable, it actually serves
// the purpose of indicating whether a timer task is
// generated for this timer info
info.TaskStatus = v.(int64)
}
}
return info
Expand Down Expand Up @@ -2310,7 +2313,10 @@ func resetTimerInfoMap(
tInfo["timer_id"] = t.TimerID
tInfo["started_id"] = t.StartedID
tInfo["expiry_time"] = t.ExpiryTime
tInfo["task_id"] = t.TaskID
// task_id is a misleading variable, it actually serves
// the purpose of indicating whether a timer task is
// generated for this timer info
tInfo["task_id"] = t.TaskStatus

tMap[t.TimerID] = tInfo
}
Expand Down
5 changes: 1 addition & 4 deletions common/persistence/dataInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,7 @@ type (
TimerID string
StartedID int64
ExpiryTime time.Time
// TaskID is a misleading variable, it actually serves
// the purpose of indicating whether a timer task is
// generated for this timer info
TaskID int64
TaskStatus int64
}

// ChildExecutionInfo has details for pending child executions.
Expand Down
24 changes: 12 additions & 12 deletions common/persistence/persistence-tests/executionManagerTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,7 @@ func (s *ExecutionManagerSuite) TestWorkflowMutableStateTimers() {
Version: 3345,
TimerID: timerID,
ExpiryTime: currentTime,
TaskID: 2,
TaskStatus: 2,
StartedID: 5,
}}
err2 := s.UpdateWorkflowExecution(updatedInfo, updatedStats, nil, []int64{int64(4)}, nil, int64(3), nil, nil, nil, timerInfos, nil)
Expand All @@ -2525,7 +2525,7 @@ func (s *ExecutionManagerSuite) TestWorkflowMutableStateTimers() {
s.Equal(int64(3345), state.TimerInfos[timerID].Version)
s.Equal(timerID, state.TimerInfos[timerID].TimerID)
s.EqualTimesWithPrecision(currentTime, state.TimerInfos[timerID].ExpiryTime, time.Millisecond*500)
s.Equal(int64(2), state.TimerInfos[timerID].TaskID)
s.Equal(int64(2), state.TimerInfos[timerID].TaskStatus)
s.Equal(int64(5), state.TimerInfos[timerID].StartedID)

err2 = s.UpdateWorkflowExecution(updatedInfo, updatedStats, nil, nil, nil, int64(5), nil, nil, nil, nil, []string{timerID})
Expand Down Expand Up @@ -3348,21 +3348,21 @@ func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionCurrentIsSel
TimerID: "t1",
StartedID: 1,
ExpiryTime: expiryTime,
TaskID: 500,
TaskStatus: 500,
},
"t2": {
Version: 2333,
TimerID: "t2",
StartedID: 2,
ExpiryTime: expiryTime,
TaskID: 501,
TaskStatus: 501,
},
"t3": {
Version: 2333,
TimerID: "t3",
StartedID: 3,
ExpiryTime: expiryTime,
TaskID: 502,
TaskStatus: 502,
},
},

Expand Down Expand Up @@ -3490,7 +3490,7 @@ func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionCurrentIsSel
s.Equal("t1", ti.TimerID)
s.Equal(int64(1), ti.StartedID)
s.EqualTimes(expiryTime, ti.ExpiryTime)
s.Equal(int64(500), ti.TaskID)
s.Equal(int64(500), ti.TaskStatus)

ti, ok = state1.TimerInfos["t2"]
s.True(ok)
Expand All @@ -3499,7 +3499,7 @@ func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionCurrentIsSel
s.Equal("t2", ti.TimerID)
s.Equal(int64(2), ti.StartedID)
s.EqualTimes(expiryTime, ti.ExpiryTime)
s.Equal(int64(501), ti.TaskID)
s.Equal(int64(501), ti.TaskStatus)

ti, ok = state1.TimerInfos["t3"]
s.True(ok)
Expand All @@ -3508,7 +3508,7 @@ func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionCurrentIsSel
s.Equal("t3", ti.TimerID)
s.Equal(int64(3), ti.StartedID)
s.EqualTimes(expiryTime, ti.ExpiryTime)
s.Equal(int64(502), ti.TaskID)
s.Equal(int64(502), ti.TaskStatus)

s.Equal(1, len(state1.ChildExecutionInfos))
ci, ok := state1.ChildExecutionInfos[9]
Expand Down Expand Up @@ -3565,14 +3565,14 @@ func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionCurrentIsSel
TimerID: "t1_new",
StartedID: 1,
ExpiryTime: expiryTime,
TaskID: 600,
TaskStatus: 600,
},
{
Version: 3333,
TimerID: "t2_new",
StartedID: 2,
ExpiryTime: expiryTime,
TaskID: 601,
TaskStatus: 601,
}}

resetChildExecutionInfos := []*p.ChildExecutionInfo{
Expand Down Expand Up @@ -3659,7 +3659,7 @@ func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionCurrentIsSel
s.Equal("t1_new", ti.TimerID)
s.Equal(int64(1), ti.StartedID)
s.EqualTimes(expiryTime, ti.ExpiryTime)
s.Equal(int64(600), ti.TaskID)
s.Equal(int64(600), ti.TaskStatus)

ti, ok = state4.TimerInfos["t2_new"]
s.True(ok)
Expand All @@ -3668,7 +3668,7 @@ func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionCurrentIsSel
s.Equal("t2_new", ti.TimerID)
s.Equal(int64(2), ti.StartedID)
s.EqualTimes(expiryTime, ti.ExpiryTime)
s.Equal(int64(601), ti.TaskID)
s.Equal(int64(601), ti.TaskStatus)

s.Equal(1, len(state4.ChildExecutionInfos))
ci, ok = state4.ChildExecutionInfos[10]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (s *ExecutionManagerSuiteForEventsV2) TestWorkflowCreation() {
Version: 3345,
TimerID: timerID,
ExpiryTime: currentTime,
TaskID: 2,
TaskStatus: 2,
StartedID: 5,
}}
updatedInfo.BranchToken = []byte("branchToken2")
Expand All @@ -153,7 +153,7 @@ func (s *ExecutionManagerSuiteForEventsV2) TestWorkflowCreation() {
s.Equal(int64(3345), state.TimerInfos[timerID].Version)
s.Equal(timerID, state.TimerInfos[timerID].TimerID)
s.EqualTimesWithPrecision(currentTime, state.TimerInfos[timerID].ExpiryTime, time.Millisecond*500)
s.Equal(int64(2), state.TimerInfos[timerID].TaskID)
s.Equal(int64(2), state.TimerInfos[timerID].TaskStatus)
s.Equal(int64(5), state.TimerInfos[timerID].StartedID)

err2 = s.UpdateWorkflowExecution(updatedInfo, updatedStats, nil, nil, nil, int64(5), nil, nil, nil, nil, []string{timerID})
Expand Down Expand Up @@ -235,7 +235,7 @@ func (s *ExecutionManagerSuiteForEventsV2) TestWorkflowCreationWithVersionHistor
Version: 3345,
TimerID: timerID,
ExpiryTime: currentTime,
TaskID: 2,
TaskStatus: 2,
StartedID: 5,
}}
versionHistory, err := versionHistories.GetCurrentVersionHistory()
Expand All @@ -253,7 +253,7 @@ func (s *ExecutionManagerSuiteForEventsV2) TestWorkflowCreationWithVersionHistor
s.Equal(int64(3345), state.TimerInfos[timerID].Version)
s.Equal(timerID, state.TimerInfos[timerID].TimerID)
s.EqualTimesWithPrecision(currentTime, state.TimerInfos[timerID].ExpiryTime, time.Millisecond*500)
s.Equal(int64(2), state.TimerInfos[timerID].TaskID)
s.Equal(int64(2), state.TimerInfos[timerID].TaskStatus)
s.Equal(int64(5), state.TimerInfos[timerID].StartedID)
s.Equal(state.VersionHistories, versionHistories)
}
Expand Down Expand Up @@ -853,7 +853,7 @@ func (s *ExecutionManagerSuiteForEventsV2) TestWorkflowResetWithCurrWithReplicat
Version: 100,
TimerID: "id101",
ExpiryTime: currentTime,
TaskID: 102,
TaskStatus: 102,
StartedID: 103,
}}

Expand Down Expand Up @@ -1268,7 +1268,7 @@ func (s *ExecutionManagerSuiteForEventsV2) TestWorkflowResetNoCurrWithReplicate(
Version: 100,
TimerID: "id101",
ExpiryTime: currentTime,
TaskID: 102,
TaskStatus: 102,
StartedID: 103,
}}

Expand Down Expand Up @@ -1553,7 +1553,7 @@ func (s *ExecutionManagerSuiteForEventsV2) TestWorkflowResetNoCurrNoReplicate()
Version: 100,
TimerID: "id101",
ExpiryTime: currentTime,
TaskID: 102,
TaskStatus: 102,
StartedID: 103,
}}

Expand Down
10 changes: 8 additions & 2 deletions common/persistence/sql/workflowStateMaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ func updateTimerInfos(
Version: &v.Version,
StartedID: &v.StartedID,
ExpiryTimeNanos: common.Int64Ptr(v.ExpiryTime.UnixNano()),
TaskID: &v.TaskID,
// TaskID is a misleading variable, it actually serves
// the purpose of indicating whether a timer task is
// generated for this timer info
TaskID: &v.TaskStatus,
})
if err != nil {
return err
Expand Down Expand Up @@ -324,7 +327,10 @@ func getTimerInfoMap(
Version: info.GetVersion(),
StartedID: info.GetStartedID(),
ExpiryTime: time.Unix(0, info.GetExpiryTimeNanos()),
TaskID: info.GetTaskID(),
// TaskID is a misleading variable, it actually serves
// the purpose of indicating whether a timer task is
// generated for this timer info
TaskStatus: info.GetTaskID(),
}
}

Expand Down
3 changes: 3 additions & 0 deletions idl/github.com/uber/cadence/sqlblobs.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ struct TimerInfo {
10: optional i64 (js.type = "Long") version
12: optional i64 (js.type = "Long") startedID
14: optional i64 (js.type = "Long") expiryTimeNanos
// TaskID is a misleading variable, it actually serves
// the purpose of indicating whether a timer task is
// generated for this timer info
16: optional i64 (js.type = "Long") taskID
}

Expand Down
5 changes: 4 additions & 1 deletion schema/cassandra/cadence/schema.cql
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ CREATE TYPE timer_info (
timer_id text, -- User defined timer ID
started_id bigint, -- The event ID corresponding to timer started.
expiry_time timestamp, -- Timestamp at which this timer expires or fires
task_id bigint, -- The task ID if we have one created for this timer
-- task_id is a misleading variable, it actually serves
-- the purpose of indicating whether a timer task is
-- generated for this timer info
task_id bigint,
);

-- Child execution in progress mutable state
Expand Down
2 changes: 1 addition & 1 deletion service/history/historyEngine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5189,7 +5189,7 @@ func copyTimerInfo(sourceInfo *persistence.TimerInfo) *persistence.TimerInfo {
TimerID: sourceInfo.TimerID,
StartedID: sourceInfo.StartedID,
ExpiryTime: sourceInfo.ExpiryTime,
TaskID: sourceInfo.TaskID,
TaskStatus: sourceInfo.TaskStatus,
}
}

Expand Down
2 changes: 1 addition & 1 deletion service/history/mutableStateBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2978,7 +2978,7 @@ func (e *mutableStateBuilder) ReplicateTimerStartedEvent(
TimerID: timerID,
ExpiryTime: expiryTime,
StartedID: event.GetEventId(),
TaskID: timerTaskStatusNone,
TaskStatus: timerTaskStatusNone,
}

e.pendingTimerInfoIDs[timerID] = ti
Expand Down
5 changes: 1 addition & 4 deletions service/history/mutableStateTaskRefresher.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,7 @@ func (r *mutableStateTaskRefresherImpl) refreshTasksForTimer(

for _, timerInfo := range pendingTimerInfos {
// clear all timer task mask for later timer task re-generation
// TaskID is a misleading variable, it actually serves
// the purpose of indicating whether a timer task is
// generated for this timer info
timerInfo.TaskID = timerTaskStatusNone
timerInfo.TaskStatus = timerTaskStatusNone

// need to update user timer task mask for which task is generated
if err := mutableState.UpdateUserTimer(
Expand Down
2 changes: 1 addition & 1 deletion service/history/stateBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ func (s *stateBuilderSuite) TestApplyEvents_EventTypeTimerStarted() {
TimerID: timerID,
ExpiryTime: time.Unix(0, event.GetTimestamp()).Add(time.Duration(timeoutSecond) * time.Second),
StartedID: event.GetEventId(),
TaskID: timerTaskStatusNone,
TaskStatus: timerTaskStatusNone,
}
s.mockMutableState.EXPECT().ReplicateTimerStartedEvent(event).Return(ti, nil).Times(1)
s.mockUpdateVersion(event)
Expand Down
4 changes: 2 additions & 2 deletions service/history/timerSequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (t *timerSequenceImpl) createNextUserTimer() (bool, error) {
}
// mark timer task mask as indication that timer task is generated
// here TaskID is misleading attr, should be called timer created flag or something
timerInfo.TaskID = timerTaskStatusCreated
timerInfo.TaskStatus = timerTaskStatusCreated
if err := t.mutableState.UpdateUserTimer(timerInfo); err != nil {
return false, err
}
Expand Down Expand Up @@ -240,7 +240,7 @@ func (t *timerSequenceImpl) getUserTimerTimeout(
eventID: timerInfo.StartedID,
timestamp: timerInfo.ExpiryTime,
timerType: timerTypeStartToClose,
timerCreated: timerInfo.TaskID == timerTaskStatusCreated,
timerCreated: timerInfo.TaskStatus == timerTaskStatusCreated,
attempt: 0,
}
}
Expand Down
16 changes: 8 additions & 8 deletions service/history/timerSequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *timerSequenceSuite) TestCreateNextUserTimer_AlreadyCreated() {
TimerID: "some random timer ID",
StartedID: 456,
ExpiryTime: now.Add(100 * time.Second),
TaskID: timerTaskStatusCreated,
TaskStatus: timerTaskStatusCreated,
}
timerInfos := map[string]*persistence.TimerInfo{timerInfo.TimerID: timerInfo}
s.mockMutableState.EXPECT().GetPendingTimerInfos().Return(timerInfos).Times(1)
Expand All @@ -99,14 +99,14 @@ func (s *timerSequenceSuite) TestCreateNextUserTimer_NotCreated() {
TimerID: "some random timer ID",
StartedID: 456,
ExpiryTime: now.Add(100 * time.Second),
TaskID: timerTaskStatusNone,
TaskStatus: timerTaskStatusNone,
}
timerInfos := map[string]*persistence.TimerInfo{timerInfo.TimerID: timerInfo}
s.mockMutableState.EXPECT().GetPendingTimerInfos().Return(timerInfos).Times(1)
s.mockMutableState.EXPECT().GetUserTimerInfoByEventID(timerInfo.StartedID).Return(timerInfo, true).Times(1)

var timerInfoUpdated = *timerInfo // make a copy
timerInfoUpdated.TaskID = timerTaskStatusCreated
timerInfoUpdated.TaskStatus = timerTaskStatusCreated
s.mockMutableState.EXPECT().UpdateUserTimer(&timerInfoUpdated).Return(nil).Times(1)
s.mockMutableState.EXPECT().GetCurrentVersion().Return(currentVersion).Times(1)
s.mockMutableState.EXPECT().AddTimerTasks(&persistence.UserTimerTask{
Expand Down Expand Up @@ -203,7 +203,7 @@ func (s *timerSequenceSuite) TestLoadAndSortUserTimers_One() {
TimerID: "some random timer ID",
StartedID: 456,
ExpiryTime: now.Add(100 * time.Second),
TaskID: timerTaskStatusCreated,
TaskStatus: timerTaskStatusCreated,
}
timerInfos := map[string]*persistence.TimerInfo{timerInfo.TimerID: timerInfo}
s.mockMutableState.EXPECT().GetPendingTimerInfos().Return(timerInfos).Times(1)
Expand All @@ -225,14 +225,14 @@ func (s *timerSequenceSuite) TestLoadAndSortUserTimers_Multiple() {
TimerID: "some random timer ID",
StartedID: 456,
ExpiryTime: now.Add(100 * time.Second),
TaskID: timerTaskStatusCreated,
TaskStatus: timerTaskStatusCreated,
}
timerInfo2 := &persistence.TimerInfo{
Version: 1234,
TimerID: "other random timer ID",
StartedID: 4567,
ExpiryTime: now.Add(200 * time.Second),
TaskID: timerTaskStatusNone,
TaskStatus: timerTaskStatusNone,
}
timerInfos := map[string]*persistence.TimerInfo{
timerInfo1.TimerID: timerInfo1,
Expand Down Expand Up @@ -608,7 +608,7 @@ func (s *timerSequenceSuite) TestGetUserTimerTimeout() {
TimerID: "some random timer ID",
StartedID: 456,
ExpiryTime: now.Add(100 * time.Second),
TaskID: timerTaskStatusCreated,
TaskStatus: timerTaskStatusCreated,
}

expectedTimerSequence := &timerSequenceID{
Expand All @@ -622,7 +622,7 @@ func (s *timerSequenceSuite) TestGetUserTimerTimeout() {
timerSequence := s.timerSequence.getUserTimerTimeout(timerInfo)
s.Equal(expectedTimerSequence, timerSequence)

timerInfo.TaskID = timerTaskStatusNone
timerInfo.TaskStatus = timerTaskStatusNone
expectedTimerSequence.timerCreated = false
timerSequence = s.timerSequence.getUserTimerTimeout(timerInfo)
s.Equal(expectedTimerSequence, timerSequence)
Expand Down
2 changes: 1 addition & 1 deletion service/history/workflowResetor.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func (w *workflowResetorImpl) generateTimerTasksForReset(
// user timer task
if len(msBuilder.GetPendingTimerInfos()) > 0 {
for _, timerInfo := range msBuilder.GetPendingTimerInfos() {
timerInfo.TaskID = timerTaskStatusNone
timerInfo.TaskStatus = timerTaskStatusNone
if err := msBuilder.UpdateUserTimer(timerInfo); err != nil {
return nil, err
}
Expand Down

0 comments on commit bc1ebff

Please sign in to comment.