summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSophia Tan <sophia_tll@hotmail.com>2023-05-16 22:56:39 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-17 01:53:41 +0000
commit068c90d91fd45305bd6ee3b6f9172700516aaa85 (patch)
treed52005120ed2da87e7c65d5feee6d95980599773
parent17ecec00ebe6f1bbb5f78bb94021292789dd5a35 (diff)
downloadmongo-068c90d91fd45305bd6ee3b6f9172700516aaa85.tar.gz
SERVER-76918 Change bucket_catalog::clear to take in DatabaseName object instead of StringData object
-rw-r--r--src/mongo/db/timeseries/bucket_catalog/bucket_catalog.cpp7
-rw-r--r--src/mongo/db/timeseries/bucket_catalog/bucket_catalog.h2
-rw-r--r--src/mongo/db/timeseries/bucket_catalog/bucket_catalog_test.cpp45
-rw-r--r--src/mongo/db/timeseries/timeseries_op_observer.cpp2
4 files changed, 49 insertions, 7 deletions
diff --git a/src/mongo/db/timeseries/bucket_catalog/bucket_catalog.cpp b/src/mongo/db/timeseries/bucket_catalog/bucket_catalog.cpp
index 6ee28976dea..f9729b5e232 100644
--- a/src/mongo/db/timeseries/bucket_catalog/bucket_catalog.cpp
+++ b/src/mongo/db/timeseries/bucket_catalog/bucket_catalog.cpp
@@ -407,10 +407,9 @@ void clear(BucketCatalog& catalog, const NamespaceString& ns) {
clear(catalog, [ns](const NamespaceString& bucketNs) { return bucketNs == ns; });
}
-void clear(BucketCatalog& catalog, StringData dbName) {
- clear(catalog, [dbName = dbName.toString()](const NamespaceString& bucketNs) {
- return bucketNs.db() == dbName;
- });
+void clear(BucketCatalog& catalog, const DatabaseName& dbName) {
+ clear(catalog,
+ [dbName](const NamespaceString& bucketNs) { return bucketNs.dbName() == dbName; });
}
void appendExecutionStats(const BucketCatalog& catalog,
diff --git a/src/mongo/db/timeseries/bucket_catalog/bucket_catalog.h b/src/mongo/db/timeseries/bucket_catalog/bucket_catalog.h
index 1f14f683b7d..c1b95897ca0 100644
--- a/src/mongo/db/timeseries/bucket_catalog/bucket_catalog.h
+++ b/src/mongo/db/timeseries/bucket_catalog/bucket_catalog.h
@@ -268,7 +268,7 @@ void clear(BucketCatalog& catalog, const NamespaceString& ns);
* Clears the buckets for the given database by removing the bucket from the catalog asynchronously
* through the BucketStateRegistry.
*/
-void clear(BucketCatalog& catalog, StringData dbName);
+void clear(BucketCatalog& catalog, const DatabaseName& dbName);
/**
* Appends the execution stats for the given namespace to the builder.
diff --git a/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_test.cpp b/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_test.cpp
index 4e16dd68ba3..f4e093efc8d 100644
--- a/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_test.cpp
+++ b/src/mongo/db/timeseries/bucket_catalog/bucket_catalog_test.cpp
@@ -109,6 +109,20 @@ protected:
BSONObj _makeTimeseriesOptionsForCreate() const override;
};
+class BucketCatalogInMultitenancyEnv : public BucketCatalogTest {
+protected:
+ void setUp() override;
+
+private:
+ boost::optional<RAIIServerParameterControllerForTest> __multitenancyController;
+
+protected:
+ NamespaceString _tenant1Ns1 =
+ NamespaceString::createNamespaceString_forTest({TenantId(OID::gen())}, "db1", "coll1");
+ NamespaceString _tenant2Ns1 =
+ NamespaceString::createNamespaceString_forTest({TenantId(OID::gen())}, "db1", "coll1");
+};
+
void BucketCatalogTest::setUp() {
CatalogTestFixture::setUp();
@@ -123,6 +137,21 @@ void BucketCatalogTest::setUp() {
}
}
+void BucketCatalogInMultitenancyEnv::setUp() {
+ __multitenancyController.emplace("multitenancySupport", true);
+ CatalogTestFixture::setUp();
+
+ _opCtx = operationContext();
+ _bucketCatalog = &BucketCatalog::get(_opCtx);
+
+ for (const auto& ns : {_tenant1Ns1, _tenant2Ns1}) {
+ ASSERT_OK(createCollection(
+ _opCtx,
+ ns.dbName(),
+ BSON("create" << ns.coll() << "timeseries" << _makeTimeseriesOptionsForCreate())));
+ }
+}
+
BucketCatalogTest::RunBackgroundTaskAndWaitForFailpoint::RunBackgroundTaskAndWaitForFailpoint(
const std::string& failpointName, std::function<void()>&& fn) {
auto fp = globalFailPointRegistry().find(failpointName);
@@ -586,13 +615,27 @@ TEST_F(BucketCatalogTest, ClearDatabaseBuckets) {
_insertOneAndCommit(_ns2, 0);
_insertOneAndCommit(_ns3, 0);
- clear(*_bucketCatalog, _ns1.db());
+ clear(*_bucketCatalog, _ns1.dbName());
_insertOneAndCommit(_ns1, 0);
_insertOneAndCommit(_ns2, 0);
_insertOneAndCommit(_ns3, 1);
}
+TEST_F(BucketCatalogInMultitenancyEnv, ClearDatabaseBuckets) {
+ _insertOneAndCommit(_tenant1Ns1, 0);
+ _insertOneAndCommit(_tenant2Ns1, 0);
+
+ // Clear the buckets for the database of tenant1.
+ clear(*_bucketCatalog, _tenant1Ns1.dbName());
+ _insertOneAndCommit(_tenant1Ns1, 0);
+ _insertOneAndCommit(_tenant2Ns1, 1);
+
+ // Clear the buckets for the database of tenant2.
+ clear(*_bucketCatalog, _tenant2Ns1.dbName());
+ _insertOneAndCommit(_tenant2Ns1, 0);
+}
+
TEST_F(BucketCatalogTest, InsertBetweenPrepareAndFinish) {
auto batch1 = insert(_opCtx,
*_bucketCatalog,
diff --git a/src/mongo/db/timeseries/timeseries_op_observer.cpp b/src/mongo/db/timeseries/timeseries_op_observer.cpp
index bf2164770b0..4edbb87c418 100644
--- a/src/mongo/db/timeseries/timeseries_op_observer.cpp
+++ b/src/mongo/db/timeseries/timeseries_op_observer.cpp
@@ -107,7 +107,7 @@ void TimeSeriesOpObserver::aboutToDelete(OperationContext* opCtx,
void TimeSeriesOpObserver::onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) {
auto& bucketCatalog = timeseries::bucket_catalog::BucketCatalog::get(opCtx);
- timeseries::bucket_catalog::clear(bucketCatalog, dbName.db());
+ timeseries::bucket_catalog::clear(bucketCatalog, dbName);
}
repl::OpTime TimeSeriesOpObserver::onDropCollection(OperationContext* opCtx,