Skip to content

Commit 4cd5fbb

Browse files
Add a reshard cancel test.
Signed-off-by: Arthur Schreiber <[email protected]>
1 parent 6e5203b commit 4cd5fbb

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

go/test/endtoend/vreplication/vreplication_vtctldclient_cli_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,86 @@ func TestVtctldclientCLI(t *testing.T) {
127127

128128
splitShard(t, targetKeyspaceName, reshardWorkflowName, sourceShard, newShards, tablets)
129129
})
130+
131+
t.Run("Reshard Cancel", func(t *testing.T) {
132+
cell := vc.Cells["zone1"]
133+
targetKeyspace := cell.Keyspaces[targetKeyspaceName]
134+
sourceShard := "80-"
135+
newShards := "80-c0,c0-"
136+
require.NoError(t, vc.AddShards(t, []*Cell{cell}, targetKeyspace, newShards, 1, 0, 600, nil))
137+
reshardWorkflowName := "reshard"
138+
139+
tablets := map[string]*cluster.VttabletProcess{
140+
"80-c0": targetKeyspace.Shards["80-c0"].Tablets["zone1-600"].Vttablet,
141+
"c0-": targetKeyspace.Shards["c0-"].Tablets["zone1-700"].Vttablet,
142+
}
143+
144+
sourceReplicaTab = vc.Cells["zone1"].Keyspaces[targetKeyspaceName].Shards["80-"].Tablets["zone1-301"].Vttablet
145+
require.NotNil(t, sourceReplicaTab)
146+
sourceTab = vc.Cells["zone1"].Keyspaces[targetKeyspaceName].Shards["80-"].Tablets["zone1-300"].Vttablet
147+
require.NotNil(t, sourceTab)
148+
149+
targetTab1 = tablets["80-c0"]
150+
require.NotNil(t, targetTab1)
151+
targetTab2 = tablets["c0-"]
152+
require.NotNil(t, targetTab2)
153+
targetReplicaTab1 = vc.Cells["zone1"].Keyspaces[targetKeyspaceName].Shards["80-c0"].Tablets["zone1-601"].Vttablet
154+
require.NotNil(t, targetReplicaTab1)
155+
156+
overrides := map[string]string{
157+
"vreplication_copy_phase_duration": "10h11m12s",
158+
"vreplication_experimental_flags": "7",
159+
"vreplication-parallel-insert-workers": "4",
160+
"vreplication_net_read_timeout": "6000",
161+
"relay_log_max_items": "10000",
162+
}
163+
createFlags := []string{"--auto-start=false", "--defer-secondary-keys=false",
164+
"--on-ddl", "STOP", "--tablet-types", "primary,rdonly", "--tablet-types-in-preference-order=true",
165+
"--all-cells", "--format=json",
166+
"--config-overrides", mapToCSV(overrides),
167+
}
168+
169+
rs := newReshard(vc, &reshardWorkflow{
170+
workflowInfo: &workflowInfo{
171+
vc: vc,
172+
workflowName: reshardWorkflowName,
173+
targetKeyspace: targetKeyspaceName,
174+
},
175+
sourceShards: sourceShard,
176+
targetShards: newShards,
177+
createFlags: createFlags,
178+
}, workflowFlavorVtctld)
179+
180+
rs.Create()
181+
182+
resp := getReshardResponse(rs)
183+
require.NotNil(vc.t, resp)
184+
require.NotNil(vc.t, resp.ShardStreams)
185+
require.Equal(vc.t, len(resp.ShardStreams), 2)
186+
keyspace := "customer"
187+
for _, shard := range []string{"80-c0", "c0-"} {
188+
streams := resp.ShardStreams[fmt.Sprintf("%s/%s", keyspace, shard)]
189+
require.Equal(vc.t, 1, len(streams.Streams))
190+
require.Equal(vc.t, binlogdatapb.VReplicationWorkflowState_Stopped.String(), streams.Streams[0].Status)
191+
}
192+
193+
rs.Start()
194+
waitForWorkflowState(t, vc, fmt.Sprintf("%s.%s", keyspace, workflowName), binlogdatapb.VReplicationWorkflowState_Running.String())
195+
196+
rs.Cancel()
197+
198+
res, err := targetTab1.QueryTablet("show tables", keyspace, true)
199+
require.NoError(t, err)
200+
require.NotNil(t, res)
201+
202+
require.Empty(t, res.Rows)
203+
204+
res, err = targetTab2.QueryTablet("show tables", keyspace, true)
205+
require.NoError(t, err)
206+
require.NotNil(t, res)
207+
208+
require.Empty(t, res.Rows)
209+
})
130210
}
131211

132212
// Tests several create flags and some complete flags and validates that some of them are set correctly for the workflow.

0 commit comments

Comments
 (0)