Skip to content

Commit 0ad6e12

Browse files
ivanmorozov333ivanmorozov333
andauthored
compaction priorities weight (#21675)
Co-authored-by: ivanmorozov333 <[email protected]>
1 parent 9bbe17e commit 0ad6e12

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ydb/core/protos/flat_scheme_op.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ message TCompactionSelectorConstructorContainer {
577577
message TCompactionPlannerConstructorContainer {
578578
optional string ClassName = 1;
579579
optional uint64 NodePortionsCountLimit = 2;
580+
optional double WeightKff = 3 [default = 1.0];
580581

581582
message TLOptimizer {
582583

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class TOptimizationPriority {
3636
}
3737

3838
public:
39+
void Mul(const ui32 kff) {
40+
InternalLevelWeight *= kff;
41+
}
42+
3943
ui64 GetGeneralPriority() const {
4044
return ((ui64)Level << 56) + InternalLevelWeight;
4145
}
@@ -88,13 +92,15 @@ using TPortionInfoForCompaction = NPortion::TPortionInfoForCompaction;
8892

8993
class IOptimizerPlanner {
9094
private:
95+
friend class IOptimizerPlannerConstructor;
9196
const TInternalPathId PathId;
9297
YDB_READONLY(TInstant, ActualizationInstant, TInstant::Zero());
9398

9499
virtual bool DoIsOverloaded() const {
95100
return false;
96101
}
97102
const ui32 NodePortionsCountLimit = 0;
103+
double WeightKff = 1;
98104
static inline TAtomicCounter NodePortionsCounter = 0;
99105
TPositiveControlInteger LocalPortionsCount;
100106
std::shared_ptr<TCounters> Counters = std::make_shared<TCounters>();
@@ -191,7 +197,9 @@ class IOptimizerPlanner {
191197
std::shared_ptr<TColumnEngineChanges> GetOptimizationTask(
192198
std::shared_ptr<TGranuleMeta> granule, const std::shared_ptr<NDataLocks::TManager>& dataLocksManager) const;
193199
TOptimizationPriority GetUsefulMetric() const {
194-
return DoGetUsefulMetric();
200+
auto result = DoGetUsefulMetric();
201+
result.Mul(WeightKff);
202+
return result;
195203
}
196204
void Actualize(const TInstant currentInstant) {
197205
ActualizationInstant = currentInstant;
@@ -228,6 +236,7 @@ class IOptimizerPlannerConstructor {
228236

229237
private:
230238
ui32 NodePortionsCountLimit = 1000000;
239+
double WeightKff = 1.0;
231240

232241
virtual TConclusion<std::shared_ptr<IOptimizerPlanner>> DoBuildPlanner(const TBuildContext& context) const = 0;
233242
virtual void DoSerializeToProto(TProto& proto) const = 0;
@@ -263,16 +272,29 @@ class IOptimizerPlannerConstructor {
263272
}
264273
NodePortionsCountLimit = jsonValue.GetUInteger();
265274
}
275+
if (jsonInfo.Has("weight_kff")) {
276+
const auto& jsonValue = jsonInfo["weight_kff"];
277+
if (!jsonValue.IsDouble()) {
278+
return TConclusionStatus::Fail("incorrect weight_kff value have to be double");
279+
}
280+
WeightKff = jsonValue.GetDouble();
281+
}
266282
return DoDeserializeFromJson(jsonInfo);
267283
}
268284

269285
TConclusion<std::shared_ptr<IOptimizerPlanner>> BuildPlanner(const TBuildContext& context) const {
270-
return DoBuildPlanner(context);
286+
auto result = DoBuildPlanner(context);
287+
if (result.IsFail()) {
288+
return result;
289+
}
290+
(*result)->WeightKff = WeightKff;
291+
return result;
271292
}
272293

273294
virtual TString GetClassName() const = 0;
274295
void SerializeToProto(TProto& proto) const {
275296
proto.SetNodePortionsCountLimit(NodePortionsCountLimit);
297+
proto.SetWeightKff(WeightKff);
276298
DoSerializeToProto(proto);
277299
}
278300

@@ -292,6 +314,9 @@ class IOptimizerPlannerConstructor {
292314
if (proto.HasNodePortionsCountLimit()) {
293315
NodePortionsCountLimit = proto.GetNodePortionsCountLimit();
294316
}
317+
if (proto.HasWeightKff()) {
318+
WeightKff = proto.GetWeightKff();
319+
}
295320
return DoDeserializeFromProto(proto);
296321
}
297322
};

0 commit comments

Comments
 (0)