From 4a01bb629285c01c3ba307723747d06310a1a6b4 Mon Sep 17 00:00:00 2001 From: Suganthi Mani Date: Thu, 22 Oct 2020 21:56:36 -0400 Subject: Revert "SERVER-51743 Fix query operator for regex in cloner utils. SERVER-51744 Fix the filter for OplogFetcher::_makeFindQuery(). SERVER-51746 Fix the application name for tenant migration recipient collection cloner & oplog fetcher DBClientConnection. SERVER-51745 Set setRequestMetadataWriter() for tenant collection cloner." This reverts commit a730e454f65fd41dd8526c56946c67a05e9f8f7d. --- src/mongo/client/dbclient_base.h | 30 ---------------- src/mongo/db/repl/cloner_utils.cpp | 2 +- src/mongo/db/repl/oplog_fetcher.cpp | 2 +- src/mongo/db/repl/oplog_fetcher_test.cpp | 2 +- src/mongo/db/repl/tenant_collection_cloner.cpp | 41 ++++++++++++---------- src/mongo/db/repl/tenant_collection_cloner.h | 6 ++++ .../db/repl/tenant_migration_recipient_service.cpp | 15 ++------ 7 files changed, 33 insertions(+), 65 deletions(-) diff --git a/src/mongo/client/dbclient_base.h b/src/mongo/client/dbclient_base.h index a9dbe457a84..19bf9d2c417 100644 --- a/src/mongo/client/dbclient_base.h +++ b/src/mongo/client/dbclient_base.h @@ -852,34 +852,4 @@ private: BSONElement getErrField(const BSONObj& result); bool hasErrField(const BSONObj& result); -/* - * RAII-style class to set new RequestMetadataWriter and ReplyMetadataReader on DBClientConnection - * "_conn". On object destruction, '_conn' is set back to it's old RequestsMetadataWriter and - * ReplyMetadataReader. - */ -class ScopedMetadataWriterAndReader { - ScopedMetadataWriterAndReader(const ScopedMetadataWriterAndReader&) = delete; - ScopedMetadataWriterAndReader& operator=(const ScopedMetadataWriterAndReader&) = delete; - -public: - ScopedMetadataWriterAndReader(DBClientBase* conn, - rpc::RequestMetadataWriter writer, - rpc::ReplyMetadataReader reader) - : _conn(conn), - _oldWriter(std::move(conn->getRequestMetadataWriter())), - _oldReader(std::move(conn->getReplyMetadataReader())) { - _conn->setRequestMetadataWriter(std::move(writer)); - _conn->setReplyMetadataReader(std::move(reader)); - } - ~ScopedMetadataWriterAndReader() { - _conn->setRequestMetadataWriter(std::move(_oldWriter)); - _conn->setReplyMetadataReader(std::move(_oldReader)); - } - -private: - DBClientBase* const _conn; // not owned. - rpc::RequestMetadataWriter _oldWriter; - rpc::ReplyMetadataReader _oldReader; -}; - } // namespace mongo diff --git a/src/mongo/db/repl/cloner_utils.cpp b/src/mongo/db/repl/cloner_utils.cpp index ae7f11a89e8..7f061a4f1ff 100644 --- a/src/mongo/db/repl/cloner_utils.cpp +++ b/src/mongo/db/repl/cloner_utils.cpp @@ -38,7 +38,7 @@ namespace mongo { namespace repl { BSONObj ClonerUtils::makeTenantDatabaseRegex(StringData prefix) { - return BSON("$regex" + return BSON("$regexp" << "^" + prefix + "_"); } diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp index e9763ae329f..d9f3db55ae7 100644 --- a/src/mongo/db/repl/oplog_fetcher.cpp +++ b/src/mongo/db/repl/oplog_fetcher.cpp @@ -499,7 +499,7 @@ BSONObj OplogFetcher::_makeFindQuery(long long findTimeout) const { filterBob.append("ts", BSON("$gte" << lastOpTimeFetched.getTimestamp())); // Handle caller-provided filter. if (!_queryFilter.isEmpty()) { - filterBob.append("$and", BSON_ARRAY(_queryFilter)); + filterBob.append("$and", _queryFilter); } filterBob.done(); diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp index 8f9410e2c2a..ef4c0ff2785 100644 --- a/src/mongo/db/repl/oplog_fetcher_test.cpp +++ b/src/mongo/db/repl/oplog_fetcher_test.cpp @@ -2316,7 +2316,7 @@ TEST_F(OplogFetcherTest, CheckFindCommandIncludesFilter) { // Create an oplog fetcher without any retries but with a filter. Note the filter is not // respected as our Mock objects do not respect them; this unit test only tests the command // is well-formed. - const BSONObj filter = BSON("ns" << BSON("$regex" + const BSONObj filter = BSON("ns" << BSON("$regexp" << "/^tenant_.*/")); auto oplogFetcher = getOplogFetcherAfterConnectionCreated(std::ref(shutdownState), diff --git a/src/mongo/db/repl/tenant_collection_cloner.cpp b/src/mongo/db/repl/tenant_collection_cloner.cpp index e1e023960d2..43251eb6294 100644 --- a/src/mongo/db/repl/tenant_collection_cloner.cpp +++ b/src/mongo/db/repl/tenant_collection_cloner.cpp @@ -250,25 +250,8 @@ BaseCloner::AfterStageBehavior TenantCollectionCloner::createCollectionStage() { } BaseCloner::AfterStageBehavior TenantCollectionCloner::queryStage() { - // Sets up tracking the lastVisibleOpTime from response metadata. - auto requestMetadataWriter = [this](OperationContext* opCtx, - BSONObjBuilder* metadataBob) -> Status { - *metadataBob << rpc::kReplSetMetadataFieldName << 1; - return Status::OK(); - }; - auto replyMetadataReader = - [this](OperationContext* opCtx, const BSONObj& metadataObj, StringData source) -> Status { - auto readResult = rpc::ReplSetMetadata::readFromMetadata(metadataObj); - if (!readResult.isOK()) { - return readResult.getStatus().withContext( - "tenant collection cloner failed to read repl set metadata"); - } - stdx::lock_guard lk(*getSharedData()); - getSharedData()->setLastVisibleOpTime(lk, readResult.getValue().getLastOpVisible()); - return Status::OK(); - }; - ScopedMetadataWriterAndReader mwr(getClient(), requestMetadataWriter, replyMetadataReader); - + ON_BLOCK_EXIT([this] { this->unsetMetadataReader(); }); + setMetadataReader(); runQuery(); waitForDatabaseWorkToComplete(); return kContinueNormally; @@ -374,6 +357,26 @@ void TenantCollectionCloner::waitForDatabaseWorkToComplete() { _dbWorkTaskRunner.join(); } +void TenantCollectionCloner::setMetadataReader() { + getClient()->setReplyMetadataReader( + [this](OperationContext* opCtx, const BSONObj& metadataObj, StringData source) { + auto readResult = rpc::ReplSetMetadata::readFromMetadata(metadataObj); + if (!readResult.isOK()) { + return readResult.getStatus().withContext( + "tenant collection cloner failed to read repl set metadata"); + } + stdx::lock_guard lk(*getSharedData()); + getSharedData()->setLastVisibleOpTime(lk, readResult.getValue().getLastOpVisible()); + return Status::OK(); + }); +} + +void TenantCollectionCloner::unsetMetadataReader() { + getClient()->setReplyMetadataReader([this](OperationContext* opCtx, + const BSONObj& metadataObj, + StringData source) { return Status::OK(); }); +} + bool TenantCollectionCloner::isMyFailPoint(const BSONObj& data) const { auto nss = data["nss"].str(); return (nss.empty() || nss == _sourceNss.toString()) && BaseCloner::isMyFailPoint(data); diff --git a/src/mongo/db/repl/tenant_collection_cloner.h b/src/mongo/db/repl/tenant_collection_cloner.h index f0b654326dc..45d0ba022f7 100644 --- a/src/mongo/db/repl/tenant_collection_cloner.h +++ b/src/mongo/db/repl/tenant_collection_cloner.h @@ -191,6 +191,12 @@ private: */ void waitForDatabaseWorkToComplete(); + /** + * Sets up tracking the lastVisibleOpTime from response metadata. + */ + void setMetadataReader(); + void unsetMetadataReader(); + // All member variables are labeled with one of the following codes indicating the // synchronization rules for accessing them. // diff --git a/src/mongo/db/repl/tenant_migration_recipient_service.cpp b/src/mongo/db/repl/tenant_migration_recipient_service.cpp index 13ab60cebba..03901fc5fe8 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_service.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_service.cpp @@ -297,22 +297,11 @@ TenantMigrationRecipientService::Instance::_createAndConnectClients() { return _donorReplicaSetMonitor->getHostOrRefresh(_readPreference, findHostTimeout) .thenRunOn(**_scopedExecutor) .then([this](const HostAndPort& serverAddress) { - // Application name is constructed such that it doesn't exceeds - // kMaxApplicationNameByteLength (128 bytes). - // "TenantMigration_" (16 bytes) + (61 bytes) + "_" (1 byte) + - // (36 bytes) = 114 bytes length. - // Note: Since the total length of tenant database name (_) can't exceed 63 bytes and the user provided db name should be at least one - // character long, the maximum length of tenantId can only be 61 bytes. auto applicationName = - "TenantMigration_" + getTenantId() + "_" + getMigrationUUID().toString(); + "TenantMigrationRecipient_" + getTenantId() + "_" + getMigrationUUID().toString(); auto client = _connectAndAuth(serverAddress, applicationName, _authParams); - // Application name is constructed such that it doesn't exceeds - // kMaxApplicationNameByteLength (128 bytes). - // "TenantMigration_" (16 bytes) + (61 bytes) + "_" (1 byte) + - // (36 bytes) + _oplogFetcher" (13 bytes) = 127 bytes length. - applicationName += "_oplogFetcher"; + applicationName += "_fetcher"; auto oplogFetcherClient = _connectAndAuth(serverAddress, applicationName, _authParams); return ConnectionPair(std::move(client), std::move(oplogFetcherClient)); }) -- cgit v1.2.1