@@ -112,7 +112,6 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
112
112
return false ;
113
113
}
114
114
115
- THashMap<ui64, NOlap::TSnapshot> lastVersion;
116
115
while (!rowset.EndOfSet ()) {
117
116
const ui64 pathId = rowset.GetValue <Schema::TableVersionInfo::PathId>();
118
117
Y_ABORT_UNLESS (Tables.contains (pathId));
@@ -126,22 +125,8 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
126
125
AFL_VERIFY (preset);
127
126
AFL_VERIFY (preset->Id == versionInfo.GetSchemaPresetId ())(" preset" , preset->Id )(" table" , versionInfo.GetSchemaPresetId ());
128
127
129
- if (!table.IsDropped () && versionInfo.HasTtlSettings ()) {
130
- auto & ttlSettings = versionInfo.GetTtlSettings ();
131
- auto vIt = lastVersion.find (pathId);
132
- if (vIt == lastVersion.end ()) {
133
- vIt = lastVersion.emplace (pathId, version).first ;
134
- }
135
- if (vIt->second <= version) {
136
- if (ttlSettings.HasEnabled ()) {
137
- NOlap::TTiering deserializedTtl;
138
- AFL_VERIFY (deserializedTtl.DeserializeFromProto (ttlSettings.GetEnabled ()).IsSuccess ());
139
- Ttl[pathId] = std::move (deserializedTtl);
140
- } else {
141
- Ttl.erase (pathId);
142
- }
143
- vIt->second = version;
144
- }
128
+ if (versionInfo.HasTtlSettings ()) {
129
+ Ttl.AddVersionFromProto (pathId, version, versionInfo.GetTtlSettings ());
145
130
}
146
131
table.AddVersion (version);
147
132
if (!rowset.Next ()) {
@@ -230,7 +215,7 @@ const TTableInfo& TTablesManager::GetTable(const ui64 pathId) const {
230
215
}
231
216
232
217
ui64 TTablesManager::GetMemoryUsage () const {
233
- ui64 memory = Tables.size () * sizeof (TTableInfo) + PathsToDrop.size () * sizeof (ui64) + Ttl.size () * sizeof (NOlap::TTiering );
218
+ ui64 memory = Tables.size () * sizeof (TTableInfo) + PathsToDrop.size () * sizeof (ui64) + Ttl.GetMemoryUsage ( );
234
219
if (PrimaryIndex) {
235
220
memory += PrimaryIndex->MemoryUsage ();
236
221
}
@@ -242,7 +227,6 @@ void TTablesManager::DropTable(const ui64 pathId, const NOlap::TSnapshot& versio
242
227
auto & table = Tables[pathId];
243
228
table.SetDropVersion (version);
244
229
AFL_VERIFY (PathsToDrop[version].emplace (pathId).second );
245
- Ttl.erase (pathId);
246
230
Schema::SaveTableDropVersion (db, pathId, version.GetPlanStep (), version.GetTxId ());
247
231
}
248
232
@@ -299,7 +283,7 @@ void TTablesManager::AddSchemaVersion(
299
283
for (auto && i : Tables) {
300
284
PrimaryIndex->RegisterTable (i.first );
301
285
}
302
- PrimaryIndex->OnTieringModified (Ttl );
286
+ PrimaryIndex->OnTieringModified (GetTtl () );
303
287
} else {
304
288
PrimaryIndex->RegisterSchemaVersion (version, presetId, NOlap::IColumnEngine::TSchemaInitializationData (versionInfo));
305
289
}
@@ -319,14 +303,7 @@ void TTablesManager::AddTableVersion(const ui64 pathId, const NOlap::TSnapshot&
319
303
bool isTtlModified = false ;
320
304
if (versionInfo.HasTtlSettings ()) {
321
305
isTtlModified = true ;
322
- const auto & ttlSettings = versionInfo.GetTtlSettings ();
323
- if (ttlSettings.HasEnabled ()) {
324
- NOlap::TTiering deserializedTtl;
325
- AFL_VERIFY (deserializedTtl.DeserializeFromProto (ttlSettings.GetEnabled ()).IsSuccess ());
326
- Ttl[pathId] = std::move (deserializedTtl);
327
- } else {
328
- Ttl.erase (pathId);
329
- }
306
+ Ttl.AddVersionFromProto (pathId, version, versionInfo.GetTtlSettings ());
330
307
}
331
308
332
309
if (versionInfo.HasSchemaPresetId ()) {
@@ -344,11 +321,7 @@ void TTablesManager::AddTableVersion(const ui64 pathId, const NOlap::TSnapshot&
344
321
345
322
if (isTtlModified) {
346
323
if (PrimaryIndex) {
347
- if (auto findTtl = Ttl.FindPtr (pathId)) {
348
- PrimaryIndex->OnTieringModified (*findTtl, pathId);
349
- } else {
350
- PrimaryIndex->OnTieringModified ({}, pathId);
351
- }
324
+ PrimaryIndex->OnTieringModified (GetTableTtl (pathId), pathId);
352
325
}
353
326
}
354
327
Schema::SaveTableVersionInfo (db, pathId, version, versionInfo);
0 commit comments