Skip to content

Commit ad41bff

Browse files
authored
Merge f474754 into 9c831b2
2 parents 9c831b2 + f474754 commit ad41bff

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

ydb/core/tx/columnshard/engines/column_engine_logs.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ void TColumnEngineForLogs::RegisterSchemaVersion(const TSnapshot& snapshot, TInd
171171
}
172172

173173
void TColumnEngineForLogs::RegisterSchemaVersion(const TSnapshot& snapshot, const TSchemaInitializationData& schema) {
174+
AFL_VERIFY(VersionedIndex.IsEmpty() || schema.GetVersion() >= VersionedIndex.GetLastSchema()->GetVersion())("empty", VersionedIndex.IsEmpty())("current", schema.GetVersion())(
175+
"last", VersionedIndex.GetLastSchema()->GetVersion());
176+
174177
std::optional<NOlap::TIndexInfo> indexInfoOptional;
175178
if (schema.GetDiff()) {
176179
AFL_VERIFY(!VersionedIndex.IsEmpty());

ydb/core/tx/columnshard/engines/scheme/versions/versioned_index.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ class TVersionedIndex {
100100
}
101101

102102
ISnapshotSchema::TPtr GetLastSchemaBeforeOrEqualSnapshotOptional(const ui64 version) const {
103-
ISnapshotSchema::TPtr res = nullptr;
104-
for (auto it = SnapshotByVersion.rbegin(); it != SnapshotByVersion.rend(); ++it) {
105-
if (it->first <= version) {
106-
res = it->second;
107-
break;
108-
}
103+
if (SnapshotByVersion.empty()) {
104+
return nullptr;
105+
}
106+
auto upperBound = SnapshotByVersion.upper_bound(version);
107+
if (upperBound == SnapshotByVersion.begin()) {
108+
return nullptr;
109109
}
110-
return res;
110+
return std::prev(upperBound)->second;
111111
}
112112

113113
ISnapshotSchema::TPtr GetLastSchema() const {

ydb/core/tx/columnshard/tables_manager.cpp

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ bool TTablesManager::FillMonitoringReport(NTabletFlatExecutor::TTransactionConte
4444
}
4545

4646
bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
47-
THashMap<ui32, TSchemaPreset> schemaPresets;
4847
{
4948
TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->TableLoadTimeCounters.StartGuard();
5049
TMemoryProfileGuard g("TTablesManager/InitFromDB::Tables");
@@ -73,7 +72,7 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
7372
}
7473
}
7574

76-
bool isFakePresetOnly = true;
75+
std::optional<TSchemaPreset> preset;
7776
{
7877
TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->SchemaPresetLoadTimeCounters.StartGuard();
7978
TMemoryProfileGuard g("TTablesManager/InitFromDB::SchemaPresets");
@@ -83,23 +82,25 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
8382
return false;
8483
}
8584

86-
while (!rowset.EndOfSet()) {
87-
TSchemaPreset preset;
88-
preset.InitFromDB(rowset);
85+
if (!rowset.EndOfSet()) {
86+
preset = TSchemaPreset();
87+
preset->InitFromDB(rowset);
8988

90-
if (preset.IsStandaloneTable()) {
91-
Y_VERIFY_S(!preset.GetName(), "Preset name: " + preset.GetName());
89+
if (preset->IsStandaloneTable()) {
90+
Y_VERIFY_S(!preset->GetName(), "Preset name: " + preset->GetName());
91+
AFL_VERIFY(!preset->Id);
9292
} else {
93-
Y_VERIFY_S(preset.GetName() == "default", "Preset name: " + preset.GetName());
94-
isFakePresetOnly = false;
93+
Y_VERIFY_S(preset->GetName() == "default", "Preset name: " + preset->GetName());
94+
AFL_VERIFY(preset->Id);
9595
}
96-
AFL_VERIFY(schemaPresets.emplace(preset.GetId(), preset).second);
97-
AFL_VERIFY(SchemaPresetsIds.emplace(preset.GetId()).second);
96+
AFL_VERIFY(SchemaPresetsIds.emplace(preset->GetId()).second);
9897
if (!rowset.Next()) {
9998
timer.AddLoadingFail();
10099
return false;
101100
}
102101
}
102+
103+
AFL_VERIFY(rowset.EndOfSet())("reson", "multiple_presets_not_supported");
103104
}
104105

105106
{
@@ -122,7 +123,8 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
122123
NKikimrTxColumnShard::TTableVersionInfo versionInfo;
123124
Y_ABORT_UNLESS(versionInfo.ParseFromString(rowset.GetValue<Schema::TableVersionInfo::InfoProto>()));
124125
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "load_table_version")("path_id", pathId)("snapshot", version);
125-
Y_ABORT_UNLESS(schemaPresets.contains(versionInfo.GetSchemaPresetId()));
126+
AFL_VERIFY(preset);
127+
AFL_VERIFY(preset->Id == versionInfo.GetSchemaPresetId())("preset", preset->Id)("table", versionInfo.GetSchemaPresetId());
126128

127129
if (!table.IsDropped()) {
128130
auto& ttlSettings = versionInfo.GetTtlSettings();
@@ -152,6 +154,7 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
152154
{
153155
TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->SchemaPresetVersionsLoadTimeCounters.StartGuard();
154156
TMemoryProfileGuard g("TTablesManager/InitFromDB::PresetVersions");
157+
155158
auto rowset = db.Table<Schema::SchemaPresetVersionInfo>().Select();
156159
if (!rowset.IsReady()) {
157160
timer.AddLoadingFail();
@@ -160,46 +163,38 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
160163

161164
while (!rowset.EndOfSet()) {
162165
const ui32 id = rowset.GetValue<Schema::SchemaPresetVersionInfo::Id>();
163-
Y_ABORT_UNLESS(schemaPresets.contains(id));
164-
auto& preset = schemaPresets[id];
166+
AFL_VERIFY(preset);
167+
AFL_VERIFY(preset->Id == id)("preset", preset->Id)("schema", id);
165168
NOlap::TSnapshot version(
166169
rowset.GetValue<Schema::SchemaPresetVersionInfo::SinceStep>(), rowset.GetValue<Schema::SchemaPresetVersionInfo::SinceTxId>());
167170

168171
TSchemaPreset::TSchemaPresetVersionInfo info;
169172
Y_ABORT_UNLESS(info.ParseFromString(rowset.GetValue<Schema::SchemaPresetVersionInfo::InfoProto>()));
170173
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "load_preset")("preset_id", id)("snapshot", version)(
171174
"version", info.HasSchema() ? info.GetSchema().GetVersion() : -1);
172-
preset.AddVersion(version, info);
173-
if (!rowset.Next()) {
174-
timer.AddLoadingFail();
175-
return false;
176-
}
177-
}
178-
}
179175

180-
TMemoryProfileGuard g("TTablesManager/InitFromDB::Other");
181-
for (auto& [id, preset] : schemaPresets) {
182-
if (isFakePresetOnly) {
183-
Y_ABORT_UNLESS(id == 0);
184-
} else {
185-
Y_ABORT_UNLESS(id > 0);
186-
}
187-
for (auto it = preset.MutableVersionsById().begin(); it != preset.MutableVersionsById().end();) {
188-
const auto version = it->first;
189-
const auto& schemaInfo = it->second;
190-
AFL_VERIFY(schemaInfo.HasSchema());
176+
AFL_VERIFY(info.HasSchema());
191177
AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "index_schema")("preset_id", id)("snapshot", version)(
192-
"version", schemaInfo.GetSchema().GetVersion());
193-
NOlap::IColumnEngine::TSchemaInitializationData schemaInitializationData(schemaInfo);
178+
"version", info.GetSchema().GetVersion());
179+
NOlap::IColumnEngine::TSchemaInitializationData schemaInitializationData(info);
194180
if (!PrimaryIndex) {
195181
PrimaryIndex = std::make_unique<NOlap::TColumnEngineForLogs>(TabletId, DataAccessorsManager, StoragesManager,
196-
preset.GetMinVersionForId(schemaInfo.GetSchema().GetVersion()), schemaInitializationData);
182+
version, schemaInitializationData);
183+
} else if (PrimaryIndex->GetVersionedIndex().IsEmpty() ||
184+
info.GetSchema().GetVersion() > PrimaryIndex->GetVersionedIndex().GetLastSchema()->GetVersion()) {
185+
PrimaryIndex->RegisterSchemaVersion(version, schemaInitializationData);
197186
} else {
198-
PrimaryIndex->RegisterSchemaVersion(preset.GetMinVersionForId(schemaInfo.GetSchema().GetVersion()), schemaInitializationData);
187+
PrimaryIndex->RegisterOldSchemaVersion(version, schemaInitializationData);
188+
}
189+
190+
if (!rowset.Next()) {
191+
timer.AddLoadingFail();
192+
return false;
199193
}
200-
it = preset.MutableVersionsById().erase(it);
201194
}
202195
}
196+
197+
TMemoryProfileGuard g("TTablesManager/InitFromDB::Other");
203198
for (auto&& i : Tables) {
204199
PrimaryIndex->RegisterTable(i.first);
205200
}

ydb/core/tx/columnshard/ut_rw/ut_normalizer.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ class TSchemaVersionsCleaner : public NYDBTest::ILocalDBModifier {
124124
db.Table<Schema::TableVersionInfo>().Key(1, 5, 1).Update(
125125
NIceDb::TUpdate<Schema::TableVersionInfo::InfoProto>(versionInfo.SerializeAsString()));
126126
}
127-
128-
db.Table<Schema::SchemaPresetInfo>().Key(10).Update(NIceDb::TUpdate<Schema::SchemaPresetInfo::Name>("default"));
129-
130127
}
131128
};
132129

ydb/core/tx/schemeshard/olap/store/store.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ bool TOlapStoreInfo::ParseFromRequest(const NKikimrSchemeOp::TColumnStoreDescrip
132132
return false;
133133
}
134134

135+
if (descriptionProto.SchemaPresetsSize() > 1) {
136+
errors.AddError("trying to create an OLAP store with multiple schema presets (not supported yet)");
137+
return false;
138+
}
139+
135140
Name = descriptionProto.GetName();
136141
StorageConfig = descriptionProto.GetStorageConfig();
137142
// Make it easier by having data channel count always specified internally

0 commit comments

Comments
 (0)