@@ -23,20 +23,44 @@ class TSchemaVersionNormalizer::TNormalizerResult : public INormalizerChanges {
23
23
}
24
24
};
25
25
26
+ class TTableKey {
27
+ public:
28
+ ui64 PathId;
29
+ ui64 Step;
30
+ ui64 TxId;
31
+ ui64 Version;
32
+
33
+ public:
34
+ TTableKey (ui64 pathId, ui64 step, ui64 txId, ui64 version)
35
+ : PathId(pathId)
36
+ , Step(step)
37
+ , TxId(txId)
38
+ , Version(version)
39
+ {
40
+ }
41
+ };
42
+
26
43
std::vector<TKey> VersionsToRemove;
44
+ std::vector<TTableKey> TableVersionsToRemove;
27
45
28
46
public:
29
- TNormalizerResult (std::vector<TKey>&& versions)
47
+ TNormalizerResult (std::vector<TKey>&& versions, std::vector<TTableKey>&& tableVersions )
30
48
: VersionsToRemove(versions)
49
+ , TableVersionsToRemove(tableVersions)
31
50
{
32
51
}
33
52
34
53
bool ApplyOnExecute (NTabletFlatExecutor::TTransactionContext& txc, const TNormalizationController& /* normController */ ) const override {
35
54
using namespace NColumnShard ;
36
55
NIceDb::TNiceDb db (txc.DB );
37
56
for (auto & key: VersionsToRemove) {
57
+ LOG_S_DEBUG (" Removing schema version in TSchemaVersionNormalizer " << key.Version );
38
58
db.Table <Schema::SchemaPresetVersionInfo>().Key (key.Id , key.Step , key.TxId ).Delete ();
39
59
}
60
+ for (auto & key: TableVersionsToRemove) {
61
+ LOG_S_DEBUG (" Removing table version in TSchemaVersionNormalizer " << key.Version << " pathId " << key.PathId );
62
+ db.Table <Schema::TableVersionInfo>().Key (key.PathId , key.Step , key.TxId ).Delete ();
63
+ }
40
64
return true ;
41
65
}
42
66
@@ -78,6 +102,7 @@ class TSchemaVersionNormalizer::TNormalizerResult : public INormalizerChanges {
78
102
}
79
103
80
104
std::vector<TKey> unusedSchemaIds;
105
+ std::vector<TTableKey> unusedTableSchemaIds;
81
106
std::optional<ui64> maxVersion;
82
107
std::vector<INormalizerChanges::TPtr> changes;
83
108
@@ -107,18 +132,57 @@ class TSchemaVersionNormalizer::TNormalizerResult : public INormalizerChanges {
107
132
}
108
133
}
109
134
135
+ {
136
+ auto rowset = db.Table <Schema::TableVersionInfo>().Select ();
137
+ if (!rowset.IsReady ()) {
138
+ return std::nullopt;
139
+ }
140
+
141
+ while (!rowset.EndOfSet ()) {
142
+ const ui64 pathId = rowset.GetValue <Schema::TableVersionInfo::PathId>();
143
+
144
+ NKikimrTxColumnShard::TTableVersionInfo versionInfo;
145
+ Y_ABORT_UNLESS (versionInfo.ParseFromString (rowset.GetValue <Schema::TableVersionInfo::InfoProto>()));
146
+ if (versionInfo.HasSchema ()) {
147
+ ui64 version = versionInfo.GetSchema ().GetVersion ();
148
+ if (!usedSchemaVersions.contains (version)) {
149
+ unusedTableSchemaIds.emplace_back (pathId, rowset.GetValue <Schema::TableVersionInfo::SinceStep>(), rowset.GetValue <Schema::TableVersionInfo::SinceTxId>(), version);
150
+ }
151
+ }
152
+
153
+ if (!rowset.Next ()) {
154
+ return std::nullopt;
155
+ }
156
+ }
157
+ }
158
+
159
+ std::vector<TTableKey> tablePortion;
110
160
std::vector<TKey> portion;
161
+ tablePortion.reserve (10000 );
111
162
portion.reserve (10000 );
163
+ auto addPortion = [&]() {
164
+ if (portion.size () + tablePortion.size () >= 10000 ) {
165
+ changes.emplace_back (std::make_shared<TNormalizerResult>(std::move (portion), std::move (tablePortion)));
166
+ portion = std::vector<TKey>();
167
+ tablePortion = std::vector<TTableKey>();
168
+ }
169
+ };
112
170
for (const auto & id: unusedSchemaIds) {
113
171
if (!maxVersion.has_value () || (id.Version != *maxVersion)) {
114
172
portion.push_back (id);
115
- if (portion.size () >= 10000 ) {
116
- changes.emplace_back (std::make_shared<TNormalizerResult>(std::move (portion)));
117
- }
173
+ addPortion ();
174
+ }
175
+ }
176
+
177
+ for (const auto & id: unusedTableSchemaIds) {
178
+ if (!maxVersion.has_value () || (id.Version != *maxVersion)) {
179
+ tablePortion.push_back (id);
180
+ addPortion ();
118
181
}
119
182
}
120
- if (portion.size () > 0 ) {
121
- changes.emplace_back (std::make_shared<TNormalizerResult>(std::move (portion)));
183
+
184
+ if (portion.size () + tablePortion.size () > 0 ) {
185
+ changes.emplace_back (std::make_shared<TNormalizerResult>(std::move (portion), std::move (tablePortion)));
122
186
}
123
187
return changes;
124
188
}
0 commit comments