diff options
author | Haley Connelly <haley.connelly@mongodb.com> | 2022-05-18 14:37:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-18 15:52:21 +0000 |
commit | 12e5524bd86cae9dde0f04c57c96f9622c1c5ab9 (patch) | |
tree | d4644d78837c2d669cc7a78ef023a411f79b359a /src/mongo/db | |
parent | c9c71fa2a7c872a2c146b62cb9e94e93e7e8bed9 (diff) | |
download | mongo-12e5524bd86cae9dde0f04c57c96f9622c1c5ab9.tar.gz |
SERVER-66537 Combine BatchedDeleteStage<Batch/Pass>Params
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/exec/batched_delete_stage.cpp | 56 | ||||
-rw-r--r-- | src/mongo/db/exec/batched_delete_stage.h | 59 | ||||
-rw-r--r-- | src/mongo/db/exec/plan_stats.h | 8 | ||||
-rw-r--r-- | src/mongo/db/pipeline/change_stream_expired_pre_image_remover.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/query/get_executor.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/query/internal_plans.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/query/internal_plans.h | 9 | ||||
-rw-r--r-- | src/mongo/db/ttl.cpp | 6 |
8 files changed, 76 insertions, 94 deletions
diff --git a/src/mongo/db/exec/batched_delete_stage.cpp b/src/mongo/db/exec/batched_delete_stage.cpp index 8b66cc8143f..fdb2df9537a 100644 --- a/src/mongo/db/exec/batched_delete_stage.cpp +++ b/src/mongo/db/exec/batched_delete_stage.cpp @@ -125,31 +125,16 @@ bool ensureStillMatchesAndUpdateStats(const CollectionPtr& collection, return write_stage_common::ensureStillMatches(collection, opCtx, ws, id, cq); } -BatchedDeleteStage::BatchedDeleteStage(ExpressionContext* expCtx, - std::unique_ptr<DeleteStageParams> params, - std::unique_ptr<BatchedDeleteStageBatchParams> batchParams, - WorkingSet* ws, - const CollectionPtr& collection, - PlanStage* child) - : BatchedDeleteStage(expCtx, - std::move(params), - std::move(batchParams), - std::make_unique<BatchedDeleteStagePassParams>(), - ws, - collection, - child) {} - -BatchedDeleteStage::BatchedDeleteStage(ExpressionContext* expCtx, - std::unique_ptr<DeleteStageParams> params, - std::unique_ptr<BatchedDeleteStageBatchParams> batchParams, - std::unique_ptr<BatchedDeleteStagePassParams> passParams, - WorkingSet* ws, - const CollectionPtr& collection, - PlanStage* child) +BatchedDeleteStage::BatchedDeleteStage( + ExpressionContext* expCtx, + std::unique_ptr<DeleteStageParams> params, + std::unique_ptr<BatchedDeleteStageParams> batchedDeleteParams, + WorkingSet* ws, + const CollectionPtr& collection, + PlanStage* child) : DeleteStage::DeleteStage( kStageType.rawData(), expCtx, std::move(params), ws, collection, child), - _batchParams(std::move(batchParams)), - _passParams(std::move(passParams)), + _batchedDeleteParams(std::move(batchedDeleteParams)), _stagedDeletesBuffer(ws), _stagedDeletesWatermarkBytes(0), _passTotalDocsStaged(0), @@ -175,8 +160,9 @@ BatchedDeleteStage::BatchedDeleteStage(ExpressionContext* expCtx, !_params->numStatsForDoc); tassert(6303807, "batch size parameters must be greater than or equal to zero", - _batchParams->targetStagedDocBytes >= 0 && _batchParams->targetBatchDocs >= 0 && - _batchParams->targetBatchTimeMS >= Milliseconds(0)); + _batchedDeleteParams->targetStagedDocBytes >= 0 && + _batchedDeleteParams->targetBatchDocs >= 0 && + _batchedDeleteParams->targetBatchTimeMS >= Milliseconds(0)); } BatchedDeleteStage::~BatchedDeleteStage() {} @@ -386,8 +372,8 @@ PlanStage::StageState BatchedDeleteStage::_deleteBatch(WorkingSetID* out) { } const Milliseconds elapsedMillis(batchTimer.millis()); - if (_batchParams->targetBatchTimeMS != Milliseconds(0) && - elapsedMillis >= _batchParams->targetBatchTimeMS) { + if (_batchedDeleteParams->targetBatchTimeMS != Milliseconds(0) && + elapsedMillis >= _batchedDeleteParams->targetBatchTimeMS) { // Met 'targetBatchTimeMS' after evaluating the staged delete at 'bufferOffset'. break; } @@ -486,17 +472,19 @@ PlanStage::StageState BatchedDeleteStage::_prepareToRetryDrainAfterWCE( } bool BatchedDeleteStage::_batchTargetMet() { - return (_batchParams->targetBatchDocs && - _stagedDeletesBuffer.size() >= static_cast<size_t>(_batchParams->targetBatchDocs)) || - (_batchParams->targetStagedDocBytes && + return (_batchedDeleteParams->targetBatchDocs && + _stagedDeletesBuffer.size() >= + static_cast<size_t>(_batchedDeleteParams->targetBatchDocs)) || + (_batchedDeleteParams->targetStagedDocBytes && _stagedDeletesWatermarkBytes >= - static_cast<unsigned long long>(_batchParams->targetStagedDocBytes)); + static_cast<unsigned long long>(_batchedDeleteParams->targetStagedDocBytes)); } bool BatchedDeleteStage::_passTargetMet() { - return (_passParams->targetPassDocs && _passTotalDocsStaged >= _passParams->targetPassDocs) || - (_passParams->targetPassTimeMS != Milliseconds(0) && - Milliseconds(_passTimer.millis()) >= _passParams->targetPassTimeMS); + return (_batchedDeleteParams->targetPassDocs && + _passTotalDocsStaged >= _batchedDeleteParams->targetPassDocs) || + (_batchedDeleteParams->targetPassTimeMS != Milliseconds(0) && + Milliseconds(_passTimer.millis()) >= _batchedDeleteParams->targetPassTimeMS); } } // namespace mongo diff --git a/src/mongo/db/exec/batched_delete_stage.h b/src/mongo/db/exec/batched_delete_stage.h index 0dee55290c0..bd2754433fa 100644 --- a/src/mongo/db/exec/batched_delete_stage.h +++ b/src/mongo/db/exec/batched_delete_stage.h @@ -37,37 +37,44 @@ namespace mongo { -/** - * 'Batch' sizing parameters. A batch of staged document deletes is committed as soon - * as one of the targets below is met, or upon reaching EOF. - */ -struct BatchedDeleteStageBatchParams { - BatchedDeleteStageBatchParams() +struct BatchedDeleteStageParams { + BatchedDeleteStageParams() : targetBatchDocs(gBatchedDeletesTargetBatchDocs.load()), targetBatchTimeMS(Milliseconds(gBatchedDeletesTargetBatchTimeMS.load())), - targetStagedDocBytes(gBatchedDeletesTargetStagedDocBytes.load()) {} + targetStagedDocBytes(gBatchedDeletesTargetStagedDocBytes.load()), + targetPassDocs(0), + targetPassTimeMS(Milliseconds(0)) {} + // - // A 'batch' refers to the deletes executed in a single WriteUnitOfWork. + // A 'batch' refers to the deletes executed in a single WriteUnitOfWork. A batch of staged + // document deletes is committed as soon as one of the batch targets is met, or upon reach EOF. + // + // 'Batch' targets have no impact on the total number of documents removed in the batched delete + // operation. // // Documents staged for deletions are processed in a batch once this document count target is // met. A value of zero means unlimited. long long targetBatchDocs = 0; + // A batch is committed as soon as this target execution time is met. Zero means unlimited. Milliseconds targetBatchTimeMS = Milliseconds(0); + // Documents staged for deletions are processed in a batch once this size target is met. // Accounts for document size, not for indexes. A value of zero means unlimited. long long targetStagedDocBytes = 0; -}; -/** - * 'Pass' parameters. A 'pass' defines a approximate target number of documents or runtime after - * which the deletion stops staging documents, executes any remaining deletes, and eventually - * returns completion. 'Pass' parameters are approximate because they are checked at a per batch - * commit granularity. - */ -struct BatchedDeleteStagePassParams { - BatchedDeleteStagePassParams() : targetPassDocs(0), targetPassTimeMS(Milliseconds(0)) {} + // + // A 'pass' defines a approximate target number of documents or runtime after which the + // deletion stops staging documents, executes any remaining deletes, and eventually returns + // completion. 'Pass' parameters are approximate because they are checked at a per batch commit + // granularity. + // + // 'Pass' targets may impact the total number of documents removed in the batched delete + // operation. When set, there is no guarantee all matching documents will be removed in the + // operation. For this reason, 'pass' targets are only exposed to internal users for specific + // use cases. + // // Limits the amount of documents processed in a single pass. Once met, no more documents will // be fetched for delete - any remaining staged deletes will be executed provided they still @@ -96,23 +103,12 @@ class BatchedDeleteStage final : public DeleteStage { public: static constexpr StringData kStageType = "BATCHED_DELETE"_sd; - // Preferred constructor that uses default 'BatchedDeleteStagePassParams'. Changing the - // 'BatchedDeletePassParams' from their default may cause the delete operation to only partially - // delete results that match the query and should only be done for specific internal operations. BatchedDeleteStage(ExpressionContext* expCtx, std::unique_ptr<DeleteStageParams> params, - std::unique_ptr<BatchedDeleteStageBatchParams> batchParams, + std::unique_ptr<BatchedDeleteStageParams> batchedDeleteParams, WorkingSet* ws, const CollectionPtr& collection, PlanStage* child); - BatchedDeleteStage(ExpressionContext* expCtx, - std::unique_ptr<DeleteStageParams> params, - std::unique_ptr<BatchedDeleteStageBatchParams> batchParams, - std::unique_ptr<BatchedDeleteStagePassParams> passParams, - WorkingSet* ws, - const CollectionPtr& collection, - PlanStage* child); - ~BatchedDeleteStage(); // Returns true when no more work can be done (there are no more deletes to commit). @@ -163,10 +159,7 @@ private: bool _passTargetMet(); // Batch targeting parameters. - std::unique_ptr<BatchedDeleteStageBatchParams> _batchParams; - - // Pass targeting parameters. - std::unique_ptr<BatchedDeleteStagePassParams> _passParams; + std::unique_ptr<BatchedDeleteStageParams> _batchedDeleteParams; // Holds information for each document staged for delete. BatchedDeleteStageBuffer _stagedDeletesBuffer; diff --git a/src/mongo/db/exec/plan_stats.h b/src/mongo/db/exec/plan_stats.h index 6032654c63e..e65934f19bc 100644 --- a/src/mongo/db/exec/plan_stats.h +++ b/src/mongo/db/exec/plan_stats.h @@ -425,14 +425,14 @@ struct BatchedDeleteStats : public DeleteStats { BatchedDeleteStats() = default; // Unlike a standard multi:true delete, BatchedDeleteStage can complete with PlanStage::IS_EOF - // before deleting all the documents that match the query, if a 'BatchedDeleteStagePassParams' - // target is met. + // before deleting all the documents that match the query, if a 'BatchedDeleteStageParams' + // 'pass' target is met. // - // True indicates the operation reaches completion because a pass target is met. + // True indicates the operation reaches completion because a 'pass' target is met. // // False indicates either (1) the operation hasn't reached completion or (2) the operation // removed all the documents that matched the criteria to reach completion - this is always the - // case with the default BatchedDeleteStagePassParams. + // case with the default 'BatchedDeleteStageParams'. bool passTargetMet = false; }; diff --git a/src/mongo/db/pipeline/change_stream_expired_pre_image_remover.cpp b/src/mongo/db/pipeline/change_stream_expired_pre_image_remover.cpp index 37eaa0d26d3..4a2c7f46542 100644 --- a/src/mongo/db/pipeline/change_stream_expired_pre_image_remover.cpp +++ b/src/mongo/db/pipeline/change_stream_expired_pre_image_remover.cpp @@ -365,9 +365,10 @@ void deleteExpiredChangeStreamPreImages(Client* client, Date_t currentTimeForTim auto params = std::make_unique<DeleteStageParams>(); params->isMulti = true; - std::unique_ptr<BatchedDeleteStageBatchParams> batchParams; + std::unique_ptr<BatchedDeleteStageParams> batchedDeleteParams; if (isBatchedRemoval) { - batchParams = std::make_unique<BatchedDeleteStageBatchParams>(); + batchedDeleteParams = + std::make_unique<BatchedDeleteStageParams>(); } auto exec = InternalPlanner::deleteWithCollectionScan( @@ -378,7 +379,7 @@ void deleteExpiredChangeStreamPreImages(Client* client, Date_t currentTimeForTim InternalPlanner::Direction::FORWARD, RecordIdBound(collectionRange.first), RecordIdBound(collectionRange.second), - std::move(batchParams)); + std::move(batchedDeleteParams)); numberOfRemovals += exec->executeDelete(); }); } diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp index df84d16f0e0..537ec7d5c69 100644 --- a/src/mongo/db/query/get_executor.cpp +++ b/src/mongo/db/query/get_executor.cpp @@ -1676,13 +1676,12 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorDele !deleteStageParams->numStatsForDoc; if (batchDelete) { - root = - std::make_unique<BatchedDeleteStage>(cq->getExpCtxRaw(), - std::move(deleteStageParams), - std::make_unique<BatchedDeleteStageBatchParams>(), - ws.get(), - collection, - root.release()); + root = std::make_unique<BatchedDeleteStage>(cq->getExpCtxRaw(), + std::move(deleteStageParams), + std::make_unique<BatchedDeleteStageParams>(), + ws.get(), + collection, + root.release()); } else { root = std::make_unique<DeleteStage>( cq->getExpCtxRaw(), std::move(deleteStageParams), ws.get(), collection, root.release()); diff --git a/src/mongo/db/query/internal_plans.cpp b/src/mongo/db/query/internal_plans.cpp index e40fdc523ef..27614038ae2 100644 --- a/src/mongo/db/query/internal_plans.cpp +++ b/src/mongo/db/query/internal_plans.cpp @@ -208,7 +208,7 @@ std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> InternalPlanner::deleteWith Direction direction, boost::optional<RecordIdBound> minRecord, boost::optional<RecordIdBound> maxRecord, - std::unique_ptr<BatchedDeleteStageBatchParams> batchParams) { + std::unique_ptr<BatchedDeleteStageParams> batchedDeleteParams) { const auto& collection = *coll; invariant(collection); auto ws = std::make_unique<WorkingSet>(); @@ -225,10 +225,10 @@ std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> InternalPlanner::deleteWith auto root = _collectionScan(expCtx, ws.get(), &collection, collScanParams); - if (batchParams) { + if (batchedDeleteParams) { root = std::make_unique<BatchedDeleteStage>(expCtx.get(), std::move(params), - std::move(batchParams), + std::move(batchedDeleteParams), ws.get(), collection, root.release()); @@ -295,7 +295,7 @@ std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> InternalPlanner::deleteWith BoundInclusion boundInclusion, PlanYieldPolicy::YieldPolicy yieldPolicy, Direction direction, - std::unique_ptr<BatchedDeleteStageBatchParams> batchParams) { + std::unique_ptr<BatchedDeleteStageParams> batchedDeleteParams) { const auto& collection = *coll; invariant(collection); auto ws = std::make_unique<WorkingSet>(); @@ -313,10 +313,10 @@ std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> InternalPlanner::deleteWith direction, InternalPlanner::IXSCAN_FETCH); - if (batchParams) { + if (batchedDeleteParams) { root = std::make_unique<BatchedDeleteStage>(expCtx.get(), std::move(params), - std::move(batchParams), + std::move(batchedDeleteParams), ws.get(), collection, root.release()); diff --git a/src/mongo/db/query/internal_plans.h b/src/mongo/db/query/internal_plans.h index 3bcf3e02b1c..49666492c87 100644 --- a/src/mongo/db/query/internal_plans.h +++ b/src/mongo/db/query/internal_plans.h @@ -90,7 +90,8 @@ public: PlanYieldPolicy::YieldPolicy yieldPolicy); /** - * Returns a FETCH => DELETE plan, or a FETCH => BATCHED_DELETE plan if 'batchParams' is set. + * Returns a FETCH => DELETE plan, or a FETCH => BATCHED_DELETE plan if 'batchedDeleteParams' is + * set. */ static std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> deleteWithCollectionScan( OperationContext* opCtx, @@ -100,7 +101,7 @@ public: Direction direction = FORWARD, boost::optional<RecordIdBound> minRecord = boost::none, boost::optional<RecordIdBound> maxRecord = boost::none, - std::unique_ptr<BatchedDeleteStageBatchParams> batchParams = nullptr); + std::unique_ptr<BatchedDeleteStageParams> batchedDeleteParams = nullptr); /** * Returns an index scan. Caller owns returned pointer. @@ -118,7 +119,7 @@ public: /** * Returns an IXSCAN => FETCH => DELETE plan, or an IXSCAN => FETCH => BATCHED_DELETE plan if - * 'batchParams' is set. + * 'batchedDeleteParams' is set. */ static std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> deleteWithIndexScan( OperationContext* opCtx, @@ -130,7 +131,7 @@ public: BoundInclusion boundInclusion, PlanYieldPolicy::YieldPolicy yieldPolicy, Direction direction = FORWARD, - std::unique_ptr<BatchedDeleteStageBatchParams> batchParams = nullptr); + std::unique_ptr<BatchedDeleteStageParams> batchedDeleteParams = nullptr); /** * Returns a scan over the 'shardKeyIdx'. If the 'shardKeyIdx' is a non-clustered index, returns diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index 78fa7d74847..1183624d2f2 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -74,14 +74,14 @@ namespace mongo { namespace { const auto getTTLMonitor = ServiceContext::declareDecoration<std::unique_ptr<TTLMonitor>>(); -// Returns BatchedDeleteStageBatchParams pointer only if the feature flag and the server +// Returns BatchedDeleteStageParams pointer only if the feature flag and the server // parameter are enabled. -std::unique_ptr<BatchedDeleteStageBatchParams> getBatchedDeleteParamsIfEnabled( +std::unique_ptr<BatchedDeleteStageParams> getBatchedDeleteParamsIfEnabled( const CollectionPtr& collection) { // Load batched delete parameters. if (feature_flags::gBatchMultiDeletes.isEnabled(serverGlobalParams.featureCompatibility) && ttlMonitorBatchDeletes.load()) { - return std::make_unique<BatchedDeleteStageBatchParams>(); + return std::make_unique<BatchedDeleteStageParams>(); } return nullptr; } |