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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
'use strict';
/**
* Returns true if the process is a mongos, and false otherwise.
*
*/
function isMongos(db) {
// Run isMaster directly on the database's session's client to bypass any session machinery.
const res = assert.commandWorked(db.getSession().getClient().adminCommand('ismaster'));
return 'isdbgrid' === res.msg;
}
/**
* Returns true if the process is a mongod, and false otherwise.
*
*/
function isMongod(db) {
return !isMongos(db);
}
/**
* Returns true if the process is a mongod configsvr, and false otherwise.
*
*/
function isMongodConfigsvr(db) {
if (!isMongod(db)) {
return false;
}
var res = db.adminCommand('getCmdLineOpts');
assert.commandWorked(res);
return res.parsed && res.parsed.sharding && res.parsed.sharding.clusterRole === 'configsvr';
}
/**
* Returns the name of the current storage engine.
*
* Throws an error if db is connected to a mongos, or if there is no reported storage engine.
*/
function getStorageEngineName(db) {
var status = db.serverStatus();
assert.commandWorked(status);
assert(isMongod(db), 'no storage engine is reported when connected to mongos');
assert.neq(
'undefined', typeof status.storageEngine, 'missing storage engine info in server status');
return status.storageEngine.name;
}
/**
* Returns true if the current storage engine is wiredTiger, and false otherwise.
*/
function isWiredTiger(db) {
return getStorageEngineName(db) === 'wiredTiger';
}
/**
* Returns true if the current storage engine is ephemeralForTest, and false otherwise.
*/
function isEphemeralForTest(db) {
return getStorageEngineName(db) === 'ephemeralForTest';
}
/**
* Returns true if the current storage engine is ephemeral, and false otherwise.
*/
function isEphemeral(db) {
var engine = getStorageEngineName(db);
return (engine === 'inMemory') || (engine === 'ephemeralForTest');
}
/**
* Returns true if the current storage engine supports committed reads.
*
* Throws an error if db is connected to a mongos, or if there is no reported storage engine.
*/
function supportsCommittedReads(db) {
var status = db.serverStatus();
assert.commandWorked(status);
assert(isMongod(db), 'no storage engine is reported when connected to mongos');
assert.neq(
'undefined', typeof status.storageEngine, 'missing storage engine info in server status');
return status.storageEngine.supportsCommittedReads;
}
|