diff options
author | Kevin Pulo <kevin.pulo@mongodb.com> | 2020-02-20 21:42:07 +1100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-05 13:03:43 +0000 |
commit | 747ff353cbc819d032fa727d4bd7ffad16ea0437 (patch) | |
tree | d9b3d7e9af26138d7b74e0416a93d6110e326af0 /src/mongo/s/request_types | |
parent | 7c4b875a8858c5bd5efc9bf4f285f7f440fdfdc0 (diff) | |
download | mongo-747ff353cbc819d032fa727d4bd7ffad16ea0437.tar.gz |
SERVER-45692 add explicit RWC to inter-node commands (even if merely kImplicitDefault)
Diffstat (limited to 'src/mongo/s/request_types')
6 files changed, 34 insertions, 24 deletions
diff --git a/src/mongo/s/request_types/merge_chunk_request_test.cpp b/src/mongo/s/request_types/merge_chunk_request_test.cpp index 94a7bf68511..88d5d165148 100644 --- a/src/mongo/s/request_types/merge_chunk_request_test.cpp +++ b/src/mongo/s/request_types/merge_chunk_request_test.cpp @@ -61,13 +61,13 @@ TEST(MergeChunkRequest, ConfigCommandtoBSON) { << BSON_ARRAY(BSON("a" << 1) << BSON("a" << 5) << BSON("a" << 10)) << "shard" << "shard0000" << "validAfter" << Timestamp{100}); - BSONObj writeConcernObj = BSON("writeConcern" << BSON("w" - << "majority")); + BSONObj writeConcernObj = BSON("w" + << "majority"); BSONObjBuilder cmdBuilder; { cmdBuilder.appendElements(serializedRequest); - cmdBuilder.appendElements(writeConcernObj); + cmdBuilder.append("writeConcern", writeConcernObj); } auto request = assertGet(MergeChunkRequest::parseFromConfigCommand(serializedRequest)); diff --git a/src/mongo/s/request_types/merge_chunk_request_type.cpp b/src/mongo/s/request_types/merge_chunk_request_type.cpp index 4bd9844578b..387bacc16b0 100644 --- a/src/mongo/s/request_types/merge_chunk_request_type.cpp +++ b/src/mongo/s/request_types/merge_chunk_request_type.cpp @@ -33,6 +33,7 @@ #include "mongo/bson/bsonobjbuilder.h" #include "mongo/bson/util/bson_extract.h" +#include "mongo/db/write_concern_options.h" namespace mongo { namespace { @@ -131,7 +132,7 @@ BSONObj MergeChunkRequest::toConfigCommandBSON(const BSONObj& writeConcern) { appendAsConfigCommand(&cmdBuilder); // Tack on passed-in writeConcern - cmdBuilder.appendElements(writeConcern); + cmdBuilder.append(WriteConcernOptions::kWriteConcernField, writeConcern); return cmdBuilder.obj(); } diff --git a/src/mongo/s/request_types/migration_secondary_throttle_options.cpp b/src/mongo/s/request_types/migration_secondary_throttle_options.cpp index d739671b1e3..c143fc9ea60 100644 --- a/src/mongo/s/request_types/migration_secondary_throttle_options.cpp +++ b/src/mongo/s/request_types/migration_secondary_throttle_options.cpp @@ -98,8 +98,12 @@ StatusWith<MigrationSecondaryThrottleOptions> MigrationSecondaryThrottleOptions: } if (secondaryThrottle != kOn) { - return Status(ErrorCodes::UnsupportedFormat, - "Cannot specify write concern when secondaryThrottle is not set"); + // Ignore the specified writeConcern, since it won't be used. This is necessary + // to normalize the otherwise non-standard way that moveChunk uses writeConcern (ie. + // only using it when secondaryThrottle: true), so that shardsvrs can enforce always + // receiving writeConcern on internalClient connections (at the ServiceEntryPoint + // layer). + return MigrationSecondaryThrottleOptions(secondaryThrottle, boost::none); } writeConcernBSON = writeConcernElem.Obj().getOwned(); diff --git a/src/mongo/s/request_types/migration_secondary_throttle_options_test.cpp b/src/mongo/s/request_types/migration_secondary_throttle_options_test.cpp index b295e3f0b3d..59c3fb130bd 100644 --- a/src/mongo/s/request_types/migration_secondary_throttle_options_test.cpp +++ b/src/mongo/s/request_types/migration_secondary_throttle_options_test.cpp @@ -168,20 +168,24 @@ TEST(MigrationSecondaryThrottleOptions, DisabledInBalancerConfig) { ASSERT_EQ(MigrationSecondaryThrottleOptions::kOff, options.getSecondaryThrottle()); } -TEST(MigrationSecondaryThrottleOptions, ParseFailsDisabledInCommandBSONWriteConcernSpecified) { - auto status = MigrationSecondaryThrottleOptions::createFromCommand( - BSON("someOtherField" << 1 << "secondaryThrottle" << false << "writeConcern" - << BSON("w" - << "majority"))); - ASSERT_EQ(ErrorCodes::UnsupportedFormat, status.getStatus().code()); -} - -TEST(MigrationSecondaryThrottleOptions, ParseFailsNotSpecifiedInCommandBSONWriteConcernSpecified) { - auto status = MigrationSecondaryThrottleOptions::createFromCommand( - BSON("someOtherField" << 1 << "writeConcern" - << BSON("w" - << "majority"))); - ASSERT_EQ(ErrorCodes::UnsupportedFormat, status.getStatus().code()); +TEST(MigrationSecondaryThrottleOptions, IgnoreWriteConcernWhenSecondaryThrottleOff) { + MigrationSecondaryThrottleOptions options = + assertGet(MigrationSecondaryThrottleOptions::createFromCommand( + BSON("someOtherField" << 1 << "_secondaryThrottle" << false << "writeConcern" + << BSON("w" + << "majority")))); + ASSERT_EQ(MigrationSecondaryThrottleOptions::kOff, options.getSecondaryThrottle()); + ASSERT(!options.isWriteConcernSpecified()); +} + +TEST(MigrationSecondaryThrottleOptions, IgnoreWriteConcernWhenSecondaryThrottleAbsent) { + MigrationSecondaryThrottleOptions options = + assertGet(MigrationSecondaryThrottleOptions::createFromCommand( + BSON("someOtherField" << 1 << "writeConcern" + << BSON("w" + << "majority")))); + ASSERT_EQ(MigrationSecondaryThrottleOptions::kDefault, options.getSecondaryThrottle()); + ASSERT(!options.isWriteConcernSpecified()); } TEST(MigrationSecondaryThrottleOptions, EqualityOperatorSameValue) { diff --git a/src/mongo/s/request_types/split_chunk_request_test.cpp b/src/mongo/s/request_types/split_chunk_request_test.cpp index 1727c3aa792..5759519a2b4 100644 --- a/src/mongo/s/request_types/split_chunk_request_test.cpp +++ b/src/mongo/s/request_types/split_chunk_request_test.cpp @@ -77,13 +77,13 @@ TEST(SplitChunkRequest, ConfigCommandtoBSON) { << "collEpoch" << OID("7fffffff0000000000000001") << "min" << BSON("a" << 1) << "max" << BSON("a" << 10) << "splitPoints" << BSON_ARRAY(BSON("a" << 5)) << "shard" << "shard0000"); - BSONObj writeConcernObj = BSON("writeConcern" << BSON("w" - << "majority")); + BSONObj writeConcernObj = BSON("w" + << "majority"); BSONObjBuilder cmdBuilder; { cmdBuilder.appendElements(serializedRequest); - cmdBuilder.appendElements(writeConcernObj); + cmdBuilder.append("writeConcern", writeConcernObj); } auto request = assertGet(SplitChunkRequest::parseFromConfigCommand(serializedRequest)); diff --git a/src/mongo/s/request_types/split_chunk_request_type.cpp b/src/mongo/s/request_types/split_chunk_request_type.cpp index 6773e413197..20e826c1400 100644 --- a/src/mongo/s/request_types/split_chunk_request_type.cpp +++ b/src/mongo/s/request_types/split_chunk_request_type.cpp @@ -33,6 +33,7 @@ #include "mongo/bson/bsonobjbuilder.h" #include "mongo/bson/util/bson_extract.h" +#include "mongo/db/write_concern_options.h" namespace mongo { @@ -120,7 +121,7 @@ BSONObj SplitChunkRequest::toConfigCommandBSON(const BSONObj& writeConcern) { appendAsConfigCommand(&cmdBuilder); // Tack on passed-in writeConcern - cmdBuilder.appendElements(writeConcern); + cmdBuilder.append(WriteConcernOptions::kWriteConcernField, writeConcern); return cmdBuilder.obj(); } |