diff options
author | Matt Walak <matt.walak@mongodb.com> | 2021-07-22 19:54:27 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-10 21:14:09 +0000 |
commit | 54c7e59e3b9d498fff915026c2d7abc8db2a83f7 (patch) | |
tree | 531b7acabc73d6eb47424f755451c82f45caae2a | |
parent | f411e71d6f3e5767484ae712b9f14bc46d7c8891 (diff) | |
download | mongo-54c7e59e3b9d498fff915026c2d7abc8db2a83f7.tar.gz |
SERVER-58389 Removed $maxTimeMS for updates performed by shards on the config server during a resharding operation
9 files changed, 94 insertions, 8 deletions
diff --git a/src/mongo/db/s/resharding/resharding_donor_service.cpp b/src/mongo/db/s/resharding/resharding_donor_service.cpp index 06c1bd095f2..77c2f3d1c51 100644 --- a/src/mongo/db/s/resharding/resharding_donor_service.cpp +++ b/src/mongo/db/s/resharding/resharding_donor_service.cpp @@ -159,7 +159,8 @@ public: query, update, false, /* upsert */ - ShardingCatalogClient::kMajorityWriteConcern)); + ShardingCatalogClient::kMajorityWriteConcern, + Milliseconds::max())); if (!docWasModified) { LOGV2_DEBUG( diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_external_state.cpp b/src/mongo/db/s/resharding/resharding_recipient_service_external_state.cpp index bea04e3e894..fc3b553aa18 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service_external_state.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service_external_state.cpp @@ -160,7 +160,8 @@ void RecipientStateMachineExternalStateImpl::updateCoordinatorDocument(Operation query, update, false, /* upsert */ - ShardingCatalogClient::kMajorityWriteConcern)); + ShardingCatalogClient::kMajorityWriteConcern, + Milliseconds::max())); if (!docWasModified) { LOGV2_DEBUG( diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_external_state_test.cpp b/src/mongo/db/s/resharding/resharding_recipient_service_external_state_test.cpp index eada2183685..491aa085f15 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service_external_state_test.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service_external_state_test.cpp @@ -245,6 +245,32 @@ public: } }; +TEST_F(RecipientServiceExternalStateTest, ReshardingConfigServerUpdatesHaveNoTimeout) { + // TODO (SERVER-57194): enable lock-free reads. + bool disableLockFreeReadsOriginalValue = storageGlobalParams.disableLockFreeReads; + storageGlobalParams.disableLockFreeReads = true; + ON_BLOCK_EXIT( + [&] { storageGlobalParams.disableLockFreeReads = disableLockFreeReadsOriginalValue; }); + + RecipientStateMachineExternalStateImpl externalState; + + auto future = launchAsync([&] { + externalState.updateCoordinatorDocument(operationContext(), + BSON("query" + << "test"), + BSON("update" + << "test")); + }); + + onCommand([&](const executor::RemoteCommandRequest& request) { + ASSERT_FALSE(request.cmdObj.hasField("maxTimeMS")); + ASSERT_EQUALS(request.timeout, executor::RemoteCommandRequest::kNoTimeout); + return BSON("ok" << 1); + }); + + future.default_timed_get(); +} + TEST_F(RecipientServiceExternalStateTest, CreateLocalReshardingCollectionBasic) { auto shards = setupNShards(2); diff --git a/src/mongo/s/catalog/SConscript b/src/mongo/s/catalog/SConscript index 21828701cf4..964be746811 100644 --- a/src/mongo/s/catalog/SConscript +++ b/src/mongo/s/catalog/SConscript @@ -39,6 +39,7 @@ env.Library( 'sharding_catalog_client_mock.cpp', ], LIBDEPS=[ - 'sharding_catalog_client', + '$BUILD_DIR/mongo/s/client/shard_interface', + 'sharding_catalog_client' ] ) diff --git a/src/mongo/s/catalog/sharding_catalog_client.h b/src/mongo/s/catalog/sharding_catalog_client.h index f33b89e188b..84a59927b87 100644 --- a/src/mongo/s/catalog/sharding_catalog_client.h +++ b/src/mongo/s/catalog/sharding_catalog_client.h @@ -336,6 +336,19 @@ public: const WriteConcernOptions& writeConcern) = 0; /** + * Overload version of updateConfigDocument with the extra parameter 'maxTimeMs' for setting a + * custom timeout duration. Setting 'maxTimeMs' to Milliseconds::max() will entirely remove + * maxTimeMs from the command object sent over the wire. + */ + virtual StatusWith<bool> updateConfigDocument(OperationContext* opCtx, + const NamespaceString& nss, + const BSONObj& query, + const BSONObj& update, + bool upsert, + const WriteConcernOptions& writeConcern, + Milliseconds maxTimeMs) = 0; + + /** * Removes documents matching a particular query predicate from the specified namespace on the * config server. Must only be used for deletions from the 'config' database. * diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp index 1a810b73f39..69afa7aa58b 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp @@ -427,7 +427,8 @@ Status ShardingCatalogClientImpl::updateShardingCatalogEntryForCollection( BSON(CollectionType::kNssFieldName << nss.ns()), coll.toBSON(), upsert, - ShardingCatalogClient::kMajorityWriteConcern); + ShardingCatalogClient::kMajorityWriteConcern, + Shard::kDefaultConfigCommandTimeout); return status.getStatus().withContext(str::stream() << "Collection metadata write failed"); } @@ -1195,7 +1196,19 @@ StatusWith<bool> ShardingCatalogClientImpl::updateConfigDocument( const BSONObj& update, bool upsert, const WriteConcernOptions& writeConcern) { - return _updateConfigDocument(opCtx, nss, query, update, upsert, writeConcern); + return _updateConfigDocument( + opCtx, nss, query, update, upsert, writeConcern, Shard::kDefaultConfigCommandTimeout); +} + +StatusWith<bool> ShardingCatalogClientImpl::updateConfigDocument( + OperationContext* opCtx, + const NamespaceString& nss, + const BSONObj& query, + const BSONObj& update, + bool upsert, + const WriteConcernOptions& writeConcern, + Milliseconds maxTimeMs) { + return _updateConfigDocument(opCtx, nss, query, update, upsert, writeConcern, maxTimeMs); } StatusWith<bool> ShardingCatalogClientImpl::_updateConfigDocument( @@ -1204,7 +1217,8 @@ StatusWith<bool> ShardingCatalogClientImpl::_updateConfigDocument( const BSONObj& query, const BSONObj& update, bool upsert, - const WriteConcernOptions& writeConcern) { + const WriteConcernOptions& writeConcern, + Milliseconds maxTimeMs) { invariant(nss.db() == NamespaceString::kConfigDb); BatchedCommandRequest request([&] { @@ -1223,7 +1237,7 @@ StatusWith<bool> ShardingCatalogClientImpl::_updateConfigDocument( auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard(); auto response = configShard->runBatchWriteCommand( - opCtx, Shard::kDefaultConfigCommandTimeout, request, Shard::RetryPolicy::kIdempotent); + opCtx, maxTimeMs, request, Shard::RetryPolicy::kIdempotent); Status status = response.toStatus(); if (!status.isOK()) { diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.h b/src/mongo/s/catalog/sharding_catalog_client_impl.h index 1526dfd0302..93656823e06 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_impl.h +++ b/src/mongo/s/catalog/sharding_catalog_client_impl.h @@ -150,6 +150,14 @@ public: bool upsert, const WriteConcernOptions& writeConcern) override; + StatusWith<bool> updateConfigDocument(OperationContext* opCtx, + const NamespaceString& nss, + const BSONObj& query, + const BSONObj& update, + bool upsert, + const WriteConcernOptions& writeConcern, + Milliseconds maxTimeMs) override; + Status removeConfigDocuments(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& query, @@ -181,7 +189,8 @@ private: const BSONObj& query, const BSONObj& update, bool upsert, - const WriteConcernOptions& writeConcern); + const WriteConcernOptions& writeConcern, + Milliseconds maxTimeMs); StatusWith<repl::OpTimeWith<std::vector<BSONObj>>> _exhaustiveFindOnConfig( OperationContext* opCtx, diff --git a/src/mongo/s/catalog/sharding_catalog_client_mock.cpp b/src/mongo/s/catalog/sharding_catalog_client_mock.cpp index 90a1661b481..2688849cbc4 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_mock.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_mock.cpp @@ -37,6 +37,7 @@ #include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog/type_tags.h" +#include "mongo/s/client/shard.h" namespace mongo { @@ -155,6 +156,18 @@ StatusWith<bool> ShardingCatalogClientMock::updateConfigDocument( const BSONObj& update, bool upsert, const WriteConcernOptions& writeConcern) { + return {updateConfigDocument( + opCtx, nss, query, update, upsert, writeConcern, Shard::kDefaultConfigCommandTimeout)}; +} + +StatusWith<bool> ShardingCatalogClientMock::updateConfigDocument( + OperationContext* opCtx, + const NamespaceString& nss, + const BSONObj& query, + const BSONObj& update, + bool upsert, + const WriteConcernOptions& writeConcern, + Milliseconds maxTimeMs) { return {ErrorCodes::InternalError, "Method not implemented"}; } diff --git a/src/mongo/s/catalog/sharding_catalog_client_mock.h b/src/mongo/s/catalog/sharding_catalog_client_mock.h index bc58f1fd84e..ea4a386c2a6 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_mock.h +++ b/src/mongo/s/catalog/sharding_catalog_client_mock.h @@ -128,6 +128,14 @@ public: bool upsert, const WriteConcernOptions& writeConcern) override; + StatusWith<bool> updateConfigDocument(OperationContext* opCtx, + const NamespaceString& nss, + const BSONObj& query, + const BSONObj& update, + bool upsert, + const WriteConcernOptions& writeConcern, + Milliseconds maxTimeMs) override; + Status removeConfigDocuments(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& query, |