Skip to content

Commit 4519c8f

Browse files
MoveTables: remove option to specify source keyspace alias for multi-tenant migrations (#15712)
Signed-off-by: Rohit Nayak <[email protected]>
1 parent ad0a508 commit 4519c8f

File tree

11 files changed

+2036
-2157
lines changed

11 files changed

+2036
-2157
lines changed

go/cmd/vtctldclient/command/vreplication/movetables/movetables.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func registerCommands(root *cobra.Command) {
4848
create.Flags().BoolVar(&createOptions.NoRoutingRules, "no-routing-rules", false, "(Advanced) Do not create routing rules while creating the workflow. See the reference documentation for limitations if you use this flag.")
4949
create.Flags().BoolVar(&createOptions.AtomicCopy, "atomic-copy", false, "(EXPERIMENTAL) A single copy phase is run for all tables from the source. Use this, for example, if your source keyspace has tables which use foreign key constraints.")
5050
create.Flags().StringVar(&createOptions.WorkflowOptions.TenantId, "tenant-id", "", "(EXPERIMENTAL) The tenant ID to use for the MoveTables workflow into a multi-tenant keyspace.")
51-
create.Flags().StringVar(&createOptions.WorkflowOptions.SourceKeyspaceAlias, "source-keyspace-alias", "", "(EXPERIMENTAL) Used currently only for multi-tenant migrations. This value will be used instead of the source keyspace name in the keyspace routing rules.")
5251
create.Flags().BoolVar(&createOptions.WorkflowOptions.StripShardedAutoIncrement, "remove-sharded-auto-increment", true, "If moving the table(s) to a sharded keyspace, remove any auto_increment clauses when copying the schema to the target as sharded keyspaces should rely on either user/application generated values or Vitess sequences to ensure uniqueness.")
5352
base.AddCommand(create)
5453

go/test/endtoend/vreplication/multi_tenant_test.go

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ const (
5252
tenantMigrationStatusMigrating
5353
tenantMigrationStatusMigrated
5454

55-
sourceKeyspaceTemplate = "s%d"
56-
sourceAliasKeyspaceTemplate = "a%d"
57-
targetKeyspaceName = "mt"
55+
sourceKeyspaceTemplate = "s%d"
56+
targetKeyspaceName = "mt"
5857

5958
numTenants = 10
6059
numInitialRowsPerTenant = 10
@@ -130,7 +129,6 @@ func TestMultiTenantSimple(t *testing.T) {
130129

131130
tenantId := int64(1)
132131
sourceKeyspace := getSourceKeyspace(tenantId)
133-
sourceAliasKeyspace := getSourceAliasKeyspace(tenantId)
134132
_, err = vc.AddKeyspace(t, []*Cell{vc.Cells["zone1"]}, sourceKeyspace, "0", stVSchema, stSchema, 1, 0, getInitialTabletIdForTenant(tenantId), nil)
135133
require.NoError(t, err)
136134

@@ -163,19 +161,16 @@ func TestMultiTenantSimple(t *testing.T) {
163161
sourceKeyspace: sourceKeyspace,
164162
createFlags: []string{
165163
"--tenant-id", strconv.FormatInt(tenantId, 10),
166-
"--source-keyspace-alias", sourceAliasKeyspace,
167164
},
168165
})
169166

170167
preSwitchRules := &vschemapb.KeyspaceRoutingRules{
171168
Rules: []*vschemapb.KeyspaceRoutingRule{
172-
{FromKeyspace: "a1", ToKeyspace: "s1"},
173169
{FromKeyspace: "s1", ToKeyspace: "s1"},
174170
},
175171
}
176172
postSwitchRules := &vschemapb.KeyspaceRoutingRules{
177173
Rules: []*vschemapb.KeyspaceRoutingRule{
178-
{FromKeyspace: "a1", ToKeyspace: "mt"},
179174
{FromKeyspace: "s1", ToKeyspace: "mt"},
180175
},
181176
}
@@ -187,25 +182,21 @@ func TestMultiTenantSimple(t *testing.T) {
187182
mt.Create()
188183
validateKeyspaceRoutingRules(t, vc, primaries, rulesMap, false)
189184
// Note: we cannot insert into the target keyspace since that is never routed to the source keyspace.
190-
for _, ks := range []string{sourceKeyspace, sourceAliasKeyspace} {
191-
lastIndex = insertRows(lastIndex, ks)
192-
}
185+
lastIndex = insertRows(lastIndex, sourceKeyspace)
193186
waitForWorkflowState(t, vc, fmt.Sprintf("%s.%s", targetKeyspace, mt.workflowName), binlogdatapb.VReplicationWorkflowState_Running.String())
194187
mt.SwitchReadsAndWrites()
195188
validateKeyspaceRoutingRules(t, vc, primaries, rulesMap, true)
196-
// Note: here we have already switched and we can insert into the target keyspace and it should get reverse
197-
// replicated to the source keyspace. The source and alias are also routed to the target keyspace at this point.
198-
for _, ks := range []string{sourceKeyspace, sourceAliasKeyspace, targetKeyspace} {
199-
lastIndex = insertRows(lastIndex, ks)
200-
}
189+
// Note: here we have already switched, and we can insert into the target keyspace, and it should get reverse
190+
// replicated to the source keyspace. The source keyspace is routed to the target keyspace at this point.
191+
lastIndex = insertRows(lastIndex, sourceKeyspace)
201192
mt.Complete()
202193
require.Zero(t, len(getKeyspaceRoutingRules(t, vc).Rules))
203194
actualRowsInserted := getRowCount(t, vtgateConn, fmt.Sprintf("%s.%s", targetKeyspace, "t1"))
204195
log.Infof("Migration completed, total rows in target: %d", actualRowsInserted)
205196
require.Equal(t, lastIndex, int64(actualRowsInserted))
206197
}
207198

208-
// If switched queries with source/alias qualifiers should execute on target, else on source. Confirm that
199+
// If switched, queries with source qualifiers should execute on target, else on source. Confirm that
209200
// the routing rules are as expected and that the query executes on the expected tablet.
210201
func validateKeyspaceRoutingRules(t *testing.T, vc *VitessCluster, primaries map[string]*cluster.VttabletProcess, rulesMap map[string]*vschemapb.KeyspaceRoutingRules, switched bool) {
211202
currentRules := getKeyspaceRoutingRules(t, vc)
@@ -224,25 +215,19 @@ func validateKeyspaceRoutingRules(t *testing.T, vc *VitessCluster, primaries map
224215
require.ElementsMatch(t, rulesMap["post"].Rules, currentRules.Rules)
225216
validateQueryRoute("mt", "target")
226217
validateQueryRoute("s1", "target")
227-
validateQueryRoute("a1", "target")
228218
} else {
229219
require.ElementsMatch(t, rulesMap["pre"].Rules, currentRules.Rules)
230220
// Note that with multi-tenant migration, we cannot redirect the target keyspace since
231221
// there are multiple source keyspaces and the target has the aggregate of all the tenants.
232222
validateQueryRoute("mt", "target")
233223
validateQueryRoute("s1", "source")
234-
validateQueryRoute("a1", "source")
235224
}
236225
}
237226

238227
func getSourceKeyspace(tenantId int64) string {
239228
return fmt.Sprintf(sourceKeyspaceTemplate, tenantId)
240229
}
241230

242-
func getSourceAliasKeyspace(tenantId int64) string {
243-
return fmt.Sprintf(sourceAliasKeyspaceTemplate, tenantId)
244-
}
245-
246231
func (mtm *multiTenantMigration) insertSomeData(t *testing.T, tenantId int64, keyspace string, numRows int64) {
247232
vtgateConn, closeConn := getVTGateConn()
248233
defer closeConn()
@@ -362,7 +347,7 @@ func (mtm *multiTenantMigration) getLastID(tenantId int64) int64 {
362347
return mtm.lastIDs[tenantId]
363348
}
364349

365-
func (mtm *multiTenantMigration) initTenantData(t *testing.T, tenantId int64, sourceAliasKeyspace string) {
350+
func (mtm *multiTenantMigration) initTenantData(t *testing.T, tenantId int64) {
366351
mtm.insertSomeData(t, tenantId, getSourceKeyspace(tenantId), numInitialRowsPerTenant)
367352
}
368353

@@ -374,16 +359,14 @@ func (mtm *multiTenantMigration) setup(tenantId int64) {
374359
log.Infof("Creating MoveTables for tenant %d", tenantId)
375360
mtm.setLastID(tenantId, 0)
376361
sourceKeyspace := getSourceKeyspace(tenantId)
377-
sourceAliasKeyspace := getSourceAliasKeyspace(tenantId)
378362
_, err := vc.AddKeyspace(mtm.t, []*Cell{vc.Cells["zone1"]}, sourceKeyspace, "0", stVSchema, stSchema,
379363
1, 0, getInitialTabletIdForTenant(tenantId), nil)
380364
require.NoError(mtm.t, err)
381-
mtm.initTenantData(mtm.t, tenantId, sourceAliasKeyspace)
365+
mtm.initTenantData(mtm.t, tenantId)
382366
}
383367

384368
func (mtm *multiTenantMigration) start(tenantId int64) {
385369
sourceKeyspace := getSourceKeyspace(tenantId)
386-
sourceAliasKeyspace := getSourceAliasKeyspace(tenantId)
387370
mtm.setTenantMigrationStatus(tenantId, tenantMigrationStatusMigrating)
388371
mt := newVtctldMoveTables(&moveTablesWorkflow{
389372
workflowInfo: &workflowInfo{
@@ -395,7 +378,6 @@ func (mtm *multiTenantMigration) start(tenantId int64) {
395378
tables: mtm.tables,
396379
createFlags: []string{
397380
"--tenant-id", strconv.FormatInt(tenantId, 10),
398-
"--source-keyspace-alias", sourceAliasKeyspace,
399381
},
400382
})
401383
mtm.setActiveMoveTables(tenantId, mt)
@@ -404,13 +386,11 @@ func (mtm *multiTenantMigration) start(tenantId int64) {
404386

405387
func (mtm *multiTenantMigration) switchTraffic(tenantId int64) {
406388
t := mtm.t
407-
sourceAliasKeyspace := getSourceAliasKeyspace(tenantId)
408389
sourceKeyspaceName := getSourceKeyspace(tenantId)
409390
mt := mtm.getActiveMoveTables(tenantId)
410391
ksWorkflow := fmt.Sprintf("%s.%s", mtm.targetKeyspace, mt.workflowName)
411392
waitForWorkflowState(t, vc, ksWorkflow, binlogdatapb.VReplicationWorkflowState_Running.String())
412-
// we intentionally insert first into the source alias keyspace and then the source keyspace to test routing rules for both.
413-
mtm.insertSomeData(t, tenantId, sourceAliasKeyspace, numAdditionalRowsPerTenant)
393+
mtm.insertSomeData(t, tenantId, sourceKeyspaceName, numAdditionalRowsPerTenant)
414394
mt.SwitchReadsAndWrites()
415395
mtm.insertSomeData(t, tenantId, sourceKeyspaceName, numAdditionalRowsPerTenant)
416396
}

0 commit comments

Comments
 (0)