Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions internal/verifier/migration_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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+.)
Expand All @@ -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{
Expand Down
53 changes: 53 additions & 0 deletions internal/verifier/migration_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down