Skip to content

Commit 14a54ab

Browse files
fix cleanup volume limits and speed up versions index copy (#12249)
1 parent e0898ef commit 14a54ab

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

ydb/core/tx/columnshard/columnshard_impl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ void TColumnShard::StartIndexTask(std::vector<const NOlap::TCommittedData*>&& da
717717
auto indexChanges = TablesManager.MutablePrimaryIndex().StartInsert(std::move(data));
718718
Y_ABORT_UNLESS(indexChanges);
719719

720-
auto actualIndexInfo = std::make_shared<NOlap::TVersionedIndex>(TablesManager.GetPrimaryIndex()->GetVersionedIndex());
720+
auto actualIndexInfo = TablesManager.GetPrimaryIndex()->GetVersionedIndexReadonlyCopy();
721721
indexChanges->Start(*this);
722722
auto ev = std::make_unique<TEvPrivate::TEvWriteIndex>(actualIndexInfo, indexChanges, Settings.CacheDataAfterIndexing);
723723

@@ -875,7 +875,7 @@ void TColumnShard::StartCompaction(const std::shared_ptr<NPrioritiesQueue::TAllo
875875
compaction->SetQueueGuard(guard);
876876
compaction->Start(*this);
877877

878-
auto actualIndexInfo = std::make_shared<NOlap::TVersionedIndex>(TablesManager.GetPrimaryIndex()->GetVersionedIndex());
878+
auto actualIndexInfo = TablesManager.GetPrimaryIndex()->GetVersionedIndexReadonlyCopy();
879879
auto request = compaction->ExtractDataAccessorsRequest();
880880
const ui64 accessorsMemory = request->PredictAccessorsMemory(TablesManager.GetPrimaryIndex()->GetVersionedIndex().GetLastSchema()) +
881881
indexChanges->CalcMemoryForUsage();
@@ -973,7 +973,7 @@ bool TColumnShard::SetupTtl(const THashMap<ui64, NOlap::TTiering>& pathTtls) {
973973
return false;
974974
}
975975

976-
auto actualIndexInfo = std::make_shared<NOlap::TVersionedIndex>(TablesManager.GetPrimaryIndex()->GetVersionedIndex());
976+
auto actualIndexInfo = TablesManager.GetPrimaryIndex()->GetVersionedIndexReadonlyCopy();
977977
for (auto&& i : indexChanges) {
978978
i->Start(*this);
979979
auto request = i->ExtractDataAccessorsRequest();
@@ -1033,7 +1033,7 @@ void TColumnShard::SetupCleanupPortions() {
10331033
changes->Start(*this);
10341034

10351035
auto request = changes->ExtractDataAccessorsRequest();
1036-
auto actualIndexInfo = std::make_shared<NOlap::TVersionedIndex>(TablesManager.GetPrimaryIndex()->GetVersionedIndex());
1036+
auto actualIndexInfo = TablesManager.GetPrimaryIndex()->GetVersionedIndexReadonlyCopy();
10371037
const ui64 accessorsMemory = request->PredictAccessorsMemory(TablesManager.GetPrimaryIndex()->GetVersionedIndex().GetLastSchema());
10381038
const auto subscriber = std::make_shared<TCleanupPortionsDataAccessorsSubscriber>(SelfId(), changes, actualIndexInfo);
10391039

@@ -1064,7 +1064,7 @@ void TColumnShard::SetupCleanupTables() {
10641064
}
10651065

10661066
ACFL_DEBUG("background", "cleanup")("changes_info", changes->DebugString());
1067-
auto actualIndexInfo = std::make_shared<NOlap::TVersionedIndex>(TablesManager.GetPrimaryIndex()->GetVersionedIndex());
1067+
auto actualIndexInfo = TablesManager.GetPrimaryIndex()->GetVersionedIndexReadonlyCopy();
10681068
auto ev = std::make_unique<TEvPrivate::TEvWriteIndex>(actualIndexInfo, changes, false);
10691069
ev->SetPutStatus(NKikimrProto::OK); // No new blobs to write
10701070

ydb/core/tx/columnshard/engines/column_engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ class IColumnEngine {
329329

330330
virtual std::vector<TCSMetadataRequest> CollectMetadataRequests() const = 0;
331331
virtual const TVersionedIndex& GetVersionedIndex() const = 0;
332+
virtual const std::shared_ptr<TVersionedIndex>& GetVersionedIndexReadonlyCopy() = 0;
332333
virtual std::shared_ptr<TVersionedIndex> CopyVersionedIndexPtr() const = 0;
333334
virtual const std::shared_ptr<arrow::Schema>& GetReplaceKey() const;
334335

ydb/core/tx/columnshard/engines/column_engine_logs.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ std::shared_ptr<TCleanupPortionsColumnEngineChanges> TColumnEngineForLogs::Start
333333
ui32 skipLocked = 0;
334334
ui32 portionsFromDrop = 0;
335335
bool limitExceeded = false;
336-
const ui32 maxChunksCount = 100000;
336+
const ui32 maxChunksCount = 500000;
337337
const ui32 maxPortionsCount = 1000;
338338
for (ui64 pathId : pathsToDrop) {
339339
auto g = GranulesStorage->GetGranuleOptional(pathId);
@@ -401,7 +401,8 @@ std::shared_ptr<TCleanupPortionsColumnEngineChanges> TColumnEngineForLogs::Start
401401
}
402402
}
403403
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "StartCleanup")("portions_count", CleanupPortions.size())(
404-
"portions_prepared", changes->GetPortionsToDrop().size())("drop", portionsFromDrop)("skip", skipLocked);
404+
"portions_prepared", changes->GetPortionsToDrop().size())("drop", portionsFromDrop)("skip", skipLocked)("portions_counter", portionsCount)(
405+
"chunks", chunksCount)("limit", limitExceeded)("max_portions", maxPortionsCount)("max_chunks", maxChunksCount);
405406

406407
if (changes->GetPortionsToDrop().empty()) {
407408
return nullptr;

ydb/core/tx/columnshard/engines/column_engine_logs.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,17 @@ class TColumnEngineForLogs: public IColumnEngine {
6363

6464
std::shared_ptr<NActualizer::TController> ActualizationController;
6565
std::shared_ptr<TSchemaObjectsCache> SchemaObjectsCache = std::make_shared<TSchemaObjectsCache>();
66+
TVersionedIndex VersionedIndex;
67+
std::shared_ptr<TVersionedIndex> VersionedIndexCopy;
6668

6769
public:
70+
virtual const std::shared_ptr<TVersionedIndex>& GetVersionedIndexReadonlyCopy() override {
71+
if (!VersionedIndexCopy || !VersionedIndexCopy->IsEqualTo(VersionedIndex)) {
72+
VersionedIndexCopy = std::make_shared<TVersionedIndex>(VersionedIndex);
73+
}
74+
return VersionedIndexCopy;
75+
}
76+
6877
const std::shared_ptr<NActualizer::TController>& GetActualizationController() const {
6978
return ActualizationController;
7079
}
@@ -224,7 +233,6 @@ class TColumnEngineForLogs: public IColumnEngine {
224233
void AppendPortion(const TPortionDataAccessor& portionInfo, const bool addAsAccessor = true);
225234

226235
private:
227-
TVersionedIndex VersionedIndex;
228236
ui64 TabletId;
229237
TMap<ui64, std::shared_ptr<TColumnEngineStats>> PathStats; // per path_id stats sorted by path_id
230238
std::map<TInstant, std::vector<TPortionInfo::TConstPtr>> CleanupPortions;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ui64 TPortionInfo::GetMetadataMemorySize() const {
5151
}
5252

5353
ui64 TPortionInfo::GetApproxChunksCount(const ui32 schemaColumnsCount) const {
54-
return schemaColumnsCount * 256 * (GetRecordsCount() / 10000 + 1);
54+
return schemaColumnsCount * (GetRecordsCount() / 10000 + 1);
5555
}
5656

5757
void TPortionInfo::SerializeToProto(NKikimrColumnShardDataSharingProto::TPortionInfo& proto) const {

ydb/core/tx/columnshard/engines/scheme/versions/versioned_index.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class TVersionedIndex {
3333
ISnapshotSchema::TPtr SchemeForActualization;
3434

3535
public:
36+
bool IsEqualTo(const TVersionedIndex& vIndex) {
37+
return LastSchemaVersion == vIndex.LastSchemaVersion && SnapshotByVersion.size() == vIndex.SnapshotByVersion.size() &&
38+
ShardingInfo.size() == vIndex.ShardingInfo.size() && SchemeVersionForActualization == vIndex.SchemeVersionForActualization;
39+
}
40+
3641
ISnapshotSchema::TPtr GetLastCriticalSchema() const {
3742
return SchemeForActualization;
3843
}

0 commit comments

Comments
 (0)