Skip to content

Commit 9bd5c07

Browse files
committed
accommodate 4.2 indexes that have “ns”
1 parent 9904357 commit 9bd5c07

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

internal/verifier/migration_verifier.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/10gen/migration-verifier/internal/util"
2424
"github.com/10gen/migration-verifier/internal/uuidutil"
2525
"github.com/10gen/migration-verifier/mbson"
26+
"github.com/10gen/migration-verifier/mslices"
2627
"github.com/10gen/migration-verifier/option"
2728
"github.com/olekukonko/tablewriter"
2829
"github.com/pkg/errors"
@@ -887,14 +888,44 @@ func (verifier *Verifier) doIndexSpecsMatch(ctx context.Context, srcSpec bson.Ra
887888
coll.DeleteOne(ctx, bson.M{"_id": insert.InsertedID})
888889
}()
889890

890-
count, err := coll.CountDocuments(
891+
cursor, err := coll.Aggregate(
891892
ctx,
892-
bson.D{
893-
{"_id", insert.InsertedID},
894-
{"spec", dstSpec},
893+
mongo.Pipeline{
894+
// Select our source spec.
895+
{{"$match", bson.D{{"_id", insert.InsertedID}}}},
896+
897+
// Add the destination spec.
898+
{{"$addFields", bson.D{
899+
{"dstSpec", dstSpec},
900+
}}},
901+
902+
// Remove the “ns” field from both. (NB: 4.4+ don’t create these,
903+
// though in-place upgrades may cause them still to exist.)
904+
{{"$addFields", bson.D{
905+
{"spec.ns", "$$REMOVE"},
906+
{"dstSpec.ns", "$$REMOVE"},
907+
}}},
908+
909+
// Now check to be sure that those specs match.
910+
{{"$match", bson.D{
911+
{"$expr", bson.D{
912+
{"$eq", mslices.Of("$spec", "$dstSpec")},
913+
}},
914+
}}},
895915
},
896916
)
897917

918+
if err != nil {
919+
return false, errors.Wrap(err, "failed to check index specification match in metadata")
920+
}
921+
var docs []bson.Raw
922+
err = cursor.All(ctx, &docs)
923+
if err != nil {
924+
return false, errors.Wrap(err, "failed to parse index specification match’s result")
925+
}
926+
927+
count := len(docs)
928+
898929
switch count {
899930
case 0:
900931
return false, nil
@@ -1212,7 +1243,6 @@ func (verifier *Verifier) verifyMetadataAndPartitionCollection(ctx context.Conte
12121243
partitions, shardKeys, docsCount, bytesCount, err := verifier.partitionAndInspectNamespace(ctx, srcNs)
12131244
if err != nil {
12141245
task.Status = verificationTaskFailed
1215-
12161246
verifier.logger.Error().Msgf("[Worker %d] Error partitioning collection: %+v", workerNum, err)
12171247
return
12181248
}

internal/verifier/migration_verifier_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,21 @@ func (suite *IntegrationTestSuite) TestVerifierCompareIndexSpecs() {
10191019
},
10201020
shouldMatch: true,
10211021
},
1022+
1023+
{
1024+
label: "ignore `ns` field",
1025+
src: bson.D{
1026+
{"name", "testIndex"},
1027+
{"key", bson.M{"foo": 123}},
1028+
{"ns", "foo.bar"},
1029+
},
1030+
dst: bson.D{
1031+
{"name", "testIndex"},
1032+
{"key", bson.M{"foo": 123}},
1033+
},
1034+
shouldMatch: true,
1035+
},
1036+
10221037
{
10231038
label: "ignore number types",
10241039
src: bson.D{

0 commit comments

Comments
 (0)