diff options
author | Haley Connelly <haley.connelly@mongodb.com> | 2022-05-09 14:32:44 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-09 16:32:43 +0000 |
commit | cd9c111f2707f7e641765e9c00c1cb036df61c9f (patch) | |
tree | 40c0a4c65852f0ae4db1fb6784567d1a094c3305 /src/mongo/db/exec | |
parent | 1cb03bb7e99accaa2f3abefd0f32448d86265efc (diff) | |
download | mongo-cd9c111f2707f7e641765e9c00c1cb036df61c9f.tar.gz |
SERVER-66210 Indicate when pass targets cause BatchedDeleteStage completion
Diffstat (limited to 'src/mongo/db/exec')
-rw-r--r-- | src/mongo/db/exec/batched_delete_stage.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/exec/batched_delete_stage.h | 6 | ||||
-rw-r--r-- | src/mongo/db/exec/delete_stage.h | 4 | ||||
-rw-r--r-- | src/mongo/db/exec/plan_stats.h | 15 |
4 files changed, 46 insertions, 3 deletions
diff --git a/src/mongo/db/exec/batched_delete_stage.cpp b/src/mongo/db/exec/batched_delete_stage.cpp index 79a12600418..32f5bfe5d99 100644 --- a/src/mongo/db/exec/batched_delete_stage.cpp +++ b/src/mongo/db/exec/batched_delete_stage.cpp @@ -185,6 +185,19 @@ bool BatchedDeleteStage::isEOF() { return _stagedDeletesBuffer.empty() && _passStagingComplete; } +std::unique_ptr<PlanStageStats> BatchedDeleteStage::getStats() { + _commonStats.isEOF = isEOF(); + std::unique_ptr<PlanStageStats> stats = + std::make_unique<PlanStageStats>(_commonStats, stageType()); + stats->specific = std::make_unique<BatchedDeleteStats>(_specificStats); + stats->children.emplace_back(child()->getStats()); + return stats; +} + +const SpecificStats* BatchedDeleteStage::getSpecificStats() const { + return &_specificStats; +} + PlanStage::StageState BatchedDeleteStage::doWork(WorkingSetID* out) { WorkingSetID idToReturn = WorkingSet::INVALID_ID; PlanStage::StageState planStageState = PlanStage::NEED_TIME; @@ -213,7 +226,16 @@ PlanStage::StageState BatchedDeleteStage::doWork(WorkingSetID* out) { _stagedDeletesWatermarkBytes = 0; planStageState = _deleteBatch(&idToReturn); - _passStagingComplete = _passStagingComplete || _passTargetMet(); + if (!_passStagingComplete) { + tassert(6621000, "Expected staging to be permitted", !_specificStats.passTargetMet); + + // Staging hasn't yielded PlanStage::IS_EOF. + // + // Indicate whether the operation should reach completion due to a pass target. + _specificStats.passTargetMet = _passTargetMet(); + } + + _passStagingComplete = _passStagingComplete || _specificStats.passTargetMet; _commitStagedDeletes = _passStagingComplete || !_stagedDeletesBuffer.empty(); } diff --git a/src/mongo/db/exec/batched_delete_stage.h b/src/mongo/db/exec/batched_delete_stage.h index 89e99a5e6db..0dee55290c0 100644 --- a/src/mongo/db/exec/batched_delete_stage.h +++ b/src/mongo/db/exec/batched_delete_stage.h @@ -118,6 +118,10 @@ public: // Returns true when no more work can be done (there are no more deletes to commit). bool isEOF() final; + std::unique_ptr<PlanStageStats> getStats() final; + + const SpecificStats* getSpecificStats() const final; + StageState doWork(WorkingSetID* out); StageType stageType() const final { @@ -148,6 +152,8 @@ private: PlanStage::StageState _prepareToRetryDrainAfterWCE( WorkingSetID* out, const std::set<WorkingSetID>& recordsThatNoLongerMatch); + BatchedDeleteStats _specificStats; + // Returns true if one or more of the batch targets are met and it is time to delete the batch. bool _batchTargetMet(); diff --git a/src/mongo/db/exec/delete_stage.h b/src/mongo/db/exec/delete_stage.h index 244c8fb7c16..ef2b12624b8 100644 --- a/src/mongo/db/exec/delete_stage.h +++ b/src/mongo/db/exec/delete_stage.h @@ -128,9 +128,9 @@ public: return STAGE_DELETE; } - std::unique_ptr<PlanStageStats> getStats() final; + std::unique_ptr<PlanStageStats> getStats(); - const SpecificStats* getSpecificStats() const final; + const SpecificStats* getSpecificStats() const; protected: void doSaveStateRequiresCollection() final { diff --git a/src/mongo/db/exec/plan_stats.h b/src/mongo/db/exec/plan_stats.h index 36014955c0d..6032654c63e 100644 --- a/src/mongo/db/exec/plan_stats.h +++ b/src/mongo/db/exec/plan_stats.h @@ -421,6 +421,21 @@ struct DeleteStats : public SpecificStats { size_t docsDeleted = 0u; }; +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. + // + // 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. + bool passTargetMet = false; +}; + struct DistinctScanStats : public SpecificStats { std::unique_ptr<SpecificStats> clone() const final { auto specific = std::make_unique<DistinctScanStats>(*this); |