diff --git a/ydb/core/tx/columnshard/engines/column_engine_logs.cpp b/ydb/core/tx/columnshard/engines/column_engine_logs.cpp index 30ad46d591de..7ebc69d5904c 100644 --- a/ydb/core/tx/columnshard/engines/column_engine_logs.cpp +++ b/ydb/core/tx/columnshard/engines/column_engine_logs.cpp @@ -171,6 +171,9 @@ void TColumnEngineForLogs::RegisterSchemaVersion(const TSnapshot& snapshot, TInd } void TColumnEngineForLogs::RegisterSchemaVersion(const TSnapshot& snapshot, const TSchemaInitializationData& schema) { + AFL_VERIFY(VersionedIndex.IsEmpty() || schema.GetVersion() >= VersionedIndex.GetLastSchema()->GetVersion())("empty", VersionedIndex.IsEmpty())("current", schema.GetVersion())( + "last", VersionedIndex.GetLastSchema()->GetVersion()); + std::optional indexInfoOptional; if (schema.GetDiff()) { AFL_VERIFY(!VersionedIndex.IsEmpty()); diff --git a/ydb/core/tx/columnshard/engines/scheme/versions/versioned_index.h b/ydb/core/tx/columnshard/engines/scheme/versions/versioned_index.h index c5fc018e7e32..e4e22071f1ed 100644 --- a/ydb/core/tx/columnshard/engines/scheme/versions/versioned_index.h +++ b/ydb/core/tx/columnshard/engines/scheme/versions/versioned_index.h @@ -100,14 +100,14 @@ class TVersionedIndex { } ISnapshotSchema::TPtr GetLastSchemaBeforeOrEqualSnapshotOptional(const ui64 version) const { - ISnapshotSchema::TPtr res = nullptr; - for (auto it = SnapshotByVersion.rbegin(); it != SnapshotByVersion.rend(); ++it) { - if (it->first <= version) { - res = it->second; - break; - } + if (SnapshotByVersion.empty()) { + return nullptr; + } + auto upperBound = SnapshotByVersion.upper_bound(version); + if (upperBound == SnapshotByVersion.begin()) { + return nullptr; } - return res; + return std::prev(upperBound)->second; } ISnapshotSchema::TPtr GetLastSchema() const { diff --git a/ydb/core/tx/columnshard/tables_manager.cpp b/ydb/core/tx/columnshard/tables_manager.cpp index c53dec2190d7..c3c9a53845f8 100644 --- a/ydb/core/tx/columnshard/tables_manager.cpp +++ b/ydb/core/tx/columnshard/tables_manager.cpp @@ -44,7 +44,6 @@ bool TTablesManager::FillMonitoringReport(NTabletFlatExecutor::TTransactionConte } bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) { - THashMap schemaPresets; { TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->TableLoadTimeCounters.StartGuard(); TMemoryProfileGuard g("TTablesManager/InitFromDB::Tables"); @@ -73,7 +72,7 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) { } } - bool isFakePresetOnly = true; + std::optional preset; { TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->SchemaPresetLoadTimeCounters.StartGuard(); TMemoryProfileGuard g("TTablesManager/InitFromDB::SchemaPresets"); @@ -83,23 +82,25 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) { return false; } - while (!rowset.EndOfSet()) { - TSchemaPreset preset; - preset.InitFromDB(rowset); + if (!rowset.EndOfSet()) { + preset = TSchemaPreset(); + preset->InitFromDB(rowset); - if (preset.IsStandaloneTable()) { - Y_VERIFY_S(!preset.GetName(), "Preset name: " + preset.GetName()); + if (preset->IsStandaloneTable()) { + Y_VERIFY_S(!preset->GetName(), "Preset name: " + preset->GetName()); + AFL_VERIFY(!preset->Id); } else { - Y_VERIFY_S(preset.GetName() == "default", "Preset name: " + preset.GetName()); - isFakePresetOnly = false; + Y_VERIFY_S(preset->GetName() == "default", "Preset name: " + preset->GetName()); + AFL_VERIFY(preset->Id); } - AFL_VERIFY(schemaPresets.emplace(preset.GetId(), preset).second); - AFL_VERIFY(SchemaPresetsIds.emplace(preset.GetId()).second); + AFL_VERIFY(SchemaPresetsIds.emplace(preset->GetId()).second); if (!rowset.Next()) { timer.AddLoadingFail(); return false; } } + + AFL_VERIFY(rowset.EndOfSet())("reson", "multiple_presets_not_supported"); } { @@ -122,7 +123,8 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) { NKikimrTxColumnShard::TTableVersionInfo versionInfo; Y_ABORT_UNLESS(versionInfo.ParseFromString(rowset.GetValue())); AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "load_table_version")("path_id", pathId)("snapshot", version); - Y_ABORT_UNLESS(schemaPresets.contains(versionInfo.GetSchemaPresetId())); + AFL_VERIFY(preset); + AFL_VERIFY(preset->Id == versionInfo.GetSchemaPresetId())("preset", preset->Id)("table", versionInfo.GetSchemaPresetId()); if (!table.IsDropped()) { auto& ttlSettings = versionInfo.GetTtlSettings(); @@ -152,6 +154,7 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) { { TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->SchemaPresetVersionsLoadTimeCounters.StartGuard(); TMemoryProfileGuard g("TTablesManager/InitFromDB::PresetVersions"); + auto rowset = db.Table().Select(); if (!rowset.IsReady()) { timer.AddLoadingFail(); @@ -160,8 +163,8 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) { while (!rowset.EndOfSet()) { const ui32 id = rowset.GetValue(); - Y_ABORT_UNLESS(schemaPresets.contains(id)); - auto& preset = schemaPresets[id]; + AFL_VERIFY(preset); + AFL_VERIFY(preset->Id == id)("preset", preset->Id)("schema", id); NOlap::TSnapshot version( rowset.GetValue(), rowset.GetValue()); @@ -169,37 +172,28 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) { Y_ABORT_UNLESS(info.ParseFromString(rowset.GetValue())); AFL_DEBUG(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()) { timer.AddLoadingFail(); return false; } - } - } - TMemoryProfileGuard g("TTablesManager/InitFromDB::Other"); - for (auto& [id, preset] : schemaPresets) { - if (isFakePresetOnly) { - Y_ABORT_UNLESS(id == 0); - } else { - Y_ABORT_UNLESS(id > 0); - } - for (auto it = preset.MutableVersionsById().begin(); it != preset.MutableVersionsById().end();) { - const auto version = it->first; - const auto& schemaInfo = it->second; - AFL_VERIFY(schemaInfo.HasSchema()); + AFL_VERIFY(info.HasSchema()); AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "index_schema")("preset_id", id)("snapshot", version)( - "version", schemaInfo.GetSchema().GetVersion()); - NOlap::IColumnEngine::TSchemaInitializationData schemaInitializationData(schemaInfo); + "version", info.GetSchema().GetVersion()); + NOlap::IColumnEngine::TSchemaInitializationData schemaInitializationData(info); if (!PrimaryIndex) { PrimaryIndex = std::make_unique(TabletId, DataAccessorsManager, StoragesManager, - preset.GetMinVersionForId(schemaInfo.GetSchema().GetVersion()), schemaInitializationData); + version, schemaInitializationData); + } else if (PrimaryIndex->GetVersionedIndex().IsEmpty() || + info.GetSchema().GetVersion() > PrimaryIndex->GetVersionedIndex().GetLastSchema()->GetVersion()) { + PrimaryIndex->RegisterSchemaVersion(version, schemaInitializationData); } else { - PrimaryIndex->RegisterSchemaVersion(preset.GetMinVersionForId(schemaInfo.GetSchema().GetVersion()), schemaInitializationData); + PrimaryIndex->RegisterOldSchemaVersion(version, schemaInitializationData); } - it = preset.MutableVersionsById().erase(it); } } + + TMemoryProfileGuard g("TTablesManager/InitFromDB::Other"); for (auto&& i : Tables) { PrimaryIndex->RegisterTable(i.first); } diff --git a/ydb/core/tx/schemeshard/olap/store/store.cpp b/ydb/core/tx/schemeshard/olap/store/store.cpp index 3ba2ec38375b..32f01d231d70 100644 --- a/ydb/core/tx/schemeshard/olap/store/store.cpp +++ b/ydb/core/tx/schemeshard/olap/store/store.cpp @@ -132,6 +132,11 @@ bool TOlapStoreInfo::ParseFromRequest(const NKikimrSchemeOp::TColumnStoreDescrip return false; } + if (descriptionProto.SchemaPresetsSize() > 1) { + errors.AddError("trying to create an OLAP store with multiple schema presets (not supported yet)"); + return false; + } + Name = descriptionProto.GetName(); StorageConfig = descriptionProto.GetStorageConfig(); // Make it easier by having data channel count always specified internally