Skip to content

Commit 76c9871

Browse files
authored
REP-5274: Ignore the “background” field in index specifications. (#55)
This fixes breakage found in mongosync’s testing after REP-5274.
1 parent da9b7a6 commit 76c9871

File tree

2 files changed

+69
-6
lines changed

2 files changed

+69
-6
lines changed

internal/verifier/migration_verifier.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/10gen/migration-verifier/option"
2828
"github.com/olekukonko/tablewriter"
2929
"github.com/pkg/errors"
30+
"github.com/samber/lo"
3031
"go.mongodb.org/mongo-driver/bson"
3132
"go.mongodb.org/mongo-driver/bson/primitive"
3233
"go.mongodb.org/mongo-driver/mongo"
@@ -888,6 +889,14 @@ func (verifier *Verifier) doIndexSpecsMatch(ctx context.Context, srcSpec bson.Ra
888889
return true, nil
889890
}
890891

892+
var fieldsToRemove = []string{
893+
// v4.4 stopped adding “ns” to index fields.
894+
"ns",
895+
896+
// v4.2+ ignores this field.
897+
"background",
898+
}
899+
891900
// Next check to see if the only differences are type differences.
892901
// (We can safely use $documents here since this is against the metadata
893902
// cluster, which we can require to be v5+.)
@@ -904,12 +913,13 @@ func (verifier *Verifier) doIndexSpecsMatch(ctx context.Context, srcSpec bson.Ra
904913
{"dstSpec", dstSpec},
905914
}}},
906915

907-
// Remove the “ns” field from both. (NB: 4.4+ don’t create these,
908-
// though in-place upgrades may cause them still to exist.)
909-
{{"$addFields", bson.D{
910-
{"spec.ns", "$$REMOVE"},
911-
{"dstSpec.ns", "$$REMOVE"},
912-
}}},
916+
{{"$unset", lo.Reduce(
917+
fieldsToRemove,
918+
func(cur []string, field string, _ int) []string {
919+
return append(cur, "spec."+field, "dstSpec."+field)
920+
},
921+
[]string{},
922+
)}},
913923

914924
// Now check to be sure that those specs match.
915925
{{"$match", bson.D{

internal/verifier/migration_verifier_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,59 @@ func (suite *IntegrationTestSuite) TestVerifierWithFilter() {
14931493
<-checkDoneChan
14941494
}
14951495

1496+
func (suite *IntegrationTestSuite) TestBackgroundInIndexSpec() {
1497+
ctx := suite.Context()
1498+
1499+
srcDB := suite.srcMongoClient.Database(suite.DBNameForTest())
1500+
dstDB := suite.dstMongoClient.Database(suite.DBNameForTest())
1501+
1502+
suite.Require().NoError(
1503+
srcDB.RunCommand(
1504+
ctx,
1505+
bson.D{
1506+
{"createIndexes", "mycoll"},
1507+
{"indexes", []bson.D{
1508+
{
1509+
{"name", "index1"},
1510+
{"key", bson.D{{"someField", 1}}},
1511+
},
1512+
}},
1513+
},
1514+
).Err(),
1515+
)
1516+
1517+
suite.Require().NoError(
1518+
dstDB.RunCommand(
1519+
ctx,
1520+
bson.D{
1521+
{"createIndexes", "mycoll"},
1522+
{"indexes", []bson.D{
1523+
{
1524+
{"name", "index1"},
1525+
{"key", bson.D{{"someField", 1}}},
1526+
{"background", 1},
1527+
},
1528+
}},
1529+
},
1530+
).Err(),
1531+
)
1532+
1533+
verifier := suite.BuildVerifier()
1534+
verifier.SetSrcNamespaces([]string{srcDB.Name() + ".mycoll"})
1535+
verifier.SetDstNamespaces([]string{dstDB.Name() + ".mycoll"})
1536+
verifier.SetNamespaceMap()
1537+
1538+
runner := RunVerifierCheck(ctx, suite.T(), verifier)
1539+
runner.AwaitGenerationEnd()
1540+
1541+
status, err := verifier.GetVerificationStatus()
1542+
suite.Require().NoError(err)
1543+
suite.Assert().Zero(
1544+
status.MetadataMismatchTasks,
1545+
"no metadata mismatch",
1546+
)
1547+
}
1548+
14961549
func (suite *IntegrationTestSuite) TestPartitionWithFilter() {
14971550
zerolog.SetGlobalLevel(zerolog.DebugLevel)
14981551

0 commit comments

Comments
 (0)