diff options
Diffstat (limited to 'src/mongo/db')
32 files changed, 135 insertions, 375 deletions
diff --git a/src/mongo/db/ops/write_ops_retryability.cpp b/src/mongo/db/ops/write_ops_retryability.cpp index 65fffa768d9..4cbc3a20366 100644 --- a/src/mongo/db/ops/write_ops_retryability.cpp +++ b/src/mongo/db/ops/write_ops_retryability.cpp @@ -118,8 +118,8 @@ BSONObj extractPreOrPostImage(OperationContext* opCtx, const repl::OplogEntry& o LogicalSessionId sessionId = oplog.getSessionId().get(); TxnNumber txnNumber = oplog.getTxnNumber().get(); Timestamp ts = oplog.getTimestamp(); - BSONObj imageDoc = client.findOne(NamespaceString::kConfigImagesNamespace.ns(), - BSON("_id" << sessionId.toBSON()) /*filter*/); + BSONObj imageDoc = client.findOne(NamespaceString::kConfigImagesNamespace, + BSON("_id" << sessionId.toBSON())); if (imageDoc.isEmpty()) { LOGV2_WARNING(5676402, "Image lookup for a retryable findAndModify was not found", @@ -170,8 +170,7 @@ BSONObj extractPreOrPostImage(OperationContext* opCtx, const repl::OplogEntry& o auto opTime = oplog.getPreImageOpTime() ? oplog.getPreImageOpTime().value() : oplog.getPostImageOpTime().value(); - auto oplogDoc = - client.findOne(NamespaceString::kRsOplogNamespace.ns(), opTime.asQuery(), Query(), nullptr); + auto oplogDoc = client.findOne(NamespaceString::kRsOplogNamespace, opTime.asQuery()); uassert(40613, str::stream() << "oplog no longer contains the complete write history of this " diff --git a/src/mongo/db/query/query_request_helper.cpp b/src/mongo/db/query/query_request_helper.cpp index 90d6e386d56..27b0cf5c969 100644 --- a/src/mongo/db/query/query_request_helper.cpp +++ b/src/mongo/db/query/query_request_helper.cpp @@ -44,33 +44,17 @@ namespace mongo { namespace query_request_helper { namespace { - /** - * Initializes options based on the value of the 'options' bit vector. - * - * This contains flags such as tailable, exhaust, and noCursorTimeout. + * Add the meta projection to this object if needed. */ -void initFromInt(int options, FindCommandRequest* findCommand) { - bool tailable = (options & QueryOption_CursorTailable) != 0; - bool awaitData = (options & QueryOption_AwaitData) != 0; - if (awaitData) { - findCommand->setAwaitData(true); - } - if (tailable) { - findCommand->setTailable(true); - } - - if ((options & QueryOption_NoCursorTimeout) != 0) { - findCommand->setNoCursorTimeout(true); - } - if ((options & QueryOption_PartialResults) != 0) { - findCommand->setAllowPartialResults(true); +void addMetaProjection(FindCommandRequest* findCommand) { + if (findCommand->getShowRecordId()) { + addShowRecordIdMetaProj(findCommand); } } -/** - * Updates the projection object with a $meta projection for the showRecordId option. - */ +} // namespace + void addShowRecordIdMetaProj(FindCommandRequest* findCommand) { if (findCommand->getProjection()["$recordId"]) { // There's already some projection on $recordId. Don't overwrite it. @@ -84,136 +68,6 @@ void addShowRecordIdMetaProj(FindCommandRequest* findCommand) { findCommand->setProjection(projBob.obj()); } -/** - * Add the meta projection to this object if needed. - */ -void addMetaProjection(FindCommandRequest* findCommand) { - if (findCommand->getShowRecordId()) { - addShowRecordIdMetaProj(findCommand); - } -} - -Status initFullQuery(const BSONObj& top, FindCommandRequest* findCommand) { - BSONObjIterator i(top); - - while (i.more()) { - BSONElement e = i.next(); - StringData name = e.fieldNameStringData(); - - if (name == "$orderby" || name == "orderby") { - if (Object == e.type()) { - findCommand->setSort(e.embeddedObject().getOwned()); - } else if (Array == e.type()) { - findCommand->setSort(e.embeddedObject()); - - // TODO: Is this ever used? I don't think so. - // Quote: - // This is for languages whose "objects" are not well ordered (JSON is well - // ordered). - // [ { a : ... } , { b : ... } ] -> { a : ..., b : ... } - // note: this is slow, but that is ok as order will have very few pieces - BSONObjBuilder b; - char p[2] = "0"; - - while (1) { - BSONObj j = findCommand->getSort().getObjectField(p); - if (j.isEmpty()) { - break; - } - BSONElement e = j.firstElement(); - if (e.eoo()) { - return Status(ErrorCodes::BadValue, "bad order array"); - } - if (!e.isNumber()) { - return Status(ErrorCodes::BadValue, "bad order array [2]"); - } - b.append(e); - (*p)++; - if (!(*p <= '9')) { - return Status(ErrorCodes::BadValue, "too many ordering elements"); - } - } - - findCommand->setSort(b.obj()); - } else { - return Status(ErrorCodes::BadValue, "sort must be object or array"); - } - } else if (name.startsWith("$")) { - name = name.substr(1); // chop first char - if (name == "min") { - if (!e.isABSONObj()) { - return Status(ErrorCodes::BadValue, "$min must be a BSONObj"); - } - findCommand->setMin(e.embeddedObject().getOwned()); - } else if (name == "max") { - if (!e.isABSONObj()) { - return Status(ErrorCodes::BadValue, "$max must be a BSONObj"); - } - findCommand->setMax(e.embeddedObject().getOwned()); - } else if (name == "hint") { - if (e.isABSONObj()) { - findCommand->setHint(e.embeddedObject().getOwned()); - } else if (String == e.type()) { - findCommand->setHint(e.wrap()); - } else { - return Status(ErrorCodes::BadValue, - "$hint must be either a string or nested object"); - } - } else if (name == "returnKey") { - // Won't throw. - if (e.trueValue()) { - findCommand->setReturnKey(true); - } - } else if (name == "showDiskLoc") { - // Won't throw. - if (e.trueValue()) { - findCommand->setShowRecordId(true); - addShowRecordIdMetaProj(findCommand); - } - } else if (name == "maxTimeMS") { - StatusWith<int> maxTimeMS = parseMaxTimeMS(e); - if (!maxTimeMS.isOK()) { - return maxTimeMS.getStatus(); - } - findCommand->setMaxTimeMS(maxTimeMS.getValue()); - } - } - } - - return Status::OK(); -} - -Status initFindCommandRequest(int ntoskip, - int queryOptions, - const BSONObj& filter, - const Query& querySettings, - const BSONObj& proj, - FindCommandRequest* findCommand) { - if (!proj.isEmpty()) { - findCommand->setProjection(proj.getOwned()); - } - if (ntoskip) { - findCommand->setSkip(ntoskip); - } - - // Initialize flags passed as 'queryOptions' bit vector. - initFromInt(queryOptions, findCommand); - - findCommand->setFilter(filter.getOwned()); - Status status = initFullQuery(querySettings.getFullSettingsDeprecated(), findCommand); - if (!status.isOK()) { - return status; - } - - // It's not possible to specify readConcern in a legacy query message, so initialize it to - // an empty readConcern object, ie. equivalent to `readConcern: {}`. This ensures that - // mongos passes this empty readConcern to shards. - findCommand->setReadConcern(BSONObj()); - - return validateFindCommandRequest(*findCommand); -} - -} // namespace Status validateGetMoreCollectionName(StringData collectionName) { if (collectionName.empty()) { @@ -380,27 +234,6 @@ void validateCursorResponse(const BSONObj& outputAsBson) { } } -// -// Old QueryRequest parsing code: SOON TO BE DEPRECATED. -// - -StatusWith<std::unique_ptr<FindCommandRequest>> fromLegacyQuery(NamespaceStringOrUUID nssOrUuid, - const BSONObj& filter, - const Query& querySettings, - const BSONObj& proj, - int ntoskip, - int queryOptions) { - auto findCommand = std::make_unique<FindCommandRequest>(std::move(nssOrUuid)); - - Status status = initFindCommandRequest( - ntoskip, queryOptions, filter, querySettings, proj, findCommand.get()); - if (!status.isOK()) { - return status; - } - - return std::move(findCommand); -} - StatusWith<BSONObj> asAggregationCommand(const FindCommandRequest& findCommand) { BSONObjBuilder aggregationBuilder; diff --git a/src/mongo/db/query/query_request_helper.h b/src/mongo/db/query/query_request_helper.h index 3c7cbc53b89..4044083d89f 100644 --- a/src/mongo/db/query/query_request_helper.h +++ b/src/mongo/db/query/query_request_helper.h @@ -144,19 +144,10 @@ TailableModeEnum getTailableMode(const FindCommandRequest& findCommand); */ void validateCursorResponse(const BSONObj& outputAsBson); -// -// Old parsing code: SOON TO BE DEPRECATED. -// - /** - * Parse the provided legacy query object and parameters to construct a FindCommandRequest. + * Updates the projection object with a $meta projection for the showRecordId option. */ -StatusWith<std::unique_ptr<FindCommandRequest>> fromLegacyQuery(NamespaceStringOrUUID nsOrUuid, - const BSONObj& filter, - const Query& querySettings, - const BSONObj& proj, - int ntoskip, - int queryOptions); +void addShowRecordIdMetaProj(FindCommandRequest* findCommand); } // namespace query_request_helper } // namespace mongo diff --git a/src/mongo/db/query/query_request_test.cpp b/src/mongo/db/query/query_request_test.cpp index eba29f8c27e..88c41a2d821 100644 --- a/src/mongo/db/query/query_request_test.cpp +++ b/src/mongo/db/query/query_request_test.cpp @@ -1548,64 +1548,6 @@ TEST(QueryRequestTest, ConvertToFindWithAllowDiskUseFalseSucceeds) { ASSERT_FALSE(findCmd[FindCommandRequest::kAllowDiskUseFieldName].booleanSafe()); } -TEST(QueryRequestTest, ParseFromLegacyQuery) { - const auto kSkip = 1; - const NamespaceString nss("test.testns"); - - unique_ptr<FindCommandRequest> findCommand(assertGet(query_request_helper::fromLegacyQuery( - nss, - fromjson("{query: 1}") /*filter*/, - Query().sort(BSON("sort" << 1)).hint(BSON("hint" << 1)), - BSON("proj" << 1), - kSkip, - QueryOption_Exhaust))); - - ASSERT_EQ(*findCommand->getNamespaceOrUUID().nss(), nss); - ASSERT_BSONOBJ_EQ(findCommand->getFilter(), fromjson("{query: 1}")); - ASSERT_BSONOBJ_EQ(findCommand->getProjection(), fromjson("{proj: 1}")); - ASSERT_BSONOBJ_EQ(findCommand->getSort(), fromjson("{sort: 1}")); - ASSERT_BSONOBJ_EQ(findCommand->getHint(), fromjson("{hint: 1}")); - ASSERT_EQ(findCommand->getSkip(), boost::optional<int64_t>(kSkip)); - ASSERT_FALSE(findCommand->getNtoreturn()); - ASSERT_EQ(findCommand->getSingleBatch(), false); - ASSERT_EQ(findCommand->getNoCursorTimeout(), false); - ASSERT_EQ(findCommand->getTailable(), false); - ASSERT_EQ(findCommand->getAllowPartialResults(), false); -} - -TEST(QueryRequestTest, ParseFromLegacyQueryOplogReplayFlagAllowed) { - const NamespaceString nss("test.testns"); - const BSONObj projectionObj{}; - const auto nToSkip = 0; - - // Test that parsing succeeds even if the oplog replay bit is set in the OP_QUERY message. This - // flag may be set by old clients. - auto options = QueryOption_OplogReplay_DEPRECATED; - unique_ptr<FindCommandRequest> findCommand(assertGet(query_request_helper::fromLegacyQuery( - nss, fromjson("{query: 1}"), Query().sort("sort", 1), projectionObj, nToSkip, options))); - - // Verify that if we reserialize the find command, the 'oplogReplay' field - // does not appear. - BSONObjBuilder bob; - findCommand->serialize(BSONObj(), &bob); - auto reserialized = bob.obj(); - - ASSERT_BSONOBJ_EQ(reserialized, - BSON("find" - << "testns" - << "filter" << BSON("query" << 1) << "sort" << BSON("sort" << 1) - << "readConcern" << BSONObj{})); -} - -TEST(QueryRequestTest, ParseFromLegacyQueryUnwrapped) { - const NamespaceString nss("test.testns"); - unique_ptr<FindCommandRequest> findCommand(assertGet(query_request_helper::fromLegacyQuery( - nss, fromjson("{foo: 1}"), Query(), BSONObj(), 0, QueryOption_Exhaust))); - - ASSERT_EQ(*findCommand->getNamespaceOrUUID().nss(), nss); - ASSERT_BSONOBJ_EQ(findCommand->getFilter(), fromjson("{foo: 1}")); -} - TEST(QueryRequestHelperTest, ValidateResponseMissingFields) { BSONObjBuilder builder; ASSERT_THROWS_CODE( diff --git a/src/mongo/db/read_write_concern_defaults_cache_lookup_mongod.cpp b/src/mongo/db/read_write_concern_defaults_cache_lookup_mongod.cpp index 1b341ab4b11..08f95264959 100644 --- a/src/mongo/db/read_write_concern_defaults_cache_lookup_mongod.cpp +++ b/src/mongo/db/read_write_concern_defaults_cache_lookup_mongod.cpp @@ -49,7 +49,7 @@ BSONObj getPersistedDefaultRWConcernDocument(OperationContext* opCtx) { !MONGO_unlikely(failRWCDefaultsLookup.shouldFail())); DBDirectClient client(opCtx); - return client.findOne(NamespaceString::kConfigSettingsNamespace.toString(), + return client.findOne(NamespaceString::kConfigSettingsNamespace, BSON("_id" << ReadWriteConcernDefaults::kPersistedDocumentId)); } diff --git a/src/mongo/db/repl/all_database_cloner.cpp b/src/mongo/db/repl/all_database_cloner.cpp index 8a7159b5dde..d18f67cc39f 100644 --- a/src/mongo/db/repl/all_database_cloner.cpp +++ b/src/mongo/db/repl/all_database_cloner.cpp @@ -132,7 +132,8 @@ BaseCloner::AfterStageBehavior AllDatabaseCloner::getInitialSyncIdStage() { if (wireVersion < WireVersion::RESUMABLE_INITIAL_SYNC) return kContinueNormally; auto initialSyncId = getClient()->findOne( - ReplicationConsistencyMarkersImpl::kDefaultInitialSyncIdNamespace.toString(), BSONObj{}); + NamespaceString{ReplicationConsistencyMarkersImpl::kDefaultInitialSyncIdNamespace}, + BSONObj{}); uassert(ErrorCodes::InitialSyncFailure, "Cannot retrieve sync source initial sync ID", !initialSyncId.isEmpty()); diff --git a/src/mongo/db/repl/apply_ops.cpp b/src/mongo/db/repl/apply_ops.cpp index 6be1ed0b32b..50d012ab6c8 100644 --- a/src/mongo/db/repl/apply_ops.cpp +++ b/src/mongo/db/repl/apply_ops.cpp @@ -286,9 +286,13 @@ Status _checkPrecondition(OperationContext* opCtx, } DBDirectClient db(opCtx); - // The preconditions come in "q: {{query: {...}, orderby: ..., etc.}}" format. + // The preconditions come in "q: {{query: {...}, orderby: ..., etc.}}" format. This format + // is no longer used either internally or over the wire in other contexts. We are using a + // legacy API from 'DBDirectClient' in order to parse this format and convert it into the + // corresponding find command. auto preconditionQuery = Query::fromBSONDeprecated(preCondition["q"].Obj()); - BSONObj realres = db.findOne(nss.ns(), preconditionQuery.getFilter(), preconditionQuery); + auto cursor = db.query(nss, preconditionQuery.getFilter(), preconditionQuery, 1 /*limit*/); + BSONObj realres = cursor->more() ? cursor->nextSafe() : BSONObj{}; // Get collection default collation. auto databaseHolder = DatabaseHolder::get(opCtx); diff --git a/src/mongo/db/repl/initial_sync_base_cloner.cpp b/src/mongo/db/repl/initial_sync_base_cloner.cpp index 0c00012b3f7..c08d102ca9c 100644 --- a/src/mongo/db/repl/initial_sync_base_cloner.cpp +++ b/src/mongo/db/repl/initial_sync_base_cloner.cpp @@ -128,7 +128,7 @@ Status InitialSyncBaseCloner::checkInitialSyncIdIsUnchanged() { BSONObj initialSyncId; try { initialSyncId = getClient()->findOne( - ReplicationConsistencyMarkersImpl::kDefaultInitialSyncIdNamespace.toString(), + NamespaceString{ReplicationConsistencyMarkersImpl::kDefaultInitialSyncIdNamespace}, BSONObj{}); } catch (DBException& e) { if (ErrorCodes::isRetriableError(e)) { diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index df142f4a773..0a22256070e 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -1951,11 +1951,10 @@ void setNewTimestamp(ServiceContext* service, const Timestamp& newTime) { void initTimestampFromOplog(OperationContext* opCtx, const NamespaceString& oplogNss) { DBDirectClient c(opCtx); static const BSONObj reverseNaturalObj = BSON("$natural" << -1); - BSONObj lastOp = c.findOne(oplogNss.ns(), - BSONObj{}, - Query().sort(reverseNaturalObj), - nullptr, - QueryOption_SecondaryOk); + FindCommandRequest findCmd{oplogNss}; + findCmd.setSort(reverseNaturalObj); + BSONObj lastOp = + c.findOne(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryPreferred}); if (!lastOp.isEmpty()) { LOGV2_DEBUG(21256, 1, "replSet setting last Timestamp"); diff --git a/src/mongo/db/repl/oplog_applier_impl_test.cpp b/src/mongo/db/repl/oplog_applier_impl_test.cpp index 9996da62a0e..b6f814be2de 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test.cpp @@ -2990,7 +2990,7 @@ TEST_F(OplogApplierImplTxnTableTest, MultiApplyUpdatesTheTransactionTable) { // The txnNum and optime of the only write were saved. auto resultSingleDoc = - client.findOne(NamespaceString::kSessionTransactionsTableNamespace.ns(), + client.findOne(NamespaceString::kSessionTransactionsTableNamespace, BSON(SessionTxnRecord::kSessionIdFieldName << lsidSingle.toBSON())); ASSERT_TRUE(!resultSingleDoc.isEmpty()); @@ -3002,7 +3002,7 @@ TEST_F(OplogApplierImplTxnTableTest, MultiApplyUpdatesTheTransactionTable) { // The txnNum and optime of the write with the larger txnNum were saved. auto resultDiffTxnDoc = - client.findOne(NamespaceString::kSessionTransactionsTableNamespace.ns(), + client.findOne(NamespaceString::kSessionTransactionsTableNamespace, BSON(SessionTxnRecord::kSessionIdFieldName << lsidDiffTxn.toBSON())); ASSERT_TRUE(!resultDiffTxnDoc.isEmpty()); @@ -3014,7 +3014,7 @@ TEST_F(OplogApplierImplTxnTableTest, MultiApplyUpdatesTheTransactionTable) { // The txnNum and optime of the write with the later optime were saved. auto resultSameTxnDoc = - client.findOne(NamespaceString::kSessionTransactionsTableNamespace.ns(), + client.findOne(NamespaceString::kSessionTransactionsTableNamespace, BSON(SessionTxnRecord::kSessionIdFieldName << lsidSameTxn.toBSON())); ASSERT_TRUE(!resultSameTxnDoc.isEmpty()); @@ -3026,7 +3026,7 @@ TEST_F(OplogApplierImplTxnTableTest, MultiApplyUpdatesTheTransactionTable) { // There is no entry for the write with no txnNumber. auto resultNoTxn = - client.findOne(NamespaceString::kSessionTransactionsTableNamespace.ns(), + client.findOne(NamespaceString::kSessionTransactionsTableNamespace, BSON(SessionTxnRecord::kSessionIdFieldName << lsidNoTxn.toBSON())); ASSERT_TRUE(resultNoTxn.isEmpty()); } diff --git a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp index 72da6429fd2..0743407a534 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp @@ -348,7 +348,7 @@ void checkTxnTable(OperationContext* opCtx, boost::optional<repl::OpTime> expectedStartOpTime, boost::optional<DurableTxnStateEnum> expectedState) { DBDirectClient client(opCtx); - auto result = client.findOne(NamespaceString::kSessionTransactionsTableNamespace.ns(), + auto result = client.findOne(NamespaceString::kSessionTransactionsTableNamespace, BSON(SessionTxnRecord::kSessionIdFieldName << lsid.toBSON())); ASSERT_FALSE(result.isEmpty()); @@ -392,7 +392,7 @@ StatusWith<BSONObj> CollectionReader::next() { bool docExists(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& doc) { DBDirectClient client(opCtx); - auto result = client.findOne(nss.ns(), doc); + auto result = client.findOne(nss, doc); return !result.isEmpty(); } diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp index b3f06150854..3c57ed26f92 100644 --- a/src/mongo/db/repl/oplog_fetcher.cpp +++ b/src/mongo/db/repl/oplog_fetcher.cpp @@ -1042,10 +1042,11 @@ Status OplogFetcher::_checkTooStaleToSyncFromSource(const OpTime lastFetched, BSONObj remoteFirstOplogEntry; try { // Query for the first oplog entry in the sync source's oplog. - auto query = Query().sort(BSON("$natural" << 1)); + FindCommandRequest findRequest{_nss}; + findRequest.setSort(BSON("$natural" << 1)); // Since this function is called after the first batch, the exhaust stream has not been // started yet. As a result, using the same connection is safe. - remoteFirstOplogEntry = _conn->findOne(_nss.ns(), BSONObj{}, query); + remoteFirstOplogEntry = _conn->findOne(std::move(findRequest)); } catch (DBException& e) { // If an error occurs with the query, throw an error. return Status(ErrorCodes::TooStaleToSyncFromSource, e.reason()); diff --git a/src/mongo/db/repl/rollback_source_impl.cpp b/src/mongo/db/repl/rollback_source_impl.cpp index c6184fb7259..f174d3c718c 100644 --- a/src/mongo/db/repl/rollback_source_impl.cpp +++ b/src/mongo/db/repl/rollback_source_impl.cpp @@ -66,22 +66,19 @@ int RollbackSourceImpl::getRollbackId() const { } BSONObj RollbackSourceImpl::getLastOperation() const { - return _getConnection()->findOne(_collectionName, - BSONObj{}, - Query().sort(BSON("$natural" << -1)), - nullptr, - QueryOption_SecondaryOk, - ReadConcernArgs::kImplicitDefault); + FindCommandRequest findCmd{NamespaceString{_collectionName}}; + findCmd.setSort(BSON("$natural" << -1)); + findCmd.setReadConcern(ReadConcernArgs::kImplicitDefault); + return _getConnection()->findOne(std::move(findCmd), + ReadPreferenceSetting{ReadPreference::SecondaryPreferred}); } BSONObj RollbackSourceImpl::findOne(const NamespaceString& nss, const BSONObj& filter) const { + FindCommandRequest findCmd{nss}; + findCmd.setFilter(filter); + findCmd.setReadConcern(ReadConcernArgs::kImplicitDefault); return _getConnection() - ->findOne(nss.toString(), - filter, - Query(), - nullptr, - QueryOption_SecondaryOk, - ReadConcernArgs::kImplicitDefault) + ->findOne(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryPreferred}) .getOwned(); } diff --git a/src/mongo/db/repl/tenant_collection_cloner.cpp b/src/mongo/db/repl/tenant_collection_cloner.cpp index 35a99338271..461a6beab8a 100644 --- a/src/mongo/db/repl/tenant_collection_cloner.cpp +++ b/src/mongo/db/repl/tenant_collection_cloner.cpp @@ -348,9 +348,10 @@ BaseCloner::AfterStageBehavior TenantCollectionCloner::createCollectionStage() { // (createCollection/createIndex) don't get stamped with the fromTenantMigration field. ON_BLOCK_EXIT([&opCtx] { tenantMigrationRecipientInfo(opCtx.get()) = boost::none; }); - auto fieldsToReturn = BSON("_id" << 1); - _lastDocId = client.findOne( - _existingNss->ns(), BSONObj{}, Query().sort(BSON("_id" << -1)), &fieldsToReturn); + FindCommandRequest findCmd{*_existingNss}; + findCmd.setSort(BSON("_id" << -1)); + findCmd.setProjection(BSON("_id" << 1)); + _lastDocId = client.findOne(std::move(findCmd)); if (!_lastDocId.isEmpty()) { // The collection is not empty. Skip creating indexes and resume cloning from the last // document. diff --git a/src/mongo/db/repl/tenant_migration_recipient_service.cpp b/src/mongo/db/repl/tenant_migration_recipient_service.cpp index 16bda5828f4..a38a4357179 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_service.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_service.cpp @@ -583,13 +583,12 @@ OpTime TenantMigrationRecipientService::Instance::_getDonorMajorityOpTime( std::unique_ptr<mongo::DBClientConnection>& client) { auto oplogOpTimeFields = BSON(OplogEntry::kTimestampFieldName << 1 << OplogEntry::kTermFieldName << 1); - auto majorityOpTimeBson = - client->findOne(NamespaceString::kRsOplogNamespace.ns(), - BSONObj{}, - Query().sort("$natural", -1), - &oplogOpTimeFields, - QueryOption_SecondaryOk, - ReadConcernArgs(ReadConcernLevel::kMajorityReadConcern).toBSONInner()); + FindCommandRequest findCmd{NamespaceString::kRsOplogNamespace}; + findCmd.setSort(BSON("$natural" << -1)); + findCmd.setProjection(oplogOpTimeFields); + findCmd.setReadConcern(ReadConcernArgs(ReadConcernLevel::kMajorityReadConcern).toBSONInner()); + auto majorityOpTimeBson = client->findOne( + std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryPreferred}); uassert(5272003, "Found no entries in the remote oplog", !majorityOpTimeBson.isEmpty()); auto majorityOpTime = uassertStatusOK(OpTime::parseFromOplogEntry(majorityOpTimeBson)); @@ -878,13 +877,13 @@ void TenantMigrationRecipientService::Instance::_getStartOpTimesFromDonor(WithLo const auto preparedState = DurableTxnState_serializer(DurableTxnStateEnum::kPrepared); const auto inProgressState = DurableTxnState_serializer(DurableTxnStateEnum::kInProgress); auto transactionTableOpTimeFields = BSON(SessionTxnRecord::kStartOpTimeFieldName << 1); + FindCommandRequest findCmd{NamespaceString::kSessionTransactionsTableNamespace}; + findCmd.setFilter(BSON("state" << BSON("$in" << BSON_ARRAY(preparedState << inProgressState)))); + findCmd.setSort(BSON(SessionTxnRecord::kStartOpTimeFieldName.toString() << 1)); + findCmd.setProjection(transactionTableOpTimeFields); + findCmd.setReadConcern(ReadConcernArgs(ReadConcernLevel::kMajorityReadConcern).toBSONInner()); auto earliestOpenTransactionBson = _client->findOne( - NamespaceString::kSessionTransactionsTableNamespace.ns(), - BSON("state" << BSON("$in" << BSON_ARRAY(preparedState << inProgressState))), - Query().sort(SessionTxnRecord::kStartOpTimeFieldName.toString(), 1), - &transactionTableOpTimeFields, - QueryOption_SecondaryOk, - ReadConcernArgs(ReadConcernLevel::kMajorityReadConcern).toBSONInner()); + std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryPreferred}); LOGV2_DEBUG(4880602, 2, "Transaction table entry for earliest transaction that was open at the read " @@ -1923,13 +1922,11 @@ void TenantMigrationRecipientService::Instance::_compareRecipientAndDonorFCV() c return; } - auto donorFCVbson = - _client->findOne(NamespaceString::kServerConfigurationNamespace.ns(), - BSON("_id" << multiversion::kParameterName), - Query(), - nullptr, - QueryOption_SecondaryOk, - ReadConcernArgs(ReadConcernLevel::kMajorityReadConcern).toBSONInner()); + FindCommandRequest findCmd{NamespaceString::kServerConfigurationNamespace}; + findCmd.setFilter(BSON("_id" << multiversion::kParameterName)); + findCmd.setReadConcern(ReadConcernArgs(ReadConcernLevel::kMajorityReadConcern).toBSONInner()); + auto donorFCVbson = _client->findOne(std::move(findCmd), + ReadPreferenceSetting{ReadPreference::SecondaryPreferred}); uassert(5382302, "FCV on donor not set", !donorFCVbson.isEmpty()); diff --git a/src/mongo/db/s/chunk_splitter.cpp b/src/mongo/db/s/chunk_splitter.cpp index e41d49db40b..64224e03905 100644 --- a/src/mongo/db/s/chunk_splitter.cpp +++ b/src/mongo/db/s/chunk_splitter.cpp @@ -145,10 +145,10 @@ BSONObj findExtremeKeyForShard(OperationContext* opCtx, const NamespaceString& nss, const ShardKeyPattern& shardKeyPattern, bool doSplitAtLower) { - Query q; + FindCommandRequest findCmd{nss}; if (doSplitAtLower) { - q.sort(shardKeyPattern.toBSON()); + findCmd.setSort(shardKeyPattern.toBSON()); } else { // need to invert shard key pattern to sort backwards BSONObjBuilder r; @@ -160,7 +160,7 @@ BSONObj findExtremeKeyForShard(OperationContext* opCtx, r.append(e.fieldName(), -1 * e.number()); } - q.sort(r.obj()); + findCmd.setSort(r.obj()); } DBDirectClient client(opCtx); @@ -168,14 +168,12 @@ BSONObj findExtremeKeyForShard(OperationContext* opCtx, BSONObj end; if (doSplitAtLower) { - // Splitting close to the lower bound means that the split point will be the - // upper bound. Chunk range upper bounds are exclusive so skip a document to - // make the lower half of the split end up with a single document. - std::unique_ptr<DBClientCursor> cursor = client.query(nss, - BSONObj{}, - q, - 1, /* limit */ - 1 /* nToSkip */); + // Splitting close to the lower bound means that the split point will be the upper bound. + // Chunk range upper bounds are exclusive so skip a document to make the lower half of the + // split end up with a single document. + findCmd.setLimit(1); + findCmd.setSkip(1); + std::unique_ptr<DBClientCursor> cursor = client.find(std::move(findCmd)); uassert(40618, str::stream() << "failed to initialize cursor during auto split due to " @@ -186,7 +184,7 @@ BSONObj findExtremeKeyForShard(OperationContext* opCtx, end = cursor->next().getOwned(); } } else { - end = client.findOne(nss.ns(), BSONObj{}, q); + end = client.findOne(std::move(findCmd)); } if (end.isEmpty()) { diff --git a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp index b89a6311fbf..1adb7a78174 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp @@ -159,7 +159,7 @@ DatabaseType ShardingCatalogManager::createDatabase(OperationContext* opCtx, (std::string) "^" + pcrecpp::RE::QuoteMeta(dbName.toString()) + "$", "i"); - auto dbDoc = client.findOne(DatabaseType::ConfigNS.ns(), queryBuilder.obj()); + auto dbDoc = client.findOne(DatabaseType::ConfigNS, queryBuilder.obj()); auto const [primaryShardPtr, database] = [&] { if (!dbDoc.isEmpty()) { auto actualDb = uassertStatusOK(DatabaseType::fromBSON(dbDoc)); diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp index 603fd762ebf..7b1fd9da8a4 100644 --- a/src/mongo/db/s/create_collection_coordinator.cpp +++ b/src/mongo/db/s/create_collection_coordinator.cpp @@ -195,7 +195,7 @@ bool checkIfCollectionIsEmpty(OperationContext* opCtx, const NamespaceString& ns // command doesn't just consult the cached metadata, which may not always be // correct DBDirectClient localClient(opCtx); - return localClient.findOne(nss.ns(), BSONObj{}).isEmpty(); + return localClient.findOne(nss, BSONObj{}).isEmpty(); } int getNumShards(OperationContext* opCtx) { diff --git a/src/mongo/db/s/persistent_task_queue.h b/src/mongo/db/s/persistent_task_queue.h index fcd75ced175..25736e6d6ba 100644 --- a/src/mongo/db/s/persistent_task_queue.h +++ b/src/mongo/db/s/persistent_task_queue.h @@ -221,16 +221,19 @@ bool PersistentTaskQueue<T>::empty(OperationContext* opCtx) const { template <typename T> TaskId PersistentTaskQueue<T>::_loadLastId(DBDirectClient& client) { - auto fieldsToReturn = BSON("_id" << 1); - auto maxId = client.findOne( - _storageNss.toString(), BSONObj{}, Query().sort(BSON("_id" << -1)), &fieldsToReturn); + FindCommandRequest findCmd{_storageNss}; + findCmd.setSort(BSON("_id" << -1)); + findCmd.setProjection(BSON("_id" << 1)); + auto maxId = client.findOne(std::move(findCmd)); return maxId.getField("_id").Long(); } template <typename T> typename boost::optional<typename BlockingTaskQueue<T>::Record> PersistentTaskQueue<T>::_loadNextRecord(DBDirectClient& client) { - auto bson = client.findOne(_storageNss.toString(), BSONObj{}, Query().sort("_id")); + FindCommandRequest findCmd{_storageNss}; + findCmd.setSort(BSON("_id" << 1)); + auto bson = client.findOne(std::move(findCmd)); boost::optional<typename PersistentTaskQueue<T>::Record> result; diff --git a/src/mongo/db/s/resharding/resharding_agg_test.cpp b/src/mongo/db/s/resharding/resharding_agg_test.cpp index 5d49e96409d..1c507297bd1 100644 --- a/src/mongo/db/s/resharding/resharding_agg_test.cpp +++ b/src/mongo/db/s/resharding/resharding_agg_test.cpp @@ -154,7 +154,7 @@ public: const Document& documentKey, boost::optional<BSONObj> readConcern) { DBDirectClient client(expCtx->opCtx); - auto result = client.findOne(nss.ns(), documentKey.toBson()); + auto result = client.findOne(nss, documentKey.toBson()); if (result.isEmpty()) { return boost::none; } diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp index ae801434182..eed075dfe3a 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp @@ -225,8 +225,7 @@ public: ReshardingCoordinatorDocument getCoordinatorDoc(OperationContext* opCtx) { DBDirectClient client(opCtx); - auto doc = - client.findOne(NamespaceString::kConfigReshardingOperationsNamespace.ns(), BSONObj{}); + auto doc = client.findOne(NamespaceString::kConfigReshardingOperationsNamespace, BSONObj{}); IDLParserErrorContext errCtx("reshardingCoordFromTest"); return ReshardingCoordinatorDocument::parse(errCtx, doc); } @@ -879,7 +878,7 @@ TEST_F(ReshardingCoordinatorServiceTest, StepDownStepUpEachTransition) { // config.collections should not have the document with the old UUID. std::vector<ChunkType> foundCollections; auto collection = - client.findOne(CollectionType::ConfigNS.ns(), + client.findOne(CollectionType::ConfigNS, BSON(CollectionType::kNssFieldName << doc.getSourceNss().ns())); ASSERT_EQUALS(collection.isEmpty(), false); @@ -924,9 +923,8 @@ TEST_F(ReshardingCoordinatorServiceTest, ReshardingCoordinatorFailsIfMigrationNo // Check that reshardCollection keeps allowMigrations setting intact. { DBDirectClient client(opCtx); - CollectionType collDoc( - client.findOne(CollectionType::ConfigNS.ns(), - BSON(CollectionType::kNssFieldName << _originalNss.ns()))); + CollectionType collDoc(client.findOne( + CollectionType::ConfigNS, BSON(CollectionType::kNssFieldName << _originalNss.ns()))); ASSERT_FALSE(collDoc.getAllowMigrations()); } } diff --git a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp index 91eb6d31aa0..9116e731841 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp @@ -237,7 +237,7 @@ protected: void readReshardingCoordinatorDocAndAssertMatchesExpected( OperationContext* opCtx, ReshardingCoordinatorDocument expectedCoordinatorDoc) { DBDirectClient client(opCtx); - auto doc = client.findOne(NamespaceString::kConfigReshardingOperationsNamespace.ns(), + auto doc = client.findOne(NamespaceString::kConfigReshardingOperationsNamespace, BSON("ns" << expectedCoordinatorDoc.getSourceNss().ns())); auto coordinatorDoc = ReshardingCoordinatorDocument::parse( @@ -320,7 +320,7 @@ protected: const ReshardingCoordinatorDocument& expectedCoordinatorDoc) { DBDirectClient client(opCtx); CollectionType onDiskEntry( - client.findOne(CollectionType::ConfigNS.ns(), BSON("_id" << _originalNss.ns()))); + client.findOne(CollectionType::ConfigNS, BSON("_id" << _originalNss.ns()))); ASSERT_EQUALS(onDiskEntry.getAllowMigrations(), expectedCollType.getAllowMigrations()); @@ -379,7 +379,7 @@ protected: void assertTemporaryCollectionCatalogEntryMatchesExpected( OperationContext* opCtx, boost::optional<CollectionType> expectedCollType) { DBDirectClient client(opCtx); - auto doc = client.findOne(CollectionType::ConfigNS.ns(), BSON("_id" << _tempNss.ns())); + auto doc = client.findOne(CollectionType::ConfigNS, BSON("_id" << _tempNss.ns())); if (!expectedCollType) { ASSERT(doc.isEmpty()); return; @@ -618,10 +618,10 @@ protected: // Check that chunks and tags under the temp namespace have been removed DBDirectClient client(opCtx); - auto chunkDoc = client.findOne(ChunkType::ConfigNS.ns(), BSON("ns" << _tempNss.ns())); + auto chunkDoc = client.findOne(ChunkType::ConfigNS, BSON("ns" << _tempNss.ns())); ASSERT(chunkDoc.isEmpty()); - auto tagDoc = client.findOne(TagsType::ConfigNS.ns(), BSON("ns" << _tempNss.ns())); + auto tagDoc = client.findOne(TagsType::ConfigNS, BSON("ns" << _tempNss.ns())); ASSERT(tagDoc.isEmpty()); } @@ -647,7 +647,7 @@ protected: // Check that the entry is removed from config.reshardingOperations DBDirectClient client(opCtx); - auto doc = client.findOne(NamespaceString::kConfigReshardingOperationsNamespace.ns(), + auto doc = client.findOne(NamespaceString::kConfigReshardingOperationsNamespace, BSON("ns" << expectedCoordinatorDoc.getSourceNss().ns())); ASSERT(doc.isEmpty()); diff --git a/src/mongo/db/s/resharding/resharding_oplog_applier.cpp b/src/mongo/db/s/resharding/resharding_oplog_applier.cpp index 1e47f26b6c0..69cf7393006 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_applier.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_applier.cpp @@ -200,7 +200,7 @@ boost::optional<ReshardingOplogApplierProgress> ReshardingOplogApplier::checkSto OperationContext* opCtx, const ReshardingSourceId& id) { DBDirectClient client(opCtx); auto doc = client.findOne( - NamespaceString::kReshardingApplierProgressNamespace.ns(), + NamespaceString::kReshardingApplierProgressNamespace, BSON(ReshardingOplogApplierProgress::kOplogSourceIdFieldName << id.toBSON())); if (doc.isEmpty()) { diff --git a/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp index aead93e4313..4459fdf5b22 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp @@ -413,10 +413,10 @@ TEST_F(ReshardingOplogApplierTest, ApplyBasicCrud) { ASSERT_OK(future.getNoThrow()); DBDirectClient client(operationContext()); - auto doc = client.findOne(appliedToNs().ns(), BSON("_id" << 1)); + auto doc = client.findOne(appliedToNs(), BSON("_id" << 1)); ASSERT_BSONOBJ_EQ(BSONObj(), doc); - doc = client.findOne(appliedToNs().ns(), BSON("_id" << 2)); + doc = client.findOne(appliedToNs(), BSON("_id" << 2)); ASSERT_BSONOBJ_EQ(BSON("_id" << 2 << "x" << 1), doc); auto progressDoc = ReshardingOplogApplier::checkStoredProgress(operationContext(), sourceId()); @@ -489,7 +489,7 @@ TEST_F(ReshardingOplogApplierTest, InsertTypeOplogAppliedInMultipleBatches) { DBDirectClient client(operationContext()); for (int x = 0; x < 19; x++) { - auto doc = client.findOne(appliedToNs().ns(), BSON("_id" << x)); + auto doc = client.findOne(appliedToNs(), BSON("_id" << x)); ASSERT_BSONOBJ_EQ(BSON("_id" << x), doc); } @@ -527,7 +527,7 @@ TEST_F(ReshardingOplogApplierTest, ErrorDuringFirstBatchApply) { ASSERT_EQ(future.getNoThrow(), ErrorCodes::FailedToParse); DBDirectClient client(operationContext()); - auto doc = client.findOne(appliedToNs().ns(), BSON("_id" << 1)); + auto doc = client.findOne(appliedToNs(), BSON("_id" << 1)); ASSERT_BSONOBJ_EQ(BSON("_id" << 1), doc); auto progressDoc = ReshardingOplogApplier::checkStoredProgress(operationContext(), sourceId()); @@ -569,13 +569,13 @@ TEST_F(ReshardingOplogApplierTest, ErrorDuringSecondBatchApply) { ASSERT_EQ(future.getNoThrow(), ErrorCodes::FailedToParse); DBDirectClient client(operationContext()); - auto doc = client.findOne(appliedToNs().ns(), BSON("_id" << 1)); + auto doc = client.findOne(appliedToNs(), BSON("_id" << 1)); ASSERT_BSONOBJ_EQ(BSON("_id" << 1), doc); - doc = client.findOne(appliedToNs().ns(), BSON("_id" << 2)); + doc = client.findOne(appliedToNs(), BSON("_id" << 2)); ASSERT_BSONOBJ_EQ(BSON("_id" << 2), doc); - doc = client.findOne(appliedToNs().ns(), BSON("_id" << 3)); + doc = client.findOne(appliedToNs(), BSON("_id" << 3)); ASSERT_BSONOBJ_EQ(BSON("_id" << 3), doc); auto progressDoc = ReshardingOplogApplier::checkStoredProgress(operationContext(), sourceId()); @@ -610,7 +610,7 @@ TEST_F(ReshardingOplogApplierTest, ErrorWhileIteratingFirstOplog) { ASSERT_EQ(future.getNoThrow(), ErrorCodes::InternalError); DBDirectClient client(operationContext()); - auto doc = client.findOne(appliedToNs().ns(), BSON("_id" << 1)); + auto doc = client.findOne(appliedToNs(), BSON("_id" << 1)); ASSERT_BSONOBJ_EQ(BSONObj(), doc); auto progressDoc = ReshardingOplogApplier::checkStoredProgress(operationContext(), sourceId()); @@ -646,7 +646,7 @@ TEST_F(ReshardingOplogApplierTest, ErrorWhileIteratingFirstBatch) { ASSERT_EQ(future.getNoThrow(), ErrorCodes::InternalError); DBDirectClient client(operationContext()); - auto doc = client.findOne(appliedToNs().ns(), BSON("_id" << 1)); + auto doc = client.findOne(appliedToNs(), BSON("_id" << 1)); ASSERT_BSONOBJ_EQ(BSONObj(), doc); auto progressDoc = ReshardingOplogApplier::checkStoredProgress(operationContext(), sourceId()); @@ -686,13 +686,13 @@ TEST_F(ReshardingOplogApplierTest, ErrorWhileIteratingSecondBatch) { ASSERT_EQ(future.getNoThrow(), ErrorCodes::InternalError); DBDirectClient client(operationContext()); - auto doc = client.findOne(appliedToNs().ns(), BSON("_id" << 1)); + auto doc = client.findOne(appliedToNs(), BSON("_id" << 1)); ASSERT_BSONOBJ_EQ(BSON("_id" << 1), doc); - doc = client.findOne(appliedToNs().ns(), BSON("_id" << 2)); + doc = client.findOne(appliedToNs(), BSON("_id" << 2)); ASSERT_BSONOBJ_EQ(BSON("_id" << 2), doc); - doc = client.findOne(appliedToNs().ns(), BSON("_id" << 3)); + doc = client.findOne(appliedToNs(), BSON("_id" << 3)); ASSERT_BSONOBJ_EQ(BSONObj(), doc); auto progressDoc = ReshardingOplogApplier::checkStoredProgress(operationContext(), sourceId()); @@ -727,7 +727,7 @@ TEST_F(ReshardingOplogApplierTest, ExecutorIsShutDown) { ASSERT_EQ(future.getNoThrow(), ErrorCodes::ShutdownInProgress); DBDirectClient client(operationContext()); - auto doc = client.findOne(appliedToNs().ns(), BSON("_id" << 1)); + auto doc = client.findOne(appliedToNs(), BSON("_id" << 1)); ASSERT_BSONOBJ_EQ(BSONObj(), doc); auto progressDoc = ReshardingOplogApplier::checkStoredProgress(operationContext(), sourceId()); @@ -766,10 +766,10 @@ TEST_F(ReshardingOplogApplierTest, UnsupportedCommandOpsShouldError) { ASSERT_EQ(future.getNoThrow(), ErrorCodes::OplogOperationUnsupported); DBDirectClient client(operationContext()); - auto doc = client.findOne(appliedToNs().ns(), BSON("_id" << 1)); + auto doc = client.findOne(appliedToNs(), BSON("_id" << 1)); ASSERT_BSONOBJ_EQ(BSON("_id" << 1), doc); - doc = client.findOne(appliedToNs().ns(), BSON("_id" << 2)); + doc = client.findOne(appliedToNs(), BSON("_id" << 2)); ASSERT_BSONOBJ_EQ(BSONObj(), doc); auto progressDoc = ReshardingOplogApplier::checkStoredProgress(operationContext(), sourceId()); diff --git a/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp b/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp index 895f1ad225f..d8c0b8f8335 100644 --- a/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp +++ b/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp @@ -255,10 +255,10 @@ protected: DBDirectClient client(operationContext()); // The same logical session entry may be inserted more than once by a test case, so use a // $natural sort to find the most recently inserted entry. - auto bsonOplog = - client.findOne(NamespaceString::kRsOplogNamespace.ns(), - BSON(repl::OplogEntryBase::kSessionIdFieldName << sessionId.toBSON()), - Query().sort(BSON("$natural" << -1))); + FindCommandRequest findCmd{NamespaceString::kRsOplogNamespace}; + findCmd.setFilter(BSON(repl::OplogEntryBase::kSessionIdFieldName << sessionId.toBSON())); + findCmd.setSort(BSON("$natural" << -1)); + auto bsonOplog = client.findOne(std::move(findCmd)); ASSERT(!bsonOplog.isEmpty()); auto oplogEntry = repl::MutableOplogEntry::parse(bsonOplog).getValue(); ASSERT_EQ(oplogEntry.getTxnNumber().get(), txnNum); @@ -267,7 +267,7 @@ protected: ASSERT(oplogEntry.getOpType() == repl::OpTypeEnum::kNoop); auto bsonTxn = - client.findOne(NamespaceString::kSessionTransactionsTableNamespace.ns(), + client.findOne(NamespaceString::kSessionTransactionsTableNamespace, BSON(SessionTxnRecord::kSessionIdFieldName << sessionId.toBSON())); ASSERT(!bsonTxn.isEmpty()); auto txn = SessionTxnRecord::parse( @@ -284,7 +284,7 @@ protected: DBDirectClient client(operationContext()); auto bsonOplog = - client.findOne(NamespaceString::kRsOplogNamespace.ns(), + client.findOne(NamespaceString::kRsOplogNamespace, BSON(repl::OplogEntryBase::kSessionIdFieldName << sessionId.toBSON())); ASSERT_BSONOBJ_EQ(bsonOplog, {}); @@ -295,7 +295,7 @@ protected: const ReshardingSourceId& sourceId) { DBDirectClient client(operationContext()); auto progressDoc = client.findOne( - NamespaceString::kReshardingTxnClonerProgressNamespace.ns(), + NamespaceString::kReshardingTxnClonerProgressNamespace, BSON(ReshardingTxnClonerProgress::kSourceIdFieldName << sourceId.toBSON())); if (progressDoc.isEmpty()) { diff --git a/src/mongo/db/s/session_catalog_migration_destination_test.cpp b/src/mongo/db/s/session_catalog_migration_destination_test.cpp index 639e9ac0a02..518f122762c 100644 --- a/src/mongo/db/s/session_catalog_migration_destination_test.cpp +++ b/src/mongo/db/s/session_catalog_migration_destination_test.cpp @@ -163,7 +163,7 @@ public: repl::OplogEntry getOplog(OperationContext* opCtx, const repl::OpTime& opTime) { DBDirectClient client(opCtx); - auto oplogBSON = client.findOne(NamespaceString::kRsOplogNamespace.ns(), opTime.asQuery()); + auto oplogBSON = client.findOne(NamespaceString::kRsOplogNamespace, opTime.asQuery()); ASSERT_FALSE(oplogBSON.isEmpty()); auto parseStatus = repl::OplogEntry::parse(oplogBSON); @@ -1998,7 +1998,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, MigratingKnownStmtWhileOplogTrunc { // Confirm that oplog is indeed empty. DBDirectClient client(opCtx); - auto result = client.findOne(NamespaceString::kRsOplogNamespace.ns(), BSONObj{}); + auto result = client.findOne(NamespaceString::kRsOplogNamespace, BSONObj{}); ASSERT_TRUE(result.isEmpty()); } diff --git a/src/mongo/db/s/session_catalog_migration_source.cpp b/src/mongo/db/s/session_catalog_migration_source.cpp index 2981f132087..31f006da764 100644 --- a/src/mongo/db/s/session_catalog_migration_source.cpp +++ b/src/mongo/db/s/session_catalog_migration_source.cpp @@ -61,10 +61,8 @@ boost::optional<repl::OplogEntry> forgeNoopEntryFromImageCollection( DBDirectClient client(opCtx); BSONObj imageObj = - client.findOne(NamespaceString::kConfigImagesNamespace.ns(), - BSON("_id" << retryableFindAndModifyOplogEntry.getSessionId()->toBSON()), - Query(), - nullptr); + client.findOne(NamespaceString::kConfigImagesNamespace, + BSON("_id" << retryableFindAndModifyOplogEntry.getSessionId()->toBSON())); if (imageObj.isEmpty()) { return boost::none; } @@ -124,8 +122,7 @@ boost::optional<repl::OplogEntry> fetchPrePostImageOplog(OperationContext* opCtx auto opTime = opTimeToFetch.value(); DBDirectClient client(opCtx); - auto oplogBSON = - client.findOne(NamespaceString::kRsOplogNamespace.ns(), opTime.asQuery(), Query(), nullptr); + auto oplogBSON = client.findOne(NamespaceString::kRsOplogNamespace, opTime.asQuery()); return uassertStatusOK(repl::OplogEntry::parse(oplogBSON)); } @@ -437,8 +434,8 @@ bool SessionCatalogMigrationSource::_fetchNextNewWriteOplog(OperationContext* op } DBDirectClient client(opCtx); - const auto& newWriteOplogDoc = client.findOne( - NamespaceString::kRsOplogNamespace.ns(), nextOpTimeToFetch.asQuery(), Query(), nullptr); + const auto& newWriteOplogDoc = + client.findOne(NamespaceString::kRsOplogNamespace, nextOpTimeToFetch.asQuery()); uassert(40620, str::stream() << "Unable to fetch oplog entry with opTime: " diff --git a/src/mongo/db/s/shard_key_util.cpp b/src/mongo/db/s/shard_key_util.cpp index 601a1624208..6f12df7d24d 100644 --- a/src/mongo/db/s/shard_key_util.cpp +++ b/src/mongo/db/s/shard_key_util.cpp @@ -227,7 +227,7 @@ void ValidationBehaviorsShardCollection::verifyCanCreateShardKeyIndex( uassert(ErrorCodes::InvalidOptions, "Please create an index that starts with the proposed shard key before " "sharding the collection", - _localClient->findOne(nss.ns(), BSONObj{}).isEmpty()); + _localClient->findOne(nss, BSONObj{}).isEmpty()); } void ValidationBehaviorsShardCollection::createShardKeyIndex( diff --git a/src/mongo/db/s/sharding_ddl_util_test.cpp b/src/mongo/db/s/sharding_ddl_util_test.cpp index e182d0f4431..9084f8ef170 100644 --- a/src/mongo/db/s/sharding_ddl_util_test.cpp +++ b/src/mongo/db/s/sharding_ddl_util_test.cpp @@ -156,7 +156,7 @@ TEST_F(ShardingDDLUtilTest, ShardedRenameMetadata) { setupCollection(kToNss, KeyPattern(BSON("x" << 1)), originalToChunks); // Get FROM collection document and chunks - auto fromDoc = client.findOne(CollectionType::ConfigNS.ns(), fromCollQuery); + auto fromDoc = client.findOne(CollectionType::ConfigNS, fromCollQuery); CollectionType fromCollection(fromDoc); std::vector<BSONObj> fromChunks; findN(client, @@ -172,10 +172,10 @@ TEST_F(ShardingDDLUtilTest, ShardedRenameMetadata) { opCtx, fromCollType, kToNss, ShardingCatalogClient::kMajorityWriteConcern); // Check that the FROM config.collections entry has been deleted - ASSERT(client.findOne(CollectionType::ConfigNS.ns(), fromCollQuery).isEmpty()); + ASSERT(client.findOne(CollectionType::ConfigNS, fromCollQuery).isEmpty()); // Get TO collection document and chunks - auto toDoc = client.findOne(CollectionType::ConfigNS.ns(), toCollQuery); + auto toDoc = client.findOne(CollectionType::ConfigNS, toCollQuery); CollectionType toCollection(toDoc); std::vector<BSONObj> toChunks; findN(client, diff --git a/src/mongo/db/s/transaction_coordinator_test.cpp b/src/mongo/db/s/transaction_coordinator_test.cpp index 43fe5c3e48a..2d1187bc215 100644 --- a/src/mongo/db/s/transaction_coordinator_test.cpp +++ b/src/mongo/db/s/transaction_coordinator_test.cpp @@ -142,7 +142,7 @@ protected: void waitUntilCoordinatorDocIsPresent() { DBDirectClient dbClient(operationContext()); - while (dbClient.findOne(NamespaceString::kTransactionCoordinatorsNamespace.ns(), BSONObj{}) + while (dbClient.findOne(NamespaceString::kTransactionCoordinatorsNamespace, BSONObj{}) .isEmpty()) ; } @@ -156,14 +156,13 @@ protected: do { doc = TransactionCoordinatorDocument::parse( IDLParserErrorContext("dummy"), - dbClient.findOne(NamespaceString::kTransactionCoordinatorsNamespace.ns(), - BSONObj{})); + dbClient.findOne(NamespaceString::kTransactionCoordinatorsNamespace, BSONObj{})); } while (!doc.getDecision()); } void waitUntilNoCoordinatorDocIsPresent() { DBDirectClient dbClient(operationContext()); - while (!dbClient.findOne(NamespaceString::kTransactionCoordinatorsNamespace.ns(), BSONObj{}) + while (!dbClient.findOne(NamespaceString::kTransactionCoordinatorsNamespace, BSONObj{}) .isEmpty()) ; } diff --git a/src/mongo/db/s/transaction_coordinator_util.cpp b/src/mongo/db/s/transaction_coordinator_util.cpp index bb6832314b7..f814b11f52c 100644 --- a/src/mongo/db/s/transaction_coordinator_util.cpp +++ b/src/mongo/db/s/transaction_coordinator_util.cpp @@ -168,7 +168,7 @@ repl::OpTime persistParticipantListBlocking( // exists. Note that this is best-effort: the document may have been deleted or manually // changed since the update above ran. const auto doc = client.findOne( - NamespaceString::kTransactionCoordinatorsNamespace.toString(), + NamespaceString::kTransactionCoordinatorsNamespace, BSON(TransactionCoordinatorDocument::kIdFieldName << sessionInfo.toBSON())); uasserted(51025, str::stream() << "While attempting to write participant list " @@ -400,7 +400,7 @@ repl::OpTime persistDecisionBlocking(OperationContext* opCtx, // exists. Note that this is best-effort: the document may have been deleted or manually // changed since the update above ran. const auto doc = client.findOne( - NamespaceString::kTransactionCoordinatorsNamespace.ns(), + NamespaceString::kTransactionCoordinatorsNamespace, BSON(TransactionCoordinatorDocument::kIdFieldName << sessionInfo.toBSON())); uasserted(51026, str::stream() << "While attempting to write decision " @@ -602,7 +602,7 @@ void deleteCoordinatorDocBlocking(OperationContext* opCtx, // exists. Note that this is best-effort: the document may have been deleted or manually // changed since the update above ran. const auto doc = client.findOne( - NamespaceString::kTransactionCoordinatorsNamespace.toString(), + NamespaceString::kTransactionCoordinatorsNamespace, BSON(TransactionCoordinatorDocument::kIdFieldName << sessionInfo.toBSON())); uasserted(51027, str::stream() << "While attempting to delete document for " << lsid.getId() << ':' diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp index f28244b594c..53dc2af4998 100644 --- a/src/mongo/db/transaction_participant.cpp +++ b/src/mongo/db/transaction_participant.cpp @@ -154,7 +154,7 @@ ActiveTransactionHistory fetchActiveTransactionHistory(OperationContext* opCtx, // field has been set, bumping the global lock acquisition to an IX. That upconvert would // require a flow control ticket to be obtained. FlowControl::Bypass flowControlBypass(opCtx); - auto result = client.findOne(NamespaceString::kSessionTransactionsTableNamespace.ns(), + auto result = client.findOne(NamespaceString::kSessionTransactionsTableNamespace, BSON(SessionTxnRecord::kSessionIdFieldName << lsid.toBSON())); if (result.isEmpty()) { return boost::none; |