diff options
Diffstat (limited to 'src/mongo')
-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 |
15 files changed, 0 insertions, 350 deletions
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; }; |