From 3f3a0158200ee2f5f5297f893bf089ad55cb8342 Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Mon, 25 Nov 2024 11:50:02 -0500 Subject: [PATCH 1/2] =?UTF-8?q?Ignore=20the=20=E2=80=9Cbackground=E2=80=9D?= =?UTF-8?q?=20field=20in=20index=20specifications.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes breakage found in mongosync’s testing after REP-5274. --- internal/verifier/migration_verifier.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/verifier/migration_verifier.go b/internal/verifier/migration_verifier.go index 7a6b0d39..bca4fc0a 100644 --- a/internal/verifier/migration_verifier.go +++ b/internal/verifier/migration_verifier.go @@ -27,6 +27,7 @@ import ( "github.com/10gen/migration-verifier/option" "github.com/olekukonko/tablewriter" "github.com/pkg/errors" + "github.com/samber/lo" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" @@ -888,6 +889,14 @@ func (verifier *Verifier) doIndexSpecsMatch(ctx context.Context, srcSpec bson.Ra return true, nil } + var fieldsToRemove = []string{ + // v4.4 stopped adding “ns” to index fields. + "ns", + + // v4.2+ ignores this field. + "background", + } + // Next check to see if the only differences are type differences. // (We can safely use $documents here since this is against the metadata // cluster, which we can require to be v5+.) @@ -904,12 +913,13 @@ func (verifier *Verifier) doIndexSpecsMatch(ctx context.Context, srcSpec bson.Ra {"dstSpec", dstSpec}, }}}, - // Remove the “ns” field from both. (NB: 4.4+ don’t create these, - // though in-place upgrades may cause them still to exist.) - {{"$addFields", bson.D{ - {"spec.ns", "$$REMOVE"}, - {"dstSpec.ns", "$$REMOVE"}, - }}}, + {{"$unset", lo.Reduce( + fieldsToRemove, + func(cur []string, field string, _ int) []string { + return append(cur, "spec."+field, "dstSpec."+field) + }, + []string{}, + )}}, // Now check to be sure that those specs match. {{"$match", bson.D{ From 2be867a67300a49ed812bb22ccffb9daef4e8f43 Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Mon, 25 Nov 2024 13:19:52 -0500 Subject: [PATCH 2/2] metadata mismatch --- internal/verifier/migration_verifier_test.go | 53 ++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/internal/verifier/migration_verifier_test.go b/internal/verifier/migration_verifier_test.go index 10317f76..2413af92 100644 --- a/internal/verifier/migration_verifier_test.go +++ b/internal/verifier/migration_verifier_test.go @@ -1493,6 +1493,59 @@ func (suite *IntegrationTestSuite) TestVerifierWithFilter() { <-checkDoneChan } +func (suite *IntegrationTestSuite) TestBackgroundInIndexSpec() { + ctx := suite.Context() + + srcDB := suite.srcMongoClient.Database(suite.DBNameForTest()) + dstDB := suite.dstMongoClient.Database(suite.DBNameForTest()) + + suite.Require().NoError( + srcDB.RunCommand( + ctx, + bson.D{ + {"createIndexes", "mycoll"}, + {"indexes", []bson.D{ + { + {"name", "index1"}, + {"key", bson.D{{"someField", 1}}}, + }, + }}, + }, + ).Err(), + ) + + suite.Require().NoError( + dstDB.RunCommand( + ctx, + bson.D{ + {"createIndexes", "mycoll"}, + {"indexes", []bson.D{ + { + {"name", "index1"}, + {"key", bson.D{{"someField", 1}}}, + {"background", 1}, + }, + }}, + }, + ).Err(), + ) + + verifier := suite.BuildVerifier() + verifier.SetSrcNamespaces([]string{srcDB.Name() + ".mycoll"}) + verifier.SetDstNamespaces([]string{dstDB.Name() + ".mycoll"}) + verifier.SetNamespaceMap() + + runner := RunVerifierCheck(ctx, suite.T(), verifier) + runner.AwaitGenerationEnd() + + status, err := verifier.GetVerificationStatus() + suite.Require().NoError(err) + suite.Assert().Zero( + status.MetadataMismatchTasks, + "no metadata mismatch", + ) +} + func (suite *IntegrationTestSuite) TestPartitionWithFilter() { zerolog.SetGlobalLevel(zerolog.DebugLevel)