summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRomans Kasperovics <romans.kasperovics@mongodb.com>2022-09-28 18:44:04 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-28 19:50:24 +0000
commita6cb05b658ea5ce9a6e7c335339901dfd9ff0f65 (patch)
treebb087e8f6313a29c8ce33beb4168258453eb4327
parentbef2975bdd054b9c9826b7a4bac1fda2cb174be3 (diff)
downloadmongo-a6cb05b658ea5ce9a6e7c335339901dfd9ff0f65.tar.gz
SERVER-69541 Modify Helpers::findById() to accept NamespaceString type collection name
-rw-r--r--src/mongo/db/dbhelpers.cpp3
-rw-r--r--src/mongo/db/dbhelpers.h3
-rw-r--r--src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp2
-rw-r--r--src/mongo/db/repl/idempotency_test.cpp2
-rw-r--r--src/mongo/db/repl/oplog.cpp7
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp5
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp4
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_application.cpp2
-rw-r--r--src/mongo/dbtests/dbhelper_tests.cpp10
-rw-r--r--src/mongo/dbtests/querytests.cpp8
10 files changed, 20 insertions, 26 deletions
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp
index 75ee7c1283e..89f71139f07 100644
--- a/src/mongo/db/dbhelpers.cpp
+++ b/src/mongo/db/dbhelpers.cpp
@@ -138,13 +138,12 @@ RecordId Helpers::findOne(OperationContext* opCtx,
}
bool Helpers::findById(OperationContext* opCtx,
- StringData ns,
+ const NamespaceString& nss,
BSONObj query,
BSONObj& result,
bool* nsFound,
bool* indexFound) {
// TODO ForRead?
- NamespaceString nss{ns};
CollectionPtr collection =
CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
if (!collection) {
diff --git a/src/mongo/db/dbhelpers.h b/src/mongo/db/dbhelpers.h
index c4741ffba17..c620351824a 100644
--- a/src/mongo/db/dbhelpers.h
+++ b/src/mongo/db/dbhelpers.h
@@ -87,9 +87,8 @@ struct Helpers {
*
* Returns true if a matching document was found.
*/
- // TODO SERVER-69541 pass in NamespaceString object instead
static bool findById(OperationContext* opCtx,
- StringData ns,
+ const NamespaceString& nss,
BSONObj query,
BSONObj& result,
bool* nsFound = nullptr,
diff --git a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
index 4e72fa27af3..6496741af7d 100644
--- a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
+++ b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
@@ -878,7 +878,7 @@ boost::optional<Document> CommonMongodProcessInterface::lookupSingleDocumentLoca
const Document& documentKey) {
AutoGetCollectionForRead autoColl(expCtx->opCtx, nss);
BSONObj document;
- if (!Helpers::findById(expCtx->opCtx, nss.ns(), documentKey.toBson(), document)) {
+ if (!Helpers::findById(expCtx->opCtx, nss, documentKey.toBson(), document)) {
return boost::none;
}
return Document(document).getOwned();
diff --git a/src/mongo/db/repl/idempotency_test.cpp b/src/mongo/db/repl/idempotency_test.cpp
index a0a4c66aef0..64b5a7e0ad5 100644
--- a/src/mongo/db/repl/idempotency_test.cpp
+++ b/src/mongo/db/repl/idempotency_test.cpp
@@ -118,7 +118,7 @@ BSONObj RandomizedIdempotencyTest::canonicalizeDocumentForDataHash(const BSONObj
BSONObj RandomizedIdempotencyTest::getDoc() {
AutoGetCollectionForReadCommand autoColl(_opCtx.get(), nss);
BSONObj doc;
- Helpers::findById(_opCtx.get(), nss.ns(), kDocIdQuery, doc);
+ Helpers::findById(_opCtx.get(), nss, kDocIdQuery, doc);
return doc.getOwned();
}
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 3d7259d73bb..83866de6c9d 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -1628,11 +1628,8 @@ Status applyOperation_inlock(OperationContext* opCtx,
invariant(op.getObject2());
auto&& documentId = *op.getObject2();
- // TODO SERVER-69541 pass in NamespaceString object instead
- auto documentFound = Helpers::findById(opCtx,
- collection->ns().toStringWithTenantId(),
- documentId,
- changeStreamPreImage);
+ auto documentFound = Helpers::findById(
+ opCtx, collection->ns(), documentId, changeStreamPreImage);
invariant(documentFound);
}
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
index 09b16381cb1..f22cf09e623 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
@@ -773,7 +773,6 @@ Status MigrationChunkClonerSourceLegacy::nextModsBatch(OperationContext* opCtx,
updateList.splice(updateList.cbegin(), _reload);
}
- StringData ns = nss().ns().c_str();
BSONArrayBuilder arrDel(builder->subarrayStart("deleted"));
auto noopFn = [](BSONObj idDoc, BSONObj* fullDoc) {
*fullDoc = idDoc;
@@ -784,8 +783,8 @@ Status MigrationChunkClonerSourceLegacy::nextModsBatch(OperationContext* opCtx,
if (deleteList.empty()) {
BSONArrayBuilder arrUpd(builder->subarrayStart("reload"));
- auto findByIdWrapper = [opCtx, ns](BSONObj idDoc, BSONObj* fullDoc) {
- return Helpers::findById(opCtx, ns, idDoc, *fullDoc);
+ auto findByIdWrapper = [opCtx, this](BSONObj idDoc, BSONObj* fullDoc) {
+ return Helpers::findById(opCtx, this->nss(), idDoc, *fullDoc);
};
totalDocSize = xferMods(&arrUpd, &updateList, totalDocSize, findByIdWrapper);
arrUpd.done();
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 435cb76e8f5..41b07e77870 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -209,7 +209,7 @@ bool willOverrideLocalId(OperationContext* opCtx,
BSONObj remoteDoc,
BSONObj* localDoc) {
*localDoc = BSONObj();
- if (Helpers::findById(opCtx, nss.ns(), remoteDoc, *localDoc)) {
+ if (Helpers::findById(opCtx, nss, remoteDoc, *localDoc)) {
return !isInRange(*localDoc, min, max, shardKeyPattern);
}
@@ -1752,7 +1752,7 @@ bool MigrationDestinationManager::_applyMigrateOp(OperationContext* opCtx, const
// Do not apply delete if doc does not belong to the chunk being migrated
BSONObj fullObj;
- if (Helpers::findById(opCtx, _nss.ns(), id, fullObj)) {
+ if (Helpers::findById(opCtx, _nss, id, fullObj)) {
if (!isInRange(fullObj, _min, _max, _shardKeyPattern)) {
if (MONGO_unlikely(failMigrationReceivedOutOfRangeOperation.shouldFail())) {
MONGO_UNREACHABLE;
diff --git a/src/mongo/db/s/resharding/resharding_oplog_application.cpp b/src/mongo/db/s/resharding/resharding_oplog_application.cpp
index 89da093dda5..f7d4dcb468f 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_application.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_application.cpp
@@ -554,7 +554,7 @@ BSONObj ReshardingOplogApplicationRules::_queryStashCollById(OperationContext* o
indexCatalog->haveIdIndex(opCtx));
BSONObj result;
- Helpers::findById(opCtx, _myStashNss.ns(), idQuery, result);
+ Helpers::findById(opCtx, _myStashNss, idQuery, result);
return result;
}
} // namespace mongo
diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp
index 188e287dc84..11b50ad7d9e 100644
--- a/src/mongo/dbtests/dbhelper_tests.cpp
+++ b/src/mongo/dbtests/dbhelper_tests.cpp
@@ -146,7 +146,7 @@ public:
}
BSONObj result;
- Helpers::findById(opCtx1.get(), nss.ns(), idQuery, result, nullptr, nullptr);
+ Helpers::findById(opCtx1.get(), nss, idQuery, result, nullptr, nullptr);
ASSERT_BSONOBJ_EQ(result, doc);
// Assert that the same doc still exists after findByIdAndNoopUpdate
@@ -210,11 +210,11 @@ private:
// Assert that the doc still exists in the collection.
BSONObj res1;
- Helpers::findById(opCtx1, nss.ns(), idQuery, res1, nullptr, nullptr);
+ Helpers::findById(opCtx1, nss, idQuery, res1, nullptr, nullptr);
ASSERT_BSONOBJ_EQ(res1, doc);
BSONObj res2;
- Helpers::findById(opCtx2, nss.ns(), idQuery, res2, nullptr, nullptr);
+ Helpers::findById(opCtx2, nss, idQuery, res2, nullptr, nullptr);
ASSERT_BSONOBJ_EQ(res2, doc);
// Assert that findByIdAndNoopUpdate did not generate an oplog entry.
@@ -254,11 +254,11 @@ private:
// Assert that the first storage transaction succeeded and that the doc is removed.
BSONObj res1;
- Helpers::findById(opCtx1, nss.ns(), idQuery, res1, nullptr, nullptr);
+ Helpers::findById(opCtx1, nss, idQuery, res1, nullptr, nullptr);
ASSERT_BSONOBJ_EQ(res1, BSONObj());
BSONObj res2;
- Helpers::findById(opCtx2, nss.ns(), idQuery, res2, nullptr, nullptr);
+ Helpers::findById(opCtx2, nss, idQuery, res2, nullptr, nullptr);
ASSERT_BSONOBJ_EQ(res2, BSONObj());
}
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index fa8ff99ae97..4b906f00f2d 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -1401,10 +1401,10 @@ public:
ASSERT(Helpers::findOne(&_opCtx, ctx.getCollection(), BSON("_id" << 20), res));
ASSERT_EQUALS(40, res["x"].numberInt());
- ASSERT(Helpers::findById(&_opCtx, ns(), BSON("_id" << 20), res));
+ ASSERT(Helpers::findById(&_opCtx, nss(), BSON("_id" << 20), res));
ASSERT_EQUALS(40, res["x"].numberInt());
- ASSERT(!Helpers::findById(&_opCtx, ns(), BSON("_id" << 200), res));
+ ASSERT(!Helpers::findById(&_opCtx, nss(), BSON("_id" << 200), res));
long long slow;
long long fast;
@@ -1420,7 +1420,7 @@ public:
{
Timer t;
for (int i = 0; i < n; i++) {
- ASSERT(Helpers::findById(&_opCtx, ns(), BSON("_id" << 20), res));
+ ASSERT(Helpers::findById(&_opCtx, nss(), BSON("_id" << 20), res));
}
fast = t.micros();
}
@@ -1445,7 +1445,7 @@ public:
BSONObj res;
for (int i = 0; i < 1000; i++) {
- bool found = Helpers::findById(&_opCtx, ns(), BSON("_id" << i), res);
+ bool found = Helpers::findById(&_opCtx, nss(), BSON("_id" << i), res);
ASSERT_EQUALS(i % 2, int(found));
}
}