@@ -44,10 +44,7 @@ bool TTablesManager::FillMonitoringReport(NTabletFlatExecutor::TTransactionConte
4444}
4545
4646bool TTablesManager::InitFromDB (NIceDb::TNiceDb& db) {
47- using TTableVersionsInfo = TVersionedSchema<NKikimrTxColumnShard::TTableVersionInfo>;
48-
4947 THashMap<ui32, TSchemaPreset> schemaPresets;
50- THashMap<ui32, TTableVersionsInfo> tableVersions;
5148 {
5249 TMemoryProfileGuard g (" TTablesManager/InitFromDB::Tables" );
5350 auto rowset = db.Table <Schema::TableInfo>().Select ();
@@ -64,7 +61,6 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
6461 PathsToDrop.insert (table.GetPathId ());
6562 }
6663
67- AFL_VERIFY (tableVersions.emplace (table.GetPathId (), TTableVersionsInfo ()).second );
6864 AFL_VERIFY (Tables.emplace (table.GetPathId (), std::move (table)).second );
6965
7066 if (!rowset.Next ()) {
@@ -115,7 +111,6 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
115111 rowset.GetValue <Schema::TableVersionInfo::SinceTxId>());
116112
117113 auto & table = Tables[pathId];
118- auto & versionsInfo = tableVersions[pathId];
119114 NKikimrTxColumnShard::TTableVersionInfo versionInfo;
120115 Y_ABORT_UNLESS (versionInfo.ParseFromString (rowset.GetValue <Schema::TableVersionInfo::InfoProto>()));
121116 AFL_DEBUG (NKikimrServices::TX_COLUMNSHARD)(" event" , " load_table_version" )(" path_id" , pathId)(" snapshot" , version)(" version" , versionInfo.HasSchema () ? versionInfo.GetSchema ().GetVersion () : -1 );
@@ -125,15 +120,17 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
125120 auto & ttlSettings = versionInfo.GetTtlSettings ();
126121 if (ttlSettings.HasEnabled ()) {
127122 auto vIt = lastVersion.find (pathId);
128- if (vIt == lastVersion.end () || vIt->second < version) {
123+ if (vIt == lastVersion.end ()) {
124+ vIt = lastVersion.emplace (pathId, version).first ;
125+ }
126+ if (vIt->second <= version) {
129127 TTtl::TDescription description (ttlSettings.GetEnabled ());
130128 Ttl.SetPathTtl (pathId, std::move (description));
131- lastVersion. emplace (pathId, version) ;
129+ vIt-> second = version;
132130 }
133131 }
134132 }
135133 table.AddVersion (version);
136- versionsInfo.AddVersion (version, versionInfo);
137134 if (!rowset.Next ()) {
138135 return false ;
139136 }
@@ -152,8 +149,7 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
152149 Y_ABORT_UNLESS (schemaPresets.contains (id));
153150 auto & preset = schemaPresets[id];
154151 NOlap::TSnapshot version (
155- rowset.GetValue <Schema::SchemaPresetVersionInfo::SinceStep>(),
156- rowset.GetValue <Schema::SchemaPresetVersionInfo::SinceTxId>());
152+ rowset.GetValue <Schema::SchemaPresetVersionInfo::SinceStep>(), rowset.GetValue <Schema::SchemaPresetVersionInfo::SinceTxId>());
157153
158154 TSchemaPreset::TSchemaPresetVersionInfo info;
159155 Y_ABORT_UNLESS (info.ParseFromString (rowset.GetValue <Schema::SchemaPresetVersionInfo::InfoProto>()));
@@ -166,21 +162,27 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
166162 }
167163
168164 TMemoryProfileGuard g (" TTablesManager/InitFromDB::Other" );
169- for (const auto & [id, preset] : schemaPresets) {
165+ for (auto & [id, preset] : schemaPresets) {
170166 if (isFakePresetOnly) {
171167 Y_ABORT_UNLESS (id == 0 );
172168 } else {
173169 Y_ABORT_UNLESS (id > 0 );
174170 }
175- for (const auto & [version, schemaInfo] : preset.GetVersionsById ()) {
176- if (schemaInfo.HasSchema ()) {
177- AFL_INFO (NKikimrServices::TX_COLUMNSHARD)(" event" , " index_schema" )(" preset_id" , id)(" snapshot" , version)(" version" , schemaInfo.GetSchema ().GetVersion ());
178- if (!PrimaryIndex) {
179- PrimaryIndex = std::make_unique<NOlap::TColumnEngineForLogs>(TabletId, StoragesManager, preset.GetMinVersionForId (schemaInfo.GetSchema ().GetVersion ()), schemaInfo.GetSchema ());
180- } else {
181- PrimaryIndex->RegisterSchemaVersion (preset.GetMinVersionForId (schemaInfo.GetSchema ().GetVersion ()), schemaInfo.GetSchema ());
182- }
171+ for (auto it = preset.MutableVersionsById ().begin (); it != preset.MutableVersionsById ().end ();) {
172+ const auto version = it->first ;
173+ const auto & schemaInfo = it->second ;
174+ if (!schemaInfo.HasSchema ()) {
175+ continue ;
176+ }
177+ AFL_INFO (NKikimrServices::TX_COLUMNSHARD)(" event" , " index_schema" )(" preset_id" , id)(" snapshot" , version)(
178+ " version" , schemaInfo.GetSchema ().GetVersion ());
179+ if (!PrimaryIndex) {
180+ PrimaryIndex = std::make_unique<NOlap::TColumnEngineForLogs>(
181+ TabletId, StoragesManager, preset.GetMinVersionForId (schemaInfo.GetSchema ().GetVersion ()), schemaInfo.GetSchema ());
182+ } else {
183+ PrimaryIndex->RegisterSchemaVersion (preset.GetMinVersionForId (schemaInfo.GetSchema ().GetVersion ()), schemaInfo.GetSchema ());
183184 }
185+ it = preset.MutableVersionsById ().erase (it);
184186 }
185187 }
186188 for (auto && i : Tables) {
0 commit comments