Skip to content

Commit 9fdd7b1

Browse files
authored
REP-6743 Ignore MongoDB-internal databases (#180)
MongoDB will soon designate `__mdb_internal` as a prefix for MongoDB-internal services. This changeset teaches Migration Verifier to ignore databases with that prefix.
1 parent d817822 commit 9fdd7b1

File tree

3 files changed

+57
-9
lines changed

3 files changed

+57
-9
lines changed

internal/verifier/change_stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (csr *ChangeStreamReader) GetChangeStreamFilter() (pipeline mongo.Pipeline)
8787
{{"$match", util.ExcludePrefixesQuery(
8888
"ns.db",
8989
append(
90-
slices.Clone(MongosyncMetaDBPrefixes),
90+
slices.Clone(ExcludedDBPrefixes),
9191
csr.metaDB.Name(),
9292
),
9393
)}},

internal/verifier/list_namespaces.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,26 @@ import (
1212
"go.mongodb.org/mongo-driver/v2/mongo/options"
1313
)
1414

15+
const (
16+
// ExcludedSystemCollPrefix is the prefix of system collections,
17+
// which we ignore.
18+
ExcludedSystemCollPrefix = "system."
19+
20+
// MongoDBInternalDBPrefix is the prefix for MongoDB-internal databases.
21+
// (e.g., Atlas’s availability canary)
22+
MongoDBInternalDBPrefix = "__mdb_internal"
23+
)
24+
1525
var (
16-
MongosyncMetaDBPrefixes = mslices.Of(
26+
ExcludedDBPrefixes = mslices.Of(
27+
// mongosync metadata:
1728
"mongosync_internal_",
1829
"mongosync_reserved_",
30+
MongoDBInternalDBPrefix,
1931
)
20-
)
2132

22-
var (
2333
// ExcludedSystemDBs are system databases that are excluded from verification.
2434
ExcludedSystemDBs = []string{"admin", "config", "local"}
25-
26-
// ExcludedSystemCollPrefix is the prefix of system collections,
27-
// which we ignore.
28-
ExcludedSystemCollPrefix = "system."
2935
)
3036

3137
// ListAllUserNamespaces lists all the user collections on a cluster,
@@ -52,7 +58,7 @@ func ListAllUserNamespaces(
5258
dbNames, err := client.ListDatabaseNames(ctx, bson.D{
5359
{"$and", []bson.D{
5460
{{"name", bson.D{{"$nin", excluded}}}},
55-
util.ExcludePrefixesQuery("name", MongosyncMetaDBPrefixes),
61+
util.ExcludePrefixesQuery("name", ExcludedDBPrefixes),
5662
}},
5763
})
5864

internal/verifier/migration_verifier_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,48 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
22402240
suite.Require().NoError(runner.Await())
22412241
}
22422242

2243+
func (suite *IntegrationTestSuite) TestMongoDBInternalDB() {
2244+
ctx := suite.Context()
2245+
2246+
dbName := MongoDBInternalDBPrefix + "internalDBTest"
2247+
2248+
_, err := suite.srcMongoClient.
2249+
Database(dbName).
2250+
Collection("foo").
2251+
InsertOne(ctx, bson.D{})
2252+
suite.Require().NoError(err)
2253+
2254+
verifier := suite.BuildVerifier()
2255+
runner := RunVerifierCheck(ctx, suite.T(), verifier)
2256+
2257+
// Dry run generation 0 to make sure change stream reader is started.
2258+
suite.Require().NoError(runner.AwaitGenerationEnd())
2259+
2260+
status, err := verifier.GetVerificationStatus(ctx)
2261+
suite.Require().NoError(err)
2262+
2263+
suite.Assert().Zero(status.FailedTasks, "gen0 should have no failed tasks: %+v", status)
2264+
2265+
_, err = suite.srcMongoClient.
2266+
Database(dbName).
2267+
Collection("foo").
2268+
InsertOne(ctx, bson.D{})
2269+
suite.Require().NoError(err)
2270+
2271+
suite.Require().NoError(runner.StartNextGeneration())
2272+
suite.Require().NoError(runner.AwaitGenerationEnd())
2273+
status, err = verifier.GetVerificationStatus(ctx)
2274+
suite.Require().NoError(err)
2275+
suite.Assert().Zero(status.FailedTasks, "gen1 should have no failed tasks: %+v", status)
2276+
2277+
suite.Require().NoError(verifier.WritesOff(ctx))
2278+
suite.Require().NoError(runner.Await())
2279+
2280+
status, err = verifier.GetVerificationStatus(ctx)
2281+
suite.Require().NoError(err)
2282+
suite.Assert().Zero(status.FailedTasks, "end should have no failed tasks: %+v", status)
2283+
}
2284+
22432285
func (suite *IntegrationTestSuite) TestVerifierWithFilter() {
22442286
zerolog.SetGlobalLevel(zerolog.DebugLevel)
22452287

0 commit comments

Comments
 (0)