@@ -20,14 +20,12 @@ func TestBcpMatchCluster(t *testing.T) {
2020 expect defs.Status
2121 }
2222 cases := []struct {
23- confsrv string
24- shards []topo.Shard
25- bcps []bcase
23+ shards []topo.Shard
24+ bcps []bcase
2625 }{
2726 {
28- confsrv : "config" ,
2927 shards : []topo.Shard {
30- {RS : "config" },
28+ {ID : "config" , RS : "config" },
3129 {RS : "rs1" },
3230 {RS : "rs2" },
3331 },
@@ -104,7 +102,6 @@ func TestBcpMatchCluster(t *testing.T) {
104102 },
105103 },
106104 {
107- confsrv : "rs1" ,
108105 shards : []topo.Shard {
109106 {RS : "rs1" },
110107 },
@@ -171,7 +168,7 @@ func TestBcpMatchCluster(t *testing.T) {
171168 b .meta .Status = defs .StatusDone
172169 m = append (m , b .meta )
173170 }
174- bcpsMatchCluster (m , "" , "" , c .shards , c . confsrv , nil )
171+ bcpsMatchCluster (m , "" , "" , c .shards , nil )
175172 for i := 0 ; i < len (c .bcps ); i ++ {
176173 if c .bcps [i ].expect != m [i ].Status {
177174 t .Errorf ("wrong status for %s, expect %s, got %s" , m [i ].Name , c .bcps [i ].expect , m [i ].Status )
@@ -316,6 +313,31 @@ func TestBcpMatchRemappedCluster(t *testing.T) {
316313 }
317314}
318315
316+ func TestBackupRequiredRSMap (t * testing.T ) {
317+ t .Run ("sharded cluster uses config shard rs" , func (t * testing.T ) {
318+ sh := backupRequiredRSMap ([]topo.Shard {
319+ {ID : "config" , RS : "cfg" },
320+ {ID : "rs1" , RS : "rs1" },
321+ {ID : "rs2" , RS : "rs2" },
322+ })
323+
324+ if ! sh ["cfg" ] {
325+ t .Fatal ("expected config RS to be marked as required" )
326+ }
327+ if sh ["rs1" ] || sh ["rs2" ] {
328+ t .Fatal ("expected only config RS to be marked as required" )
329+ }
330+ })
331+
332+ t .Run ("sole rs cluster uses only replset" , func (t * testing.T ) {
333+ sh := backupRequiredRSMap ([]topo.Shard {{RS : "rs1" }})
334+
335+ if ! sh ["rs1" ] {
336+ t .Fatal ("expected sole RS to be marked as required" )
337+ }
338+ })
339+ }
340+
319341func checkBcpMatchClusterError (err , target error ) string {
320342 if err == nil && target == nil {
321343 return ""
@@ -354,7 +376,7 @@ func checkBcpMatchClusterError(err, target error) string {
354376
355377func BenchmarkBcpMatchCluster3x10 (b * testing.B ) {
356378 shards := []topo.Shard {
357- {RS : "config" },
379+ {ID : "config" , RS : "config" },
358380 {RS : "rs1" },
359381 {RS : "rs2" },
360382 }
@@ -374,13 +396,13 @@ func BenchmarkBcpMatchCluster3x10(b *testing.B) {
374396 }
375397 b .ResetTimer ()
376398 for i := 0 ; i < b .N ; i ++ {
377- bcpsMatchCluster (bcps , "" , "" , shards , "config" , nil )
399+ bcpsMatchCluster (bcps , "" , "" , shards , nil )
378400 }
379401}
380402
381403func BenchmarkBcpMatchCluster3x100 (b * testing.B ) {
382404 shards := []topo.Shard {
383- {RS : "config" },
405+ {ID : "config" , RS : "config" },
384406 {RS : "rs1" },
385407 {RS : "rs2" },
386408 }
@@ -400,13 +422,13 @@ func BenchmarkBcpMatchCluster3x100(b *testing.B) {
400422 }
401423 b .ResetTimer ()
402424 for i := 0 ; i < b .N ; i ++ {
403- bcpsMatchCluster (bcps , "" , "" , shards , "config" , nil )
425+ bcpsMatchCluster (bcps , "" , "" , shards , nil )
404426 }
405427}
406428
407429func BenchmarkBcpMatchCluster17x100 (b * testing.B ) {
408430 shards := []topo.Shard {
409- {RS : "config" },
431+ {ID : "config" , RS : "config" },
410432 {RS : "rs1" },
411433 {RS : "rs12" },
412434 {RS : "rs112" },
@@ -454,13 +476,13 @@ func BenchmarkBcpMatchCluster17x100(b *testing.B) {
454476 }
455477 b .ResetTimer ()
456478 for i := 0 ; i < b .N ; i ++ {
457- bcpsMatchCluster (bcps , "" , "" , shards , "config" , nil )
479+ bcpsMatchCluster (bcps , "" , "" , shards , nil )
458480 }
459481}
460482
461483func BenchmarkBcpMatchCluster3x1000 (b * testing.B ) {
462484 shards := []topo.Shard {
463- {RS : "config" },
485+ {ID : "config" , RS : "config" },
464486 {RS : "rs1" },
465487 {RS : "rs2" },
466488 }
@@ -480,12 +502,12 @@ func BenchmarkBcpMatchCluster3x1000(b *testing.B) {
480502 }
481503 b .ResetTimer ()
482504 for i := 0 ; i < b .N ; i ++ {
483- bcpsMatchCluster (bcps , "" , "" , shards , "config" , nil )
505+ bcpsMatchCluster (bcps , "" , "" , shards , nil )
484506 }
485507}
486508
487509func BenchmarkBcpMatchCluster1000x1000 (b * testing.B ) {
488- shards := []topo.Shard {{RS : "config" }}
510+ shards := []topo.Shard {{ID : "config" , RS : "config" }}
489511 rss := []backup.BackupReplset {{Name : "config" }}
490512
491513 for i := 0 ; i < 1000 ; i ++ {
@@ -503,13 +525,13 @@ func BenchmarkBcpMatchCluster1000x1000(b *testing.B) {
503525 }
504526 b .ResetTimer ()
505527 for i := 0 ; i < b .N ; i ++ {
506- bcpsMatchCluster (bcps , "" , "" , shards , "config" , nil )
528+ bcpsMatchCluster (bcps , "" , "" , shards , nil )
507529 }
508530}
509531
510532func BenchmarkBcpMatchCluster3x10Err (b * testing.B ) {
511533 shards := []topo.Shard {
512- {RS : "config" },
534+ {ID : "config" , RS : "config" },
513535 {RS : "rs2" },
514536 }
515537
@@ -543,12 +565,12 @@ func BenchmarkBcpMatchCluster3x10Err(b *testing.B) {
543565 })
544566 }
545567 for i := 0 ; i < b .N ; i ++ {
546- bcpsMatchCluster (bcps , "" , "" , shards , "config" , nil )
568+ bcpsMatchCluster (bcps , "" , "" , shards , nil )
547569 }
548570}
549571
550572func BenchmarkBcpMatchCluster1000x1000Err (b * testing.B ) {
551- shards := []topo.Shard {{RS : "config" }}
573+ shards := []topo.Shard {{ID : "config" , RS : "config" }}
552574 rss := []backup.BackupReplset {{Name : "config" }}
553575
554576 for i := 0 ; i < 1000 ; i ++ {
@@ -567,6 +589,6 @@ func BenchmarkBcpMatchCluster1000x1000Err(b *testing.B) {
567589 }
568590 b .ResetTimer ()
569591 for i := 0 ; i < b .N ; i ++ {
570- bcpsMatchCluster (bcps , "" , "" , shards , "config" , nil )
592+ bcpsMatchCluster (bcps , "" , "" , shards , nil )
571593 }
572594}
0 commit comments