Skip to content

Commit de47558

Browse files
authored
Merge 5565e0b into 974cc86
2 parents 974cc86 + 5565e0b commit de47558

File tree

4 files changed

+38
-40
lines changed

4 files changed

+38
-40
lines changed

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

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

173173
void TColumnEngineForLogs::RegisterSchemaVersion(const TSnapshot& snapshot, const TSchemaInitializationData& schema) {
174+
AFL_VERIFY(schema.GetVersion() >= VersionedIndex.GetLastSchema()->GetVersion())("current", schema.GetVersion())("last", VersionedIndex.GetLastSchema()->GetVersion());
174175
std::optional<NOlap::TIndexInfo> indexInfoOptional;
175176
if (schema.GetDiff()) {
176177
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: 25 additions & 33 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,24 @@ 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->InitFromDB(rowset);
8987

90-
if (preset.IsStandaloneTable()) {
91-
Y_VERIFY_S(!preset.GetName(), "Preset name: " + preset.GetName());
88+
if (preset->IsStandaloneTable()) {
89+
Y_VERIFY_S(!preset->GetName(), "Preset name: " + preset->GetName());
90+
AFL_VERIFY(!preset->Id);
9291
} else {
93-
Y_VERIFY_S(preset.GetName() == "default", "Preset name: " + preset.GetName());
94-
isFakePresetOnly = false;
92+
Y_VERIFY_S(preset->GetName() == "default", "Preset name: " + preset->GetName());
93+
AFL_VERIFY(preset->Id);
9594
}
96-
AFL_VERIFY(schemaPresets.emplace(preset.GetId(), preset).second);
97-
AFL_VERIFY(SchemaPresetsIds.emplace(preset.GetId()).second);
95+
AFL_VERIFY(SchemaPresetsIds.emplace(preset->GetId()).second);
9896
if (!rowset.Next()) {
9997
timer.AddLoadingFail();
10098
return false;
10199
}
102100
}
101+
102+
AFL_VERIFY(rowset.EndOfSet())("reson", "multiple_presets_not_supported");
103103
}
104104

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

127128
if (!table.IsDropped()) {
128129
auto& ttlSettings = versionInfo.GetTtlSettings();
@@ -152,6 +153,7 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
152153
{
153154
TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->SchemaPresetVersionsLoadTimeCounters.StartGuard();
154155
TMemoryProfileGuard g("TTablesManager/InitFromDB::PresetVersions");
156+
155157
auto rowset = db.Table<Schema::SchemaPresetVersionInfo>().Select();
156158
if (!rowset.IsReady()) {
157159
timer.AddLoadingFail();
@@ -160,46 +162,36 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
160162

161163
while (!rowset.EndOfSet()) {
162164
const ui32 id = rowset.GetValue<Schema::SchemaPresetVersionInfo::Id>();
163-
Y_ABORT_UNLESS(schemaPresets.contains(id));
164-
auto& preset = schemaPresets[id];
165+
AFL_VERIFY(preset);
166+
AFL_VERIFY(preset->Id == id)("preset", preset->Id)("schema", id);
165167
NOlap::TSnapshot version(
166168
rowset.GetValue<Schema::SchemaPresetVersionInfo::SinceStep>(), rowset.GetValue<Schema::SchemaPresetVersionInfo::SinceTxId>());
167169

168170
TSchemaPreset::TSchemaPresetVersionInfo info;
169171
Y_ABORT_UNLESS(info.ParseFromString(rowset.GetValue<Schema::SchemaPresetVersionInfo::InfoProto>()));
170172
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "load_preset")("preset_id", id)("snapshot", version)(
171173
"version", info.HasSchema() ? info.GetSchema().GetVersion() : -1);
172-
preset.AddVersion(version, info);
173174
if (!rowset.Next()) {
174175
timer.AddLoadingFail();
175176
return false;
176177
}
177-
}
178-
}
179178

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());
179+
AFL_VERIFY(info.HasSchema());
191180
AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "index_schema")("preset_id", id)("snapshot", version)(
192-
"version", schemaInfo.GetSchema().GetVersion());
193-
NOlap::IColumnEngine::TSchemaInitializationData schemaInitializationData(schemaInfo);
181+
"version", info.GetSchema().GetVersion());
182+
NOlap::IColumnEngine::TSchemaInitializationData schemaInitializationData(info);
194183
if (!PrimaryIndex) {
195184
PrimaryIndex = std::make_unique<NOlap::TColumnEngineForLogs>(TabletId, DataAccessorsManager, StoragesManager,
196-
preset.GetMinVersionForId(schemaInfo.GetSchema().GetVersion()), schemaInitializationData);
185+
version, schemaInitializationData);
186+
} else if (info.GetSchema().GetVersion() > PrimaryIndex->GetVersionedIndex().GetLastSchema()->GetVersion()) {
187+
PrimaryIndex->RegisterSchemaVersion(version, schemaInitializationData);
197188
} else {
198-
PrimaryIndex->RegisterSchemaVersion(preset.GetMinVersionForId(schemaInfo.GetSchema().GetVersion()), schemaInitializationData);
189+
PrimaryIndex->RegisterOldSchemaVersion(version, schemaInitializationData);
199190
}
200-
it = preset.MutableVersionsById().erase(it);
201191
}
202192
}
193+
194+
TMemoryProfileGuard g("TTablesManager/InitFromDB::Other");
203195
for (auto&& i : Tables) {
204196
PrimaryIndex->RegisterTable(i.first);
205197
}

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)