Skip to content

Commit

Permalink
improve optimizer performance (ydb-platform#4776)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmorozov333 authored May 23, 2024
1 parent 34e9cf8 commit 50b9d76
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,17 @@ class TPortionsPool {
}
}

void Actualize(const TInstant currentInstant) {
[[nodiscard]] TInstant Actualize(const TInstant currentInstant) {
TInstant result = TInstant::Max();
auto border = GetFutureBorder();
if (border) {
for (auto&& i : Futures) {
if (currentInstant - i.first >= FutureDetector) {
for (auto&& p : i.second) {
AFL_VERIFY(AddPreActual(p.second));
}
} else {
result = std::min(result, i.first + FutureDetector);
}
}
while (Futures.size() && currentInstant - Futures.begin()->first >= FutureDetector) {
Expand Down Expand Up @@ -501,6 +504,7 @@ class TPortionsPool {
AFL_VERIFY(RemoveActual(i));
}
}
return result;
}

void SplitTo(TPortionsPool& dest, const NArrow::TReplaceKey& destStart) {
Expand Down Expand Up @@ -626,6 +630,7 @@ class TPortionsBucket: public TMoveOnly {
const std::shared_ptr<TCounters> Counters;
mutable std::optional<i64> LastWeight;
TPortionsPool Others;
TInstant NextActualizeInstant = TInstant::Zero();
std::optional<NArrow::TReplaceKey> NextBorder;

void MoveNextBorderTo(TPortionsBucket& dest) {
Expand All @@ -652,11 +657,11 @@ class TPortionsBucket: public TMoveOnly {
public:
class TModificationGuard: TNonCopyable {
private:
const TPortionsBucket& Owner;
TPortionsBucket& Owner;
const bool IsEmptyOthers = false;
const bool HasNextBorder = false;
public:
TModificationGuard(const TPortionsBucket& owner)
TModificationGuard(TPortionsBucket& owner)
: Owner(owner)
, IsEmptyOthers(Owner.Others.ActualsEmpty())
, HasNextBorder(Owner.NextBorder)
Expand All @@ -666,6 +671,7 @@ class TPortionsBucket: public TMoveOnly {

~TModificationGuard() {
AFL_VERIFY_DEBUG(Owner.Validate());
Owner.NextActualizeInstant = TInstant::Zero();
if (!Owner.MainPortion) {
return;
}
Expand Down Expand Up @@ -850,15 +856,15 @@ class TPortionsBucket: public TMoveOnly {
auto gChartsThis = StartModificationGuard();
if (NextBorder && MainPortion) {
AFL_VERIFY(portion->CrossPKWith(MainPortion->IndexKeyStart(), *NextBorder));
#ifndef NDEBUG
auto oldPortionInfo = GetOldestPortion(true);
auto youngPortionInfo = GetYoungestPortion(true);
AFL_VERIFY(oldPortionInfo && youngPortionInfo);
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)
("event", "other_not_final")("delta", youngPortionInfo->RecordSnapshotMax().GetPlanStep() - oldPortionInfo->RecordSnapshotMax().GetPlanStep())
("main", MainPortion->DebugString(true))
("current", portion->DebugString(true))
("oldest", oldPortionInfo->DebugString(true))("young", youngPortionInfo->DebugString(true))
("bucket_from", MainPortion->IndexKeyStart().DebugString())("bucket_to", NextBorder->DebugString());
("event", "other_not_final")("delta", youngPortionInfo->RecordSnapshotMax().GetPlanStep() - oldPortionInfo->RecordSnapshotMax().GetPlanStep())
("main", MainPortion->DebugString(true))("current", portion->DebugString(true))("oldest", oldPortionInfo->DebugString(true))
("young", youngPortionInfo->DebugString(true))("bucket_from", MainPortion->IndexKeyStart().DebugString())("bucket_to", NextBorder->DebugString());
#endif
}
Others.Add(portion, now);
}
Expand All @@ -876,8 +882,11 @@ class TPortionsBucket: public TMoveOnly {
}

void Actualize(const TInstant currentInstant) {
if (currentInstant < NextActualizeInstant) {
return;
}
auto gChartsThis = StartModificationGuard();
Others.Actualize(currentInstant);
NextActualizeInstant = Others.Actualize(currentInstant);
RebuildOptimizedFeature(currentInstant);
}

Expand Down

0 comments on commit 50b9d76

Please sign in to comment.