Skip to content

Commit

Permalink
chunks count for limit in compaction (ydb-platform#10812)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmorozov333 authored and zverevgeny committed Jan 8, 2025
1 parent 9aa2369 commit 3750139
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ydb/core/tx/columnshard/counters/portions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void TSimplePortionsGroupInfo::AddPortion(const TPortionInfo& p) {
RawBytes += p.GetTotalRawBytes();
Count += 1;
RecordsCount += p.NumRows();
ChunksCount += p.GetChunksCount();
}

void TSimplePortionsGroupInfo::RemovePortion(const std::shared_ptr<TPortionInfo>& p) {
Expand All @@ -41,10 +42,12 @@ void TSimplePortionsGroupInfo::RemovePortion(const TPortionInfo& p) {
RawBytes -= p.GetTotalRawBytes();
Count -= 1;
RecordsCount -= p.NumRows();
ChunksCount -= p.GetChunksCount();
AFL_VERIFY(RawBytes >= 0);
AFL_VERIFY(BlobBytes >= 0);
AFL_VERIFY(Count >= 0);
AFL_VERIFY(RecordsCount >= 0);
AFL_VERIFY(ChunksCount >= 0);
}

} // namespace NKikimr::NOlap
3 changes: 3 additions & 0 deletions ydb/core/tx/columnshard/counters/portions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TSimplePortionsGroupInfo {
YDB_READONLY(i64, RawBytes, 0);
YDB_READONLY(i64, Count, 0);
YDB_READONLY(i64, RecordsCount, 0);
YDB_READONLY(i64, ChunksCount, 0);

public:
NJson::TJsonValue SerializeToJson() const {
Expand All @@ -23,6 +24,7 @@ class TSimplePortionsGroupInfo {
result.InsertValue("raw_bytes", RawBytes);
result.InsertValue("count", Count);
result.InsertValue("records_count", RecordsCount);
result.InsertValue("chunks_count", ChunksCount);
return result;
}

Expand All @@ -45,6 +47,7 @@ class TSimplePortionsGroupInfo {
result.RawBytes = RawBytes + item.RawBytes;
result.Count = Count + item.Count;
result.RecordsCount = RecordsCount + item.RecordsCount;
result.ChunksCount = ChunksCount + item.ChunksCount;
return result;
}

Expand Down
4 changes: 4 additions & 0 deletions ydb/core/tx/columnshard/engines/portions/portion_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ class TPortionInfo {

bool NeedShardingFilter(const TGranuleShardingInfo& shardingInfo) const;

ui64 GetChunksCount() const {
return Records.size() + Indexes.size();
}

NSplitter::TEntityGroups GetEntityGroupsByStorageId(
const TString& specialTier, const IStoragesManager& storages, const TIndexInfo& indexInfo) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ class TCompactionTaskData {
}

bool CanTakeMore() const {
return MemoryUsage < (((ui64)512) << 20) && Portions.size() < 10000;
if (Portions.size() <= 1) {
return true;
}
return MemoryUsage < (((ui64)512) << 20) && CurrentLevelPortionsInfo.GetChunksCount() + TargetLevelPortionsInfo.GetChunksCount() < 100000
&& Portions.size() < 10000;
}

TCompactionTaskData(const ui64 targetCompactionLevel)
Expand Down

0 comments on commit 3750139

Please sign in to comment.