-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathrun_check_repl_oplogs.js
34 lines (26 loc) · 1.16 KB
/
run_check_repl_oplogs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {ReplSetTest} from "jstests/libs/replsettest.js";
var startTime = Date.now();
assert.neq(typeof db, 'undefined', 'No `db` object, is the shell connected to a mongod?');
let runCheckOnReplSet = function(db) {
let primaryInfo = db.adminCommand("isMaster");
assert(primaryInfo.ismaster,
'shell is not connected to the primary or master node: ' + tojson(primaryInfo));
let testFixture = new ReplSetTest(db.getMongo().host);
testFixture.checkOplogs();
};
if (db.getMongo().isMongos()) {
let configDB = db.getSiblingDB('config');
// Run check on every shard.
configDB.shards.find().forEach(shardEntry => {
let newConn = new Mongo(shardEntry.host, undefined, {gRPC: false});
runCheckOnReplSet(newConn.getDB('admin'));
});
// Run check on config server.
let cmdLineOpts = db.adminCommand({getCmdLineOpts: 1});
let configConn = new Mongo(cmdLineOpts.parsed.sharding.configDB, undefined, {gRPC: false});
runCheckOnReplSet(configConn.getDB('admin'));
} else {
runCheckOnReplSet(db);
}
var totalTime = Date.now() - startTime;
print('Finished consistency oplog checks of cluster in ' + totalTime + ' ms.');