summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2021-11-05 20:49:13 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-11-05 21:23:48 +0000
commit15489f917a1e0f36fff3d92dc2b10b82eb1f03a1 (patch)
tree87f087cdf484cd80e6fdb757f10073a24e12eb5b /src
parent22e5249879a847e94861c2e54161d9798d7ff2ab (diff)
downloadmongo-15489f917a1e0f36fff3d92dc2b10b82eb1f03a1.tar.gz
SERVER-60129 Create a replication passthrough suite for clustered collections
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/clustered_collection_util.cpp10
-rw-r--r--src/mongo/db/catalog/clustered_collection_util.h5
-rw-r--r--src/mongo/db/catalog/create_collection.cpp11
-rw-r--r--src/mongo/db/catalog/list_indexes.cpp8
4 files changed, 25 insertions, 9 deletions
diff --git a/src/mongo/db/catalog/clustered_collection_util.cpp b/src/mongo/db/catalog/clustered_collection_util.cpp
index 23ab7550f00..02134b3f47c 100644
--- a/src/mongo/db/catalog/clustered_collection_util.cpp
+++ b/src/mongo/db/catalog/clustered_collection_util.cpp
@@ -48,9 +48,15 @@ void ensureClusteredIndexName(ClusteredIndexSpec& indexSpec) {
}
ClusteredCollectionInfo makeCanonicalClusteredInfoForLegacyFormat() {
- auto indexSpec = ClusteredIndexSpec{BSON("_id" << 1), true};
+ auto indexSpec = ClusteredIndexSpec{BSON("_id" << 1), true /* unique */};
indexSpec.setName(kDefaultClusteredIndexName);
- return ClusteredCollectionInfo(std::move(indexSpec), true);
+ return ClusteredCollectionInfo(std::move(indexSpec), true /* legacy */);
+}
+
+ClusteredCollectionInfo makeDefaultClusteredIdIndex() {
+ auto indexSpec = ClusteredIndexSpec{BSON("_id" << 1), true /* unique */};
+ indexSpec.setName(kDefaultClusteredIndexName);
+ return makeCanonicalClusteredInfo(indexSpec);
}
ClusteredCollectionInfo makeCanonicalClusteredInfo(ClusteredIndexSpec indexSpec) {
diff --git a/src/mongo/db/catalog/clustered_collection_util.h b/src/mongo/db/catalog/clustered_collection_util.h
index 84e4275cce5..fc49d3ec156 100644
--- a/src/mongo/db/catalog/clustered_collection_util.h
+++ b/src/mongo/db/catalog/clustered_collection_util.h
@@ -42,6 +42,11 @@ namespace clustered_util {
ClusteredCollectionInfo makeCanonicalClusteredInfoForLegacyFormat();
/**
+ * Generates the default _id clustered index.
+ */
+ClusteredCollectionInfo makeDefaultClusteredIdIndex();
+
+/**
* Constructs ClusteredCollectionInfo according to the 'indexSpec'. Constructs a 'name' by default
* if the field is not yet defined. Stores the information is provided in the non-legacy format.
*/
diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp
index 9c226916957..be8b98420f2 100644
--- a/src/mongo/db/catalog/create_collection.cpp
+++ b/src/mongo/db/catalog/create_collection.cpp
@@ -65,6 +65,7 @@ namespace {
MONGO_FAIL_POINT_DEFINE(failTimeseriesViewCreation);
MONGO_FAIL_POINT_DEFINE(failPreimagesCollectionCreation);
+MONGO_FAIL_POINT_DEFINE(clusterAllCollectionsByDefault);
using IndexVersion = IndexDescriptor::IndexVersion;
@@ -450,7 +451,12 @@ Status _createCollection(OperationContext* opCtx,
str::stream() << "A view already exists. NS: " << nss);
}
-
+ if (!collectionOptions.clusteredIndex && (!idIndex || idIndex->isEmpty()) &&
+ // Capped, clustered collections different in behavior significantly from normal capped
+ // collections. Notably, they allow out-of-order insertion.
+ !collectionOptions.capped && clusterAllCollectionsByDefault.shouldFail()) {
+ collectionOptions.clusteredIndex = clustered_util::makeDefaultClusteredIdIndex();
+ }
if (auto clusteredIndex = collectionOptions.clusteredIndex) {
bool clusteredIndexesEnabled =
feature_flags::gClusteredIndexes.isEnabled(serverGlobalParams.featureCompatibility);
@@ -653,9 +659,8 @@ void createChangeStreamPreImagesCollection(OperationContext* opCtx) {
CollectionOptions preImagesCollectionOptions;
// Make the collection clustered by _id.
- auto preImagesCollectionKey = BSON("_id" << 1);
preImagesCollectionOptions.clusteredIndex.emplace(
- ClusteredIndexSpec{preImagesCollectionKey, true /*unique*/}, false /*legacyFormat*/);
+ clustered_util::makeDefaultClusteredIdIndex());
const auto status =
_createCollection(opCtx, nss, std::move(preImagesCollectionOptions), BSONObj());
uassert(status.code(),
diff --git a/src/mongo/db/catalog/list_indexes.cpp b/src/mongo/db/catalog/list_indexes.cpp
index 1175a7f3e0c..1518dd0c5b4 100644
--- a/src/mongo/db/catalog/list_indexes.cpp
+++ b/src/mongo/db/catalog/list_indexes.cpp
@@ -78,6 +78,10 @@ std::list<BSONObj> listIndexesInLock(OperationContext* opCtx,
std::list<BSONObj> indexSpecs;
collection->getAllIndexes(&indexNames);
+ if (collection->isClustered() && !collection->ns().isTimeseriesBucketsCollection()) {
+ indexSpecs.push_back(clustered_util::formatClusterKeyForListIndexes(
+ collection->getClusteredInfo().get()));
+ }
for (size_t i = 0; i < indexNames.size(); i++) {
if (!includeBuildUUIDs.value_or(false) || collection->isIndexReady(indexNames[i])) {
indexSpecs.push_back(collection->getIndexSpec(indexNames[i]));
@@ -96,10 +100,6 @@ std::list<BSONObj> listIndexesInLock(OperationContext* opCtx,
durableBuildUUID->appendToBuilder(&builder, "buildUUID"_sd);
indexSpecs.push_back(builder.obj());
}
- if (collection->isClustered() && !collection->ns().isTimeseriesBucketsCollection()) {
- indexSpecs.push_back(clustered_util::formatClusterKeyForListIndexes(
- collection->getClusteredInfo().get()));
- }
return indexSpecs;
});
}