@@ -112,7 +112,6 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
112112 return false ;
113113 }
114114
115- THashMap<ui64, NOlap::TSnapshot> lastVersion;
116115 while (!rowset.EndOfSet ()) {
117116 const ui64 pathId = rowset.GetValue <Schema::TableVersionInfo::PathId>();
118117 Y_ABORT_UNLESS (Tables.contains (pathId));
@@ -126,22 +125,8 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
126125 AFL_VERIFY (preset);
127126 AFL_VERIFY (preset->Id == versionInfo.GetSchemaPresetId ())(" preset" , preset->Id )(" table" , versionInfo.GetSchemaPresetId ());
128127
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 ());
145130 }
146131 table.AddVersion (version);
147132 if (!rowset.Next ()) {
@@ -230,7 +215,7 @@ const TTableInfo& TTablesManager::GetTable(const ui64 pathId) const {
230215}
231216
232217ui64 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 ( );
234219 if (PrimaryIndex) {
235220 memory += PrimaryIndex->MemoryUsage ();
236221 }
@@ -242,7 +227,6 @@ void TTablesManager::DropTable(const ui64 pathId, const NOlap::TSnapshot& versio
242227 auto & table = Tables[pathId];
243228 table.SetDropVersion (version);
244229 AFL_VERIFY (PathsToDrop[version].emplace (pathId).second );
245- Ttl.erase (pathId);
246230 Schema::SaveTableDropVersion (db, pathId, version.GetPlanStep (), version.GetTxId ());
247231}
248232
@@ -299,7 +283,7 @@ void TTablesManager::AddSchemaVersion(
299283 for (auto && i : Tables) {
300284 PrimaryIndex->RegisterTable (i.first );
301285 }
302- PrimaryIndex->OnTieringModified (Ttl );
286+ PrimaryIndex->OnTieringModified (GetTtl () );
303287 } else {
304288 PrimaryIndex->RegisterSchemaVersion (version, presetId, NOlap::IColumnEngine::TSchemaInitializationData (versionInfo));
305289 }
@@ -319,14 +303,7 @@ void TTablesManager::AddTableVersion(const ui64 pathId, const NOlap::TSnapshot&
319303 bool isTtlModified = false ;
320304 if (versionInfo.HasTtlSettings ()) {
321305 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 ());
330307 }
331308
332309 if (versionInfo.HasSchemaPresetId ()) {
@@ -344,11 +321,7 @@ void TTablesManager::AddTableVersion(const ui64 pathId, const NOlap::TSnapshot&
344321
345322 if (isTtlModified) {
346323 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);
352325 }
353326 }
354327 Schema::SaveTableVersionInfo (db, pathId, version, versionInfo);
0 commit comments