Skip to content

Commit 97664ef

Browse files
judahschvimerevergreen
authored andcommitted
SERVER-43045 dbhash checks all replicated collections
1 parent cd96f9b commit 97664ef

File tree

6 files changed

+46
-22
lines changed

6 files changed

+46
-22
lines changed

jstests/replsets/dbhash_system_collections.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function checkDbHash(mongo) {
3232

3333
var replicatedAdminSystemCollections = [
3434
'system.backup_users',
35+
'system.keys',
3536
'system.new_users',
3637
'system.roles',
3738
'system.version',

src/mongo/db/commands/dbhash.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,6 @@ class DBHashCmd : public ErrmsgCommandDeprecated {
212212
md5_state_t globalState;
213213
md5_init(&globalState);
214214

215-
// A set of 'system' collections that are replicated, and therefore included in the db hash.
216-
const std::set<StringData> replicatedSystemCollections{"system.backup_users",
217-
"system.js",
218-
"system.new_users",
219-
"system.roles",
220-
"system.users",
221-
"system.version",
222-
"system.views"};
223-
224215
std::map<std::string, std::string> collectionToHashMap;
225216
std::map<std::string, OptionalCollectionUUID> collectionToUUIDMap;
226217
std::set<std::string> cappedCollectionSet;
@@ -235,11 +226,9 @@ class DBHashCmd : public ErrmsgCommandDeprecated {
235226
return false;
236227
}
237228

238-
// Only include 'system' collections that are replicated.
239-
bool isReplicatedSystemColl =
240-
(replicatedSystemCollections.count(collNss.coll().toString()) > 0);
241-
if (collNss.isSystem() && !isReplicatedSystemColl)
229+
if (repl::ReplicationCoordinator::isOplogDisabledForNS(collNss)) {
242230
return true;
231+
}
243232

244233
if (collNss.coll().startsWith("tmp.mr.")) {
245234
// We skip any incremental map reduce collections as they also aren't

src/mongo/db/namespace_string.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ class NamespaceString {
251251
* Returns whether a namespace is replicated, based only on its string value. One notable
252252
* omission is that map reduce `tmp.mr` collections may or may not be replicated. Callers must
253253
* decide how to handle that case separately.
254+
*
255+
* Note: This function considers "replicated" to be any namespace that should be timestamped.
256+
* Not all collections that are timestamped are replicated explicitly through the oplog.
257+
* Drop-pending collections are a notable example. Please use
258+
* ReplicationCoordinator::isOplogDisabledForNS to determine if a namespace gets logged in the
259+
* oplog.
254260
*/
255261
bool isReplicated() const;
256262

src/mongo/db/repl/replication_coordinator.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void ReplicationCoordinator::set(ServiceContext* service,
6666
}
6767

6868
bool ReplicationCoordinator::isOplogDisabledFor(OperationContext* opCtx,
69-
const NamespaceString& nss) {
69+
const NamespaceString& nss) const {
7070
if (getReplicationMode() == ReplicationCoordinator::modeNone) {
7171
return true;
7272
}
@@ -75,7 +75,17 @@ bool ReplicationCoordinator::isOplogDisabledFor(OperationContext* opCtx,
7575
return true;
7676
}
7777

78-
if (nss.db() == "local") {
78+
if (ReplicationCoordinator::isOplogDisabledForNS(nss)) {
79+
return true;
80+
}
81+
82+
fassert(28626, opCtx->recoveryUnit());
83+
84+
return false;
85+
}
86+
87+
bool ReplicationCoordinator::isOplogDisabledForNS(const NamespaceString& nss) {
88+
if (nss.isLocal()) {
7989
return true;
8090
}
8191

@@ -87,8 +97,6 @@ bool ReplicationCoordinator::isOplogDisabledFor(OperationContext* opCtx,
8797
return true;
8898
}
8999

90-
fassert(28626, opCtx->recoveryUnit());
91-
92100
return false;
93101
}
94102

src/mongo/db/repl/replication_coordinator.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,17 @@ class ReplicationCoordinator : public SyncSourceSelector {
890890
virtual void signalDropPendingCollectionsRemovedFromStorage() = 0;
891891

892892
/**
893-
* Returns true if logOp() should not append an entry to the oplog for the namespace for this
894-
* operation.
893+
* Returns true if logOp() should not append an entry to the oplog for this operation.
895894
*/
896-
bool isOplogDisabledFor(OperationContext* opCtx, const NamespaceString& nss);
895+
bool isOplogDisabledFor(OperationContext* opCtx, const NamespaceString& nss) const;
896+
897+
/**
898+
* Returns true if logOp() should never append an entry to the oplog for this namespace. logOp()
899+
* may not want to append an entry to the oplog for other reasons, even if the namespace is
900+
* allowed to be replicated in the oplog (e.g. being a secondary).
901+
*/
902+
static bool isOplogDisabledForNS(const NamespaceString& nss);
903+
897904

898905
/**
899906
* Returns the stable timestamp that the storage engine recovered to on startup. If the

src/mongo/shell/replsettest.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ var ReplSetTest = function(opts) {
9393
var _allocatePortForBridge;
9494

9595
var _causalConsistency;
96+
var _isMultiVersion = false;
9697

9798
// Some code still references kDefaultTimeoutMS as a (non-static) member variable, so make sure
9899
// it's still accessible that way.
@@ -1583,8 +1584,12 @@ var ReplSetTest = function(opts) {
15831584
// unreplicated "tmp.mr." collection may be left behind. We remove it from the
15841585
// dbHash command response to avoid an already known case of a mismatch.
15851586
// TODO SERVER-27147: Stop filtering out "tmp.mr." collections.
1587+
//
1588+
// TODO SERVER-43072: Stop filtering out 'system.keys' once 'last-stable' servers
1589+
// return 'system.keys' collections in dbhash responses (when 'last-stable' is 4.4).
15861590
if (cappedCollections.has(collName) ||
1587-
(filterMapReduce && collName.startsWith("tmp.mr."))) {
1591+
(filterMapReduce && collName.startsWith("tmp.mr.") ||
1592+
(_isMultiVersion && collName === "system.keys"))) {
15881593
delete res.collections[collName];
15891594
// The "uuids" field in the dbHash command response is new as of MongoDB 4.0.
15901595
if (res.hasOwnProperty("uuids")) {
@@ -1979,7 +1984,11 @@ var ReplSetTest = function(opts) {
19791984
// If the primary and secondary have the same hashes for all the
19801985
// collections in the database and there aren't any capped collections,
19811986
// then the hashes for the whole database should match.
1982-
if (primaryDBHash.md5 !== secondaryDBHash.md5) {
1987+
1988+
// TODO SERVER-43072: Remove isMultiVersion exemption once 'last-stable'
1989+
// servers return 'system.keys' collections in dbhash responses (when
1990+
// 'last-stable' is 4.4).
1991+
if (!_isMultiVersion && (primaryDBHash.md5 !== secondaryDBHash.md5)) {
19831992
print(msgPrefix +
19841993
', the primary and secondary have a different hash for ' +
19851994
'the ' + dbName + ' database: ' + tojson(dbHashes));
@@ -2326,6 +2335,10 @@ var ReplSetTest = function(opts) {
23262335
throw new Error("Failed to start node " + n);
23272336
}
23282337

2338+
if (options.binVersion) {
2339+
_isMultiVersion = true;
2340+
}
2341+
23292342
// Make sure to call _addPath, otherwise folders won't be cleaned.
23302343
this._addPath(conn.dbpath);
23312344

0 commit comments

Comments
 (0)