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

KIKIMR-20380: min max portion keys validation #822

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
2 changes: 1 addition & 1 deletion ydb/core/formats/arrow/special_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bool TSpecialKeys::DeserializeFromString(const TString& data) {
return !!Data;
}

std::optional<NKikimr::NArrow::TReplaceKey> TSpecialKeys::GetKeyByIndex(const ui32 position, const std::shared_ptr<arrow::Schema>& schema) const {
NKikimr::NArrow::TReplaceKey TSpecialKeys::GetKeyByIndex(const ui32 position, const std::shared_ptr<arrow::Schema>& schema) const {
Y_ABORT_UNLESS(position < Data->num_rows());
if (schema) {
return NArrow::TReplaceKey::FromBatch(Data, schema, position);
Expand Down
10 changes: 5 additions & 5 deletions ydb/core/formats/arrow/special_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TSpecialKeys {

bool DeserializeFromString(const TString& data);

std::optional<TReplaceKey> GetKeyByIndex(const ui32 position, const std::shared_ptr<arrow::Schema>& schema) const;
TReplaceKey GetKeyByIndex(const ui32 position, const std::shared_ptr<arrow::Schema>& schema) const;

TSpecialKeys() = default;
TSpecialKeys(std::shared_ptr<arrow::RecordBatch> data)
Expand Down Expand Up @@ -45,10 +45,10 @@ class TFirstLastSpecialKeys: public TSpecialKeys {

std::shared_ptr<TFirstLastSpecialKeys> BuildAccordingToSchemaVerified(const std::shared_ptr<arrow::Schema>& schema) const;

std::optional<TReplaceKey> GetFirst(const std::shared_ptr<arrow::Schema>& schema = nullptr) const {
TReplaceKey GetFirst(const std::shared_ptr<arrow::Schema>& schema = nullptr) const {
return GetKeyByIndex(0, schema);
}
std::optional<TReplaceKey> GetLast(const std::shared_ptr<arrow::Schema>& schema = nullptr) const {
TReplaceKey GetLast(const std::shared_ptr<arrow::Schema>& schema = nullptr) const {
return GetKeyByIndex(Data->num_rows() - 1, schema);
}

Expand All @@ -75,10 +75,10 @@ class TMinMaxSpecialKeys: public TSpecialKeys {
return Data;
}

std::optional<TReplaceKey> GetMin(const std::shared_ptr<arrow::Schema>& schema = nullptr) const {
TReplaceKey GetMin(const std::shared_ptr<arrow::Schema>& schema = nullptr) const {
return GetKeyByIndex(0, schema);
}
std::optional<TReplaceKey> GetMax(const std::shared_ptr<arrow::Schema>& schema = nullptr) const {
TReplaceKey GetMax(const std::shared_ptr<arrow::Schema>& schema = nullptr) const {
return GetKeyByIndex(Data->num_rows() - 1, schema);
}

Expand Down
15 changes: 3 additions & 12 deletions ydb/core/tx/columnshard/engines/changes/compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ bool TCompactColumnEngineChanges::DoApplyChanges(TColumnEngineForLogs& self, TAp
return TBase::DoApplyChanges(self, context);
}

ui32 TCompactColumnEngineChanges::NumSplitInto(const ui32 srcRows) const {
Y_ABORT_UNLESS(srcRows > 1);
const ui64 totalBytes = TotalBlobsSize();
const ui32 numSplitInto = (totalBytes / Limits.GranuleSizeForOverloadPrevent) + 1;
return std::max<ui32>(2, numSplitInto);
}

void TCompactColumnEngineChanges::DoWriteIndex(NColumnShard::TColumnShard& self, TWriteIndexContext& context) {
TBase::DoWriteIndex(self, context);
}
Expand Down Expand Up @@ -75,11 +68,9 @@ void TCompactColumnEngineChanges::DoOnFinish(NColumnShard::TColumnShard& self, T
NeedGranuleStatusProvide = false;
}

TCompactColumnEngineChanges::TCompactColumnEngineChanges(const TCompactionLimits& limits, std::shared_ptr<TGranuleMeta> granule, const std::vector<std::shared_ptr<TPortionInfo>>& portions, const TSaverContext& saverContext)
: TBase(limits.GetSplitSettings(), saverContext, StaticTypeName())
, Limits(limits)
, GranuleMeta(granule)
{
TCompactColumnEngineChanges::TCompactColumnEngineChanges(const TSplitSettings& splitSettings, std::shared_ptr<TGranuleMeta> granule, const std::vector<std::shared_ptr<TPortionInfo>>& portions, const TSaverContext& saverContext)
: TBase(splitSettings, saverContext, StaticTypeName())
, GranuleMeta(granule) {
Y_ABORT_UNLESS(GranuleMeta);

SwitchedPortions.reserve(portions.size());
Expand Down
5 changes: 1 addition & 4 deletions ydb/core/tx/columnshard/engines/changes/compaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class TCompactColumnEngineChanges: public TChangesWithAppend {
using TBase = TChangesWithAppend;
bool NeedGranuleStatusProvide = false;
protected:
const TCompactionLimits Limits;
std::shared_ptr<TGranuleMeta> GranuleMeta;

virtual void DoStart(NColumnShard::TColumnShard& self) override;
Expand All @@ -31,14 +30,12 @@ class TCompactColumnEngineChanges: public TChangesWithAppend {

virtual THashSet<TPortionAddress> GetTouchedPortions() const override;

TCompactColumnEngineChanges(const TCompactionLimits& limits, std::shared_ptr<TGranuleMeta> granule, const std::vector<std::shared_ptr<TPortionInfo>>& portions, const TSaverContext& saverContext);
TCompactColumnEngineChanges(const TSplitSettings& splitSettings, std::shared_ptr<TGranuleMeta> granule, const std::vector<std::shared_ptr<TPortionInfo>>& portions, const TSaverContext& saverContext);
~TCompactColumnEngineChanges();

static TString StaticTypeName() {
return "CS::GENERAL";
}

ui32 NumSplitInto(const ui32 srcRows) const;
};

}
16 changes: 8 additions & 8 deletions ydb/core/tx/columnshard/engines/changes/general_compaction.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@

#include "general_compaction.h"
#include "compaction/column_portion_chunk.h"

#include "compaction/column_cursor.h"
#include "compaction/column_portion_chunk.h"
#include "compaction/merge_context.h"
#include "compaction/merged_column.h"
#include "counters/general.h"

#include <ydb/core/formats/arrow/simple_builder/array.h>
#include <ydb/core/formats/arrow/simple_builder/filler.h>
#include <ydb/core/tx/columnshard/columnshard_impl.h>
#include <ydb/core/tx/columnshard/engines/portions/with_blobs.h>
#include <ydb/core/tx/columnshard/splitter/batch_slice.h>
#include <ydb/core/tx/columnshard/splitter/rb_splitter.h>
#include <ydb/core/formats/arrow/simple_builder/array.h>
#include <ydb/core/formats/arrow/simple_builder/filler.h>
#include "../reader/read_filter_merger.h"

namespace NKikimr::NOlap::NCompaction {

Expand Down Expand Up @@ -111,8 +112,8 @@ TConclusionStatus TGeneralCompactColumnEngineChanges::DoConstructBlobs(TConstruc
std::map<std::string, std::vector<TColumnPortionResult>> columnChunks;
ui32 batchIdx = 0;
for (auto&& batchResult : batchResults) {
const ui32 portionRecordsCountLimit = batchResult->num_rows() / (batchResult->num_rows() / 10000 + 1) + 1;
TColumnMergeContext context(columnId, resultSchema, portionRecordsCountLimit, 50 * 1024 * 1024, columnInfo, SaverContext);
const ui32 portionRecordsCountLimit = batchResult->num_rows() / (batchResult->num_rows() / GetSplitSettings().GetExpectedRecordsCountOnPage() + 1) + 1;
TColumnMergeContext context(columnId, resultSchema, portionRecordsCountLimit, GetSplitSettings().GetExpectedUnpackColumnChunkRawSize(), columnInfo, SaverContext);
TMergedColumn mColumn(context);

auto columnPortionIdx = batchResult->GetColumnByName(portionIdFieldName);
Expand Down Expand Up @@ -176,8 +177,7 @@ TConclusionStatus TGeneralCompactColumnEngineChanges::DoConstructBlobs(TConstruc
}
batchSlices.emplace_back(portionColumns, schemaDetails, context.Counters.SplitterCounters, GetSplitSettings());
}

TSimilarSlicer slicer(4 * 1024 * 1024);
TSimilarSlicer slicer(GetSplitSettings().GetExpectedPortionSize());
auto packs = slicer.Split(batchSlices);

ui32 recordIdx = 0;
Expand Down
3 changes: 2 additions & 1 deletion ydb/core/tx/columnshard/engines/changes/with_appended.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ namespace NKikimr::NOlap {
class TChangesWithAppend: public TColumnEngineChanges {
private:
using TBase = TColumnEngineChanges;
TSplitSettings SplitSettings;

protected:
TSplitSettings SplitSettings;
TSaverContext SaverContext;
virtual void DoDebugString(TStringOutput& out) const override;
virtual void DoCompile(TFinalizationContext& context) override;
Expand Down
10 changes: 9 additions & 1 deletion ydb/core/tx/columnshard/engines/portions/meta.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "meta.h"
#include <ydb/core/tx/columnshard/engines/scheme/index_info.h>

#include <ydb/core/formats/arrow/arrow_filter.h>
#include <ydb/core/tx/columnshard/engines/scheme/index_info.h>

#include <ydb/library/actors/core/log.h>

namespace NKikimr::NOlap {
Expand All @@ -10,6 +12,9 @@ void TPortionMeta::FillBatchInfo(const NArrow::TFirstLastSpecialKeys& primaryKey
ReplaceKeyEdges = primaryKeys.BuildAccordingToSchemaVerified(indexInfo.GetReplaceKey());
IndexKeyStart = ReplaceKeyEdges->GetFirst();
IndexKeyEnd = ReplaceKeyEdges->GetLast();
AFL_VERIFY(IndexKeyStart);
AFL_VERIFY(IndexKeyEnd);
AFL_VERIFY(*IndexKeyStart <= *IndexKeyEnd)("start", IndexKeyStart->DebugString())("end", IndexKeyEnd->DebugString());
}

{
Expand Down Expand Up @@ -49,6 +54,9 @@ bool TPortionMeta::DeserializeFromProto(const NKikimrTxColumnShard::TIndexPortio
ReplaceKeyEdges = std::make_shared<NArrow::TFirstLastSpecialKeys>(portionMeta.GetPrimaryKeyBorders(), indexInfo.GetReplaceKey());
IndexKeyStart = ReplaceKeyEdges->GetFirst();
IndexKeyEnd = ReplaceKeyEdges->GetLast();
AFL_VERIFY(IndexKeyStart);
AFL_VERIFY(IndexKeyEnd);
AFL_VERIFY (*IndexKeyStart <= *IndexKeyEnd)("start", IndexKeyStart->DebugString())("end", IndexKeyEnd->DebugString());
}

if (portionMeta.HasRecordSnapshotMin()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ std::shared_ptr<NKikimr::NOlap::TColumnEngineChanges> TBlobsWithSizeLimit::Build
if (currentSum > SizeLimitToMerge || PortionsCount > CountLimitToMerge) {
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "take_granule_with_small")("portions", portions.size())("current_sum", currentSum);
TSaverContext saverContext(StoragesManager->GetOperator(tierName.value_or(IStoragesManager::DefaultStorageId)), StoragesManager);
return std::make_shared<NCompaction::TGeneralCompactColumnEngineChanges>(limits, granule, portions, saverContext);
return std::make_shared<NCompaction::TGeneralCompactColumnEngineChanges>(limits.GetSplitSettings(), granule, portions, saverContext);
} else {
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "take_granule_with_small")("skip", "not_enough_data");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::shared_ptr<TColumnEngineChanges> TIntervalsOptimizerPlanner::DoGetOptimizat
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "take_granule")("features", features.DebugJson().GetStringRobust())("count", features.GetPortionsCount());

TSaverContext saverContext(StoragesManager->GetOperator(tierName.value_or(IStoragesManager::DefaultStorageId)), StoragesManager);
return std::make_shared<NCompaction::TGeneralCompactColumnEngineChanges>(limits, granule, portions, saverContext);
return std::make_shared<NCompaction::TGeneralCompactColumnEngineChanges>(limits.GetSplitSettings(), granule, portions, saverContext);
}

void TIntervalsOptimizerPlanner::RemovePortion(const std::shared_ptr<TPortionInfo>& info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ class TPortionsBucket: public TMoveOnly {
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("stop_instant", stopInstant.value_or(TInstant::Zero()))("size", size)("next", NextBorder ? NextBorder->DebugString() : "")
("count", portions.size())("info", Others.DebugString())("event", "start_optimization")("stop_point", stopPoint ? stopPoint->DebugString() : "");
TSaverContext saverContext(storagesManager->GetOperator(IStoragesManager::DefaultStorageId), storagesManager);
auto result = std::make_shared<NCompaction::TGeneralCompactColumnEngineChanges>(limits, granule, portions, saverContext);
auto result = std::make_shared<NCompaction::TGeneralCompactColumnEngineChanges>(limits.GetSplitSettings(), granule, portions, saverContext);
if (MainPortion) {
NIndexedReader::TSortableBatchPosition pos(MainPortion->IndexKeyStart().ToBatch(primaryKeysSchema), 0, primaryKeysSchema->field_names(), {}, false);
result->AddCheckPoint(pos, true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class TLevel {
positions.emplace_back(*position);
}
TSaverContext saverContext(StoragesManager->GetOperator(IStoragesManager::DefaultStorageId), StoragesManager);
auto result = std::make_shared<NCompaction::TGeneralCompactColumnEngineChanges>(CompactionLimits, granule, portions, saverContext);
auto result = std::make_shared<NCompaction::TGeneralCompactColumnEngineChanges>(CompactionLimits.GetSplitSettings(), granule, portions, saverContext);
for (auto&& i : positions) {
result->AddCheckPoint(i);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "normalizer.h"

namespace NKikimr::NOlap {

}
15 changes: 14 additions & 1 deletion ydb/core/tx/columnshard/splitter/settings.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <ydb/library/accessor/accessor.h>

#include <util/system/types.h>

namespace NKikimr::NOlap {
Expand All @@ -9,11 +11,22 @@ class TSplitSettings {
static const inline i64 DefaultMaxBlobSize = 8 * 1024 * 1024;
static const inline i64 DefaultMinBlobSize = 4 * 1024 * 1024;
static const inline i64 DefaultMinRecordsCount = 10000;
static const inline i64 DefaultMaxPortionSize = 4 * DefaultMaxBlobSize;
static const inline i64 DefaultMaxPortionSize = 6 * DefaultMaxBlobSize;
YDB_ACCESSOR(i64, MaxBlobSize, DefaultMaxBlobSize);
YDB_ACCESSOR(i64, MinBlobSize, DefaultMinBlobSize);
YDB_ACCESSOR(i64, MinRecordsCount, DefaultMinRecordsCount);
YDB_ACCESSOR(i64, MaxPortionSize, DefaultMaxPortionSize);
public:
ui64 GetExpectedRecordsCountOnPage() const {
return 1.5 * MinRecordsCount;
}

ui64 GetExpectedUnpackColumnChunkRawSize() const {
return (ui64)50 * 1024 * 1024;
}

ui64 GetExpectedPortionSize() const {
return MaxPortionSize;
}
};
}
8 changes: 4 additions & 4 deletions ydb/core/tx/columnshard/splitter/simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ class TSaverSplittedChunk {
std::shared_ptr<arrow::Scalar> GetFirstScalar() const;
std::shared_ptr<arrow::Scalar> GetLastScalar() const;

TSaverSplittedChunk(std::shared_ptr<arrow::RecordBatch> batch, TString&& serializedChunk)
TSaverSplittedChunk(const std::shared_ptr<arrow::RecordBatch>& batch, TString&& serializedChunk)
: SlicedBatch(batch)
, SerializedChunk(std::move(serializedChunk))
{
, SerializedChunk(std::move(serializedChunk)) {
Y_ABORT_UNLESS(SlicedBatch);
Y_ABORT_UNLESS(SlicedBatch->num_columns() == 1);
Y_ABORT_UNLESS(SlicedBatch->num_rows());

}

bool IsCompatibleColumn(const std::shared_ptr<arrow::Field>& f) const {
if (!SlicedBatch) {
return false;
}
if (SlicedBatch->num_columns() != 1) {
AFL_ERROR(NKikimrServices::TX_COLUMNSHARD)("event", "unexpected columns count")("expectation", 1)("actual", SlicedBatch->num_columns());
return false;
}
if (!SlicedBatch->schema()->fields().front()->Equals(f)) {
AFL_ERROR(NKikimrServices::TX_COLUMNSHARD)("event", "unexpected column type")("expectation", f->ToString())("actual", SlicedBatch->schema()->fields().front()->ToString());
return false;
}
return true;
Expand Down