Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use policies for memory prediction on compaction #1130

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,12 @@ void TGeneralCompactColumnEngineChanges::AddCheckPoint(const NIndexedReader::TSo
AFL_VERIFY(CheckPoints.emplace(position, include).second || !validationDuplications);
}

std::shared_ptr<TGeneralCompactColumnEngineChanges::IMemoryPredictor> TGeneralCompactColumnEngineChanges::BuildMemoryPredictor() {
if (AppDataVerified().ColumnShardConfig.GetUseChunkedMergeOnCompaction()) {
return std::make_shared<TMemoryPredictorChunkedPolicy>();
} else {
return std::make_shared<TMemoryPredictorSimplePolicy>();
}
}

}
44 changes: 44 additions & 0 deletions ydb/core/tx/columnshard/engines/changes/general_compaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,50 @@ class TGeneralCompactColumnEngineChanges: public TCompactColumnEngineChanges {
public:
using TBase::TBase;

class IMemoryPredictor {
public:
virtual ui64 AddPortion(const std::shared_ptr<TPortionInfo>& portionInfo) = 0;
virtual ~IMemoryPredictor() = default;
};

class TMemoryPredictorSimplePolicy: public IMemoryPredictor {
private:
ui64 SumMemory = 0;
public:
virtual ui64 AddPortion(const std::shared_ptr<TPortionInfo>& portionInfo) override {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: In override methods we don't have to write virtual.

for (auto&& i : portionInfo->GetRecords()) {
SumMemory += i.BlobRange.Size;
SumMemory += i.GetMeta().GetRawBytesVerified();
}
return SumMemory;
}
};

class TMemoryPredictorChunkedPolicy: public IMemoryPredictor {
private:
ui64 SumMemory = 0;
THashMap<ui32, ui64> MaxMemoryByColumnChunk;
public:
virtual ui64 AddPortion(const std::shared_ptr<TPortionInfo>& portionInfo) override {
SumMemory += portionInfo->GetRecordsCount() * 24;
for (auto&& i : portionInfo->GetRecords()) {
SumMemory += i.BlobRange.Size;
SumMemory += i.GetMeta().GetRawBytesVerified();
auto it = MaxMemoryByColumnChunk.find(i.GetColumnId());
if (it == MaxMemoryByColumnChunk.end()) {
MaxMemoryByColumnChunk.emplace(i.GetColumnId(), i.GetMeta().GetRawBytesVerified());
} else if (it->second < i.GetMeta().GetRawBytesVerified()) {
SumMemory -= it->second;
it->second = i.GetMeta().GetRawBytesVerified();
SumMemory += it->second;
}
}
return SumMemory;
}
};

static std::shared_ptr<IMemoryPredictor> BuildMemoryPredictor();

void AddCheckPoint(const NIndexedReader::TSortableBatchPosition& position, const bool include = true, const bool validationDuplications = true);

virtual TString TypeString() const override {
Expand Down
8 changes: 6 additions & 2 deletions ydb/core/tx/columnshard/engines/portions/portion_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class TPortionInfo {
std::shared_ptr<NOlap::IBlobsStorageOperator> BlobsOperator;
ui64 DeprecatedGranuleId = 0;
public:
std::vector<TColumnRecord> Records;

const std::vector<TColumnRecord>& GetRecords() const {
return Records;
}

ui64 GetPathId() const {
return PathId;
}
Expand Down Expand Up @@ -117,8 +123,6 @@ class TPortionInfo {
return Meta;
}

std::vector<TColumnRecord> Records;

const TColumnRecord* GetRecordPointer(const TChunkAddress& address) const {
for (auto&& i : Records) {
if (i.GetAddress() == address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,12 @@ class TPortionsPool {
std::sort(sorted.begin(), sorted.end(), pred);

std::vector<std::shared_ptr<TPortionInfo>> result;
ui64 currentSize = 0;
std::shared_ptr<NCompaction::TGeneralCompactColumnEngineChanges::IMemoryPredictor> predictor = NCompaction::TGeneralCompactColumnEngineChanges::BuildMemoryPredictor();
for (auto&& i : sorted) {
if (currentSize > sizeLimit && result.size() > 1) {
result.emplace_back(i);
if (predictor->AddPortion(i) > sizeLimit && result.size() > 1) {
break;
}
result.emplace_back(i);
currentSize += i->GetBlobBytes();
}
if (result.size() < sorted.size()) {
separatePoint = sorted[result.size()]->IndexKeyStart();
Expand Down
Loading