diff options
author | Yoonsoo Kim <yoonsoo.kim@mongodb.com> | 2021-06-25 19:58:18 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-25 20:19:52 +0000 |
commit | 27c360c2ced522e2158a9ada1cd9eec42a2372ab (patch) | |
tree | 42082475bf0b72f1bb14c2a7bd9bf05442895469 | |
parent | 1b5e10ddfd3f70cd28c14c496fc58836f7442f85 (diff) | |
download | mongo-27c360c2ced522e2158a9ada1cd9eec42a2372ab.tar.gz |
Revert "SERVER-57897 Add readPrefMode option to benchRun find/findOne ops"
This reverts commit 8a8d6f27bdd2cfe3d9861126d15153ea249613e6.
-rw-r--r-- | jstests/noPassthrough/benchrun_read_pref_mode.js | 101 | ||||
-rw-r--r-- | src/mongo/shell/bench.cpp | 39 | ||||
-rw-r--r-- | src/mongo/shell/bench.h | 3 |
3 files changed, 4 insertions, 139 deletions
diff --git a/jstests/noPassthrough/benchrun_read_pref_mode.js b/jstests/noPassthrough/benchrun_read_pref_mode.js deleted file mode 100644 index d9c6027f4eb..00000000000 --- a/jstests/noPassthrough/benchrun_read_pref_mode.js +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Verifies that readPrefMode param works for find/fineOne/query ops in benchRun(). - * - * @tags: [requires_replication] - */ - -(function() { -"use strict"; - -const rs = new ReplSetTest({nodes: 2}); -rs.startSet(); -rs.initiate(); - -const primary = rs.getPrimary(); -const secondary = rs.getSecondary(); -const collName = primary.getDB(jsTestName()).getCollection("coll").getFullName(); - -const verifyNoError = res => { - assert.eq(res.errCount, 0); - assert.gt(res.totalOps, 0); -}; - -const benchArgArray = [ - { - ops: [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: "primary"}], - parallel: 1, - host: primary.host - }, - { - ops: [{ - op: "findOne", - readCmd: true, - query: {}, - ns: collName, - readPrefMode: "primaryPreferred" - }], - parallel: 1, - host: primary.host - }, - { - ops: [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: "secondary"}], - parallel: 1, - host: secondary.host - }, - { - ops: [{ - op: "findOne", - readCmd: true, - query: {}, - ns: collName, - readPrefMode: "secondaryPreferred" - }], - parallel: 1, - host: secondary.host - }, - { - ops: [{op: "query", readCmd: true, query: {}, ns: collName, readPrefMode: "nearest"}], - parallel: 1, - host: secondary.host - }, -]; - -benchArgArray.forEach(benchArg => verifyNoError(benchRun(benchArg))); - -const invalidArgAndError = [ - { - benchArg: { - ops: [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: 1}], - parallel: 1, - host: primary.host - }, - error: ErrorCodes.BadValue - }, - { - benchArg: { - ops: - [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: "invalidPref"}], - parallel: 1, - host: primary.host - }, - error: ErrorCodes.BadValue - }, - { - benchArg: { - ops: [ - {op: "insert", writeCmd: true, doc: {a: 1}, ns: collName, readPrefMode: "primary"} - ], - parallel: 1, - host: primary.host - }, - error: ErrorCodes.InvalidOptions - }, -]; - -invalidArgAndError.forEach(argAndError => { - const res = assert.throws(() => benchRun(argAndError.benchArg)); - assert.commandFailedWithCode(res, argAndError.error); -}); - -rs.stopSet(); -})(); diff --git a/src/mongo/shell/bench.cpp b/src/mongo/shell/bench.cpp index 1de6b59fff3..1f5fd3e4775 100644 --- a/src/mongo/shell/bench.cpp +++ b/src/mongo/shell/bench.cpp @@ -34,7 +34,6 @@ #include "mongo/shell/bench.h" #include <pcrecpp.h> -#include <string> #include "mongo/client/dbclient_cursor.h" #include "mongo/db/namespace_string.h" @@ -232,20 +231,16 @@ int runQueryWithReadCommands(DBClientBase* conn, boost::optional<TxnNumber> txnNumber, std::unique_ptr<QueryRequest> qr, Milliseconds delayBeforeGetMore, - BSONObj readPrefObj, BSONObj* objOut) { const auto dbName = qr->nss().db().toString(); BSONObj findCommandResult; - BSONObjBuilder findCommandBuilder; - qr->asFindCommand(&findCommandBuilder); - findCommandBuilder.append("$readPreference", readPrefObj); uassert(ErrorCodes::CommandFailed, str::stream() << "find command failed; reply was: " << findCommandResult, runCommandWithSession( conn, dbName, - findCommandBuilder.obj(), + qr->asFindCommand(), // read command with txnNumber implies performing reads in a // multi-statement transaction txnNumber ? kStartTransactionOption | kMultiStatementTransactionOption : kNoOptions, @@ -314,7 +309,7 @@ Timestamp getLatestClusterTime(DBClientBase* conn) { BSONObj oplogResult; int count = runQueryWithReadCommands( - conn, boost::none, boost::none, std::move(qr), Milliseconds(0), BSONObj(), &oplogResult); + conn, boost::none, boost::none, std::move(qr), Milliseconds(0), &oplogResult); uassert(ErrorCodes::OperationFailed, str::stream() << "Find cmd on the oplog collection failed; reply was: " << oplogResult, count == 1); @@ -642,26 +637,6 @@ BenchRunOp opFromBson(const BSONObj& op) { << opType, (opType == "find") || (opType == "query")); myOp.maxRandomMillisecondDelayBeforeGetMore = arg.numberInt(); - } else if (name == "readPrefMode") { - uassert( - ErrorCodes::InvalidOptions, - str::stream() << "Field 'readPrefMode' is only valid for find op types. Type is " - << opType, - (opType == "find") || (opType == "query") || (opType == "findOne")); - uassert(ErrorCodes::BadValue, - str::stream() << "Field 'readPrefMode' should be a string, instead it's type: " - << typeName(arg.type()), - arg.type() == BSONType::String); - - ReadPreference mode; - try { - mode = ReadPreference_parse(IDLParserErrorContext("mode"), arg.str()); - } catch (DBException& e) { - e.addContext("benchRun(): Could not parse readPrefMode argument"); - throw; - } - - myOp.readPrefObj = ReadPreferenceSetting(mode).toInnerBSON(); } else { uassert(34394, str::stream() << "Benchrun op has unsupported field: " << name, false); } @@ -1045,13 +1020,8 @@ void BenchRunOp::executeOnce(DBClientBase* conn, txnNumberForOp = state->txnNumber; state->inProgressMultiStatementTxn = true; } - runQueryWithReadCommands(conn, - lsid, - txnNumberForOp, - std::move(qr), - Milliseconds(0), - readPrefObj, - &result); + runQueryWithReadCommands( + conn, lsid, txnNumberForOp, std::move(qr), Milliseconds(0), &result); } else { if (!this->sort.isEmpty()) { fixedQuery = makeQueryLegacyCompatible(std::move(fixedQuery), this->sort); @@ -1167,7 +1137,6 @@ void BenchRunOp::executeOnce(DBClientBase* conn, txnNumberForOp, std::move(qr), Milliseconds(delayBeforeGetMore), - readPrefObj, nullptr); } else { if (!this->sort.isEmpty()) { diff --git a/src/mongo/shell/bench.h b/src/mongo/shell/bench.h index 9789f6814a9..830e3c6924a 100644 --- a/src/mongo/shell/bench.h +++ b/src/mongo/shell/bench.h @@ -140,9 +140,6 @@ struct BenchRunOp { // resources that a snapshot transaction would hold for a time. int maxRandomMillisecondDelayBeforeGetMore{0}; - // Format: {mode: modeStr}. Only mode field is allowed. - BSONObj readPrefObj; - // This is an owned copy of the raw operation. All unowned members point into this. BSONObj myBsonOp; }; |