Skip to content

usage chunked merge by optional and usage full-batches-merge for norm… #972

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

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion ydb/core/protos/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ message TActorSystemConfig {

enum EActorSystemProfile {
DEFAULT = 1;
LOW_CPU_CONSUMPTION = 2;
LOW_CPU_CONSUMPTION = 2;
LOW_LATENCY = 3;
}

Expand Down Expand Up @@ -1432,6 +1432,7 @@ message TColumnShardConfig {
optional bool TTLEnabled = 6 [default = true];
optional bool WritingEnabled = 7 [default = true];
optional uint32 WritingBufferDurationMs = 8 [default = 0];
optional bool UseChunkedMergeOnCompaction = 9 [default = false];
}

message TSchemeShardConfig {
Expand Down
70 changes: 53 additions & 17 deletions ydb/core/tx/columnshard/engines/changes/general_compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,36 @@

namespace NKikimr::NOlap::NCompaction {

TConclusionStatus TGeneralCompactColumnEngineChanges::DoConstructBlobs(TConstructionContext& context) noexcept {
void TGeneralCompactColumnEngineChanges::BuildAppendedPortionsByFullBatches(TConstructionContext& context) noexcept {
std::vector<TPortionInfoWithBlobs> portions = TPortionInfoWithBlobs::RestorePortions(SwitchedPortions, Blobs);
Blobs.clear();
i64 portionsSize = 0;
i64 portionsCount = 0;
i64 insertedPortionsSize = 0;
i64 compactedPortionsSize = 0;
i64 otherPortionsSize = 0;
for (auto&& i : SwitchedPortions) {
if (i.GetMeta().GetProduced() == TPortionMeta::EProduced::INSERTED) {
insertedPortionsSize += i.GetBlobBytes();
} else if (i.GetMeta().GetProduced() == TPortionMeta::EProduced::SPLIT_COMPACTED) {
compactedPortionsSize += i.GetBlobBytes();
} else {
otherPortionsSize += i.GetBlobBytes();
std::vector<std::shared_ptr<arrow::RecordBatch>> batchResults;
auto resultSchema = context.SchemaVersions.GetLastSchema();
{
auto resultDataSchema = resultSchema->GetIndexInfo().ArrowSchemaWithSpecials();
NIndexedReader::TMergePartialStream mergeStream(resultSchema->GetIndexInfo().GetReplaceKey(), resultDataSchema, false);
for (auto&& i : portions) {
auto dataSchema = context.SchemaVersions.GetSchema(i.GetPortionInfo().GetMinSnapshot());
auto batch = i.GetBatch(dataSchema, *resultSchema);
batch = resultSchema->NormalizeBatch(*dataSchema, batch);
Y_DEBUG_ABORT_UNLESS(NArrow::IsSortedAndUnique(batch, resultSchema->GetIndexInfo().GetReplaceKey()));
mergeStream.AddSource(batch, nullptr);
}
portionsSize += i.GetBlobBytes();
++portionsCount;
batchResults = mergeStream.DrainAllParts(CheckPoints, resultDataSchema->fields());
}
NChanges::TGeneralCompactionCounters::OnPortionsKind(insertedPortionsSize, compactedPortionsSize, otherPortionsSize);
NChanges::TGeneralCompactionCounters::OnRepackPortions(portionsCount, portionsSize);
Y_ABORT_UNLESS(batchResults.size());
for (auto&& b : batchResults) {
auto portions = MakeAppendedPortions(b, GranuleMeta->GetPathId(), resultSchema->GetSnapshot(), GranuleMeta.get(), context);
Y_ABORT_UNLESS(portions.size());
for (auto& portion : portions) {
AppendedPortions.emplace_back(std::move(portion));
}
}
}

void TGeneralCompactColumnEngineChanges::BuildAppendedPortionsByChunks(TConstructionContext& context) noexcept {
std::vector<TPortionInfoWithBlobs> portions = TPortionInfoWithBlobs::RestorePortions(SwitchedPortions, Blobs);
Blobs.clear();
static const TString portionIdFieldName = "$$__portion_id";
static const TString portionRecordIndexFieldName = "$$__portion_record_idx";
static const std::shared_ptr<arrow::Field> portionIdField = std::make_shared<arrow::Field>(portionIdFieldName, std::make_shared<arrow::UInt16Type>());
Expand Down Expand Up @@ -192,6 +200,34 @@ TConclusionStatus TGeneralCompactColumnEngineChanges::DoConstructBlobs(TConstruc
recordIdx += slice.GetRecordsCount();
}
}
}

TConclusionStatus TGeneralCompactColumnEngineChanges::DoConstructBlobs(TConstructionContext& context) noexcept {
i64 portionsSize = 0;
i64 portionsCount = 0;
i64 insertedPortionsSize = 0;
i64 compactedPortionsSize = 0;
i64 otherPortionsSize = 0;
for (auto&& i : SwitchedPortions) {
if (i.GetMeta().GetProduced() == TPortionMeta::EProduced::INSERTED) {
insertedPortionsSize += i.GetBlobBytes();
} else if (i.GetMeta().GetProduced() == TPortionMeta::EProduced::SPLIT_COMPACTED) {
compactedPortionsSize += i.GetBlobBytes();
} else {
otherPortionsSize += i.GetBlobBytes();
}
portionsSize += i.GetBlobBytes();
++portionsCount;
}
NChanges::TGeneralCompactionCounters::OnPortionsKind(insertedPortionsSize, compactedPortionsSize, otherPortionsSize);
NChanges::TGeneralCompactionCounters::OnRepackPortions(portionsCount, portionsSize);

if (AppDataVerified().ColumnShardConfig.GetUseChunkedMergeOnCompaction()) {
BuildAppendedPortionsByChunks(context);
} else {
BuildAppendedPortionsByFullBatches(context);
}

if (IS_DEBUG_LOG_ENABLED(NKikimrServices::TX_COLUMNSHARD)) {
TStringBuilder sbSwitched;
sbSwitched << "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class TGeneralCompactColumnEngineChanges: public TCompactColumnEngineChanges {
using TBase = TCompactColumnEngineChanges;
virtual void DoWriteIndexComplete(NColumnShard::TColumnShard& self, TWriteIndexCompleteContext& context) override;
std::map<NIndexedReader::TSortableBatchPosition, bool> CheckPoints;
void BuildAppendedPortionsByFullBatches(TConstructionContext& context) noexcept;
void BuildAppendedPortionsByChunks(TConstructionContext& context) noexcept;
protected:
virtual TConclusionStatus DoConstructBlobs(TConstructionContext& context) noexcept override;
virtual TPortionMeta::EProduced GetResultProducedClass() const override {
Expand Down