summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPol Pinol Castuera <pol.pinol@mongodb.com>2022-12-21 08:59:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-21 11:44:36 +0000
commit94cd2287db3d22a3876677e393f02ddc3c9c8b17 (patch)
tree515cf65d14cc1ee7d60f69276a75d372e488cc51
parent7ac8ffa47bfe83e12c361f083fdd96a721ffae60 (diff)
downloadmongo-94cd2287db3d22a3876677e393f02ddc3c9c8b17.tar.gz
Revert "SERVER-55398 Dropping a database should also drop all its associated tags."
This reverts commit fd2dd311397aa3671e69ae4e4d98056e8006620f.
-rw-r--r--jstests/sharding/drop_database.js53
-rw-r--r--src/mongo/db/s/drop_database_coordinator.cpp13
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client.h6
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_impl.cpp62
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_impl.h3
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_mock.cpp5
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_mock.h3
7 files changed, 0 insertions, 145 deletions
diff --git a/jstests/sharding/drop_database.js b/jstests/sharding/drop_database.js
index ed8a76fa1ce..2b9b768a99c 100644
--- a/jstests/sharding/drop_database.js
+++ b/jstests/sharding/drop_database.js
@@ -170,59 +170,6 @@ jsTest.log(
assertDatabaseDropped(db.getName());
}
-const db = getNewDb();
-const conn = st.rs0.getPrimary().getDB(db.getName());
-const fcvDoc = conn.adminCommand({getParameter: 1, featureCompatibilityVersion: 1});
-if (MongoRunner.compareBinVersions(fcvDoc.featureCompatibilityVersion.version, '6.3') >= 0) {
- jsTest.log(
- "Tests that dropping a database also removes all associated zones for nonexisting and " +
- "unsharded collections.");
- {
- const coll = db['shardedColl'];
- const unshardedColl = db['unshardedColl'];
- const zoneName = 'zone';
-
- st.shardColl(coll, {x: 1});
- assertDatabaseExists(db.getName());
-
- // Create an unsharded collection
- assert.commandWorked(unshardedColl.insert({x: 3}));
-
- // Append zones for a sharded collection, unsharded collection, a nonexisting collection and
- // a collection from another database.
- st.addShardTag(st.shard0.shardName, zoneName);
- assert.commandWorked(st.s.adminCommand(
- {updateZoneKeyRange: coll.getFullName(), min: {x: 0}, max: {x: 10}, zone: zoneName}));
- assert.commandWorked(st.s.adminCommand({
- updateZoneKeyRange: unshardedColl.getFullName(),
- min: {x: 10},
- max: {x: 15},
- zone: zoneName
- }));
- assert.commandWorked(st.s.adminCommand({
- updateZoneKeyRange: db.getName() + '.nonexisting',
- min: {x: 15},
- max: {x: 20},
- zone: zoneName
- }));
- assert.commandWorked(st.s.adminCommand(
- {updateZoneKeyRange: 'otherDb.coll', min: {x: 20}, max: {x: 25}, zone: zoneName}));
-
- // Assert that has been added some entries on 'config.tags'
- assert.eq(3, configDB.tags.countDocuments({ns: getDbPrefixRegExp(db.getName())}));
-
- // Drop the database
- assert.commandWorked(db.dropDatabase());
- assertDatabaseDropped(db.getName());
-
- // Assert that there are no zones left for database
- assert.eq(0, configDB.tags.countDocuments({ns: getDbPrefixRegExp(db.getName())}));
-
- // Assert that there is one zone from another database that has not been deleted.
- assert.eq(1, configDB.tags.countDocuments({ns: getDbPrefixRegExp('otherDb')}));
- }
-}
-
jsTest.log("Tests that dropping a database doesn't affects other database with the same prefix.");
// Original bug SERVER-3471
{
diff --git a/src/mongo/db/s/drop_database_coordinator.cpp b/src/mongo/db/s/drop_database_coordinator.cpp
index 1e09589b591..490bb9301f6 100644
--- a/src/mongo/db/s/drop_database_coordinator.cpp
+++ b/src/mongo/db/s/drop_database_coordinator.cpp
@@ -308,19 +308,6 @@ ExecutorFuture<void> DropDatabaseCoordinator::_runImpl(
_dropShardedCollection(opCtx, coll, executor);
}
- // First of all, we will get all namespaces that still have zones associated to
- // database _dbName from 'config.tags'. As we already have removed all zones
- // associated with each sharded collections from database _dbName, the returned
- // zones are owned by unsharded or nonexistent collections. After that, we will
- // removed these remaining zones.
- const auto& nssWithZones =
- catalogClient->getAllNssThatHaveZonesForDatabase(opCtx, _dbName);
- for (const auto& nss : nssWithZones) {
- _updateSession(opCtx);
- sharding_ddl_util::removeTagsMetadataFromConfig(
- opCtx, nss, getCurrentSession());
- }
-
const auto allShardIds = Grid::get(opCtx)->shardRegistry()->getAllShardIds(opCtx);
{
// Acquire the database critical section in order to disallow implicit
diff --git a/src/mongo/s/catalog/sharding_catalog_client.h b/src/mongo/s/catalog/sharding_catalog_client.h
index cc03a2baa28..1fafa130380 100644
--- a/src/mongo/s/catalog/sharding_catalog_client.h
+++ b/src/mongo/s/catalog/sharding_catalog_client.h
@@ -213,12 +213,6 @@ public:
const NamespaceString& nss) = 0;
/**
- * Retrieves all namespaces that have zones associated with a database.
- */
- virtual std::vector<NamespaceString> getAllNssThatHaveZonesForDatabase(
- OperationContext* opCtx, const StringData& dbName) = 0;
-
- /**
* Retrieves all shards in this sharded cluster.
* Returns a !OK status if an error occurs.
*/
diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
index 463e46ed9ff..2a287599d98 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
@@ -1039,68 +1039,6 @@ StatusWith<std::vector<TagsType>> ShardingCatalogClientImpl::getTagsForCollectio
return tags;
}
-std::vector<NamespaceString> ShardingCatalogClientImpl::getAllNssThatHaveZonesForDatabase(
- OperationContext* opCtx, const StringData& dbName) {
- auto expCtx =
- make_intrusive<ExpressionContext>(opCtx, nullptr /*collator*/, TagsType::ConfigNS);
- StringMap<ExpressionContext::ResolvedNamespace> resolvedNamespaces;
- resolvedNamespaces[TagsType::ConfigNS.coll()] = {TagsType::ConfigNS,
- std::vector<BSONObj>() /* pipeline */};
- expCtx->setResolvedNamespaces(resolvedNamespaces);
-
- // Parse pipeline:
- // - First stage will find all that namespaces on 'config.tags' that are part of the
- // given database.
- // - Second stage will group namespaces to not have repetitions.
- //
- // db.tags.aggregate([
- // {$match: {ns: {$regex : "^dbName\\..*", $options: "i"}}},
- // {$group: {_id : "$ns"}}
- // ])
- //
- const std::string regex = "^" + dbName + "\\..*";
- auto matchStageBson = BSON("ns" << BSON("$regex" << regex << "$options"
- << "i"));
- auto matchStage = DocumentSourceMatch::createFromBson(
- Document{{"$match", std::move(matchStageBson)}}.toBson().firstElement(), expCtx);
-
- auto groupStageBson = BSON("_id"
- << "$ns");
- auto groupStage = DocumentSourceGroup::createFromBson(
- Document{{"$group", std::move(groupStageBson)}}.toBson().firstElement(), expCtx);
-
- // Create pipeline
- Pipeline::SourceContainer stages;
- stages.emplace_back(std::move(matchStage));
- stages.emplace_back(std::move(groupStage));
-
- const auto pipeline = Pipeline::create(stages, expCtx);
- auto aggRequest = AggregateCommandRequest(TagsType::ConfigNS, pipeline->serializeToBson());
-
- // Run the aggregation
- const auto readConcern = [&]() -> repl::ReadConcernArgs {
- if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
- return {repl::ReadConcernLevel::kMajorityReadConcern};
- } else {
- const auto time = VectorClock::get(opCtx)->getTime();
- return {time.configTime(), repl::ReadConcernLevel::kMajorityReadConcern};
- }
- }();
-
- auto aggResult = runCatalogAggregation(opCtx,
- Grid::get(opCtx)->shardRegistry()->getConfigShard(),
- aggRequest,
- readConcern,
- Shard::kDefaultConfigCommandTimeout);
-
- // Parse the result
- std::vector<NamespaceString> nssList;
- for (const auto& doc : aggResult) {
- nssList.push_back(NamespaceString(doc.getField("_id").String()));
- }
- return nssList;
-}
-
StatusWith<repl::OpTimeWith<std::vector<ShardType>>> ShardingCatalogClientImpl::getAllShards(
OperationContext* opCtx, repl::ReadConcernLevel readConcern) {
auto findStatus = _exhaustiveFindOnConfig(opCtx,
diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.h b/src/mongo/s/catalog/sharding_catalog_client_impl.h
index 0a58457412b..c4ab7f259f0 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_impl.h
+++ b/src/mongo/s/catalog/sharding_catalog_client_impl.h
@@ -115,9 +115,6 @@ public:
StatusWith<std::vector<TagsType>> getTagsForCollection(OperationContext* opCtx,
const NamespaceString& nss) override;
- std::vector<NamespaceString> getAllNssThatHaveZonesForDatabase(
- OperationContext* opCtx, const StringData& dbName) override;
-
StatusWith<repl::OpTimeWith<std::vector<ShardType>>> getAllShards(
OperationContext* opCtx, repl::ReadConcernLevel readConcern) override;
diff --git a/src/mongo/s/catalog/sharding_catalog_client_mock.cpp b/src/mongo/s/catalog/sharding_catalog_client_mock.cpp
index 162d445aa31..a0a1b38331d 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_mock.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_mock.cpp
@@ -116,11 +116,6 @@ StatusWith<std::vector<TagsType>> ShardingCatalogClientMock::getTagsForCollectio
return {ErrorCodes::InternalError, "Method not implemented"};
}
-std::vector<NamespaceString> ShardingCatalogClientMock::getAllNssThatHaveZonesForDatabase(
- OperationContext* opCtx, const StringData& dbName) {
- uasserted(ErrorCodes::InternalError, "Method not implemented");
-}
-
StatusWith<repl::OpTimeWith<std::vector<ShardType>>> ShardingCatalogClientMock::getAllShards(
OperationContext* opCtx, repl::ReadConcernLevel readConcern) {
return {ErrorCodes::InternalError, "Method not implemented"};
diff --git a/src/mongo/s/catalog/sharding_catalog_client_mock.h b/src/mongo/s/catalog/sharding_catalog_client_mock.h
index 70ba2f74a88..1954d418dd9 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_mock.h
+++ b/src/mongo/s/catalog/sharding_catalog_client_mock.h
@@ -90,9 +90,6 @@ public:
StatusWith<std::vector<TagsType>> getTagsForCollection(OperationContext* opCtx,
const NamespaceString& nss) override;
- std::vector<NamespaceString> getAllNssThatHaveZonesForDatabase(
- OperationContext* opCtx, const StringData& dbName) override;
-
StatusWith<repl::OpTimeWith<std::vector<ShardType>>> getAllShards(
OperationContext* opCtx, repl::ReadConcernLevel readConcern) override;