diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mongo/db/catalog/capped_collection_maintenance.cpp | 15 | ||||
| -rw-r--r-- | src/mongo/db/catalog/capped_collection_maintenance.h | 3 | ||||
| -rw-r--r-- | src/mongo/db/catalog/collection_test.cpp | 11 | ||||
| -rw-r--r-- | src/mongo/db/catalog/collection_write_path.cpp | 5 | ||||
| -rw-r--r-- | src/mongo/db/curop.cpp | 7 | ||||
| -rw-r--r-- | src/mongo/db/curop.h | 5 | ||||
| -rw-r--r-- | src/mongo/db/repl/oplog.cpp | 3 |
7 files changed, 40 insertions, 9 deletions
diff --git a/src/mongo/db/catalog/capped_collection_maintenance.cpp b/src/mongo/db/catalog/capped_collection_maintenance.cpp index 0f45c8054a9..a42e2910d12 100644 --- a/src/mongo/db/catalog/capped_collection_maintenance.cpp +++ b/src/mongo/db/catalog/capped_collection_maintenance.cpp @@ -42,11 +42,13 @@ #include "mongo/db/catalog/collection_options.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/concurrency/lock_manager_defs.h" +#include "mongo/db/curop.h" #include "mongo/db/namespace_string.h" #include "mongo/db/op_observer/op_observer.h" #include "mongo/db/op_observer/op_observer_util.h" #include "mongo/db/service_context.h" #include "mongo/db/session/logical_session_id.h" +#include "mongo/db/stats/counters.h" #include "mongo/db/storage/capped_snapshots.h" #include "mongo/db/storage/record_data.h" #include "mongo/db/storage/record_store.h" @@ -134,7 +136,8 @@ bool shouldDeferCappedDeletesToOplogApplication(OperationContext* opCtx, void cappedDeleteUntilBelowConfiguredMaximum(OperationContext* opCtx, const CollectionPtr& collection, - const RecordId& justInserted) { + const RecordId& justInserted, + OpDebug* opDebug) { if (!collection->isCappedAndNeedsDelete(opCtx)) return; @@ -233,19 +236,25 @@ void cappedDeleteUntilBelowConfiguredMaximum(OperationContext* opCtx, opObserver->onDelete(opCtx, collection, kUninitializedStmtId, doc, documentKey, args); } - int64_t unusedKeysDeleted = 0; + int64_t keysDeleted = 0; collection->getIndexCatalog()->unindexRecord(opCtx, collection, doc, record->id, /*logIfError=*/false, - &unusedKeysDeleted); + &keysDeleted); // We're about to delete the record our cursor is positioned on, so advance the cursor. RecordId toDelete = std::move(record->id); record = cursor->next(); collection->getRecordStore()->deleteRecord(opCtx, toDelete); + + if (opDebug) { + opDebug->additiveMetrics.incrementKeysDeleted(keysDeleted); + opDebug->additiveMetrics.incrementNdeleted(1); + } + globalOpCounters.gotDelete(); } if (cappedDeleteSideTxn) { diff --git a/src/mongo/db/catalog/capped_collection_maintenance.h b/src/mongo/db/catalog/capped_collection_maintenance.h index aa608829b06..17f4fad3385 100644 --- a/src/mongo/db/catalog/capped_collection_maintenance.h +++ b/src/mongo/db/catalog/capped_collection_maintenance.h @@ -48,7 +48,8 @@ bool shouldDeferCappedDeletesToOplogApplication(OperationContext* opCtx, */ void cappedDeleteUntilBelowConfiguredMaximum(OperationContext* opCtx, const CollectionPtr& collection, - const RecordId& justInserted); + const RecordId& justInserted, + OpDebug* opDebug); /** * This function starts its own WUOW to truncate documents newer than the document at 'end' from the diff --git a/src/mongo/db/catalog/collection_test.cpp b/src/mongo/db/catalog/collection_test.cpp index 15c5a268c3f..ad0d2014b7e 100644 --- a/src/mongo/db/catalog/collection_test.cpp +++ b/src/mongo/db/catalog/collection_test.cpp @@ -742,23 +742,30 @@ TEST_F(CatalogTestFixture, CappedDeleteRecord) { BSONObj firstDoc = BSON("_id" << 1); BSONObj secondDoc = BSON("_id" << 2); + auto& opDebug = CurOp::get(operationContext())->debug(); { WriteUnitOfWork wuow(operationContext()); ASSERT_OK(collection_internal::insertDocument( - operationContext(), coll, InsertStatement(firstDoc), nullptr)); + operationContext(), coll, InsertStatement(firstDoc), &opDebug)); wuow.commit(); } ASSERT_EQUALS(1, coll->numRecords(operationContext())); + auto globalDeletesInitial = globalOpCounters.getDelete()->load(); // Inserting the second document will remove the first one. { WriteUnitOfWork wuow(operationContext()); ASSERT_OK(collection_internal::insertDocument( - operationContext(), coll, InsertStatement(secondDoc), nullptr)); + operationContext(), coll, InsertStatement(secondDoc), &opDebug)); wuow.commit(); } + auto globalDeletesAfterInsert = globalOpCounters.getDelete()->load(); + ASSERT_EQUALS(globalDeletesAfterInsert, globalDeletesInitial + 1); + + ASSERT_EQUALS(1, opDebug.additiveMetrics.keysDeleted.get_value_or(-1)); + ASSERT_EQUALS(1, opDebug.additiveMetrics.ndeleted.get_value_or(-1)); ASSERT_EQUALS(1, coll->numRecords(operationContext())); diff --git a/src/mongo/db/catalog/collection_write_path.cpp b/src/mongo/db/catalog/collection_write_path.cpp index 02e749c5ebb..f3011ee0e26 100644 --- a/src/mongo/db/catalog/collection_write_path.cpp +++ b/src/mongo/db/catalog/collection_write_path.cpp @@ -400,7 +400,7 @@ Status insertDocumentsImpl(OperationContext* opCtx, /*defaultFromMigrate=*/fromMigrate); } - cappedDeleteUntilBelowConfiguredMaximum(opCtx, collection, records.begin()->id); + cappedDeleteUntilBelowConfiguredMaximum(opCtx, collection, records.begin()->id, opDebug); return Status::OK(); } @@ -481,7 +481,8 @@ Status insertDocumentForBulkLoader(OperationContext* opCtx, /*fromMigrate=*/std::vector<bool>(inserts.size(), false), /*defaultFromMigrate=*/false); - cappedDeleteUntilBelowConfiguredMaximum(opCtx, collection, loc.getValue()); + cappedDeleteUntilBelowConfiguredMaximum( + opCtx, collection, loc.getValue(), &CurOp::get(opCtx)->debug()); // Capture the recordStore here instead of the CollectionPtr object itself, because the record // store's lifetime is controlled by the collection IX lock held on the write paths, whereas the diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp index db1f05822ba..bca073064cf 100644 --- a/src/mongo/db/curop.cpp +++ b/src/mongo/db/curop.cpp @@ -2298,6 +2298,13 @@ void OpDebug::AdditiveMetrics::incrementNinserted(long long n) { *ninserted += n; } +void OpDebug::AdditiveMetrics::incrementNdeleted(long long n) { + if (!ndeleted) { + ndeleted = 0; + } + *ndeleted += n; +} + void OpDebug::AdditiveMetrics::incrementNUpserted(long long n) { if (!nUpserted) { nUpserted = 0; diff --git a/src/mongo/db/curop.h b/src/mongo/db/curop.h index 803f9bfc693..27a01d4829f 100644 --- a/src/mongo/db/curop.h +++ b/src/mongo/db/curop.h @@ -186,6 +186,11 @@ public: void incrementNinserted(long long n); /** + * Increments ndeleted by n. + */ + void incrementNdeleted(long long n); + + /** * Increments nUpserted by n. */ void incrementNUpserted(long long n); diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 3d3af821c79..5533bc411a1 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -237,8 +237,9 @@ Status insertDocumentsForOplog(OperationContext* opCtx, if (!status.isOK()) return status; + OpDebug* const nullOpDebug = nullptr; collection_internal::cappedDeleteUntilBelowConfiguredMaximum( - opCtx, oplogCollection, records->begin()->id); + opCtx, oplogCollection, records->begin()->id, nullOpDebug); // We do not need to notify capped waiters, as we have not yet updated oplog visibility, so // these inserts will not be visible. When visibility updates, it will notify capped |
