Skip to content

Commit ab7ff70

Browse files
chunks count for limit in compaction (#10812)
1 parent c71ca85 commit ab7ff70

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

ydb/core/tx/columnshard/counters/portions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void TSimplePortionsGroupInfo::AddPortion(const TPortionInfo& p) {
3030
RawBytes += p.GetTotalRawBytes();
3131
Count += 1;
3232
RecordsCount += p.NumRows();
33+
ChunksCount += p.GetChunksCount();
3334
}
3435

3536
void TSimplePortionsGroupInfo::RemovePortion(const std::shared_ptr<TPortionInfo>& p) {
@@ -41,10 +42,12 @@ void TSimplePortionsGroupInfo::RemovePortion(const TPortionInfo& p) {
4142
RawBytes -= p.GetTotalRawBytes();
4243
Count -= 1;
4344
RecordsCount -= p.NumRows();
45+
ChunksCount -= p.GetChunksCount();
4446
AFL_VERIFY(RawBytes >= 0);
4547
AFL_VERIFY(BlobBytes >= 0);
4648
AFL_VERIFY(Count >= 0);
4749
AFL_VERIFY(RecordsCount >= 0);
50+
AFL_VERIFY(ChunksCount >= 0);
4851
}
4952

5053
} // namespace NKikimr::NOlap

ydb/core/tx/columnshard/counters/portions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TSimplePortionsGroupInfo {
1515
YDB_READONLY(i64, RawBytes, 0);
1616
YDB_READONLY(i64, Count, 0);
1717
YDB_READONLY(i64, RecordsCount, 0);
18+
YDB_READONLY(i64, ChunksCount, 0);
1819

1920
public:
2021
NJson::TJsonValue SerializeToJson() const {
@@ -23,6 +24,7 @@ class TSimplePortionsGroupInfo {
2324
result.InsertValue("raw_bytes", RawBytes);
2425
result.InsertValue("count", Count);
2526
result.InsertValue("records_count", RecordsCount);
27+
result.InsertValue("chunks_count", ChunksCount);
2628
return result;
2729
}
2830

@@ -45,6 +47,7 @@ class TSimplePortionsGroupInfo {
4547
result.RawBytes = RawBytes + item.RawBytes;
4648
result.Count = Count + item.Count;
4749
result.RecordsCount = RecordsCount + item.RecordsCount;
50+
result.ChunksCount = ChunksCount + item.ChunksCount;
4851
return result;
4952
}
5053

ydb/core/tx/columnshard/engines/portions/portion_info.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ class TPortionInfo {
141141

142142
bool NeedShardingFilter(const TGranuleShardingInfo& shardingInfo) const;
143143

144+
ui64 GetChunksCount() const {
145+
return Records.size() + Indexes.size();
146+
}
147+
144148
NSplitter::TEntityGroups GetEntityGroupsByStorageId(
145149
const TString& specialTier, const IStoragesManager& storages, const TIndexInfo& indexInfo) const;
146150

ydb/core/tx/columnshard/engines/storage/optimizer/lcbuckets/planner/abstract.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ class TCompactionTaskData {
251251
}
252252

253253
bool CanTakeMore() const {
254-
return MemoryUsage < (((ui64)512) << 20) && Portions.size() < 10000;
254+
if (Portions.size() <= 1) {
255+
return true;
256+
}
257+
return MemoryUsage < (((ui64)512) << 20) && CurrentLevelPortionsInfo.GetChunksCount() + TargetLevelPortionsInfo.GetChunksCount() < 100000
258+
&& Portions.size() < 10000;
255259
}
256260

257261
TCompactionTaskData(const ui64 targetCompactionLevel)

0 commit comments

Comments
 (0)