diff options
-rw-r--r-- | jstests/noPassthrough/compute_mode.js | 54 | ||||
-rw-r--r-- | src/mongo/db/mongod_main.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/query/query_knobs.idl | 13 |
3 files changed, 78 insertions, 2 deletions
diff --git a/jstests/noPassthrough/compute_mode.js b/jstests/noPassthrough/compute_mode.js new file mode 100644 index 00000000000..3f732495db9 --- /dev/null +++ b/jstests/noPassthrough/compute_mode.js @@ -0,0 +1,54 @@ +// Tests compute mode. +// +// @tags: [requires_sharding] +(function() { +'use strict'; + +const mongodOption = { + setParameter: "enableComputeMode=true" +}; + +const shardsvrOption = { + replSet: jsTestName(), + shardsvr: "", + setParameter: "enableComputeMode=true" +}; + +const configsvrOption = { + replSet: jsTestName(), + configsvr: "", + setParameter: "enableComputeMode=true" +}; + +(function testComputeModeInStandaloneMongod() { + const conn = MongoRunner.runMongod(mongodOption); + + const db = conn.getDB("admin"); + const startupLogResults = assert.commandWorked(db.adminCommand({getLog: "startupWarnings"}), + "ERROR from getting startupWarnings"); + assert.gt(startupLogResults.totalLinesWritten, 0, "ERROR from count of startup log message"); + + let warningMsgFound = false; + startupLogResults.log.forEach(log => { + if (log.match("6968201")) { + warningMsgFound = true; + } + }); + assert(warningMsgFound, "ERROR from warning message match"); + + MongoRunner.stopMongod(conn); +})(); + +(function testComputeModeWithReplSet() { + const rs = new ReplSetTest({nodes: 1}); + assert.throws(() => rs.startSet(mongodOption), [], "ERROR from replset test"); +})(); + +(function testComputeModeWithShardedCluster() { + const rs = new ReplSetTest({nodes: 1}); + // This emulates that mongod is running as a shard. + assert.throws(() => rs.startSet(shardsvrOption), [], "ERROR from shardsvr test"); + // This emulates that mongod is running as a config server. + assert.throws(() => rs.startSet(configsvrOption), [], "ERROR from configsvr test"); +})(); +}()); diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp index f1a5d2a4871..b344f20daf4 100644 --- a/src/mongo/db/mongod_main.cpp +++ b/src/mongo/db/mongod_main.cpp @@ -795,6 +795,19 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) { startChangeCollectionExpiredDocumentsRemover(serviceContext); } + if (computeModeEnabled) { + if (!isStandalone || serverGlobalParams.clusterRole != ClusterRole::None) { + LOGV2_ERROR(6968200, "'enableComputeMode' can be used only in standalone server"); + exitCleanly(ExitCode::badOptions); + } + LOGV2_WARNING_OPTIONS( + 6968201, + {logv2::LogTag::kStartupWarnings}, + "There could be security risks in using 'enableComputeMode'. It is recommended to use " + "this mode under an isolated environment and execute the server under a user with " + "restricted access permissions"); + } + // Set up the logical session cache LogicalSessionCacheServer kind = LogicalSessionCacheServer::kStandalone; if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) { diff --git a/src/mongo/db/query/query_knobs.idl b/src/mongo/db/query/query_knobs.idl index e36a60c4df3..118f87bee0a 100644 --- a/src/mongo/db/query/query_knobs.idl +++ b/src/mongo/db/query/query_knobs.idl @@ -723,7 +723,7 @@ server_parameters: expr: 100 * 1024 * 1024 validator: gt: 0 - + internalQueryCardinalityEstimatorMode: description: "Set to select a method for estimating cardinality in the Cascades optimizer." set_at: [ startup, runtime ] @@ -889,7 +889,7 @@ server_parameters: validator: gt: 0 lt: 16777216 - + internalMeasureQueryExecutionTimeInMicroseconds: description: "If true, the explain results include an additional 'executionTimeMicros' field to represent the execution time of each plan stage in microseconds" @@ -915,6 +915,15 @@ server_parameters: cpp_vartype: AtomicWord<bool> default: false + enableComputeMode: + description: "Boolean flag to enable the compute mode in which mongod is used not as a + persistent storage node, but as a worker node for executing queries." + set_at: [ startup ] + cpp_varname: "computeModeEnabled" + cpp_vartype: bool + default: + expr: false + # Note for adding additional query knobs: # # When adding a new query knob, you should consider whether or not you need to add an 'on_update' |