diff options
author | Irina Yatsenko <irina.yatsenko@mongodb.com> | 2021-08-16 15:35:51 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-23 19:44:53 +0000 |
commit | df329d8f46e1485dd5d70379f9c48bf4175f0d5a (patch) | |
tree | 80adf0442b021bdd689d59697a6b85ebf4dab24d /src/mongo/db/repl/tenant_collection_cloner.cpp | |
parent | 5cf8a293567989fcc970fb21cde4a1af111c8b58 (diff) | |
download | mongo-df329d8f46e1485dd5d70379f9c48bf4175f0d5a.tar.gz |
SERVER-58670 Tighten up what kind of BSON the 'Query' type can be wrapped around
This refactor includes:
Remove dead code from 'Query' type and reduce it public interface.
Split query argument in query/update/removed methods into filter BSON and settings (which are still passed around as 'Query' type).
Remove Query(string) constructors.
Remove most callers of 'Query(const BSONObj&)'.
Replace public 'Query(const BSON&)' and 'Query.obj' with an explicit factory method and a getter.
Diffstat (limited to 'src/mongo/db/repl/tenant_collection_cloner.cpp')
-rw-r--r-- | src/mongo/db/repl/tenant_collection_cloner.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/mongo/db/repl/tenant_collection_cloner.cpp b/src/mongo/db/repl/tenant_collection_cloner.cpp index 2409c1e81da..75827e5f6b3 100644 --- a/src/mongo/db/repl/tenant_collection_cloner.cpp +++ b/src/mongo/db/repl/tenant_collection_cloner.cpp @@ -212,7 +212,8 @@ BaseCloner::AfterStageBehavior TenantCollectionCloner::checkIfDonorCollectionIsE auto fieldsToReturn = BSON("_id" << 1); auto cursor = getClient()->query(_sourceDbAndUuid, - {} /* Query */, + BSONObj{} /* filter */, + Query() /* querySettings */, 1 /* limit */, 0 /* skip */, &fieldsToReturn, @@ -348,8 +349,8 @@ BaseCloner::AfterStageBehavior TenantCollectionCloner::createCollectionStage() { ON_BLOCK_EXIT([&opCtx] { tenantMigrationRecipientInfo(opCtx.get()) = boost::none; }); auto fieldsToReturn = BSON("_id" << 1); - _lastDocId = - client.findOne(_existingNss->ns(), Query().sort(BSON("_id" << -1)), &fieldsToReturn); + _lastDocId = client.findOne( + _existingNss->ns(), BSONObj{}, Query().sort(BSON("_id" << -1)), &fieldsToReturn); if (!_lastDocId.isEmpty()) { // The collection is not empty. Skip creating indexes and resume cloning from the last // document. @@ -462,21 +463,21 @@ BaseCloner::AfterStageBehavior TenantCollectionCloner::queryStage() { } void TenantCollectionCloner::runQuery() { - auto query = _lastDocId.isEmpty() - ? QUERY("query" << BSONObj()) - // Use $expr and the aggregation version of $gt to avoid type bracketing. - : QUERY("$expr" << BSON("$gt" << BSON_ARRAY("$_id" << _lastDocId["_id"]))); - if (_collectionOptions.clusteredIndex) { + const BSONObj& filter = _lastDocId.isEmpty() + ? BSONObj{} // Use $expr and the aggregation version of $gt to avoid type bracketing. + : BSON("$expr" << BSON("$gt" << BSON_ARRAY("$_id" << _lastDocId["_id"]))); + + auto query = _collectionOptions.clusteredIndex // RecordIds are _id values and has no separate _id index - query.hint(BSON("$natural" << 1)); - } else { - query.hint(BSON("_id" << 1)); - } + ? Query().hint(BSON("$natural" << 1)) + : Query().hint(BSON("_id" << 1)); + // Any errors that are thrown here (including NamespaceNotFound) will be handled on the stage // level. getClient()->query([this](DBClientCursorBatchIterator& iter) { handleNextBatch(iter); }, _sourceDbAndUuid, + filter, query, nullptr /* fieldsToReturn */, QueryOption_NoCursorTimeout | QueryOption_SecondaryOk | |