aboutsummaryrefslogtreecommitdiffstats
path: root/ydb/core/base/localdb.h
blob: 8679cb286fcf674c1b7430956d4fd3aaf8b48f88 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#pragma once
#include "defs.h"
#include <util/generic/map.h>
#include <util/generic/hash_set.h>
#include <util/generic/list.h>
#include <ydb/core/protos/flat_scheme_op.pb.h>
#include <ydb/core/util/yverify_stream.h>
#include <google/protobuf/util/message_differencer.h>

namespace NKikimr {
namespace NLocalDb {

struct TCompactionPolicy : public TThrRefBase {
    struct TBackgroundPolicy {
        ui32 Threshold;
        ui32 PriorityBase;
        double TimeFactor;
        TString ResourceBrokerTask;

        TBackgroundPolicy();
        TBackgroundPolicy(ui32 threshold, ui32 priorityBase, double timeFactor, const TString &resourceBrokerTask);
        TBackgroundPolicy(const NKikimrSchemeOp::TCompactionPolicy::TBackgroundPolicy &policyPb);

        void Serialize(NKikimrSchemeOp::TCompactionPolicy::TBackgroundPolicy& policyPb) const;

        bool operator ==(const TBackgroundPolicy& p) const {
            return (Threshold == p.Threshold
                    && PriorityBase == p.PriorityBase
                    && TimeFactor == p.TimeFactor
                    && ResourceBrokerTask == p.ResourceBrokerTask);
        }
    };

    struct TGenerationPolicy {
        ui64 SizeToCompact;
        ui32 CountToCompact;
        ui32 ForceCountToCompact;
        ui64 ForceSizeToCompact;
        ui32 CompactionBrokerQueue; // TODO: remove deprecated field
        TString ResourceBrokerTask;
        bool KeepInCache;
        TBackgroundPolicy BackgroundCompactionPolicy;
        ui32 ExtraCompactionPercent;
        ui32 ExtraCompactionExpPercent;
        ui64 ExtraCompactionMinSize;
        ui64 ExtraCompactionExpMaxSize;
        ui64 UpliftPartSize;

        TGenerationPolicy(ui64 sizeToCompact, ui32 countToCompact, ui32 forceCountToCompact,
                          ui64 forceSizeToCompact, const TString &resourceBrokerTask,
                          bool keepInCache,
                          const TBackgroundPolicy &backgroundCompactionPolicy = TBackgroundPolicy());
        TGenerationPolicy(const NKikimrSchemeOp::TCompactionPolicy::TGenerationPolicy &policyPb);

        void Serialize(NKikimrSchemeOp::TCompactionPolicy::TGenerationPolicy& policyPb) const;

        bool operator ==(const TGenerationPolicy& p) const {
            return SizeToCompact == p.SizeToCompact
                    && CountToCompact == p.CountToCompact
                    && ForceCountToCompact == p.ForceCountToCompact
                    && ForceSizeToCompact == p.ForceSizeToCompact
                    && CompactionBrokerQueue == p.CompactionBrokerQueue
                    && ResourceBrokerTask == p.ResourceBrokerTask
                    && KeepInCache == p.KeepInCache
                    && BackgroundCompactionPolicy == p.BackgroundCompactionPolicy
                    && ExtraCompactionPercent == p.ExtraCompactionPercent
                    && ExtraCompactionExpPercent == p.ExtraCompactionExpPercent
                    && ExtraCompactionMinSize == p.ExtraCompactionMinSize
                    && ExtraCompactionExpMaxSize == p.ExtraCompactionExpMaxSize
                    && UpliftPartSize == p.UpliftPartSize;
        }
    };

    ui64 InMemSizeToSnapshot;
    ui32 InMemStepsToSnapshot;
    ui32 InMemForceStepsToSnapshot;
    ui64 InMemForceSizeToSnapshot;
    ui32 InMemCompactionBrokerQueue; // TODO: remove deprecated field
    TString InMemResourceBrokerTask;
    ui64 ReadAheadHiThreshold;
    ui64 ReadAheadLoThreshold;
    ui32 MinDataPageSize;
    ui32 SnapshotCompactionBrokerQueue; // TODO: remove deprecated field
    TString SnapshotResourceBrokerTask;
    ui32 BackupCompactionBrokerQueue; // TODO: remove deprecated field
    TString BackupResourceBrokerTask;
    ui32 DefaultTaskPriority;
    TBackgroundPolicy BackgroundSnapshotPolicy;
    ui64 LogOverheadSizeToSnapshot;
    ui32 LogOverheadCountToSnapshot;
    ui32 DroppedRowsPercentToCompact;
    NKikimrSchemeOp::ECompactionStrategy CompactionStrategy;
    NKikimrSchemeOp::TCompactionPolicy::TShardPolicy ShardPolicy;
    bool KeepEraseMarkers;

    TVector<TGenerationPolicy> Generations;

    TCompactionPolicy();
    explicit TCompactionPolicy(const NKikimrSchemeOp::TCompactionPolicy& policyPb);

    void Serialize(NKikimrSchemeOp::TCompactionPolicy& policyPb) const;

    bool operator ==(const TCompactionPolicy& p) const {
        return InMemSizeToSnapshot == p.InMemSizeToSnapshot
                && InMemStepsToSnapshot == p.InMemStepsToSnapshot
                && InMemForceStepsToSnapshot == p.InMemForceStepsToSnapshot
                && InMemForceSizeToSnapshot == p.InMemForceSizeToSnapshot
                && InMemCompactionBrokerQueue == p.InMemCompactionBrokerQueue
                && InMemResourceBrokerTask == p.InMemResourceBrokerTask
                && ReadAheadHiThreshold == p.ReadAheadHiThreshold
                && ReadAheadLoThreshold == p.ReadAheadLoThreshold
                && MinDataPageSize == p.MinDataPageSize
                && Generations == p.Generations
                && SnapshotCompactionBrokerQueue == p.SnapshotCompactionBrokerQueue
                && SnapshotResourceBrokerTask == p.SnapshotResourceBrokerTask
                && BackupCompactionBrokerQueue == p.BackupCompactionBrokerQueue
                && BackupResourceBrokerTask == p.BackupResourceBrokerTask
                && DefaultTaskPriority == p.DefaultTaskPriority
                && BackgroundSnapshotPolicy == p.BackgroundSnapshotPolicy
                && LogOverheadSizeToSnapshot == p.LogOverheadSizeToSnapshot
                && LogOverheadCountToSnapshot == p.LogOverheadCountToSnapshot
                && DroppedRowsPercentToCompact == p.DroppedRowsPercentToCompact
                && CompactionStrategy == p.CompactionStrategy
                && KeepEraseMarkers == p.KeepEraseMarkers
                && ::google::protobuf::util::MessageDifferencer::Equals(ShardPolicy, p.ShardPolicy);
    }
};

typedef TIntrusivePtr<TCompactionPolicy> TCompactionPolicyPtr;

TCompactionPolicyPtr CreateDefaultTablePolicy();
TCompactionPolicyPtr CreateDefaultUserTablePolicy();

bool ValidateCompactionPolicyChange(const TCompactionPolicy& oldPolicy, const TCompactionPolicy& newPolicy, TString& err);

// Get Resource Broker task type name by Compaction Broker queue ID.
TString LegacyQueueIdToTaskName(ui32 id);

// Check if Resource Broker task name is for a legacy queue ID.
bool IsLegacyQueueIdTaskName(const TString& taskName);

extern const TString DefaultQueueName;
extern const TString UnknownTaskName;
extern const TString TransactionTaskName;
extern const TString ScanTaskName;
extern const TString BackgroundCompactionTaskName;
extern const TString KqpResourceManagerTaskName;
extern const TString KqpResourceManagerQueue;
extern const TString LegacyQueueIdTaskNamePrefix;

}}