Browse Source

Fix TTablesManager::Clear

nsofya 1 year ago
parent
commit
b28f93840f

+ 10 - 2
ydb/core/tx/columnshard/engines/column_engine.h

@@ -306,6 +306,7 @@ class TVersionedIndex {
     std::map<TSnapshot, ISnapshotSchema::TPtr> Snapshots;
     std::shared_ptr<arrow::Schema> IndexKey;
     std::map<ui64, ISnapshotSchema::TPtr> SnapshotByVersion;
+    ui64 LastSchemaVersion = 0;
 public:
     ISnapshotSchema::TPtr GetSchema(const ui64 version) const {
         auto it = SnapshotByVersion.find(version);
@@ -345,9 +346,16 @@ public:
             Y_VERIFY(IndexKey->Equals(indexInfo.GetIndexKey()));
         }
         auto it = Snapshots.emplace(version, std::make_shared<TSnapshotSchema>(std::move(indexInfo), version));
-        if (!SnapshotByVersion.emplace(it.first->second->GetVersion(), it.first->second).second) {
-            Y_VERIFY(GetLastSchema()->GetVersion() == it.first->second->GetVersion());
+        Y_VERIFY(it.second);
+        auto newVersion = it.first->second->GetVersion();
+
+        if (SnapshotByVersion.contains(newVersion)) {
+            Y_VERIFY_S(LastSchemaVersion != 0, TStringBuilder() << "Last: " << LastSchemaVersion);
+            Y_VERIFY_S(LastSchemaVersion == newVersion, TStringBuilder() << "Last: " << LastSchemaVersion << ";New: " << newVersion);
         }
+
+        SnapshotByVersion[newVersion] = it.first->second;
+        LastSchemaVersion = newVersion;
     }
 };
 

+ 4 - 0
ydb/core/tx/columnshard/tables_manager.cpp

@@ -78,6 +78,7 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db, const ui64 tabletId) {
             auto& table = Tables.at(pathId);
             TTableInfo::TTableVersionInfo versionInfo;
             Y_VERIFY(versionInfo.ParseFromString(rowset.GetValue<Schema::TableVersionInfo::InfoProto>()));
+            AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "load_table_version")("path_id", pathId)("snapshot", version)("version", versionInfo.HasSchema() ? versionInfo.GetSchema().GetVersion() : -1);
             Y_VERIFY(SchemaPresets.contains(versionInfo.GetSchemaPresetId()));
 
             if (!table.IsDropped()) {
@@ -113,6 +114,7 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db, const ui64 tabletId) {
 
             TSchemaPreset::TSchemaPresetVersionInfo info;
             Y_VERIFY(info.ParseFromString(rowset.GetValue<Schema::SchemaPresetVersionInfo::InfoProto>()));
+            AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "load_preset")("preset_id", id)("snapshot", version)("version", info.HasSchema() ? info.GetSchema().GetVersion() : -1);
             preset.AddVersion(version, info);
             if (!rowset.Next()) {
                 return false;
@@ -128,6 +130,7 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db, const ui64 tabletId) {
         }
         for (const auto& [version, schemaInfo] : preset.GetVersions()) {
             if (schemaInfo.HasSchema()) {
+                AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "index_schema")("preset_id", id)("snapshot", version)("version", schemaInfo.GetSchema().GetVersion());
                 IndexSchemaVersion(version, schemaInfo.GetSchema());
             }
         }
@@ -148,6 +151,7 @@ void TTablesManager::Clear() {
     Tables.clear();
     SchemaPresets.clear();
     PathsToDrop.clear();
+    PrimaryIndex.reset();
 }
 
 bool TTablesManager::HasTable(const ui64 pathId) const {