diff options
| author | Haley Connelly <haley.connelly@mongodb.com> | 2024-09-16 12:55:14 -0500 |
|---|---|---|
| committer | MongoDB Bot <mongo-bot@mongodb.com> | 2024-09-16 18:35:10 +0000 |
| commit | 203b32e0e41cf8f4660c9f86400a54ce8dd2add5 (patch) | |
| tree | f771368b6750f9e724e311c7ae33f85a1338714c /src | |
| parent | a0b188b87482b96e8afb5276a63b3d19a7eade1f (diff) | |
SERVER-93584 Report 'maxTimestampEligibleForTruncate' in pre-image stats (#26972)
GitOrigin-RevId: cbb6b8543feeb6e110f646bbeb44d8779d838db1
Diffstat (limited to 'src')
5 files changed, 18 insertions, 3 deletions
diff --git a/src/mongo/db/change_stream_pre_images_collection_manager.cpp b/src/mongo/db/change_stream_pre_images_collection_manager.cpp index 68e735a8570..8db61b3a58d 100644 --- a/src/mongo/db/change_stream_pre_images_collection_manager.cpp +++ b/src/mongo/db/change_stream_pre_images_collection_manager.cpp @@ -149,6 +149,7 @@ BSONObj ChangeStreamPreImagesCollectionManager::PurgingJobStats::toBSON() const .append("bytesDeleted", bytesDeleted.loadRelaxed()) .append("scannedCollections", scannedCollections.loadRelaxed()) .append("scannedInternalCollections", scannedInternalCollections.loadRelaxed()) + .append("maxTimestampEligibleForTruncate", maxTimestampEligibleForTruncate.loadRelaxed()) .append("maxStartWallTimeMillis", maxStartWallTime.loadRelaxed().toMillisSinceEpoch()) .append("timeElapsedMillis", timeElapsedMillis.loadRelaxed()); return builder.obj(); @@ -468,6 +469,9 @@ size_t ChangeStreamPreImagesCollectionManager::_deleteExpiredPreImagesWithTrunca const auto truncateStats = _truncateManager.truncateExpiredPreImages(opCtx, std::move(tenantId)); + _purgingJobStats.maxTimestampEligibleForTruncate.store( + truncateStats.maxTimestampEligibleForTruncate); + if (truncateStats.maxStartWallTime > _purgingJobStats.maxStartWallTime.loadRelaxed()) { _purgingJobStats.maxStartWallTime.store(truncateStats.maxStartWallTime); } @@ -478,7 +482,6 @@ size_t ChangeStreamPreImagesCollectionManager::_deleteExpiredPreImagesWithTrunca truncateStats.scannedInternalCollections); _purgingJobStats.scannedCollections.fetchAndAddRelaxed(1); - return truncateStats.docsDeleted; } diff --git a/src/mongo/db/change_stream_pre_images_collection_manager.h b/src/mongo/db/change_stream_pre_images_collection_manager.h index a5e4935b2dc..57c5a49ef03 100644 --- a/src/mongo/db/change_stream_pre_images_collection_manager.h +++ b/src/mongo/db/change_stream_pre_images_collection_manager.h @@ -109,6 +109,12 @@ public: AtomicWord<Date_t> maxStartWallTime; /** + * The maximum timestamp expired pre-images, in the most recent pass, could have to be + * eligible for truncate. + */ + AtomicWord<Timestamp> maxTimestampEligibleForTruncate; + + /** * Serializes the purging job statistics to the BSON object. */ BSONObj toBSON() const; diff --git a/src/mongo/db/change_stream_pre_images_remover_test.cpp b/src/mongo/db/change_stream_pre_images_remover_test.cpp index 1c08b20f347..485d8c656c1 100644 --- a/src/mongo/db/change_stream_pre_images_remover_test.cpp +++ b/src/mongo/db/change_stream_pre_images_remover_test.cpp @@ -730,6 +730,7 @@ TEST_F(PreImagesRemoverTest, TruncatesAreOnlyAfterAllDurable) { setExpirationTime(Seconds{1}); auto passStats = performPass(Milliseconds{0}); + ASSERT_EQ(passStats["maxTimestampEligibleForTruncate"].timestamp(), allDurableTS); ASSERT_EQ(passStats["totalPass"].numberLong(), 1); ASSERT_EQ(passStats["docsDeleted"].numberLong(), numRecordsBeforeAllDurableTimestamp); ASSERT_EQ(passStats["scannedInternalCollections"].numberLong(), 1); diff --git a/src/mongo/db/change_stream_pre_images_tenant_truncate_markers.cpp b/src/mongo/db/change_stream_pre_images_tenant_truncate_markers.cpp index b13aa1f2436..7aa81abf674 100644 --- a/src/mongo/db/change_stream_pre_images_tenant_truncate_markers.cpp +++ b/src/mongo/db/change_stream_pre_images_tenant_truncate_markers.cpp @@ -532,12 +532,14 @@ PreImagesTruncateStats PreImagesTenantMarkers::truncateExpiredPreImages(Operatio opCtx, NamespaceStringOrUUID{_preImagesCollectionNss.dbName(), _preImagesCollectionUUID}); const auto& preImagesColl = preImagesCollection.getCollectionPtr(); + PreImagesTruncateStats stats; + // All pre-images with 'ts' <= 'maxTSEligibleForTruncate' are candidates for truncation. // However, pre-images with 'ts' > 'maxTSEligibleForTruncate' are unsafe to truncate, as // there may be oplog holes or inconsistent data prior to it. Compute the value once, as it // requires making an additional call into the storage engine. Timestamp maxTSEligibleForTruncate = getMaxTSEligibleForTruncate(opCtx); - + stats.maxTimestampEligibleForTruncate = maxTSEligibleForTruncate; // TODO SERVER-90305: Explore options for handling rollback-to-stable with truncate markers. // @@ -553,7 +555,6 @@ PreImagesTruncateStats PreImagesTenantMarkers::truncateExpiredPreImages(Operatio // (3) If a truncate is issued on data that is later rolled back, unexpired pre-images will // be rolled back in the process. From the stable timestamp, oplog entries will be replayed // and re-inserted into truncate markers (mirroring truncate behavior in a stable state). - PreImagesTruncateStats stats; for (auto& [nsUUID, truncateMarkersForNsUUID] : *markersMapSnapshot) { RecordId minRecordId = change_stream_pre_image_util::getAbsoluteMinPreImageRecordIdBoundForNs(nsUUID) diff --git a/src/mongo/db/change_stream_pre_images_tenant_truncate_markers.h b/src/mongo/db/change_stream_pre_images_tenant_truncate_markers.h index 5266bb928f0..4d453a683d6 100644 --- a/src/mongo/db/change_stream_pre_images_tenant_truncate_markers.h +++ b/src/mongo/db/change_stream_pre_images_tenant_truncate_markers.h @@ -50,6 +50,10 @@ struct PreImagesTruncateStats { // The number of 'nsUUID's scanned in the truncate pass. int64_t scannedInternalCollections{0}; + // Instantaneous maximum timestamp eligible for truncation. Expired documents will only be + // truncated when their timestamp is less than or equal to it. + Timestamp maxTimestampEligibleForTruncate; + // The maximum wall time from the pre-images truncated across the collection. Date_t maxStartWallTime{}; }; |
