Skip to content

Commit 8d47f5a

Browse files
authored
V0.3.12 patch (#829)
* make transfer / timer / replication persistence layer accept page token * get task API on the cassandra side should use page size, not limit * apply pagination token to timer ack manager * move duplicated transfer code to one place * modify test to force pagination * bugfix: queue ack manager should call processor's complete task fn * do not keep the lock when doing query
1 parent 476c9bb commit 8d47f5a

21 files changed

+653
-449
lines changed

common/persistence/cassandraPersistence.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ const (
686686
`and run_id = ? ` +
687687
`and visibility_ts = ? ` +
688688
`and task_id > ? ` +
689-
`and task_id <= ? LIMIT ?`
689+
`and task_id <= ?`
690690

691691
templateGetReplicationTasksQuery = `SELECT replication ` +
692692
`FROM executions ` +
@@ -697,7 +697,7 @@ const (
697697
`and run_id = ? ` +
698698
`and visibility_ts = ? ` +
699699
`and task_id > ? ` +
700-
`and task_id <= ? LIMIT ?`
700+
`and task_id <= ?`
701701

702702
templateCompleteTransferTaskQuery = `DELETE FROM executions ` +
703703
`WHERE shard_id = ? ` +
@@ -716,7 +716,7 @@ const (
716716
`and workflow_id = ?` +
717717
`and run_id = ?` +
718718
`and visibility_ts >= ? ` +
719-
`and visibility_ts < ? LIMIT ?`
719+
`and visibility_ts < ?`
720720

721721
templateCompleteTimerTaskQuery = `DELETE FROM executions ` +
722722
`WHERE shard_id = ? ` +
@@ -742,7 +742,7 @@ const (
742742
`and task_list_type = ? ` +
743743
`and type = ? ` +
744744
`and task_id > ? ` +
745-
`and task_id <= ? LIMIT ?`
745+
`and task_id <= ?`
746746

747747
templateCompleteTaskQuery = `DELETE FROM tasks ` +
748748
`WHERE domain_id = ? ` +
@@ -1881,7 +1881,7 @@ func (d *cassandraPersistence) GetTransferTasks(request *GetTransferTasksRequest
18811881
defaultVisibilityTimestamp,
18821882
request.ReadLevel,
18831883
request.MaxReadLevel,
1884-
request.BatchSize)
1884+
).PageSize(request.BatchSize).PageState(request.NextPageToken)
18851885

18861886
iter := query.Iter()
18871887
if iter == nil {
@@ -1899,6 +1899,9 @@ func (d *cassandraPersistence) GetTransferTasks(request *GetTransferTasksRequest
18991899

19001900
response.Tasks = append(response.Tasks, t)
19011901
}
1902+
nextPageToken := iter.PageState()
1903+
response.NextPageToken = make([]byte, len(nextPageToken))
1904+
copy(response.NextPageToken, nextPageToken)
19021905

19031906
if err := iter.Close(); err != nil {
19041907
return nil, &workflow.InternalServiceError{
@@ -1922,7 +1925,7 @@ func (d *cassandraPersistence) GetReplicationTasks(request *GetReplicationTasksR
19221925
defaultVisibilityTimestamp,
19231926
request.ReadLevel,
19241927
request.MaxReadLevel,
1925-
request.BatchSize)
1928+
).PageSize(request.BatchSize).PageState(request.NextPageToken)
19261929

19271930
iter := query.Iter()
19281931
if iter == nil {
@@ -1940,6 +1943,9 @@ func (d *cassandraPersistence) GetReplicationTasks(request *GetReplicationTasksR
19401943

19411944
response.Tasks = append(response.Tasks, t)
19421945
}
1946+
nextPageToken := iter.PageState()
1947+
response.NextPageToken = make([]byte, len(nextPageToken))
1948+
copy(response.NextPageToken, nextPageToken)
19431949

19441950
if err := iter.Close(); err != nil {
19451951
return nil, &workflow.InternalServiceError{
@@ -2275,7 +2281,7 @@ func (d *cassandraPersistence) GetTasks(request *GetTasksRequest) (*GetTasksResp
22752281
rowTypeTask,
22762282
request.ReadLevel,
22772283
request.MaxReadLevel,
2278-
request.BatchSize)
2284+
).PageSize(request.BatchSize)
22792285

22802286
iter := query.Iter()
22812287
if iter == nil {
@@ -2348,7 +2354,7 @@ func (d *cassandraPersistence) GetTimerIndexTasks(request *GetTimerIndexTasksReq
23482354
rowTypeTimerRunID,
23492355
minTimestamp,
23502356
maxTimestamp,
2351-
request.BatchSize)
2357+
).PageSize(request.BatchSize).PageState(request.NextPageToken)
23522358

23532359
iter := query.Iter()
23542360
if iter == nil {
@@ -2366,6 +2372,9 @@ func (d *cassandraPersistence) GetTimerIndexTasks(request *GetTimerIndexTasksReq
23662372

23672373
response.Timers = append(response.Timers, t)
23682374
}
2375+
nextPageToken := iter.PageState()
2376+
response.NextPageToken = make([]byte, len(nextPageToken))
2377+
copy(response.NextPageToken, nextPageToken)
23692378

23702379
if err := iter.Close(); err != nil {
23712380
if isThrottlingError(err) {

common/persistence/cassandraPersistence_test.go

Lines changed: 83 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func (s *cassandraPersistenceSuite) TestTransferTasksThroughUpdate() {
405405
s.Nil(err0, "No error expected.")
406406
s.NotEmpty(task0, "Expected non empty task identifier.")
407407

408-
tasks1, err1 := s.GetTransferTasks(1)
408+
tasks1, err1 := s.GetTransferTasks(1, false)
409409
s.Nil(err1, "No error expected.")
410410
s.NotNil(tasks1, "expected valid list of tasks.")
411411
s.Equal(1, len(tasks1), "Expected 1 decision task.")
@@ -429,7 +429,7 @@ func (s *cassandraPersistenceSuite) TestTransferTasksThroughUpdate() {
429429
err2 := s.UpdateWorkflowExecution(updatedInfo, nil, []int64{int64(4)}, int64(3), nil, nil, nil, nil, nil, nil)
430430
s.Nil(err2, "No error expected.")
431431

432-
tasks2, err1 := s.GetTransferTasks(1)
432+
tasks2, err1 := s.GetTransferTasks(1, false)
433433
s.Nil(err1, "No error expected.")
434434
s.NotNil(tasks2, "expected valid list of tasks.")
435435
s.Equal(1, len(tasks2), "Expected 1 decision task.")
@@ -461,7 +461,7 @@ func (s *cassandraPersistenceSuite) TestTransferTasksThroughUpdate() {
461461
s.Nil(err6)
462462
s.Equal(*workflowExecution.RunId, runID6)
463463

464-
tasks3, err7 := s.GetTransferTasks(1)
464+
tasks3, err7 := s.GetTransferTasks(1, false)
465465
s.Nil(err7, "No error expected.")
466466
s.NotNil(tasks3, "expected valid list of tasks.")
467467
s.Equal(1, len(tasks3), "Expected 1 decision task.")
@@ -493,7 +493,7 @@ func (s *cassandraPersistenceSuite) TestCancelTransferTaskTasks() {
493493
s.Nil(err, "No error expected.")
494494
s.NotEmpty(task0, "Expected non empty task identifier.")
495495

496-
taskD, err := s.GetTransferTasks(1)
496+
taskD, err := s.GetTransferTasks(1, false)
497497
s.Equal(1, len(taskD), "Expected 1 decision task.")
498498
err = s.CompleteTransferTask(taskD[0].TaskID)
499499
s.Nil(err)
@@ -519,7 +519,7 @@ func (s *cassandraPersistenceSuite) TestCancelTransferTaskTasks() {
519519
err = s.UpdateWorkflowExecutionWithTransferTasks(updatedInfo1, int64(3), transferTasks, nil)
520520
s.Nil(err, "No error expected.")
521521

522-
tasks1, err := s.GetTransferTasks(1)
522+
tasks1, err := s.GetTransferTasks(1, false)
523523
s.Nil(err, "No error expected.")
524524
s.NotNil(tasks1, "expected valid list of tasks.")
525525
s.Equal(1, len(tasks1), "Expected 1 cancel task.")
@@ -558,7 +558,7 @@ func (s *cassandraPersistenceSuite) TestCancelTransferTaskTasks() {
558558
err = s.UpdateWorkflowExecutionWithTransferTasks(updatedInfo2, int64(3), transferTasks, nil)
559559
s.Nil(err, "No error expected.")
560560

561-
tasks2, err := s.GetTransferTasks(1)
561+
tasks2, err := s.GetTransferTasks(1, false)
562562
s.Nil(err, "No error expected.")
563563
s.NotNil(tasks2, "expected valid list of tasks.")
564564
s.Equal(1, len(tasks2), "Expected 1 cancel task.")
@@ -587,7 +587,7 @@ func (s *cassandraPersistenceSuite) TestSignalTransferTaskTasks() {
587587
s.Nil(err, "No error expected.")
588588
s.NotEmpty(task0, "Expected non empty task identifier.")
589589

590-
taskD, err := s.GetTransferTasks(1)
590+
taskD, err := s.GetTransferTasks(1, false)
591591
s.Equal(1, len(taskD), "Expected 1 decision task.")
592592
err = s.CompleteTransferTask(taskD[0].TaskID)
593593
s.Nil(err)
@@ -613,7 +613,7 @@ func (s *cassandraPersistenceSuite) TestSignalTransferTaskTasks() {
613613
err = s.UpdateWorkflowExecutionWithTransferTasks(updatedInfo1, int64(3), transferTasks, nil)
614614
s.Nil(err, "No error expected.")
615615

616-
tasks1, err := s.GetTransferTasks(1)
616+
tasks1, err := s.GetTransferTasks(1, false)
617617
s.Nil(err, "No error expected.")
618618
s.NotNil(tasks1, "expected valid list of tasks.")
619619
s.Equal(1, len(tasks1), "Expected 1 cancel task.")
@@ -652,7 +652,7 @@ func (s *cassandraPersistenceSuite) TestSignalTransferTaskTasks() {
652652
err = s.UpdateWorkflowExecutionWithTransferTasks(updatedInfo2, int64(3), transferTasks, nil)
653653
s.Nil(err, "No error expected.")
654654

655-
tasks2, err := s.GetTransferTasks(1)
655+
tasks2, err := s.GetTransferTasks(1, false)
656656
s.Nil(err, "No error expected.")
657657
s.NotNil(tasks2, "expected valid list of tasks.")
658658
s.Equal(1, len(tasks2), "Expected 1 cancel task.")
@@ -826,6 +826,70 @@ func (s *cassandraPersistenceSuite) TestLeaseAndUpdateTaskList_Sticky() {
826826
s.NoError(err) // because update with ttl doesn't check rangeID
827827
}
828828

829+
func (s *cassandraPersistenceSuite) TestReplicationTasks() {
830+
domainID := "2466d7de-6602-4ad8-b939-fb8f8c36c711"
831+
workflowExecution := gen.WorkflowExecution{
832+
WorkflowId: common.StringPtr("get-replication-tasks-test"),
833+
RunId: common.StringPtr("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"),
834+
}
835+
836+
task0, err := s.CreateWorkflowExecution(domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil)
837+
s.Nil(err, "No error expected.")
838+
s.NotEmpty(task0, "Expected non empty task identifier.")
839+
taskD, err := s.GetTransferTasks(1, false)
840+
s.Equal(1, len(taskD), "Expected 1 decision task.")
841+
err = s.CompleteTransferTask(taskD[0].TaskID)
842+
s.Nil(err)
843+
844+
state1, err := s.GetWorkflowExecutionInfo(domainID, workflowExecution)
845+
s.Nil(err, "No error expected.")
846+
info1 := state1.ExecutionInfo
847+
s.NotNil(info1, "Valid Workflow info expected.")
848+
updatedInfo1 := copyWorkflowExecutionInfo(info1)
849+
850+
replicationTasks := []Task{
851+
&HistoryReplicationTask{
852+
TaskID: s.GetNextSequenceNumber(),
853+
FirstEventID: int64(1),
854+
NextEventID: int64(3),
855+
Version: 123,
856+
LastReplicationInfo: map[string]*ReplicationInfo{
857+
"dc1": &ReplicationInfo{
858+
Version: int64(3),
859+
LastEventID: int64(1),
860+
},
861+
},
862+
},
863+
&HistoryReplicationTask{
864+
TaskID: s.GetNextSequenceNumber(),
865+
FirstEventID: int64(1),
866+
NextEventID: int64(3),
867+
Version: 456,
868+
LastReplicationInfo: map[string]*ReplicationInfo{
869+
"dc1": &ReplicationInfo{
870+
Version: int64(3),
871+
LastEventID: int64(1),
872+
},
873+
},
874+
},
875+
}
876+
err = s.UpdateWorklowStateAndReplication(updatedInfo1, nil, nil, nil, int64(3), replicationTasks)
877+
s.Nil(err, "No error expected.")
878+
879+
repTasks, err := s.GetReplicationTasks(1, true)
880+
s.Nil(err)
881+
s.Equal(len(replicationTasks), len(repTasks))
882+
883+
for index := range replicationTasks {
884+
s.Equal(replicationTasks[index].GetTaskID(), repTasks[index].GetTaskID())
885+
s.Equal(replicationTasks[index].GetType(), repTasks[index].GetTaskType())
886+
s.Equal(replicationTasks[index].GetVersion(), repTasks[index].GetVersion())
887+
888+
err = s.CompleteReplicationTask(repTasks[index].GetTaskID())
889+
s.Nil(err, "No error expected.")
890+
}
891+
}
892+
829893
func (s *cassandraPersistenceSuite) TestTransferTasks() {
830894
domainID := "8bfb47be-5b57-4d55-9109-5fb35e20b1d7"
831895
workflowExecution := gen.WorkflowExecution{
@@ -838,7 +902,7 @@ func (s *cassandraPersistenceSuite) TestTransferTasks() {
838902
s.Nil(err0, "No error expected.")
839903
s.NotEmpty(task0, "Expected non empty task identifier.")
840904

841-
tasks1, err1 := s.GetTransferTasks(1)
905+
tasks1, err1 := s.GetTransferTasks(1, false)
842906
s.Nil(err1, "No error expected.")
843907
s.NotNil(tasks1, "expected valid list of tasks.")
844908
s.Equal(1, len(tasks1), "Expected 1 decision task.")
@@ -878,7 +942,7 @@ func (s *cassandraPersistenceSuite) TestTransferTasks() {
878942
err2 := s.UpdateWorklowStateAndReplication(updatedInfo, nil, nil, nil, int64(3), tasks)
879943
s.Nil(err2, "No error expected.")
880944

881-
txTasks, err1 := s.GetTransferTasks(100)
945+
txTasks, err1 := s.GetTransferTasks(1, true) // use page size one to force pagination
882946
s.Nil(err1, "No error expected.")
883947
s.NotNil(txTasks, "expected valid list of tasks.")
884948
s.Equal(len(tasks), len(txTasks))
@@ -913,7 +977,7 @@ func (s *cassandraPersistenceSuite) TestTransferTasks() {
913977
err2 = s.CompleteTransferTask(txTasks[5].TaskID)
914978
s.Nil(err2, "No error expected.")
915979

916-
txTasks, err2 = s.GetTransferTasks(100)
980+
txTasks, err2 = s.GetTransferTasks(100, false)
917981
s.Nil(err2, "No error expected.")
918982
s.Empty(txTasks, "expected empty task list.")
919983
}
@@ -947,7 +1011,7 @@ func (s *cassandraPersistenceSuite) TestTimerTasks() {
9471011
err2 := s.UpdateWorkflowExecution(updatedInfo, []int64{int64(4)}, nil, int64(3), tasks, nil, nil, nil, nil, nil)
9481012
s.Nil(err2, "No error expected.")
9491013

950-
timerTasks, err1 := s.GetTimerIndexTasks()
1014+
timerTasks, err1 := s.GetTimerIndexTasks(1, true) // use page size one to force pagination
9511015
s.Nil(err1, "No error expected.")
9521016
s.NotNil(timerTasks, "expected valid list of tasks.")
9531017
s.Equal(len(tasks), len(timerTasks))
@@ -978,7 +1042,7 @@ func (s *cassandraPersistenceSuite) TestTimerTasks() {
9781042
err2 = s.CompleteTimerTask(timerTasks[4].VisibilityTimestamp, timerTasks[4].TaskID)
9791043
s.Nil(err2, "No error expected.")
9801044

981-
timerTasks2, err2 := s.GetTimerIndexTasks()
1045+
timerTasks2, err2 := s.GetTimerIndexTasks(100, false)
9821046
s.Nil(err2, "No error expected.")
9831047
s.Empty(timerTasks2, "expected empty task list.")
9841048
}
@@ -1590,7 +1654,7 @@ func (s *cassandraPersistenceSuite) TestReplicationTransferTaskTasks() {
15901654
s.Nil(err, "No error expected.")
15911655
s.NotEmpty(task0, "Expected non empty task identifier.")
15921656

1593-
taskD, err := s.GetTransferTasks(1)
1657+
taskD, err := s.GetTransferTasks(1, false)
15941658
s.Equal(1, len(taskD), "Expected 1 decision task.")
15951659
err = s.CompleteTransferTask(taskD[0].TaskID)
15961660
s.Nil(err)
@@ -1620,7 +1684,7 @@ func (s *cassandraPersistenceSuite) TestReplicationTransferTaskTasks() {
16201684
err = s.UpdateWorklowStateAndReplication(updatedInfo1, nil, nil, nil, int64(3), replicationTasks)
16211685
s.Nil(err, "No error expected.")
16221686

1623-
tasks1, err := s.GetReplicationTasks(1)
1687+
tasks1, err := s.GetReplicationTasks(1, false)
16241688
s.Nil(err, "No error expected.")
16251689
s.NotNil(tasks1, "expected valid list of tasks.")
16261690
s.Equal(1, len(tasks1), "Expected 1 replication task.")
@@ -1696,13 +1760,13 @@ func (s *cassandraPersistenceSuite) TestWorkflowReplicationState() {
16961760
s.Nil(err0, "No error expected.")
16971761
s.NotEmpty(task0, "Expected non empty task identifier.")
16981762

1699-
taskD, err := s.GetTransferTasks(2)
1763+
taskD, err := s.GetTransferTasks(2, false)
17001764
s.Equal(1, len(taskD), "Expected 1 decision task.")
17011765
s.Equal(TransferTaskTypeDecisionTask, taskD[0].TaskType)
17021766
err = s.CompleteTransferTask(taskD[0].TaskID)
17031767
s.Nil(err)
17041768

1705-
taskR, err := s.GetReplicationTasks(1)
1769+
taskR, err := s.GetReplicationTasks(1, false)
17061770
s.Equal(1, len(taskR), "Expected 1 replication task.")
17071771
tsk := taskR[0]
17081772
s.Equal(ReplicationTaskTypeHistory, tsk.TaskType)
@@ -1791,7 +1855,7 @@ func (s *cassandraPersistenceSuite) TestWorkflowReplicationState() {
17911855
err2 := s.UpdateWorklowStateAndReplication(updatedInfo, updatedReplicationState, nil, nil, int64(3), replicationTasks1)
17921856
s.Nil(err2, "No error expected.")
17931857

1794-
taskR1, err := s.GetReplicationTasks(1)
1858+
taskR1, err := s.GetReplicationTasks(1, false)
17951859
s.Equal(1, len(taskR1), "Expected 1 replication task.")
17961860
tsk1 := taskR1[0]
17971861
s.Equal(ReplicationTaskTypeHistory, tsk1.TaskType)

0 commit comments

Comments
 (0)