diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2022-07-09 10:05:06 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-09 10:45:56 +0000 |
commit | 50debeeaead306533741f59336aa12cdef8052ac (patch) | |
tree | 831195c56074816fe75cf7c2d4dba87e2f86e3e0 | |
parent | 9d9f8fad5bbf6423f34e7350cd86cfc67f61bdb2 (diff) | |
download | mongo-50debeeaead306533741f59336aa12cdef8052ac.tar.gz |
SERVER-67901 Stop gossiping lastCommittedOpTime in reply metadata
-rw-r--r-- | buildscripts/resmokeconfig/suites/sharding_continuous_config_stepdown.yml | 2 | ||||
-rw-r--r-- | jstests/sharding/shards_and_config_return_last_committed_optime.js | 196 | ||||
-rw-r--r-- | src/mongo/db/s/shard_local.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/s/shard_local.h | 4 | ||||
-rw-r--r-- | src/mongo/db/service_entry_point_common.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/service_entry_point_common.h | 3 | ||||
-rw-r--r-- | src/mongo/db/service_entry_point_mongod.cpp | 17 | ||||
-rw-r--r-- | src/mongo/embedded/service_entry_point_embedded.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/SConscript | 14 | ||||
-rw-r--r-- | src/mongo/s/client/shard.h | 17 | ||||
-rw-r--r-- | src/mongo/s/client/shard_remote.cpp | 14 | ||||
-rw-r--r-- | src/mongo/s/client/shard_remote.h | 17 | ||||
-rw-r--r-- | src/mongo/s/client/shard_remote_test.cpp | 109 | ||||
-rw-r--r-- | src/mongo/s/committed_optime_metadata_hook.cpp | 77 | ||||
-rw-r--r-- | src/mongo/s/committed_optime_metadata_hook.h | 59 | ||||
-rw-r--r-- | src/mongo/s/mongos_main.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/sharding_router_test_fixture.cpp | 2 |
17 files changed, 0 insertions, 548 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharding_continuous_config_stepdown.yml b/buildscripts/resmokeconfig/suites/sharding_continuous_config_stepdown.yml index 150654cf5c5..959a8eb768c 100644 --- a/buildscripts/resmokeconfig/suites/sharding_continuous_config_stepdown.yml +++ b/buildscripts/resmokeconfig/suites/sharding_continuous_config_stepdown.yml @@ -160,8 +160,6 @@ selector: # Test expects a specific chunk distribution after shardCollection and it can be broken when # a step down occurs. - jstests/sharding/regex_targeting.js - # Sets a failpoint on a config server secondary. - - jstests/sharding/shards_and_config_return_last_committed_optime.js # Calls movePrimary after data has been inserted into an unsharded collection, so will fail if # a stepdown causes the command to be sent again. - jstests/sharding/move_primary_clone_test.js diff --git a/jstests/sharding/shards_and_config_return_last_committed_optime.js b/jstests/sharding/shards_and_config_return_last_committed_optime.js deleted file mode 100644 index ab9315699fe..00000000000 --- a/jstests/sharding/shards_and_config_return_last_committed_optime.js +++ /dev/null @@ -1,196 +0,0 @@ -/** - * Tests that lastCommittedOpTime is returned in all command responses from: - * - sharding aware shards servers (primary + secondary) - * - config servers (primary + secondary) - * - * And is not returned by: - * - mongos - * - non-sharding aware shard servers (primary + secondary) - * - mongod from a standalone replica set (primary + secondary) - * - standalone mongod - */ -(function() { -"use strict"; - -load("jstests/libs/write_concern_util.js"); // For stopReplProducer - -function assertCmdDoesNotReturnLastCommittedOpTime(testDB, cmdObj, connType, expectSuccess) { - const res = testDB.runCommand(cmdObj); - assert.eq(expectSuccess ? 1 : 0, res.ok); - assert(typeof res.lastCommittedOpTime === "undefined", - "Expected response from a " + connType + " to not contain lastCommittedOpTime," + - " received: " + tojson(res) + ", cmd was: " + tojson(cmdObj)); -} - -function assertDoesNotReturnLastCommittedOpTime(testDB, collName, connType) { - // Successful commands return lastCommittedOpTime. - assertCmdDoesNotReturnLastCommittedOpTime(testDB, {find: collName}, connType, true); - - // Failed commands return lastCommittedOpTime. - assertCmdDoesNotReturnLastCommittedOpTime( - testDB, {dummyCommand: collName}, connType, false /* expectSuccess */); - assertCmdDoesNotReturnLastCommittedOpTime(testDB, - {find: collName, readConcern: {invalid: "rc"}}, - connType, - false /* expectSuccess */); - assertCmdDoesNotReturnLastCommittedOpTime( - testDB, - {insert: collName, documents: [{x: 2}], writeConcern: {invalid: "wc"}}, - connType, - false /* expectSuccess */); -} - -function assertCmdReturnsLastCommittedOpTime(testDB, cmdObj, connType, expectSuccess) { - // Retry up to one time to avoid possible failures from lag in setting the - // lastCommittedOpTime. - assert.retryNoExcept(() => { - const res = testDB.runCommand(cmdObj); - assert.eq(expectSuccess ? 1 : 0, res.ok); - assert(typeof res.lastCommittedOpTime !== "undefined", - "Expected response from a " + connType + " to contain lastCommittedOpTime," + - " received: " + tojson(res) + ", cmd was: " + tojson(cmdObj)); - - // The last committed opTime may advance after replSetGetStatus finishes executing and - // before its response's metadata is computed, in which case the response's - // lastCommittedOpTime will be greater than the lastCommittedOpTime timestamp in its - // body. Assert the timestamp is <= lastCommittedOpTime to account for this. - const statusRes = assert.commandWorked(testDB.adminCommand({replSetGetStatus: 1})); - assert.lte(bsonWoCompare(res.lastCommittedOpTime, statusRes.optimes.lastCommittedOpTime.ts), - 0, - "lastCommittedOpTime in command response, " + tojson(res.lastCommittedOpTime) + - ", is not <= to the replSetGetStatus lastCommittedOpTime timestamp, " + - tojson(statusRes.optimes.lastCommittedOpTime.ts) + - ", cmd was: " + tojson(cmdObj)); - - return true; - }, "command: " + tojson(cmdObj) + " failed to return correct lastCommittedOpTime", 2); -} - -function assertReturnsLastCommittedOpTime(testDB, collName, connType) { - // Successful commands return lastCommittedOpTime. - assertCmdReturnsLastCommittedOpTime( - testDB, {find: collName}, connType, true /* expectSuccess */); - - // Failed commands return lastCommittedOpTime. - assertCmdReturnsLastCommittedOpTime( - testDB, {dummyCommand: collName}, connType, false /* expectSuccess */); - assertCmdReturnsLastCommittedOpTime(testDB, - {find: collName, readConcern: {invalid: "rc"}}, - connType, - false /* expectSuccess */); - assertCmdReturnsLastCommittedOpTime( - testDB, - {insert: collName, documents: [{x: 2}], writeConcern: {invalid: "wc"}}, - connType, - false /* expectSuccess */); -} - -// -// Mongos should not return lastCommittedOpTime. -// - -const st = new ShardingTest({shards: 1, rs: {nodes: 2}, config: 2}); -assert.commandWorked(st.s.adminCommand({enableSharding: "test"})); -assert.commandWorked(st.s.adminCommand({shardCollection: "test.foo", key: {x: 1}})); -// The default WC is majority and stopServerReplication will prevent satisfying any majority writes. -assert.commandWorked(st.s.adminCommand( - {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); - -// Sharded collection. -assertDoesNotReturnLastCommittedOpTime( - st.s.getDB("test"), "foo", "mongos talking to a sharded collection"); - -// Unsharded collection. -assertDoesNotReturnLastCommittedOpTime( - st.s.getDB("test"), "unsharded", "mongos talking to a non-sharded collection"); - -// Collection stored on the config server. -assertDoesNotReturnLastCommittedOpTime( - st.s.getDB("config"), "foo", "mongos talking to a config server collection"); - -// -// A mongod in a sharded replica set returns lastCommittedOpTime. -// - -// To verify the lastCommittedOpTime is being returned, pause replication on the secondary to -// prevent the primary from advancing its lastCommittedOpTime and then perform a local write to -// advance the primary's lastAppliedOpTime. -let primary = st.rs0.getPrimary(); -let secondary = st.rs0.getSecondary(); - -st.rs0.awaitLastOpCommitted(); -stopServerReplication(secondary); -assert.commandWorked(primary.getDB("test").foo.insert({x: 1}, {writeConcern: {w: 1}})); - -// Sharded collection. -assertReturnsLastCommittedOpTime(primary.getDB("test"), "foo", "sharding-aware shard primary"); -assertReturnsLastCommittedOpTime(secondary.getDB("test"), "foo", "sharding-aware shard secondary"); - -// Unsharded collection. -assertReturnsLastCommittedOpTime( - primary.getDB("test"), "unsharded", "sharding-aware shard primary"); -assertReturnsLastCommittedOpTime( - secondary.getDB("test"), "unsharded", "sharding-aware shard secondary"); - -restartServerReplication(secondary); - -// -// A config server in a sharded replica set returns lastCommittedOpTime. -// - -// Split the lastCommitted and lastApplied opTimes by pausing secondary application and -// performing a local write. -primary = st.configRS.getPrimary(); -secondary = st.configRS.getSecondary(); - -st.configRS.awaitLastOpCommitted(); -stopServerReplication(secondary); -assert.commandWorked(primary.getDB("config").foo.insert({x: 1}, {writeConcern: {w: 1}})); - -assertReturnsLastCommittedOpTime(primary.getDB("test"), "foo", "config server primary"); -assertReturnsLastCommittedOpTime(secondary.getDB("test"), "foo", "config server secondary"); - -restartServerReplication(secondary); -st.stop(); - -// -// A mongod started with --shardsvr that is not sharding aware does not return -// lastCommittedOpTime. -// - -const replTestShardSvr = new ReplSetTest({nodes: 2, nodeOptions: {shardsvr: ""}}); -replTestShardSvr.startSet(); -replTestShardSvr.initiate(); - -assertDoesNotReturnLastCommittedOpTime( - replTestShardSvr.getPrimary().getDB("test"), "foo", "non-sharding aware shard primary"); -assertDoesNotReturnLastCommittedOpTime( - replTestShardSvr.getSecondary().getDB("test"), "foo", "non-sharding aware shard secondary"); - -replTestShardSvr.stopSet(); - -// -// A mongod from a standalone replica set does not return lastCommittedOpTime. -// - -const replTest = new ReplSetTest({nodes: 2}); -replTest.startSet(); -replTest.initiate(); - -assertDoesNotReturnLastCommittedOpTime( - replTest.getPrimary().getDB("test"), "foo", "standalone replica set primary"); -assertDoesNotReturnLastCommittedOpTime( - replTest.getSecondary().getDB("test"), "foo", "standalone replica set secondary"); - -replTest.stopSet(); - -// -// A standalone mongod does not return lastCommittedOpTime. -// - -const standalone = MongoRunner.runMongod(); - -assertDoesNotReturnLastCommittedOpTime(standalone.getDB("test"), "foo", "standalone mongod"); - -MongoRunner.stopMongod(standalone); -})(); diff --git a/src/mongo/db/s/shard_local.cpp b/src/mongo/db/s/shard_local.cpp index 4a71d88d22c..fb27ba0111a 100644 --- a/src/mongo/db/s/shard_local.cpp +++ b/src/mongo/db/s/shard_local.cpp @@ -71,14 +71,6 @@ void ShardLocal::updateReplSetMonitor(const HostAndPort& remoteHost, MONGO_UNREACHABLE; } -void ShardLocal::updateLastCommittedOpTime(LogicalTime lastCommittedOpTime) { - MONGO_UNREACHABLE; -} - -LogicalTime ShardLocal::getLastCommittedOpTime() const { - MONGO_UNREACHABLE; -} - std::string ShardLocal::toString() const { return getId().toString() + ":<local>"; } diff --git a/src/mongo/db/s/shard_local.h b/src/mongo/db/s/shard_local.h index 8d6abfb8826..386ceba7f13 100644 --- a/src/mongo/db/s/shard_local.h +++ b/src/mongo/db/s/shard_local.h @@ -56,10 +56,6 @@ public: bool isRetriableError(ErrorCodes::Error code, RetryPolicy options) final; - void updateLastCommittedOpTime(LogicalTime lastCommittedOpTime) final; - - LogicalTime getLastCommittedOpTime() const final; - void runFireAndForgetCommand(OperationContext* opCtx, const ReadPreferenceSetting& readPref, const std::string& dbName, diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index 10b0097a0b9..e06ee01bfb1 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -2091,8 +2091,6 @@ Future<DbResponse> receivedCommands(std::shared_ptr<HandleRequest::ExecutionCont auto opCtx = execContext->getOpCtx(); BSONObjBuilder metadataBob; - execContext->behaviors->appendReplyMetadataOnError(opCtx, &metadataBob); - BSONObjBuilder extraFieldsBuilder; appendClusterAndOperationTime( opCtx, &extraFieldsBuilder, &metadataBob, LogicalTime::kUninitialized); diff --git a/src/mongo/db/service_entry_point_common.h b/src/mongo/db/service_entry_point_common.h index 9fa9dfa886c..266a7504553 100644 --- a/src/mongo/db/service_entry_point_common.h +++ b/src/mongo/db/service_entry_point_common.h @@ -102,9 +102,6 @@ struct ServiceEntryPointCommon { MONGO_WARN_UNUSED_RESULT_FUNCTION virtual std::unique_ptr<PolymorphicScoped> scopedOperationCompletionShardingActions(OperationContext* opCtx) const = 0; - virtual void appendReplyMetadataOnError(OperationContext* opCtx, - BSONObjBuilder* metadataBob) const = 0; - virtual void appendReplyMetadata(OperationContext* opCtx, const OpMsgRequest& request, BSONObjBuilder* metadataBob) const = 0; diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp index bd3ae7d0db1..9d6102f7481 100644 --- a/src/mongo/db/service_entry_point_mongod.cpp +++ b/src/mongo/db/service_entry_point_mongod.cpp @@ -57,8 +57,6 @@ namespace mongo { -constexpr auto kLastCommittedOpTimeFieldName = "lastCommittedOpTime"_sd; - class ServiceEntryPointMongod::Hooks final : public ServiceEntryPointCommon::Hooks { public: bool lockedForWriting() const override { @@ -201,17 +199,6 @@ public: CurOp::get(opCtx)->debug().errInfo = getStatusFromCommandResult(replyObj); } - // Called from the error contexts where request may not be available. - void appendReplyMetadataOnError(OperationContext* opCtx, - BSONObjBuilder* metadataBob) const override { - const bool isConfig = serverGlobalParams.clusterRole == ClusterRole::ConfigServer; - if (ShardingState::get(opCtx)->enabled() || isConfig) { - auto lastCommittedOpTime = - repl::ReplicationCoordinator::get(opCtx)->getLastCommittedOpTime(); - metadataBob->append(kLastCommittedOpTimeFieldName, lastCommittedOpTime.getTimestamp()); - } - } - void appendReplyMetadata(OperationContext* opCtx, const OpMsgRequest& request, BSONObjBuilder* metadataBob) const override { @@ -240,10 +227,6 @@ public: .writeToMetadata(metadataBob) .transitional_ignore(); } - - auto lastCommittedOpTime = replCoord->getLastCommittedOpTime(); - metadataBob->append(kLastCommittedOpTimeFieldName, - lastCommittedOpTime.getTimestamp()); } } } diff --git a/src/mongo/embedded/service_entry_point_embedded.cpp b/src/mongo/embedded/service_entry_point_embedded.cpp index 48160f99630..4c2ca23c77b 100644 --- a/src/mongo/embedded/service_entry_point_embedded.cpp +++ b/src/mongo/embedded/service_entry_point_embedded.cpp @@ -150,9 +150,6 @@ public: return nullptr; } - void appendReplyMetadataOnError(OperationContext* opCtx, - BSONObjBuilder* metadataBob) const override {} - void appendReplyMetadata(OperationContext* opCtx, const OpMsgRequest& request, BSONObjBuilder* metadataBob) const override {} diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index 9980bc51df7..c8e55c6dbe5 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -260,7 +260,6 @@ env.Library( '$BUILD_DIR/mongo/transport/transport_layer_mock', '$BUILD_DIR/mongo/util/clock_source_mock', 'catalog/sharding_catalog_client_impl', - 'committed_optime_metadata_hook', 'coreshard', 'sharding_task_executor', 'sharding_test_fixture_common', @@ -331,17 +330,6 @@ env.Benchmark( ) env.Library( - target='committed_optime_metadata_hook', - source=[ - 'committed_optime_metadata_hook.cpp', - ], - LIBDEPS=[ - '$BUILD_DIR/mongo/rpc/metadata', - 'coreshard', - ], -) - -env.Library( target='is_mongos', source=[ 'is_mongos.cpp', @@ -478,7 +466,6 @@ env.Library( 'commands/cluster_commands_common', 'commands/sharded_cluster_commands', 'commands/sharded_cluster_sharding_commands', - 'committed_optime_metadata_hook', 'coreshard', 'is_mongos', 'mongos_server_parameters', @@ -531,7 +518,6 @@ env.Library( 'client/sharding_client', 'commands/cluster_commands', 'commands/cluster_commands_common', - 'committed_optime_metadata_hook', 'load_balancer_support', 'mongos_initializers', 'mongos_topology_coordinator', diff --git a/src/mongo/s/client/shard.h b/src/mongo/s/client/shard.h index 0059e2a95a7..bb30a2903f3 100644 --- a/src/mongo/s/client/shard.h +++ b/src/mongo/s/client/shard.h @@ -261,23 +261,6 @@ public: */ static bool shouldErrorBePropagated(ErrorCodes::Error code); - /** - * Updates this shard's lastCommittedOpTime timestamp, if the given value is greater than the - * currently stored value. - * - * This is only valid to call on ShardRemote instances. - */ - virtual void updateLastCommittedOpTime(LogicalTime lastCommittedOpTime) = 0; - - /** - * Returns the latest lastCommittedOpTime timestamp returned by the underlying shard. This - * represents the latest opTime timestamp known to be in this shard's majority committed - * snapshot. - * - * This is only valid to call on ShardRemote instances. - */ - virtual LogicalTime getLastCommittedOpTime() const = 0; - protected: Shard(const ShardId& id); diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp index 5387f37bee6..6790ed35598 100644 --- a/src/mongo/s/client/shard_remote.cpp +++ b/src/mongo/s/client/shard_remote.cpp @@ -145,20 +145,6 @@ void ShardRemote::updateReplSetMonitor(const HostAndPort& remoteHost, } } -void ShardRemote::updateLastCommittedOpTime(LogicalTime lastCommittedOpTime) { - stdx::lock_guard<Latch> lk(_lastCommittedOpTimeMutex); - - // A secondary may return a lastCommittedOpTime less than the latest seen so far. - if (lastCommittedOpTime > _lastCommittedOpTime) { - _lastCommittedOpTime = lastCommittedOpTime; - } -} - -LogicalTime ShardRemote::getLastCommittedOpTime() const { - stdx::lock_guard<Latch> lk(_lastCommittedOpTimeMutex); - return _lastCommittedOpTime; -} - std::string ShardRemote::toString() const { return getId().toString() + ":" + _connString.toString(); } diff --git a/src/mongo/s/client/shard_remote.h b/src/mongo/s/client/shard_remote.h index b2359b027f1..7262b05ce5f 100644 --- a/src/mongo/s/client/shard_remote.h +++ b/src/mongo/s/client/shard_remote.h @@ -71,10 +71,6 @@ public: bool isRetriableError(ErrorCodes::Error code, RetryPolicy options) final; - void updateLastCommittedOpTime(LogicalTime lastCommittedOpTime) final; - - LogicalTime getLastCommittedOpTime() const final; - void runFireAndForgetCommand(OperationContext* opCtx, const ReadPreferenceSetting& readPref, const std::string& dbName, @@ -139,19 +135,6 @@ private: * Targeter for obtaining hosts from which to read or to which to write. */ std::shared_ptr<RemoteCommandTargeter> _targeter; - - /** - * Protects _lastCommittedOpTime. - */ - mutable Mutex _lastCommittedOpTimeMutex = - MONGO_MAKE_LATCH("ShardRemote::_lastCommittedOpTimeMutex"); - - /** - * Logical time representing the latest opTime timestamp known to be in this shard's majority - * committed snapshot. Only the latest time is kept because lagged secondaries may return - * earlier times. - */ - LogicalTime _lastCommittedOpTime; }; } // namespace mongo diff --git a/src/mongo/s/client/shard_remote_test.cpp b/src/mongo/s/client/shard_remote_test.cpp index c7b9c1b7975..9db1c62ec2e 100644 --- a/src/mongo/s/client/shard_remote_test.cpp +++ b/src/mongo/s/client/shard_remote_test.cpp @@ -90,115 +90,6 @@ protected: } }; -BSONObj makeLastCommittedOpTimeMetadata(LogicalTime time) { - return BSON("lastCommittedOpTime" << time.asTimestamp()); -} - -TEST_F(ShardRemoteTest, GetAndSetLatestLastCommittedOpTime) { - auto shard = shardRegistry()->getShardNoReload(kTestShardIds[0]); - - // Shards can store last committed opTimes. - LogicalTime time(Timestamp(10, 2)); - shard->updateLastCommittedOpTime(time); - ASSERT_EQ(time, shard->getLastCommittedOpTime()); - - // Later times overwrite earlier times. - LogicalTime laterTime(Timestamp(20, 2)); - shard->updateLastCommittedOpTime(laterTime); - ASSERT_EQ(laterTime, shard->getLastCommittedOpTime()); - - // Earlier times are ignored. - LogicalTime earlierTime(Timestamp(5, 1)); - shard->updateLastCommittedOpTime(earlierTime); - ASSERT_EQ(laterTime, shard->getLastCommittedOpTime()); -} - -TEST_F(ShardRemoteTest, NetworkReplyWithLastCommittedOpTime) { - // Send a request to one shard. - auto targetedShard = kTestShardIds[0]; - auto future = launchAsync([&] { runDummyCommandOnShard(targetedShard); }); - - // Mock a find response with a returned lastCommittedOpTime. - LogicalTime expectedTime(Timestamp(100, 2)); - onFindWithMetadataCommand([&](const executor::RemoteCommandRequest& request) { - auto result = std::vector<BSONObj>{BSON("_id" << 1)}; - auto metadata = makeLastCommittedOpTimeMetadata(expectedTime); - return std::make_tuple(result, metadata); - }); - - future.default_timed_get(); - - // Verify the targeted shard has updated its lastCommittedOpTime. - ASSERT_EQ(expectedTime, - shardRegistry()->getShardNoReload(targetedShard)->getLastCommittedOpTime()); - - // Verify shards that were not targeted were not affected. - for (auto shardId : kTestShardIds) { - if (shardId != targetedShard) { - ASSERT(!VectorClock::isValidComponentTime( - shardRegistry()->getShardNoReload(shardId)->getLastCommittedOpTime())); - } - } -} - -TEST_F(ShardRemoteTest, NetworkReplyWithoutLastCommittedOpTime) { - // Send a request to one shard. - auto targetedShard = kTestShardIds[0]; - auto future = launchAsync([&] { runDummyCommandOnShard(targetedShard); }); - - // Mock a find response without a returned lastCommittedOpTime. - onFindWithMetadataCommand([&](const executor::RemoteCommandRequest& request) { - auto result = std::vector<BSONObj>{BSON("_id" << 1)}; - auto metadata = BSONObj(); - return std::make_tuple(result, metadata); - }); - - future.default_timed_get(); - - // Verify the targeted shard has not updated its lastCommittedOpTime. - ASSERT_EQ(LogicalTime::kUninitialized, - shardRegistry()->getShardNoReload(targetedShard)->getLastCommittedOpTime()); -} - -TEST_F(ShardRemoteTest, ScatterGatherRepliesWithLastCommittedOpTime) { - // Send requests to several shards. - auto nss = NamespaceString("test.foo"); - auto cmdObj = BSON("find" << nss.coll()); - std::vector<std::pair<ShardId, BSONObj>> remotes{ - {kTestShardIds[0], cmdObj}, {kTestShardIds[1], cmdObj}, {kTestShardIds[2], cmdObj}}; - - auto future = launchAsync([&] { - establishCursors(operationContext(), - executor(), - nss, - ReadPreferenceSetting{ReadPreference::PrimaryOnly}, - remotes, - false); // allowPartialResults - }); - - // All remotes respond with a lastCommittedOpTime. - LogicalTime expectedTime(Timestamp(50, 1)); - for (auto remote : remotes) { - onCommandWithMetadata([&](const executor::RemoteCommandRequest& request) { - std::vector<BSONObj> batch = {BSON("_id" << 1)}; - CursorResponse cursorResponse(nss, CursorId(123), batch); - auto result = BSONObjBuilder( - cursorResponse.toBSON(CursorResponse::ResponseType::InitialResponse)); - result.appendElements(makeLastCommittedOpTimeMetadata(expectedTime)); - - return executor::RemoteCommandResponse(result.obj(), Milliseconds(1)); - }); - } - - future.default_timed_get(); - - // Verify all shards updated their lastCommittedOpTime. - for (auto shardId : kTestShardIds) { - ASSERT_EQ(expectedTime, - shardRegistry()->getShardNoReload(shardId)->getLastCommittedOpTime()); - } -} - TEST_F(ShardRemoteTest, TargeterMarksHostAsDownWhenConfigStepdown) { auto targetedNode = ShardId("config"); diff --git a/src/mongo/s/committed_optime_metadata_hook.cpp b/src/mongo/s/committed_optime_metadata_hook.cpp deleted file mode 100644 index e977dcefc4c..00000000000 --- a/src/mongo/s/committed_optime_metadata_hook.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/s/committed_optime_metadata_hook.h" - -#include "mongo/s/client/shard.h" -#include "mongo/s/client/shard_registry.h" -#include "mongo/s/grid.h" - -namespace mongo { - -namespace rpc { - -namespace { -const char kLastCommittedOpTimeFieldName[] = "lastCommittedOpTime"; -} - -CommittedOpTimeMetadataHook::CommittedOpTimeMetadataHook(ServiceContext* service) - : _service(service) {} - -Status CommittedOpTimeMetadataHook::writeRequestMetadata(OperationContext* opCtx, - BSONObjBuilder* metadataBob) { - return Status::OK(); -} - -Status CommittedOpTimeMetadataHook::readReplyMetadata(OperationContext* opCtx, - StringData replySource, - const BSONObj& metadataObj) { - auto lastCommittedOpTimeField = metadataObj[kLastCommittedOpTimeFieldName]; - if (lastCommittedOpTimeField.eoo()) { - return Status::OK(); - } - - invariant(lastCommittedOpTimeField.type() == BSONType::bsonTimestamp); - - // replySource is the HostAndPort of a single server, except when this hook is triggered - // through DBClientReplicaSet, when it will be a replica set connection string. The - // shardRegistry stores connection strings and hosts in its lookup table, in addition to shard - // ids, so replySource can be correctly passed on to ShardRegistry::getShardNoReload. - auto shard = Grid::get(_service)->shardRegistry()->getShardNoReload(replySource.toString()); - if (shard) { - shard->updateLastCommittedOpTime(LogicalTime(lastCommittedOpTimeField.timestamp())); - } - - return Status::OK(); -} - -} // namespace rpc -} // namespace mongo diff --git a/src/mongo/s/committed_optime_metadata_hook.h b/src/mongo/s/committed_optime_metadata_hook.h deleted file mode 100644 index 47f0a63c1bd..00000000000 --- a/src/mongo/s/committed_optime_metadata_hook.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include "mongo/rpc/metadata/metadata_hook.h" - -namespace mongo { - -class BSONObj; -class BSONObjBuilder; -class OperationContext; -class ServiceContext; -class Status; - -namespace rpc { - -class CommittedOpTimeMetadataHook : public EgressMetadataHook { -public: - explicit CommittedOpTimeMetadataHook(ServiceContext* service); - - Status writeRequestMetadata(OperationContext* opCtx, BSONObjBuilder* metadataBob) override; - - Status readReplyMetadata(OperationContext* opCtx, - StringData replySource, - const BSONObj& metadataObj) override; - -private: - ServiceContext* _service; -}; - -} // namespace rpc -} // namespace mongo diff --git a/src/mongo/s/mongos_main.cpp b/src/mongo/s/mongos_main.cpp index 5db803ba9bd..55a705eb346 100644 --- a/src/mongo/s/mongos_main.cpp +++ b/src/mongo/s/mongos_main.cpp @@ -79,7 +79,6 @@ #include "mongo/s/client/shard_remote.h" #include "mongo/s/client/sharding_connection_hook.h" #include "mongo/s/commands/kill_sessions_remote.h" -#include "mongo/s/committed_optime_metadata_hook.h" #include "mongo/s/concurrency/locker_mongos_client_observer.h" #include "mongo/s/config_server_catalog_cache_loader.h" #include "mongo/s/grid.h" @@ -435,8 +434,6 @@ Status initializeSharding(OperationContext* opCtx) { auto hookList = std::make_unique<rpc::EgressMetadataHookList>(); hookList->addHook( std::make_unique<rpc::VectorClockMetadataHook>(opCtx->getServiceContext())); - hookList->addHook( - std::make_unique<rpc::CommittedOpTimeMetadataHook>(opCtx->getServiceContext())); hookList->addHook(std::make_unique<rpc::ClientMetadataPropagationEgressHook>()); return hookList; }, @@ -689,7 +686,6 @@ ExitCode runMongosServer(ServiceContext* serviceContext) { auto unshardedHookList = std::make_unique<rpc::EgressMetadataHookList>(); unshardedHookList->addHook(std::make_unique<rpc::VectorClockMetadataHook>(serviceContext)); unshardedHookList->addHook(std::make_unique<rpc::ClientMetadataPropagationEgressHook>()); - unshardedHookList->addHook(std::make_unique<rpc::CommittedOpTimeMetadataHook>(serviceContext)); // Add sharding hooks to both connection pools - ShardingConnectionHook includes auth hooks globalConnPool.addHook(new ShardingConnectionHook(std::move(unshardedHookList))); diff --git a/src/mongo/s/sharding_router_test_fixture.cpp b/src/mongo/s/sharding_router_test_fixture.cpp index 1f517f5bee3..8f9b7e4480b 100644 --- a/src/mongo/s/sharding_router_test_fixture.cpp +++ b/src/mongo/s/sharding_router_test_fixture.cpp @@ -62,7 +62,6 @@ #include "mongo/s/client/shard_factory.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/client/shard_remote.h" -#include "mongo/s/committed_optime_metadata_hook.h" #include "mongo/s/config_server_catalog_cache_loader.h" #include "mongo/s/grid.h" #include "mongo/s/query/cluster_cursor_manager.h" @@ -107,7 +106,6 @@ ShardingTestFixture::ShardingTestFixture() auto makeMetadataHookList = [&] { auto hookList = std::make_unique<rpc::EgressMetadataHookList>(); hookList->addHook(std::make_unique<rpc::VectorClockMetadataHook>(service)); - hookList->addHook(std::make_unique<rpc::CommittedOpTimeMetadataHook>(service)); hookList->addHook(std::make_unique<rpc::ClientMetadataPropagationEgressHook>()); return hookList; }; |