Skip to content

Commit 965073e

Browse files
Merge d66b1d6 into 1d31583
2 parents 1d31583 + d66b1d6 commit 965073e

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

ydb/core/tx/columnshard/tables_manager.cpp

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

4646
bool 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) {

ydb/core/tx/columnshard/tables_manager.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class TVersionedSchema {
2828
return VersionsById;
2929
}
3030

31+
TMap<ui64, TVersionData>& MutableVersionsById() {
32+
return VersionsById;
33+
}
34+
3135
NOlap::TSnapshot GetMinVersionForId(const ui64 sVersion) const {
3236
auto it = MinVersionById.find(sVersion);
3337
Y_ABORT_UNLESS(it != MinVersionById.end());
@@ -42,10 +46,11 @@ class TVersionedSchema {
4246
VersionsById.emplace(ssVersion, versionInfo);
4347
Y_ABORT_UNLESS(Versions.emplace(snapshot, ssVersion).second);
4448

45-
if (MinVersionById.contains(ssVersion)) {
46-
MinVersionById.emplace(ssVersion, std::min(snapshot, MinVersionById.at(ssVersion)));
47-
} else {
49+
auto it = MinVersionById.find(ssVersion);
50+
if (it == MinVersionById.end()) {
4851
MinVersionById.emplace(ssVersion, snapshot);
52+
} else {
53+
it->second = std::min(snapshot, it->second);
4954
}
5055
}
5156
};

0 commit comments

Comments
 (0)