Skip to content

Commit 7ef102f

Browse files
committed
Extract moveChunk method
... to be able to use it between e2e-tests
1 parent 0ce5793 commit 7ef102f

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

e2e-tests/pkg/tests/sharded/cmd.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ func (c *Cluster) stopBalancer(ctx context.Context, conn *mongo.Client) {
1717
log.Fatalf("ERROR: stopping balancer: %v", err)
1818
}
1919
}
20+
21+
func (c *Cluster) moveChunk(ctx context.Context, db, col string, idx int, to string) {
22+
log.Println("move chunk", idx, "to", to)
23+
err := c.mongos.Conn().Database("admin").RunCommand(
24+
ctx,
25+
bson.D{
26+
{"moveChunk", db + "." + col},
27+
{"find", bson.M{"idx": idx}},
28+
{"to", to},
29+
},
30+
).Err()
31+
if err != nil {
32+
log.Printf("ERROR: moveChunk %s.%s/idx:2000: %v", db, col, err)
33+
}
34+
}

e2e-tests/pkg/tests/sharded/trx.go

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ func (c *Cluster) DistributedTransactions(bcp Backuper, col string) {
4747

4848
c.setupTrxCollection(ctx, col)
4949

50-
c.moveChunk(ctx, col, 0, "rs1")
51-
c.moveChunk(ctx, col, 30, "rs1")
52-
c.moveChunk(ctx, col, 89, "rs1")
53-
c.moveChunk(ctx, col, 99, "rs1")
54-
c.moveChunk(ctx, col, 110, "rs1")
55-
c.moveChunk(ctx, col, 130, "rs1")
56-
c.moveChunk(ctx, col, 131, "rs1")
57-
c.moveChunk(ctx, col, 630, "rsx")
58-
c.moveChunk(ctx, col, 530, "rsx")
59-
c.moveChunk(ctx, col, 631, "rsx")
60-
c.moveChunk(ctx, col, 730, "rsx")
61-
c.moveChunk(ctx, col, 3000, "rsx")
62-
c.moveChunk(ctx, col, 3001, "rsx")
63-
c.moveChunk(ctx, col, 180, "rsx")
64-
c.moveChunk(ctx, col, 199, "rsx")
65-
c.moveChunk(ctx, col, 2001, "rsx")
50+
c.moveChunk(ctx, trxdb, col, 0, "rs1")
51+
c.moveChunk(ctx, trxdb, col, 30, "rs1")
52+
c.moveChunk(ctx, trxdb, col, 89, "rs1")
53+
c.moveChunk(ctx, trxdb, col, 99, "rs1")
54+
c.moveChunk(ctx, trxdb, col, 110, "rs1")
55+
c.moveChunk(ctx, trxdb, col, 130, "rs1")
56+
c.moveChunk(ctx, trxdb, col, 131, "rs1")
57+
c.moveChunk(ctx, trxdb, col, 630, "rsx")
58+
c.moveChunk(ctx, trxdb, col, 530, "rsx")
59+
c.moveChunk(ctx, trxdb, col, 631, "rsx")
60+
c.moveChunk(ctx, trxdb, col, 730, "rsx")
61+
c.moveChunk(ctx, trxdb, col, 3000, "rsx")
62+
c.moveChunk(ctx, trxdb, col, 3001, "rsx")
63+
c.moveChunk(ctx, trxdb, col, 180, "rsx")
64+
c.moveChunk(ctx, trxdb, col, 199, "rsx")
65+
c.moveChunk(ctx, trxdb, col, 2001, "rsx")
6666

6767
_, err = conn.Database(trxdb).Collection(col).DeleteMany(ctx, bson.M{})
6868
if err != nil {
@@ -322,21 +322,6 @@ func (c *Cluster) setupTrxCollection(ctx context.Context, col string) {
322322
}
323323
}
324324

325-
func (c *Cluster) moveChunk(ctx context.Context, col string, idx int, to string) {
326-
log.Println("move chunk", idx, "to", to)
327-
err := c.mongos.Conn().Database("admin").RunCommand(
328-
ctx,
329-
bson.D{
330-
{"moveChunk", trxdb + "." + col},
331-
{"find", bson.M{"idx": idx}},
332-
{"to", to},
333-
},
334-
).Err()
335-
if err != nil {
336-
log.Printf("ERROR: moveChunk %s.%s/idx:2000: %v", trxdb, col, err)
337-
}
338-
}
339-
340325
func (c *Cluster) checkTrxCollection(ctx context.Context, col string, bcp Backuper) {
341326
log.Println("Checking restored data")
342327

0 commit comments

Comments
 (0)