diff --git a/ydb/core/tx/columnshard/engines/storage/optimizer/lbuckets/planner/optimizer.h b/ydb/core/tx/columnshard/engines/storage/optimizer/lbuckets/planner/optimizer.h index d686fc719112..faeef812cd2e 100644 --- a/ydb/core/tx/columnshard/engines/storage/optimizer/lbuckets/planner/optimizer.h +++ b/ydb/core/tx/columnshard/engines/storage/optimizer/lbuckets/planner/optimizer.h @@ -939,13 +939,14 @@ class TPortionsBucket: public TMoveOnly { dest.MoveNextBorderTo(*this); } - void Actualize(const TInstant currentInstant) { + [[nodiscard]] bool Actualize(const TInstant currentInstant) { if (currentInstant < NextActualizeInstant) { - return; + return false; } auto gChartsThis = StartModificationGuard(); NextActualizeInstant = Others.Actualize(currentInstant); RebuildOptimizedFeature(currentInstant); + return true; } void SplitOthersWith(TPortionsBucket& dest) { @@ -984,7 +985,11 @@ class TPortionBuckets { } void RemoveBucketFromRating(const std::shared_ptr& bucket) { - auto it = BucketsByWeight.find(bucket->GetLastWeight()); + return RemoveBucketFromRating(bucket, bucket->GetLastWeight()); + } + + void RemoveBucketFromRating(const std::shared_ptr& bucket, const i64 rating) { + auto it = BucketsByWeight.find(rating); AFL_VERIFY(it != BucketsByWeight.end()); AFL_VERIFY(it->second.erase(bucket.get())); if (it->second.empty()) { @@ -1068,9 +1073,7 @@ class TPortionBuckets { if (BucketsByWeight.empty()) { return false; } - if (BucketsByWeight.rbegin()->second.empty()) { - return false; - } + AFL_VERIFY(BucketsByWeight.rbegin()->second.size()); const TPortionsBucket* bucketForOptimization = *BucketsByWeight.rbegin()->second.begin(); return bucketForOptimization->IsLocked(dataLocksManager); } @@ -1090,9 +1093,11 @@ class TPortionBuckets { LeftBucket->Actualize(currentInstant); AddBucketToRating(LeftBucket); for (auto&& i : Buckets) { - RemoveBucketFromRating(i.second); - i.second->Actualize(currentInstant); - AddBucketToRating(i.second); + const i64 rating = i.second->GetWeight(); + if (i.second->Actualize(currentInstant)) { + RemoveBucketFromRating(i.second, rating); + AddBucketToRating(i.second); + } } }