summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/collection_catalog.cpp
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2023-04-06 14:52:40 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-06 17:28:36 +0000
commit3a24641ec0d47fe410d7b69dc73089a8c36ec59b (patch)
tree6dbc3e2d27773aa7b1bd6e19514cdd8cf3bd707d /src/mongo/db/catalog/collection_catalog.cpp
parent84cb7fcd340d289dac81fce2c1b3150066a22112 (diff)
downloadmongo-3a24641ec0d47fe410d7b69dc73089a8c36ec59b.tar.gz
SERVER-75741 CollectionCatalog handles mixed-mode creates and drops during steady state
Diffstat (limited to 'src/mongo/db/catalog/collection_catalog.cpp')
-rw-r--r--src/mongo/db/catalog/collection_catalog.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp
index b81ad186811..eff104d0d4a 100644
--- a/src/mongo/db/catalog/collection_catalog.cpp
+++ b/src/mongo/db/catalog/collection_catalog.cpp
@@ -2022,8 +2022,11 @@ void CollectionCatalog::_registerCollection(OperationContext* opCtx,
_pendingCommitUUIDs = _pendingCommitUUIDs.erase(uuid);
}
- if (commitTime && !commitTime->isNull()) {
+ if (commitTime) {
coll->setMinimumValidSnapshot(commitTime.value());
+
+ // When restarting from standalone mode to a replica set, the stable timestamp may be null.
+ // We still need to register the nss and UUID with the catalog.
_pushCatalogIdForNSSAndUUID(nss, uuid, coll->getCatalogId(), commitTime);
}
@@ -2218,6 +2221,17 @@ void CollectionCatalog::_pushCatalogIdForNSSAndUUID(const NamespaceString& nss,
} else if (ids.size() == 1 && !catalogId) {
// This namespace or UUID was removed due to an untimestamped write, clear entries.
ids.clear();
+ } else if (ids.size() > 1 && catalogId && !storageGlobalParams.repair) {
+ // This namespace or UUID was added due to an untimestamped write. But this
+ // namespace or UUID already had some timestamped writes performed. In this case, we
+ // re-write the history. The only known area that does this today is when profiling
+ // is enabled (untimestamped collection creation), followed by dropping the database
+ // (timestamped collection drop).
+ // TODO SERVER-75740: Remove this branch.
+ invariant(!ids.back().ts.isNull());
+
+ ids.clear();
+ ids.push_back(TimestampedCatalogId{catalogId, Timestamp::min()});
}
return;
@@ -2238,6 +2252,10 @@ void CollectionCatalog::_pushCatalogIdForNSSAndUUID(const NamespaceString& nss,
return;
}
+ // A drop entry can't be pushed in the container if it's empty. This is because we cannot
+ // initialize the namespace or UUID with a single drop.
+ invariant(!ids.empty() || catalogId);
+
ids.push_back(TimestampedCatalogId{catalogId, *ts});
auto changes = catalogIdChangesContainer.transient();
@@ -2435,16 +2453,11 @@ void CollectionCatalog::_markForCatalogIdCleanupIfNeeded(
}
};
- // Cleanup may occur if we have more than one entry for the namespace or if the only entry is a
- // drop.
+ // Cleanup may occur if we have more than one entry for the namespace.
if (ids.size() > 1) {
// When we have multiple entries, use the time at the second entry as the cleanup time,
// when the oldest timestamp advances past this we no longer need the first entry.
markForCleanup(ids.at(1).ts);
- } else if (ids.front().id == boost::none) {
- // If we just have a single delete, we can clean this up when the oldest timestamp advances
- // past this time.
- markForCleanup(ids.front().ts);
}
}