Skip to content

Commit 9d5c94e

Browse files
authored
Add SQL specific tests for replication tasks (#859)
* Some minor code structure change * Add replication tasks tests * Add replication DLQ tasks tests
1 parent c32bb17 commit 9d5c94e

21 files changed

+1175
-140
lines changed

common/persistence/sql/sqlExecutionManager.go

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ func (m *sqlExecutionManager) RangeCompleteTransferTask(
763763
}
764764

765765
func (m *sqlExecutionManager) GetReplicationTask(request *persistence.GetReplicationTaskRequest) (*persistence.GetReplicationTaskResponse, error) {
766-
rows, err := m.db.SelectFromReplicationTasks(&sqlplugin.ReplicationTasksFilter{ShardID: request.ShardID, TaskID: request.TaskID})
766+
rows, err := m.db.SelectFromReplicationTasks(sqlplugin.ReplicationTasksFilter{ShardID: request.ShardID, TaskID: request.TaskID})
767767
if err != nil {
768768
if err == sql.ErrNoRows {
769769
return nil, serviceerror.NewNotFound(fmt.Sprintf("GetReplicationTask operation failed. Task with ID %v not found. Error: %v", request.TaskID, err))
@@ -795,8 +795,8 @@ func (m *sqlExecutionManager) GetReplicationTasks(
795795
return nil, err
796796
}
797797

798-
rows, err := m.db.SelectFromReplicationTasks(
799-
&sqlplugin.ReplicationTasksFilter{
798+
rows, err := m.db.RangeSelectFromReplicationTasks(
799+
sqlplugin.ReplicationTasksRangeFilter{
800800
ShardID: m.shardID,
801801
MinTaskID: readLevel,
802802
MaxTaskID: maxReadLevelInclusive,
@@ -854,11 +854,39 @@ func (m *sqlExecutionManager) populateGetReplicationTasksResponse(
854854
}, nil
855855
}
856856

857+
func (m *sqlExecutionManager) populateGetReplicationDLQTasksResponse(
858+
rows []sqlplugin.ReplicationDLQTasksRow,
859+
requestMaxReadLevel int64,
860+
) (*p.GetReplicationTasksResponse, error) {
861+
if len(rows) == 0 {
862+
return &p.GetReplicationTasksResponse{}, nil
863+
}
864+
865+
var tasks = make([]*persistenceblobs.ReplicationTaskInfo, len(rows))
866+
for i, row := range rows {
867+
info, err := serialization.ReplicationTaskInfoFromBlob(row.Data, row.DataEncoding)
868+
if err != nil {
869+
return nil, err
870+
}
871+
872+
tasks[i] = info
873+
}
874+
var nextPageToken []byte
875+
lastTaskID := rows[len(rows)-1].TaskID
876+
if lastTaskID < requestMaxReadLevel {
877+
nextPageToken = serializePageToken(lastTaskID)
878+
}
879+
return &p.GetReplicationTasksResponse{
880+
Tasks: tasks,
881+
NextPageToken: nextPageToken,
882+
}, nil
883+
}
884+
857885
func (m *sqlExecutionManager) CompleteReplicationTask(
858886
request *p.CompleteReplicationTaskRequest,
859887
) error {
860888

861-
if _, err := m.db.DeleteFromReplicationTasks(&sqlplugin.ReplicationTasksFilter{
889+
if _, err := m.db.DeleteFromReplicationTasks(sqlplugin.ReplicationTasksFilter{
862890
ShardID: m.shardID,
863891
TaskID: request.TaskID,
864892
}); err != nil {
@@ -871,9 +899,10 @@ func (m *sqlExecutionManager) RangeCompleteReplicationTask(
871899
request *p.RangeCompleteReplicationTaskRequest,
872900
) error {
873901

874-
if _, err := m.db.RangeDeleteFromReplicationTasks(&sqlplugin.ReplicationTasksFilter{
875-
ShardID: m.shardID,
876-
TaskID: request.InclusiveEndTaskID,
902+
if _, err := m.db.RangeDeleteFromReplicationTasks(sqlplugin.ReplicationTasksRangeFilter{
903+
ShardID: m.shardID,
904+
MinTaskID: 0,
905+
MaxTaskID: request.InclusiveEndTaskID,
877906
}); err != nil {
878907
return serviceerror.NewInternal(fmt.Sprintf("RangeCompleteReplicationTask operation failed. Error: %v", err))
879908
}
@@ -889,20 +918,17 @@ func (m *sqlExecutionManager) GetReplicationTasksFromDLQ(
889918
return nil, err
890919
}
891920

892-
filter := sqlplugin.ReplicationTasksFilter{
893-
ShardID: m.shardID,
894-
MinTaskID: readLevel,
895-
MaxTaskID: maxReadLevelInclusive,
896-
PageSize: request.BatchSize,
897-
}
898-
rows, err := m.db.SelectFromReplicationTasksDLQ(&sqlplugin.ReplicationTasksDLQFilter{
899-
ReplicationTasksFilter: filter,
900-
SourceClusterName: request.SourceClusterName,
921+
rows, err := m.db.RangeSelectFromReplicationDLQTasks(sqlplugin.ReplicationDLQTasksRangeFilter{
922+
ShardID: m.shardID,
923+
MinTaskID: readLevel,
924+
MaxTaskID: maxReadLevelInclusive,
925+
PageSize: request.BatchSize,
926+
SourceClusterName: request.SourceClusterName,
901927
})
902928

903929
switch err {
904930
case nil:
905-
return m.populateGetReplicationTasksResponse(rows, request.MaxReadLevel)
931+
return m.populateGetReplicationDLQTasksResponse(rows, request.MaxReadLevel)
906932
case sql.ErrNoRows:
907933
return &p.GetReplicationTasksResponse{}, nil
908934
default:
@@ -914,14 +940,10 @@ func (m *sqlExecutionManager) DeleteReplicationTaskFromDLQ(
914940
request *p.DeleteReplicationTaskFromDLQRequest,
915941
) error {
916942

917-
filter := sqlplugin.ReplicationTasksFilter{
918-
ShardID: m.shardID,
919-
TaskID: request.TaskID,
920-
}
921-
922-
if _, err := m.db.DeleteMessageFromReplicationTasksDLQ(&sqlplugin.ReplicationTasksDLQFilter{
923-
ReplicationTasksFilter: filter,
924-
SourceClusterName: request.SourceClusterName,
943+
if _, err := m.db.DeleteFromReplicationDLQTasks(sqlplugin.ReplicationDLQTasksFilter{
944+
ShardID: m.shardID,
945+
TaskID: request.TaskID,
946+
SourceClusterName: request.SourceClusterName,
925947
}); err != nil {
926948
return err
927949
}
@@ -932,15 +954,11 @@ func (m *sqlExecutionManager) RangeDeleteReplicationTaskFromDLQ(
932954
request *p.RangeDeleteReplicationTaskFromDLQRequest,
933955
) error {
934956

935-
filter := sqlplugin.ReplicationTasksFilter{
936-
ShardID: m.shardID,
937-
TaskID: request.ExclusiveBeginTaskID,
938-
InclusiveEndTaskID: request.InclusiveEndTaskID,
939-
}
940-
941-
if _, err := m.db.RangeDeleteMessageFromReplicationTasksDLQ(&sqlplugin.ReplicationTasksDLQFilter{
942-
ReplicationTasksFilter: filter,
943-
SourceClusterName: request.SourceClusterName,
957+
if _, err := m.db.RangeDeleteFromReplicationDLQTasks(sqlplugin.ReplicationDLQTasksRangeFilter{
958+
ShardID: m.shardID,
959+
SourceClusterName: request.SourceClusterName,
960+
MinTaskID: request.ExclusiveBeginTaskID,
961+
MaxTaskID: request.InclusiveEndTaskID,
944962
}); err != nil {
945963
return err
946964
}
@@ -1075,15 +1093,13 @@ func (m *sqlExecutionManager) PutReplicationTaskToDLQ(request *p.PutReplicationT
10751093
return err
10761094
}
10771095

1078-
row := &sqlplugin.ReplicationTaskDLQRow{
1096+
_, err = m.db.InsertIntoReplicationDLQTasks([]sqlplugin.ReplicationDLQTasksRow{{
10791097
SourceClusterName: request.SourceClusterName,
10801098
ShardID: m.shardID,
10811099
TaskID: replicationTask.GetTaskId(),
10821100
Data: blob.Data,
10831101
DataEncoding: blob.Encoding.String(),
1084-
}
1085-
1086-
_, err = m.db.InsertIntoReplicationTasksDLQ(row)
1102+
}})
10871103

10881104
// Tasks are immutable. So it's fine if we already persisted it before.
10891105
// This can happen when tasks are retried (ack and cleanup can have lag on source side).

common/persistence/sql/sqlplugin/definition.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -176,41 +176,6 @@ type (
176176
PageSize *int
177177
}
178178

179-
// ReplicationTasksRow represents a row in replication_tasks table
180-
ReplicationTasksRow struct {
181-
ShardID int32
182-
TaskID int64
183-
Data []byte
184-
DataEncoding string
185-
}
186-
187-
// ReplicationTaskDLQRow represents a row in replication_tasks_dlq table
188-
ReplicationTaskDLQRow struct {
189-
SourceClusterName string
190-
ShardID int32
191-
TaskID int64
192-
Data []byte
193-
DataEncoding string
194-
}
195-
196-
// ReplicationTasksFilter contains the column names within replication_tasks table that
197-
// can be used to filter results through a WHERE clause
198-
ReplicationTasksFilter struct {
199-
ShardID int32
200-
TaskID int64
201-
InclusiveEndTaskID int64
202-
MinTaskID int64
203-
MaxTaskID int64
204-
PageSize int
205-
}
206-
207-
// ReplicationTasksDLQFilter contains the column names within replication_tasks_dlq table that
208-
// can be used to filter results through a WHERE clause
209-
ReplicationTasksDLQFilter struct {
210-
ReplicationTasksFilter
211-
SourceClusterName string
212-
}
213-
214179
// EventsRow represents a row in events table
215180
EventsRow struct {
216181
NamespaceID primitives.UUID

common/persistence/sql/sqlplugin/history.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,4 @@ type (
4242
SelectFromBufferedEvents(filter *BufferedEventsFilter) ([]BufferedEventsRow, error)
4343
DeleteFromBufferedEvents(filter *BufferedEventsFilter) (sql.Result, error)
4444
}
45-
46-
// HistoryReplicationTask is the SQL persistence interface for history nodes and history replication tasks
47-
HistoryReplicationTask interface {
48-
InsertIntoReplicationTasks(rows []ReplicationTasksRow) (sql.Result, error)
49-
// SelectFromReplicationTasks returns one or more rows from replication_tasks table
50-
// Required filter params - {shardID, minTaskID, maxTaskID, pageSize}
51-
SelectFromReplicationTasks(filter *ReplicationTasksFilter) ([]ReplicationTasksRow, error)
52-
// DeleteFromReplicationTasks deletes a row from replication_tasks table
53-
// Required filter params - {shardID, inclusiveEndTaskID}
54-
DeleteFromReplicationTasks(filter *ReplicationTasksFilter) (sql.Result, error)
55-
// DeleteFromReplicationTasks deletes multi rows from replication_tasks table
56-
// Required filter params - {shardID, inclusiveEndTaskID}
57-
RangeDeleteFromReplicationTasks(filter *ReplicationTasksFilter) (sql.Result, error)
58-
59-
// InsertIntoReplicationTasksDLQ puts the replication task into DLQ
60-
InsertIntoReplicationTasksDLQ(row *ReplicationTaskDLQRow) (sql.Result, error)
61-
// SelectFromReplicationTasksDLQ returns one or more rows from replication_tasks_dlq table
62-
// Required filter params - {sourceClusterName, shardID, minTaskID, pageSize}
63-
SelectFromReplicationTasksDLQ(filter *ReplicationTasksDLQFilter) ([]ReplicationTasksRow, error)
64-
// DeleteMessageFromReplicationTasksDLQ deletes one row from replication_tasks_dlq table
65-
// Required filter params - {sourceClusterName, shardID, taskID}
66-
DeleteMessageFromReplicationTasksDLQ(filter *ReplicationTasksDLQFilter) (sql.Result, error)
67-
// RangeDeleteMessageFromReplicationTasksDLQ deletes one or more rows from replication_tasks_dlq table
68-
// Required filter params - {sourceClusterName, shardID, taskID, inclusiveTaskID}
69-
RangeDeleteMessageFromReplicationTasksDLQ(filter *ReplicationTasksDLQFilter) (sql.Result, error)
70-
}
7145
)

common/persistence/sql/sqlplugin/history_activity.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
// The MIT License
2+
//
3+
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
4+
//
5+
// Copyright (c) 2020 Uber Technologies, Inc.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
125
package sqlplugin
226

327
import (

common/persistence/sql/sqlplugin/history_child_workflow.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
// The MIT License
2+
//
3+
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
4+
//
5+
// Copyright (c) 2020 Uber Technologies, Inc.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
125
package sqlplugin
226

327
import (
@@ -33,7 +57,7 @@ type (
3357
InitiatedID *int64
3458
}
3559

36-
// HistoryExecutionChildWorkflow is the SQL persistence interface for history nodes and history execution child workflows
60+
// HistoryExecutionChildWorkflow is the SQL persistence interface for history execution child workflows
3761
HistoryExecutionChildWorkflow interface {
3862
ReplaceIntoChildExecutionInfoMaps(rows []ChildExecutionInfoMapsRow) (sql.Result, error)
3963
// SelectFromChildExecutionInfoMaps returns one or more rows form child_execution_info_maps table

common/persistence/sql/sqlplugin/history_execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type (
7979
RunID primitives.UUID
8080
}
8181

82-
// HistoryExecution is the SQL persistence interface for history nodes and history executions
82+
// HistoryExecution is the SQL persistence interface for history executions
8383
HistoryExecution interface {
8484
InsertIntoExecutions(row *ExecutionsRow) (sql.Result, error)
8585
UpdateExecutions(row *ExecutionsRow) (sql.Result, error)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// The MIT License
2+
//
3+
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
4+
//
5+
// Copyright (c) 2020 Uber Technologies, Inc.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
package sqlplugin
26+
27+
import "database/sql"
28+
29+
type (
30+
// ReplicationDLQTasksRow represents a row in replication_tasks_dlq table
31+
ReplicationDLQTasksRow struct {
32+
SourceClusterName string
33+
ShardID int32
34+
TaskID int64
35+
Data []byte
36+
DataEncoding string
37+
}
38+
39+
// ReplicationDLQTasksFilter contains the column names within replication_tasks_dlq table that
40+
// can be used to filter results through a WHERE clause
41+
ReplicationDLQTasksFilter struct {
42+
ShardID int32
43+
SourceClusterName string
44+
TaskID int64
45+
}
46+
47+
// ReplicationDLQTasksRangeFilter
48+
ReplicationDLQTasksRangeFilter struct {
49+
ShardID int32
50+
SourceClusterName string
51+
MinTaskID int64
52+
MaxTaskID int64
53+
PageSize int
54+
}
55+
56+
// HistoryReplicationDLQTask is the SQL persistence interface for history replication tasks DLQ
57+
HistoryReplicationDLQTask interface {
58+
// InsertIntoReplicationDLQTasks puts the replication task into DLQ
59+
InsertIntoReplicationDLQTasks(row []ReplicationDLQTasksRow) (sql.Result, error)
60+
// SelectFromReplicationDLQTasks returns one or more rows from replication_tasks_dlq table
61+
SelectFromReplicationDLQTasks(filter ReplicationDLQTasksFilter) ([]ReplicationDLQTasksRow, error)
62+
// RangeSelectFromReplicationDLQTasks returns one or more rows from replication_tasks_dlq table
63+
RangeSelectFromReplicationDLQTasks(filter ReplicationDLQTasksRangeFilter) ([]ReplicationDLQTasksRow, error)
64+
// DeleteFromReplicationDLQTasks deletes one row from replication_tasks_dlq table
65+
DeleteFromReplicationDLQTasks(filter ReplicationDLQTasksFilter) (sql.Result, error)
66+
// RangeDeleteFromReplicationDLQTasks deletes one or more rows from replication_tasks_dlq table
67+
// ReplicationDLQTasksRangeFilter - {PageSize} will be ignored
68+
RangeDeleteFromReplicationDLQTasks(filter ReplicationDLQTasksRangeFilter) (sql.Result, error)
69+
}
70+
)

0 commit comments

Comments
 (0)