Skip to content

Commit 7d8b0c2

Browse files
authored
optimize cs loading (#29001)
1 parent f38404b commit 7d8b0c2

File tree

11 files changed

+35
-26
lines changed

11 files changed

+35
-26
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NKikimr::NColumnShard {
1212
namespace {
1313

1414
ui64 GetBadPortionSizeLimit() {
15-
return HasAppData() ? AppDataVerified().ColumnShardConfig.GetBadPortionSizeLimit() : 512_KB;
15+
return HasAppData() ? AppData()->ColumnShardConfig.GetBadPortionSizeLimit() : 512_KB;
1616
}
1717

1818
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ TPortionMetaConstructor::TPortionMetaConstructor(const TPortionMeta& meta) {
4040

4141
TPortionMeta TPortionMetaConstructor::Build() {
4242
AFL_VERIFY(FirstAndLastPK);
43-
TMemoryProfileGuard mGuard1("meta_construct/pk");
43+
TMemoryProfileGuard mGuard1("meta_construct/pk", IS_DEBUG_LOG_ENABLED(NKikimrServices::TX_COLUMNSHARD_SCAN_MEMORY));
4444
static TAtomicCounter sumValues = 0;
4545
static TAtomicCounter sumValuesMeta = 0;
4646
static TAtomicCounter countValues = 0;
4747
// FirstAndLastPK->Reallocate();
4848
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("memory_size", FirstAndLastPK->GetMemorySize())("data_size", FirstAndLastPK->GetDataSize())(
4949
"sum", sumValues.Add(FirstAndLastPK->GetMemorySize()))("count", countValues.Inc());
50-
TMemoryProfileGuard mGuard("meta_construct/others");
50+
TMemoryProfileGuard mGuard("meta_construct/others", IS_DEBUG_LOG_ENABLED(NKikimrServices::TX_COLUMNSHARD_SCAN_MEMORY));
5151
AFL_VERIFY(RecordSnapshotMin);
5252
AFL_VERIFY(RecordSnapshotMax);
5353
TPortionMeta result(*FirstAndLastPK, *RecordSnapshotMin, *RecordSnapshotMax);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ std::shared_ptr<TPortionInfo> TPortionInfoConstructor::Build() {
1515
AFL_VERIFY(!Constructed);
1616
Constructed = true;
1717
std::shared_ptr<TPortionInfo> result;
18+
const bool enableGranularMemoryProfile = IS_DEBUG_LOG_ENABLED(NKikimrServices::TX_COLUMNSHARD_SCAN_MEMORY);
19+
TMemoryProfileGuard mGuard0("portion_construct/general", !enableGranularMemoryProfile);
1820
{
19-
TMemoryProfileGuard mGuard0("portion_construct/meta::" + ::ToString(GetType()));
21+
TMemoryProfileGuard mGuard0("portion_construct/meta::" + ::ToString(GetType()), enableGranularMemoryProfile);
2022
auto meta = MetaConstructor.Build();
21-
TMemoryProfileGuard mGuard("portion_construct/main::" + ::ToString(GetType()));
23+
TMemoryProfileGuard mGuard("portion_construct/main::" + ::ToString(GetType()), enableGranularMemoryProfile);
2224
result = BuildPortionImpl(std::move(meta));
2325
}
2426
{
25-
TMemoryProfileGuard mGuard1("portion_construct/others::" + ::ToString(GetType()));
27+
TMemoryProfileGuard mGuard1("portion_construct/others::" + ::ToString(GetType()), enableGranularMemoryProfile);
2628
AFL_VERIFY(PathId);
2729
result->PathId = PathId;
2830
result->PortionId = GetPortionIdVerified();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class TPortionMeta {
117117
, LastPKRow(pk.GetLast().GetContent())
118118
, RecordSnapshotMin(min)
119119
, RecordSnapshotMax(max) {
120-
AFL_VERIFY(IndexKeyStart() <= IndexKeyEnd())("start", IndexKeyStart().DebugString())("end", IndexKeyEnd().DebugString());
120+
AFL_VERIFY_DEBUG(IndexKeyStart() <= IndexKeyEnd())("start", IndexKeyStart().DebugString())("end", IndexKeyEnd().DebugString());
121121
}
122122
TSnapshot RecordSnapshotMin;
123123
TSnapshot RecordSnapshotMax;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ class TPortionInfo {
238238
RuntimeFeatures &= (Max<TRuntimeFeatures>() - (TRuntimeFeatures)feature);
239239
}
240240

241+
bool IsDefaultTier(const TString& defaultTierName) const {
242+
if (GetMeta().GetTierName()) {
243+
return GetMeta().GetTierName() == defaultTierName;
244+
}
245+
return true;
246+
}
247+
241248
TString GetTierNameDef(const TString& defaultTierName) const {
242249
if (GetMeta().GetTierName()) {
243250
return GetMeta().GetTierName();
@@ -327,7 +334,7 @@ class TPortionInfo {
327334
if (HasRemoveSnapshot()) {
328335
return NPortion::INACTIVE;
329336
}
330-
if (GetTierNameDef(NBlobOperations::TGlobal::DefaultStorageId) != NBlobOperations::TGlobal::DefaultStorageId) {
337+
if (!IsDefaultTier(NBlobOperations::TGlobal::DefaultStorageId)) {
331338
return NPortion::EVICTED;
332339
}
333340
return GetPortionType() == EPortionType::Compacted ? NPortion::EProduced::SPLIT_COMPACTED : NPortion::EProduced::INSERTED;

ydb/core/tx/columnshard/engines/storage/granule/granule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ void TGranuleMeta::ResetOptimizer(const std::shared_ptr<NStorageOptimizer::IOpti
188188
NStorageOptimizer::IOptimizerPlannerConstructor::TBuildContext context(PathId, storages, pkSchema);
189189
OptimizerPlanner = constructor->BuildPlanner(context).DetachResult();
190190
AFL_VERIFY(!!OptimizerPlanner);
191-
THashMap<ui64, std::shared_ptr<TPortionInfo>> portions;
191+
std::vector<std::shared_ptr<TPortionInfo>> portions;
192192
for (auto&& i : Portions) {
193193
if (i.second->HasRemoveSnapshot()) {
194194
continue;
195195
}
196-
portions.emplace(i.first, i.second);
196+
portions.emplace_back(i.second);
197197
}
198-
OptimizerPlanner->ModifyPortions(portions, {});
198+
OptimizerPlanner->ModifyPortions(std::move(portions), {});
199199
}
200200
/*
201201

ydb/core/tx/columnshard/engines/storage/optimizer/abstract/optimizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ std::vector<std::shared_ptr<TColumnEngineChanges>> IOptimizerPlanner::GetOptimiz
1010
}
1111

1212
IOptimizerPlanner::TModificationGuard& IOptimizerPlanner::TModificationGuard::AddPortion(const std::shared_ptr<TPortionInfo>& portion) {
13-
AFL_VERIFY(AddPortions.emplace(portion->GetPortionId(), portion).second);
13+
AddPortions.emplace_back(portion);
1414
return*this;
1515
}
1616

1717
IOptimizerPlanner::TModificationGuard& IOptimizerPlanner::TModificationGuard::RemovePortion(const std::shared_ptr<TPortionInfo>& portion) {
18-
AFL_VERIFY(RemovePortions.emplace(portion->GetPortionId(), portion).second);
18+
RemovePortions.emplace_back(portion);
1919
return*this;
2020
}
2121

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class IOptimizerPlanner {
112112

113113
protected:
114114
virtual void DoModifyPortions(
115-
const THashMap<ui64, std::shared_ptr<TPortionInfo>>& add, const THashMap<ui64, std::shared_ptr<TPortionInfo>>& remove) = 0;
115+
const std::vector<std::shared_ptr<TPortionInfo>>& add, const std::vector<std::shared_ptr<TPortionInfo>>& remove) = 0;
116116
virtual std::vector<std::shared_ptr<TColumnEngineChanges>> DoGetOptimizationTasks(
117117
std::shared_ptr<TGranuleMeta> granule, const std::shared_ptr<NDataLocks::TManager>& dataLocksManager) const = 0;
118118
virtual TOptimizationPriority DoGetUsefulMetric() const = 0;
@@ -208,8 +208,8 @@ class IOptimizerPlanner {
208208
class TModificationGuard: TNonCopyable {
209209
private:
210210
IOptimizerPlanner& Owner;
211-
THashMap<ui64, std::shared_ptr<TPortionInfo>> AddPortions;
212-
THashMap<ui64, std::shared_ptr<TPortionInfo>> RemovePortions;
211+
std::vector<std::shared_ptr<TPortionInfo>> AddPortions;
212+
std::vector<std::shared_ptr<TPortionInfo>> RemovePortions;
213213

214214
public:
215215
TModificationGuard& AddPortion(const std::shared_ptr<TPortionInfo>& portion);
@@ -241,7 +241,7 @@ class IOptimizerPlanner {
241241
return DoSerializeToJsonVisual();
242242
}
243243

244-
void ModifyPortions(const THashMap<ui64, std::shared_ptr<TPortionInfo>>& add, const THashMap<ui64, std::shared_ptr<TPortionInfo>>& remove) {
244+
void ModifyPortions(const std::vector<std::shared_ptr<TPortionInfo>>& add, const std::vector<std::shared_ptr<TPortionInfo>>& remove) {
245245
NActors::TLogContextGuard g(NActors::TLogContextBuilder::Build(NKikimrServices::TX_COLUMNSHARD)("path_id", PathId));
246246
LocalPortionsCount.Add(add.size());
247247
LocalPortionsCount.Sub(remove.size());

ydb/core/tx/columnshard/engines/storage/optimizer/lbuckets/planner/optimizer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,9 +1231,9 @@ class TOptimizerPlanner: public IOptimizerPlanner {
12311231
return Buckets.IsLocked(dataLocksManager);
12321232
}
12331233

1234-
virtual void DoModifyPortions(const THashMap<ui64, TPortionInfo::TPtr>& add, const THashMap<ui64, TPortionInfo::TPtr>& remove) override {
1234+
virtual void DoModifyPortions(const std::vector<TPortionInfo::TPtr>& add, const std::vector<TPortionInfo::TPtr>& remove) override {
12351235
const TInstant now = TInstant::Now();
1236-
for (auto&& [_, i] : remove) {
1236+
for (auto&& i : remove) {
12371237
if (i->GetMeta().GetTierName() != IStoragesManager::DefaultStorageId && i->GetMeta().GetTierName() != "") {
12381238
continue;
12391239
}
@@ -1242,7 +1242,7 @@ class TOptimizerPlanner: public IOptimizerPlanner {
12421242
Counters->OptimizersCount->Sub(1);
12431243
}
12441244
}
1245-
for (auto&& [_, i] : add) {
1245+
for (auto&& i : add) {
12461246
if (i->GetMeta().GetTierName() != IStoragesManager::DefaultStorageId && i->GetMeta().GetTierName() != "") {
12471247
continue;
12481248
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ class TOptimizerPlanner: public IOptimizerPlanner {
6767
return false;
6868
}
6969

70-
virtual void DoModifyPortions(const THashMap<ui64, TPortionInfo::TPtr>& add, const THashMap<ui64, TPortionInfo::TPtr>& remove) override {
70+
virtual void DoModifyPortions(const std::vector<TPortionInfo::TPtr>& add, const std::vector<TPortionInfo::TPtr>& remove) override {
7171
std::vector<std::vector<TPortionInfo::TPtr>> removePortionsByLevel;
7272
removePortionsByLevel.resize(Levels.size());
7373
std::vector<std::vector<TPortionInfo::TPtr>> addPortionsByLevels;
7474
addPortionsByLevels.resize(Levels.size());
75-
for (auto&& [_, i] : remove) {
75+
for (auto&& i : remove) {
7676
if (i->GetProduced() == NPortion::EProduced::EVICTED) {
7777
continue;
7878
}
@@ -81,7 +81,7 @@ class TOptimizerPlanner: public IOptimizerPlanner {
8181
removePortionsByLevel[i->GetCompactionLevel()].emplace_back(i);
8282
}
8383
std::vector<TPortionInfo::TPtr> problemPortions;
84-
for (auto&& [_, i] : add) {
84+
for (auto&& i : add) {
8585
if (i->GetProduced() == NPortion::EProduced::EVICTED) {
8686
continue;
8787
}

0 commit comments

Comments
 (0)