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/exec | |
parent | c9c71fa2a7c872a2c146b62cb9e94e93e7e8bed9 (diff) | |
download | mongo-12e5524bd86cae9dde0f04c57c96f9622c1c5ab9.tar.gz |
SERVER-66537 Combine BatchedDeleteStage<Batch/Pass>Params
Diffstat (limited to 'src/mongo/db/exec')
-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 |
3 files changed, 52 insertions, 71 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; }; |