summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPol Pinol Castuera <pol.pinol@mongodb.com>2023-01-24 15:43:57 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-01-24 17:14:50 +0000
commit87109d37572d6607caba79630f7d8f568b70f79e (patch)
tree53f331f7c9c5b542e569f53a389ebf002b6bfa9e /src
parent1acba68fc3cb501df6e9a23f1f041e1043edc101 (diff)
downloadmongo-87109d37572d6607caba79630f7d8f568b70f79e.tar.gz
SERVER-72669 Get collections sorted by namespace directly from the configsvr
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/collection_sharding_runtime_test.cpp8
-rw-r--r--src/mongo/db/s/database_sharding_state_test.cpp8
-rw-r--r--src/mongo/db/s/migration_util_test.cpp8
-rw-r--r--src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp8
-rw-r--r--src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp13
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client.h5
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_impl.cpp9
-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
10 files changed, 39 insertions, 31 deletions
diff --git a/src/mongo/db/s/collection_sharding_runtime_test.cpp b/src/mongo/db/s/collection_sharding_runtime_test.cpp
index 967b2348831..33093945864 100644
--- a/src/mongo/db/s/collection_sharding_runtime_test.cpp
+++ b/src/mongo/db/s/collection_sharding_runtime_test.cpp
@@ -311,10 +311,10 @@ public:
return repl::OpTimeWith<std::vector<ShardType>>(_shards);
}
- std::vector<CollectionType> getCollections(
- OperationContext* opCtx,
- StringData dbName,
- repl::ReadConcernLevel readConcernLevel) override {
+ std::vector<CollectionType> getCollections(OperationContext* opCtx,
+ StringData dbName,
+ repl::ReadConcernLevel readConcernLevel,
+ const BSONObj& sort) override {
return _colls;
}
diff --git a/src/mongo/db/s/database_sharding_state_test.cpp b/src/mongo/db/s/database_sharding_state_test.cpp
index fb5e249d810..4282aa00174 100644
--- a/src/mongo/db/s/database_sharding_state_test.cpp
+++ b/src/mongo/db/s/database_sharding_state_test.cpp
@@ -98,10 +98,10 @@ public:
return repl::OpTimeWith<std::vector<ShardType>>(_shards);
}
- std::vector<CollectionType> getCollections(
- OperationContext* opCtx,
- StringData dbName,
- repl::ReadConcernLevel readConcernLevel) override {
+ std::vector<CollectionType> getCollections(OperationContext* opCtx,
+ StringData dbName,
+ repl::ReadConcernLevel readConcernLevel,
+ const BSONObj& sort) override {
return _colls;
}
diff --git a/src/mongo/db/s/migration_util_test.cpp b/src/mongo/db/s/migration_util_test.cpp
index 317992375d2..84254dad0cd 100644
--- a/src/mongo/db/s/migration_util_test.cpp
+++ b/src/mongo/db/s/migration_util_test.cpp
@@ -419,10 +419,10 @@ public:
return repl::OpTimeWith<std::vector<ShardType>>(_shards);
}
- std::vector<CollectionType> getCollections(
- OperationContext* opCtx,
- StringData dbName,
- repl::ReadConcernLevel readConcernLevel) override {
+ std::vector<CollectionType> getCollections(OperationContext* opCtx,
+ StringData dbName,
+ repl::ReadConcernLevel readConcernLevel,
+ const BSONObj& sort) override {
return _colls;
}
diff --git a/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp b/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp
index 76e097498c0..f152b0e89a1 100644
--- a/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp
@@ -135,10 +135,10 @@ public:
return repl::OpTimeWith<std::vector<ShardType>>(_shards);
}
- std::vector<CollectionType> getCollections(
- OperationContext* opCtx,
- StringData dbName,
- repl::ReadConcernLevel readConcernLevel) override {
+ std::vector<CollectionType> getCollections(OperationContext* opCtx,
+ StringData dbName,
+ repl::ReadConcernLevel readConcernLevel,
+ const BSONObj& sort) override {
return _colls;
}
diff --git a/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp b/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp
index fb0b854eca9..1ae37980138 100644
--- a/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp
+++ b/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp
@@ -78,14 +78,11 @@ public:
const auto& primaryShardId = request().getPrimaryShardId();
// Get the list of collections from configsvr sorted by namespace
- // TODO: SERVER-72669: Get collections sorted by namespace directly from the configsvr
- auto catalogClientCollections =
- Grid::get(opCtx)->catalogClient()->getCollections(opCtx, nss.db());
- std::sort(catalogClientCollections.begin(),
- catalogClientCollections.end(),
- [](const CollectionType& a, const CollectionType& b) {
- return a.getNss().ns() < b.getNss().ns();
- });
+ auto catalogClientCollections = Grid::get(opCtx)->catalogClient()->getCollections(
+ opCtx,
+ nss.db(),
+ repl::ReadConcernLevel::kMajorityReadConcern,
+ BSON(CollectionType::kNssFieldName << 1) /*sort*/);
// Get the list of local collections sorted by namespace
Lock::DBLock dbLock(opCtx, nss.db(), MODE_S);
diff --git a/src/mongo/s/catalog/sharding_catalog_client.h b/src/mongo/s/catalog/sharding_catalog_client.h
index cc03a2baa28..d93e8e9bddf 100644
--- a/src/mongo/s/catalog/sharding_catalog_client.h
+++ b/src/mongo/s/catalog/sharding_catalog_client.h
@@ -132,11 +132,14 @@ public:
/**
* Retrieves all collections under a specified database (or in the system). If the dbName
* parameter is empty, returns all collections.
+ *
+ * @param sort Fields to use for sorting the results. If empty, no sorting is performed.
*/
virtual std::vector<CollectionType> getCollections(
OperationContext* opCtx,
StringData db,
- repl::ReadConcernLevel readConcernLevel = repl::ReadConcernLevel::kMajorityReadConcern) = 0;
+ repl::ReadConcernLevel readConcernLevel = repl::ReadConcernLevel::kMajorityReadConcern,
+ const BSONObj& sort = BSONObj()) = 0;
/**
* Returns the set of collections for the specified database, which have been marked as sharded.
diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
index 9a167bdad50..9afaf5e38ff 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
@@ -743,7 +743,10 @@ CollectionType ShardingCatalogClientImpl::getCollection(OperationContext* opCtx,
}
std::vector<CollectionType> ShardingCatalogClientImpl::getCollections(
- OperationContext* opCtx, StringData dbName, repl::ReadConcernLevel readConcernLevel) {
+ OperationContext* opCtx,
+ StringData dbName,
+ repl::ReadConcernLevel readConcernLevel,
+ const BSONObj& sort) {
BSONObjBuilder b;
if (!dbName.empty())
b.appendRegex(CollectionType::kNssFieldName, "^{}\\."_format(pcre_util::quoteMeta(dbName)));
@@ -753,7 +756,7 @@ std::vector<CollectionType> ShardingCatalogClientImpl::getCollections(
readConcernLevel,
CollectionType::ConfigNS,
b.obj(),
- BSONObj(),
+ sort,
boost::none))
.value;
std::vector<CollectionType> collections;
@@ -766,7 +769,7 @@ std::vector<CollectionType> ShardingCatalogClientImpl::getCollections(
std::vector<NamespaceString> ShardingCatalogClientImpl::getAllShardedCollectionsForDb(
OperationContext* opCtx, StringData dbName, repl::ReadConcernLevel readConcern) {
- auto collectionsOnConfig = getCollections(opCtx, dbName, readConcern);
+ auto collectionsOnConfig = getCollections(opCtx, dbName, readConcern, BSONObj());
std::vector<NamespaceString> collectionsToReturn;
collectionsToReturn.reserve(collectionsOnConfig.size());
diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.h b/src/mongo/s/catalog/sharding_catalog_client_impl.h
index 0a58457412b..49006332c4c 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_impl.h
+++ b/src/mongo/s/catalog/sharding_catalog_client_impl.h
@@ -82,7 +82,8 @@ public:
std::vector<CollectionType> getCollections(OperationContext* opCtx,
StringData db,
- repl::ReadConcernLevel readConcernLevel) override;
+ repl::ReadConcernLevel readConcernLevel,
+ const BSONObj& sort) override;
std::vector<NamespaceString> getAllShardedCollectionsForDb(
OperationContext* opCtx, StringData dbName, 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..47c96b6c81c 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_mock.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_mock.cpp
@@ -69,7 +69,10 @@ CollectionType ShardingCatalogClientMock::getCollection(OperationContext* opCtx,
}
std::vector<CollectionType> ShardingCatalogClientMock::getCollections(
- OperationContext* opCtx, StringData dbName, repl::ReadConcernLevel readConcernLevel) {
+ OperationContext* opCtx,
+ StringData dbName,
+ repl::ReadConcernLevel readConcernLevel,
+ const BSONObj& sort) {
uasserted(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..888d00da2c5 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_mock.h
+++ b/src/mongo/s/catalog/sharding_catalog_client_mock.h
@@ -58,7 +58,8 @@ public:
std::vector<CollectionType> getCollections(OperationContext* opCtx,
StringData db,
- repl::ReadConcernLevel readConcernLevel) override;
+ repl::ReadConcernLevel readConcernLevel,
+ const BSONObj& sort) override;
std::vector<NamespaceString> getAllShardedCollectionsForDb(
OperationContext* opCtx, StringData dbName, repl::ReadConcernLevel readConcern) override;