diff options
author | mathisbessamdb <mathis.bessa@mongodb.com> | 2023-02-15 22:02:42 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-02-16 04:09:26 +0000 |
commit | 66e7d4bf38be2643450df7d0e0fe48fedde49748 (patch) | |
tree | ad19604a46c230ef42e9b0e9c1ccb4f703c33ef6 | |
parent | e01c628d96f6e9f81df5b602cb31d75c4816f19e (diff) | |
download | mongo-66e7d4bf38be2643450df7d0e0fe48fedde49748.tar.gz |
SERVER-73530 TransactionClient API to use DatabaseName objects rather than strings
17 files changed, 126 insertions, 121 deletions
diff --git a/src/mongo/db/fle_crud.cpp b/src/mongo/db/fle_crud.cpp index 647537523f7..a5d7037da31 100644 --- a/src/mongo/db/fle_crud.cpp +++ b/src/mongo/db/fle_crud.cpp @@ -1662,7 +1662,7 @@ std::pair<write_ops::DeleteCommandReply, BSONObj> FLEQueryInterfaceImpl::deleteW ei2.setCrudProcessed(true); findAndModifyRequest.setEncryptionInformation(ei2); - auto response = _txnClient.runCommand(nss.db(), findAndModifyRequest.toBSON({})).get(); + auto response = _txnClient.runCommand(nss.dbName(), findAndModifyRequest.toBSON({})).get(); auto status = getStatusFromWriteCommandReply(response); BSONObj returnObj; @@ -1715,7 +1715,7 @@ std::pair<write_ops::UpdateCommandReply, BSONObj> FLEQueryInterfaceImpl::updateW ei2.setCrudProcessed(true); findAndModifyRequest.setEncryptionInformation(ei2); - auto response = _txnClient.runCommand(nss.db(), findAndModifyRequest.toBSON({})).get(); + auto response = _txnClient.runCommand(nss.dbName(), findAndModifyRequest.toBSON({})).get(); auto status = getStatusFromWriteCommandReply(response); uassertStatusOK(status); @@ -1785,7 +1785,7 @@ write_ops::FindAndModifyCommandReply FLEQueryInterfaceImpl::findAndModify( // WriteConcern is set at the transaction level so strip it out newFindAndModifyRequest.setWriteConcern(boost::none); - auto response = _txnClient.runCommand(nss.db(), newFindAndModifyRequest.toBSON({})).get(); + auto response = _txnClient.runCommand(nss.dbName(), newFindAndModifyRequest.toBSON({})).get(); auto status = getStatusFromWriteCommandReply(response); uassertStatusOK(status); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp index f20324f9be8..66a319f70a6 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp @@ -561,7 +561,7 @@ ShardingCatalogManager::_splitChunkInTransaction(OperationContext* opCtx, // Verify that the range matches exactly a single chunk auto countRequest = buildCountSingleChunkCommand(chunk); - return txnClient.runCommand(ChunkType::ConfigNS.db(), countRequest) + return txnClient.runCommand(ChunkType::ConfigNS.dbName(), countRequest) .thenRunOn(txnExec) .then([&txnClient, sharedBlock](auto countResponse) { auto cursorResponse = uassertStatusOK(CursorResponse::parseFromBSON(countResponse)); @@ -806,7 +806,7 @@ void ShardingCatalogManager::_mergeChunksInTransaction( const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { // Check the merge chunk precondition, chunks must not have moved. auto countRequest = buildCountChunksInRangeCommand(collectionUUID, shardId, chunkRange); - return txnClient.runCommand(ChunkType::ConfigNS.db(), countRequest) + return txnClient.runCommand(ChunkType::ConfigNS.dbName(), countRequest) .thenRunOn(txnExec) .then([&txnClient, chunksToMerge, mergeVersion, validAfter](auto commandResponse) { auto countResponse = @@ -2336,7 +2336,9 @@ void ShardingCatalogManager::_commitChunkMigrationInTransaction( DistinctCommandRequest distinctRequest(ChunkType::ConfigNS); distinctRequest.setKey(ChunkType::shard.name()); distinctRequest.setQuery(BSON(ChunkType::collectionUUID.name() << collUuid)); - return txnClient.runCommand(NamespaceString::kConfigDb, distinctRequest.toBSON({})) + return txnClient + .runCommand(DatabaseName(boost::none, NamespaceString::kConfigDb), + distinctRequest.toBSON({})) .thenRunOn(txnExec) .then([=, &txnClient](BSONObj reply) { uassertStatusOK(getStatusFromWriteCommandReply(reply)); diff --git a/src/mongo/db/s/global_index/global_index_inserter.cpp b/src/mongo/db/s/global_index/global_index_inserter.cpp index b2fb8163adc..490a26ca9c7 100644 --- a/src/mongo/db/s/global_index/global_index_inserter.cpp +++ b/src/mongo/db/s/global_index/global_index_inserter.cpp @@ -94,7 +94,7 @@ void GlobalIndexInserter::processDoc(OperationContext* opCtx, globalIndexEntryInsert.setGlobalIndexKeyEntry( GlobalIndexKeyEntry(indexKeyValues, documentKey)); - return txnClient.runCommand(_nss.db(), globalIndexEntryInsert.toBSON({})) + return txnClient.runCommand(_nss.dbName(), globalIndexEntryInsert.toBSON({})) .thenRunOn(txnExec) .then([this, documentKey, &txnClient](const auto& commandResponse) { write_ops::InsertCommandRequest skipIdInsert(_skipIdNss()); diff --git a/src/mongo/db/transaction/transaction_api.cpp b/src/mongo/db/transaction/transaction_api.cpp index 484c522c7f2..2ee41929dd4 100644 --- a/src/mongo/db/transaction/transaction_api.cpp +++ b/src/mongo/db/transaction/transaction_api.cpp @@ -377,7 +377,8 @@ Future<DbResponse> DefaultSEPTransactionClientBehaviors::handleRequest( return serviceEntryPoint->handleRequest(opCtx, request); } -SemiFuture<BSONObj> SEPTransactionClient::runCommand(StringData dbName, BSONObj cmdObj) const { +SemiFuture<BSONObj> SEPTransactionClient::runCommand(const DatabaseName& dbName, + BSONObj cmdObj) const { invariant(_hooks, "Transaction metadata hooks must be injected before a command can be run"); BSONObjBuilder cmdBuilder(_behaviors->maybeModifyCommand(std::move(cmdObj))); @@ -395,7 +396,7 @@ SemiFuture<BSONObj> SEPTransactionClient::runCommand(StringData dbName, BSONObj primeInternalClient(&cc()); - auto opMsgRequest = OpMsgRequest::fromDBAndBody(dbName, cmdBuilder.obj()); + auto opMsgRequest = OpMsgRequestBuilder::create(dbName, cmdBuilder.obj()); auto requestMessage = opMsgRequest.serialize(); return _behaviors->handleRequest(cancellableOpCtx.get(), requestMessage) .then([this](DbResponse dbResponse) { @@ -420,7 +421,7 @@ SemiFuture<BatchedCommandResponse> SEPTransactionClient::runCRUDOp( cmdBob.append(write_ops::WriteCommandRequestBase::kStmtIdsFieldName, stmtIds); } - return runCommand(cmd.getNS().db(), cmdBob.obj()) + return runCommand(cmd.getNS().dbName(), cmdBob.obj()) .thenRunOn(_executor) .then([](BSONObj reply) { uassertStatusOK(getStatusFromWriteCommandReply(reply)); @@ -437,7 +438,7 @@ SemiFuture<BatchedCommandResponse> SEPTransactionClient::runCRUDOp( SemiFuture<std::vector<BSONObj>> SEPTransactionClient::exhaustiveFind( const FindCommandRequest& cmd) const { - return runCommand(cmd.getDbName().db(), cmd.toBSON({})) + return runCommand(cmd.getDbName(), cmd.toBSON({})) .thenRunOn(_executor) .then([this, batchSize = cmd.getBatchSize(), tenantId = cmd.getDbName().tenantId()]( BSONObj reply) { @@ -464,7 +465,8 @@ SemiFuture<std::vector<BSONObj>> SEPTransactionClient::exhaustiveFind( cursorResponse->getNSS().coll().toString()); getMoreRequest.setBatchSize(batchSize); - return runCommand(cursorResponse->getNSS().db(), getMoreRequest.toBSON({})) + return runCommand(cursorResponse->getNSS().dbName(), + getMoreRequest.toBSON({})) .thenRunOn(_executor) .then([response, cursorResponse, tenantId](BSONObj reply) { // We keep the state of cursorResponse to be able to check the @@ -490,7 +492,8 @@ SemiFuture<std::vector<BSONObj>> SEPTransactionClient::exhaustiveFind( } SemiFuture<CommitResult> Transaction::commit() { - return _commitOrAbort(NamespaceString::kAdminDb, CommitTransaction::kCommandName) + return _commitOrAbort(DatabaseName(boost::none, NamespaceString::kAdminDb), + CommitTransaction::kCommandName) .thenRunOn(_executor) .then([](BSONObj res) { auto wcErrorHolder = getWriteConcernErrorDetailFromBSONObj(res); @@ -504,7 +507,8 @@ SemiFuture<CommitResult> Transaction::commit() { } SemiFuture<void> Transaction::abort() { - return _commitOrAbort(NamespaceString::kAdminDb, AbortTransaction::kCommandName) + return _commitOrAbort(DatabaseName(boost::none, NamespaceString::kAdminDb), + AbortTransaction::kCommandName) .thenRunOn(_executor) .then([](BSONObj res) { uassertStatusOK(getStatusFromCommandResult(res)); @@ -513,7 +517,7 @@ SemiFuture<void> Transaction::abort() { .semi(); } -SemiFuture<BSONObj> Transaction::_commitOrAbort(StringData dbName, StringData cmdName) { +SemiFuture<BSONObj> Transaction::_commitOrAbort(const DatabaseName& dbName, StringData cmdName) { BSONObjBuilder cmdBuilder; cmdBuilder.append(cmdName, 1); diff --git a/src/mongo/db/transaction/transaction_api.h b/src/mongo/db/transaction/transaction_api.h index e3ad045e7c4..3d893b702e5 100644 --- a/src/mongo/db/transaction/transaction_api.h +++ b/src/mongo/db/transaction/transaction_api.h @@ -96,7 +96,7 @@ public: /** * Runs the given command as part of the transaction that owns this transaction client. */ - virtual SemiFuture<BSONObj> runCommand(StringData dbName, BSONObj cmd) const = 0; + virtual SemiFuture<BSONObj> runCommand(const DatabaseName& dbName, BSONObj cmd) const = 0; /** * Helper method to run commands representable as a BatchedCommandRequest in the transaction @@ -272,7 +272,7 @@ public: _hooks = std::move(hooks); } - virtual SemiFuture<BSONObj> runCommand(StringData dbName, BSONObj cmd) const override; + virtual SemiFuture<BSONObj> runCommand(const DatabaseName& dbName, BSONObj cmd) const override; virtual SemiFuture<BatchedCommandResponse> runCRUDOp( const BatchedCommandRequest& cmd, std::vector<StmtId> stmtIds) const override; @@ -473,7 +473,7 @@ private: TxnNumber txnNumber, boost::optional<bool> startTransaction); - SemiFuture<BSONObj> _commitOrAbort(StringData dbName, StringData cmdName); + SemiFuture<BSONObj> _commitOrAbort(const DatabaseName& dbName, StringData cmdName); /** * Extracts transaction options from Operation Context and infers the internal transaction’s diff --git a/src/mongo/db/transaction/transaction_api_test.cpp b/src/mongo/db/transaction/transaction_api_test.cpp index 8cb3ff879d1..3b3ab7d7069 100644 --- a/src/mongo/db/transaction/transaction_api_test.cpp +++ b/src/mongo/db/transaction/transaction_api_test.cpp @@ -148,7 +148,7 @@ public: _hooks = std::move(hooks); } - virtual SemiFuture<BSONObj> runCommand(StringData dbName, BSONObj cmd) const override { + virtual SemiFuture<BSONObj> runCommand(const DatabaseName& dbName, BSONObj cmd) const override { stdx::unique_lock<Latch> ul(_mutex); [&]() { StringData cmdName = cmd.firstElementFieldNameStringData(); @@ -461,7 +461,7 @@ class MockClusterOperationTransactionClient : public txn_api::TransactionClient public: virtual void initialize(std::unique_ptr<txn_api::details::TxnHooks> hooks) {} - virtual SemiFuture<BSONObj> runCommand(StringData dbName, BSONObj cmd) const { + virtual SemiFuture<BSONObj> runCommand(const DatabaseName& dbName, BSONObj cmd) const { MONGO_UNREACHABLE; } @@ -488,7 +488,7 @@ TEST_F(TxnAPITest, OwnSession_AttachesTxnMetadata) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -501,7 +501,7 @@ TEST_F(TxnAPITest, OwnSession_AttachesTxnMetadata) { mockClient()->setNextCommandResponse(kOKInsertResponse); insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -546,7 +546,7 @@ TEST_F(TxnAPITest, AttachesAPIVersion) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -560,7 +560,7 @@ TEST_F(TxnAPITest, AttachesAPIVersion) { mockClient()->setNextCommandResponse(kOKInsertResponse); insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -618,7 +618,7 @@ TEST_F(TxnAPITest, OwnSession_AttachesWriteConcernOnCommit) { // No write concern on requests prior to commit/abort. mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -636,7 +636,7 @@ TEST_F(TxnAPITest, OwnSession_AttachesWriteConcernOnCommit) { mockClient()->setNextCommandResponse(kOKInsertResponse); insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -698,7 +698,7 @@ TEST_F(TxnAPITest, OwnSession_AttachesWriteConcernOnAbort) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -740,7 +740,7 @@ TEST_F(TxnAPITest, OwnSession_AttachesReadConcernOnStartTransaction) { attempt += 1; mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -759,7 +759,7 @@ TEST_F(TxnAPITest, OwnSession_AttachesReadConcernOnStartTransaction) { // Subsequent requests shouldn't have a read concern. mockClient()->setNextCommandResponse(kOKInsertResponse); insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -804,7 +804,7 @@ TEST_F(TxnAPITest, OwnSession_AbortsOnError) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -870,7 +870,7 @@ TEST_F(TxnAPITest, OwnSession_RetriesOnTransientError) { mockClient()->setNextCommandResponse(attempt == 0 ? kNoSuchTransactionResponse : kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -922,7 +922,7 @@ TEST_F(TxnAPITest, OwnSession_RetriesOnTransientClientError) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -964,7 +964,7 @@ TEST_F(TxnAPITest, OwnSession_CommitError) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1008,7 +1008,7 @@ TEST_F(TxnAPITest, OwnSession_TransientCommitError) { attempt += 1; mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1053,7 +1053,7 @@ TEST_F(TxnAPITest, OwnSession_RetryableCommitError) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1095,7 +1095,7 @@ TEST_F(TxnAPITest, OwnSession_NonRetryableCommitWCError) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1135,7 +1135,7 @@ TEST_F(TxnAPITest, OwnSession_RetryableCommitWCError) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1189,50 +1189,50 @@ TEST_F(TxnAPITest, RunThrowsOnBodyError) { } TEST_F(TxnAPITest, RunThrowsOnCommitCmdError) { - ASSERT_THROWS_CODE(txnWithRetries().run( - opCtx(), - [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { - mockClient()->setNextCommandResponse(kOKInsertResponse); - auto insertRes = txnClient - .runCommand("user"_sd, - BSON("insert" - << "foo" - << "documents" - << BSON_ARRAY(BSON("x" << 1)))) - .get(); - - // The commit response. - mockClient()->setNextCommandResponse( - BSON("ok" << 0 << "code" << ErrorCodes::InternalError)); - mockClient()->setNextCommandResponse( - kOKCommandResponse); // Best effort abort response. - return SemiFuture<void>::makeReady(); - }), - DBException, - ErrorCodes::InternalError); + ASSERT_THROWS_CODE( + txnWithRetries().run( + opCtx(), + [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { + mockClient()->setNextCommandResponse(kOKInsertResponse); + auto insertRes = txnClient + .runCommand(DatabaseName(boost::none, "user"_sd), + BSON("insert" + << "foo" + << "documents" << BSON_ARRAY(BSON("x" << 1)))) + .get(); + + // The commit response. + mockClient()->setNextCommandResponse( + BSON("ok" << 0 << "code" << ErrorCodes::InternalError)); + mockClient()->setNextCommandResponse( + kOKCommandResponse); // Best effort abort response. + return SemiFuture<void>::makeReady(); + }), + DBException, + ErrorCodes::InternalError); } TEST_F(TxnAPITest, RunThrowsOnCommitWCError) { - ASSERT_THROWS_CODE(txnWithRetries().run( - opCtx(), - [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { - mockClient()->setNextCommandResponse(kOKInsertResponse); - auto insertRes = txnClient - .runCommand("user"_sd, - BSON("insert" - << "foo" - << "documents" - << BSON_ARRAY(BSON("x" << 1)))) - .get(); - - // The commit response. - mockClient()->setNextCommandResponse(kResWithWriteConcernError); - mockClient()->setNextCommandResponse( - kOKCommandResponse); // Best effort abort response. - return SemiFuture<void>::makeReady(); - }), - DBException, - ErrorCodes::WriteConcernFailed); + ASSERT_THROWS_CODE( + txnWithRetries().run( + opCtx(), + [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { + mockClient()->setNextCommandResponse(kOKInsertResponse); + auto insertRes = txnClient + .runCommand(DatabaseName(boost::none, "user"_sd), + BSON("insert" + << "foo" + << "documents" << BSON_ARRAY(BSON("x" << 1)))) + .get(); + + // The commit response. + mockClient()->setNextCommandResponse(kResWithWriteConcernError); + mockClient()->setNextCommandResponse( + kOKCommandResponse); // Best effort abort response. + return SemiFuture<void>::makeReady(); + }), + DBException, + ErrorCodes::WriteConcernFailed); } TEST_F(TxnAPITest, UnyieldsAfterBodyError) { @@ -1241,7 +1241,7 @@ TEST_F(TxnAPITest, UnyieldsAfterBodyError) { auto swResult = txnWithRetries().runNoThrow( opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1262,7 +1262,7 @@ TEST_F(TxnAPITest, HandlesExceptionWhileYielding) { auto swResult = txnWithRetries().runNoThrow( opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1282,7 +1282,7 @@ TEST_F(TxnAPITest, HandlesExceptionWhileUnyielding) { auto swResult = txnWithRetries().runNoThrow( opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1311,7 +1311,7 @@ TEST_F(TxnAPITest, UnyieldsAfterCancellation) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1347,7 +1347,7 @@ TEST_F(TxnAPITest, ClientSession_UsesNonRetryableInternalSession) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1398,7 +1398,7 @@ TEST_F(TxnAPITest, ClientRetryableWrite_UsesRetryableInternalSession) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" @@ -1419,7 +1419,7 @@ TEST_F(TxnAPITest, ClientRetryableWrite_UsesRetryableInternalSession) { // Verify a non-retryable write command does not need to include stmtIds. mockClient()->setNextCommandResponse(kOKCommandResponse); auto findRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("find" << "foo")) .get(); @@ -1429,7 +1429,7 @@ TEST_F(TxnAPITest, ClientRetryableWrite_UsesRetryableInternalSession) { mockClient()->setNextCommandResponse(kOKInsertResponse); insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)) << "stmtId" << 1)) @@ -1474,7 +1474,7 @@ DEATH_TEST_F(TxnAPITest, opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1496,7 +1496,7 @@ TEST_F(TxnAPITest, ClientTransaction_UsesClientTransactionOptionsAndDoesNotCommi opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1536,7 +1536,7 @@ TEST_F(TxnAPITest, ClientTransaction_DoesNotAppendStartTransactionFields) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1570,7 +1570,7 @@ TEST_F(TxnAPITest, ClientTransaction_DoesNotBestEffortAbortOnFailure) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1605,7 +1605,7 @@ TEST_F(TxnAPITest, ClientTransaction_DoesNotRetryOnTransientErrors) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1635,7 +1635,7 @@ TEST_F(TxnAPITest, HandleErrorRetryCommitOnNetworkError) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1688,7 +1688,7 @@ TEST_F(TxnAPITest, RetryCommitMultipleTimesIncludesMajorityWriteConcern) { auto swResult = txnWithRetries().runNoThrow( opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1746,7 +1746,7 @@ TEST_F(TxnAPITest, CommitAfterTransientErrorAfterRetryCommitUsesOriginalWriteCon auto swResult = txnWithRetries().runNoThrow( opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1912,7 +1912,7 @@ TEST_F(TxnAPITest, OwnSession_StartTransactionRetryLimitOnTransientErrors) { // Command response used for insert below and eventually abortTransaction. mockClient()->setNextCommandResponse(kOKCommandResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1941,7 +1941,7 @@ TEST_F(TxnAPITest, OwnSession_CommitTransactionRetryLimitOnTransientErrors) { opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -1992,7 +1992,7 @@ TEST_F(TxnAPITest, MaxTimeMSIsSetIfOperationContextHasDeadlineAndIgnoresDefaultR mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -2107,7 +2107,7 @@ TEST_F(TxnAPITest, FailoverAndShutdownErrorsAreFatalForLocalTransactionBodyError mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -2156,7 +2156,7 @@ TEST_F(TxnAPITest, FailoverAndShutdownErrorsAreFatalForLocalTransactionCommandEr mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -2204,7 +2204,7 @@ TEST_F(TxnAPITest, FailoverAndShutdownErrorsAreFatalForLocalTransactionWCError) mockClient()->setNextCommandResponse(kOKInsertResponse); auto insertRes = txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -2253,7 +2253,7 @@ TEST_F(TxnAPITest, DoesNotWaitForBestEffortAbortIfCancelled) { auto swResult = txnWithRetries().runNoThrow( opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -2304,7 +2304,7 @@ TEST_F(TxnAPITest, WaitsForBestEffortAbortOnNonTransientErrorIfNotCancelled) { auto swResult = txnWithRetries().runNoThrow( opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) @@ -2368,7 +2368,7 @@ TEST_F(TxnAPITest, WaitsForBestEffortAbortOnTransientError) { auto swResult = txnWithRetries().runNoThrow( opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { txnClient - .runCommand("user"_sd, + .runCommand(DatabaseName(boost::none, "user"_sd), BSON("insert" << "foo" << "documents" << BSON_ARRAY(BSON("x" << 1)))) diff --git a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp index 1353e6f5d15..52fae27f850 100644 --- a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp @@ -171,7 +171,7 @@ void handleWouldChangeOwningShardErrorNonTransaction( opCtx, [cmdObj = request.toBSON({}), sharedBlock](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { - return txnClient.runCommand(sharedBlock->nss.db(), cmdObj) + return txnClient.runCommand(sharedBlock->nss.dbName(), cmdObj) .thenRunOn(txnExec) .then([sharedBlock](auto res) { uassertStatusOK(getStatusFromCommandResult(res)); @@ -656,7 +656,7 @@ void FindAndModifyCmd::_runCommand(OperationContext* opCtx, MultiStatementTransactionRequestsSender ars( opCtx, Grid::get(opCtx)->getExecutorPool()->getArbitraryExecutor(), - nss.db().toString(), + nss.dbName(), requests, kPrimaryOnlyReadPreference, isRetryableWrite ? Shard::RetryPolicy::kIdempotent : Shard::RetryPolicy::kNoRetry); diff --git a/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp b/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp index fa68c48fd0b..3d359126178 100644 --- a/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp +++ b/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp @@ -201,7 +201,7 @@ public: MultiStatementTransactionRequestsSender ars( opCtx, Grid::get(opCtx)->getExecutorPool()->getArbitraryExecutor(), - request().getDbName().toString(), + request().getDbName(), requests, ReadPreferenceSetting(ReadPreference::PrimaryOnly), Shard::RetryPolicy::kNoRetry); diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp index 39defdab465..a39072fbe74 100644 --- a/src/mongo/s/commands/cluster_write_cmd.cpp +++ b/src/mongo/s/commands/cluster_write_cmd.cpp @@ -178,7 +178,7 @@ void handleWouldChangeOwningShardErrorNonTransaction(OperationContext* opCtx, auto swCommitResult = txn.runNoThrow( opCtx, [sharedBlock](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { - return txnClient.runCommand(sharedBlock->nss.db(), sharedBlock->cmdObj) + return txnClient.runCommand(sharedBlock->nss.dbName(), sharedBlock->cmdObj) .thenRunOn(txnExec) .then([sharedBlock](auto res) { uassertStatusOK(getStatusFromWriteCommandReply(res)); @@ -485,7 +485,7 @@ void ClusterWriteCmd::_commandOpWrite(OperationContext* opCtx, MultiStatementTransactionRequestsSender ars( opCtx, Grid::get(opCtx)->getExecutorPool()->getArbitraryExecutor(), - nss.db(), + nss.dbName(), requests, readPref, Shard::RetryPolicy::kNoRetry); diff --git a/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp b/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp index de5297e798f..0a5b54a6217 100644 --- a/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp +++ b/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp @@ -169,7 +169,7 @@ public: MultiStatementTransactionRequestsSender ars( opCtx, Grid::get(opCtx)->getExecutorPool()->getArbitraryExecutor(), - request().getDbName().toString(), + request().getDbName(), std::move(arsRequestVector), ReadPreferenceSetting(ReadPreference::PrimaryOnly), Shard::RetryPolicy::kNoRetry); diff --git a/src/mongo/s/multi_statement_transaction_requests_sender.cpp b/src/mongo/s/multi_statement_transaction_requests_sender.cpp index 95849499a04..64426321ef5 100644 --- a/src/mongo/s/multi_statement_transaction_requests_sender.cpp +++ b/src/mongo/s/multi_statement_transaction_requests_sender.cpp @@ -77,7 +77,7 @@ void processReplyMetadata(OperationContext* opCtx, const AsyncRequestsSender::Re MultiStatementTransactionRequestsSender::MultiStatementTransactionRequestsSender( OperationContext* opCtx, std::shared_ptr<executor::TaskExecutor> executor, - StringData dbName, + const DatabaseName& dbName, const std::vector<AsyncRequestsSender::Request>& requests, const ReadPreferenceSetting& readPreference, Shard::RetryPolicy retryPolicy) @@ -85,7 +85,7 @@ MultiStatementTransactionRequestsSender::MultiStatementTransactionRequestsSender _ars(std::make_unique<AsyncRequestsSender>( opCtx, std::move(executor), - dbName, + dbName.db(), attachTxnDetails(opCtx, requests), readPreference, retryPolicy, diff --git a/src/mongo/s/multi_statement_transaction_requests_sender.h b/src/mongo/s/multi_statement_transaction_requests_sender.h index 0934c1211ef..1508e254c79 100644 --- a/src/mongo/s/multi_statement_transaction_requests_sender.h +++ b/src/mongo/s/multi_statement_transaction_requests_sender.h @@ -50,7 +50,7 @@ public: MultiStatementTransactionRequestsSender( OperationContext* opCtx, std::shared_ptr<executor::TaskExecutor> executor, - StringData dbName, + const DatabaseName& dbName, const std::vector<AsyncRequestsSender::Request>& requests, const ReadPreferenceSetting& readPreference, Shard::RetryPolicy retryPolicy); diff --git a/src/mongo/s/query/cluster_aggregation_planner.cpp b/src/mongo/s/query/cluster_aggregation_planner.cpp index bf9af2e0be1..f0223a0bb53 100644 --- a/src/mongo/s/query/cluster_aggregation_planner.cpp +++ b/src/mongo/s/query/cluster_aggregation_planner.cpp @@ -101,7 +101,7 @@ AsyncRequestsSender::Response establishMergingShardCursor(OperationContext* opCt MultiStatementTransactionRequestsSender ars( opCtx, Grid::get(opCtx)->getExecutorPool()->getArbitraryExecutor(), - nss.db().toString(), + nss.dbName(), {{mergingShardId, mergeCmdObj}}, ReadPreferenceSetting::get(opCtx), sharded_agg_helpers::getDesiredRetryPolicy(opCtx)); @@ -844,7 +844,7 @@ Status runPipelineOnSpecificShardOnly(const boost::intrusive_ptr<ExpressionConte MultiStatementTransactionRequestsSender ars( opCtx, Grid::get(opCtx)->getExecutorPool()->getArbitraryExecutor(), - namespaces.executionNss.db().toString(), + namespaces.executionNss.dbName(), {{shardId, cmdObj}}, ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent); diff --git a/src/mongo/s/query/establish_cursors.cpp b/src/mongo/s/query/establish_cursors.cpp index 21219f3db84..5855d039fe8 100644 --- a/src/mongo/s/query/establish_cursors.cpp +++ b/src/mongo/s/query/establish_cursors.cpp @@ -157,8 +157,7 @@ void CursorEstablisher::sendRequests(const ReadPreferenceSetting& readPref, "opKey"_attr = _opKey); // Send the requests - _ars.emplace( - _opCtx, _executor, _nss.db().toString(), std::move(requests), readPref, retryPolicy); + _ars.emplace(_opCtx, _executor, _nss.dbName(), std::move(requests), readPref, retryPolicy); } void CursorEstablisher::waitForResponse() noexcept { diff --git a/src/mongo/s/transaction_router.cpp b/src/mongo/s/transaction_router.cpp index cc3d6b2763b..a9a77264b59 100644 --- a/src/mongo/s/transaction_router.cpp +++ b/src/mongo/s/transaction_router.cpp @@ -195,7 +195,7 @@ BSONObj sendCommitDirectlyToShards(OperationContext* opCtx, const std::vector<Sh MultiStatementTransactionRequestsSender ars( opCtx, Grid::get(opCtx)->getExecutorPool()->getFixedExecutor(), - NamespaceString::kAdminDb, + DatabaseName(boost::none, NamespaceString::kAdminDb), requests, ReadPreferenceSetting{ReadPreference::PrimaryOnly}, Shard::RetryPolicy::kIdempotent); @@ -1138,7 +1138,7 @@ BSONObj TransactionRouter::Router::_handOffCommitToCoordinator(OperationContext* MultiStatementTransactionRequestsSender ars( opCtx, Grid::get(opCtx)->getExecutorPool()->getFixedExecutor(), - NamespaceString::kAdminDb, + DatabaseName(boost::none, NamespaceString::kAdminDb), {{*o().coordinatorId, coordinateCommitCmdObj}}, ReadPreferenceSetting{ReadPreference::PrimaryOnly}, Shard::RetryPolicy::kIdempotent); diff --git a/src/mongo/s/write_ops/batch_write_exec.cpp b/src/mongo/s/write_ops/batch_write_exec.cpp index 870bdbd36af..9d48761514e 100644 --- a/src/mongo/s/write_ops/batch_write_exec.cpp +++ b/src/mongo/s/write_ops/batch_write_exec.cpp @@ -305,7 +305,7 @@ void executeChildBatches(OperationContext* opCtx, MultiStatementTransactionRequestsSender ars( opCtx, Grid::get(opCtx)->getExecutorPool()->getArbitraryExecutor(), - clientRequest.getNS().db().toString(), + clientRequest.getNS().dbName(), requests, kPrimaryOnlyReadPreference, isRetryableWrite ? Shard::RetryPolicy::kIdempotent : Shard::RetryPolicy::kNoRetry); diff --git a/src/mongo/s/write_ops/write_without_shard_key_util.cpp b/src/mongo/s/write_ops/write_without_shard_key_util.cpp index 3a623cc02e1..389d66d78b1 100644 --- a/src/mongo/s/write_ops/write_without_shard_key_util.cpp +++ b/src/mongo/s/write_ops/write_without_shard_key_util.cpp @@ -188,7 +188,7 @@ StatusWith<ClusterWriteWithoutShardKeyResponse> runTwoPhaseWriteProtocol(Operati opCtx, [sharedBlock](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) { ClusterQueryWithoutShardKey clusterQueryWithoutShardKeyCommand(sharedBlock->cmdObj); auto queryRes = txnClient - .runCommand(sharedBlock->nss.db(), + .runCommand(sharedBlock->nss.dbName(), clusterQueryWithoutShardKeyCommand.toBSON({})) .get(); uassertStatusOK(getStatusFromCommandResult(queryRes)); @@ -210,7 +210,7 @@ StatusWith<ClusterWriteWithoutShardKeyResponse> runTwoPhaseWriteProtocol(Operati *queryResponse.getTargetDoc() /* targetDocId */); auto writeRes = txnClient - .runCommand(sharedBlock->nss.db(), + .runCommand(sharedBlock->nss.dbName(), clusterWriteWithoutShardKeyCommand.toBSON(BSONObj())) .get(); uassertStatusOK(getStatusFromCommandResult(writeRes)); |