0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-34197 Only allow global snapshot reads when test commands are enabled

This commit is contained in:
Jack Mulrow 2018-04-09 12:49:21 -04:00
parent 322f89e07a
commit 2a61597c7c
4 changed files with 72 additions and 1 deletions

View File

@ -0,0 +1,63 @@
// Verifies that snapshot readConcern on mongos is gated by the enableTestCommands flag.
//
// @tags: [requires_sharding]
(function() {
"use strict";
const dbName = "test";
const collName = "coll";
// Snapshot readConcern should fail when 'enableTestCommands' is set to false.
{
jsTest.setOption("enableTestCommands", false);
const st = new ShardingTest({shards: 1, config: 1});
const session = st.s.startSession({causalConsistency: false});
let txnNumber = 0;
assert.commandFailedWithCode(session.getDatabase(dbName).runCommand({
find: collName,
readConcern: {level: "snapshot"},
txnNumber: NumberLong(txnNumber++)
}),
ErrorCodes.InvalidOptions);
assert.commandFailedWithCode(session.getDatabase(dbName).runCommand({
aggregate: collName,
pipeline: [],
cursor: {},
readConcern: {level: "snapshot"},
txnNumber: NumberLong(txnNumber++)
}),
ErrorCodes.InvalidOptions);
session.endSession();
st.stop();
}
// Snapshot readConcern should succeed when 'enableTestCommands' is set to true.
{
jsTest.setOption("enableTestCommands", true);
const st = new ShardingTest({shards: 1, config: 1});
const session = st.s.startSession({causalConsistency: false});
let txnNumber = 0;
assert.commandWorked(session.getDatabase(dbName).runCommand({
find: collName,
readConcern: {level: "snapshot"},
txnNumber: NumberLong(txnNumber++)
}));
assert.commandWorked(session.getDatabase(dbName).runCommand({
aggregate: collName,
pipeline: [],
cursor: {},
readConcern: {level: "snapshot"},
txnNumber: NumberLong(txnNumber++)
}));
session.endSession();
st.stop();
}
}());

View File

@ -285,6 +285,7 @@ env.Library(
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/commands/test_commands_enabled',
'$BUILD_DIR/mongo/executor/thread_pool_task_executor',
'$BUILD_DIR/mongo/s/client/sharding_client',
'cluster_last_error_info',

View File

@ -41,6 +41,7 @@
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/curop.h"
#include "mongo/db/initialize_operation_session_info.h"
#include "mongo/db/lasterror.h"
@ -217,6 +218,10 @@ void execCommandClient(OperationContext* opCtx,
auto& readConcernArgs = repl::ReadConcernArgs::get(opCtx);
if (readConcernArgs.getLevel() == repl::ReadConcernLevel::kSnapshotReadConcern) {
uassert(ErrorCodes::InvalidOptions,
"readConcern level snapshot is not supported on mongos",
getTestCommandsEnabled());
// TODO SERVER-33708.
if (!invocation->supportsReadConcern(readConcernArgs.getLevel())) {
auto body = result->getBodyBuilder();

View File

@ -35,6 +35,7 @@
#include "mongo/base/disallow_copying.h"
#include "mongo/base/status_with.h"
#include "mongo/bson/timestamp.h"
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/logical_time.h"
#include "mongo/db/operation_time_tracker.h"
#include "mongo/executor/thread_pool_task_executor.h"
@ -131,7 +132,8 @@ StatusWith<TaskExecutor::CallbackHandle> ShardingTaskExecutor::scheduleRemoteCom
}
// TODO SERVER-33991.
if (request.opCtx->getTxnNumber() && request.cmdObj.hasField("getMore") &&
if (getTestCommandsEnabled() && request.opCtx->getTxnNumber() &&
request.cmdObj.hasField("getMore") &&
!request.cmdObj.hasField(OperationSessionInfo::kTxnNumberFieldName)) {
bob.append(OperationSessionInfo::kTxnNumberFieldName, *(request.opCtx->getTxnNumber()));
}