Skip to content

Commit a0b4306

Browse files
committed
Working implementation
1 parent 1fe18c0 commit a0b4306

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

ydb/core/tx/schemeshard/schemeshard_build_index.cpp

+23-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ void TSchemeShard::Handle(TEvPrivate::TEvIndexBuildingMakeABill::TPtr& ev, const
4646

4747
void TSchemeShard::PersistCreateBuildIndex(NIceDb::TNiceDb& db, const TIndexBuildInfo& info) {
4848
Y_ABORT_UNLESS(info.BuildKind != TIndexBuildInfo::EBuildKind::BuildKindUnspecified);
49-
db.Table<Schema::IndexBuild>().Key(info.Id).Update(
49+
auto persistedBuildIndex = db.Table<Schema::IndexBuild>().Key(info.Id);
50+
persistedBuildIndex.Update(
5051
NIceDb::TUpdate<Schema::IndexBuild::Uid>(info.Uid),
5152
NIceDb::TUpdate<Schema::IndexBuild::DomainOwnerId>(info.DomainPathId.OwnerId),
5253
NIceDb::TUpdate<Schema::IndexBuild::DomainLocalId>(info.DomainPathId.LocalPathId),
@@ -59,9 +60,28 @@ void TSchemeShard::PersistCreateBuildIndex(NIceDb::TNiceDb& db, const TIndexBuil
5960
NIceDb::TUpdate<Schema::IndexBuild::MaxShards>(info.Limits.MaxShards),
6061
NIceDb::TUpdate<Schema::IndexBuild::MaxRetries>(info.Limits.MaxRetries),
6162
NIceDb::TUpdate<Schema::IndexBuild::BuildKind>(ui32(info.BuildKind))
62-
63-
// TODO save info.ImplTableDescriptions
6463
);
64+
// Persist details of the index build operation: ImplTableDescriptions and SpecializedIndexDescription.
65+
// We have chosen TIndexCreationConfig's string representation as the serialization format.
66+
if (bool hasSpecializedDescription = !std::holds_alternative<std::monostate>(info.SpecializedIndexDescription);
67+
info.ImplTableDescriptions || hasSpecializedDescription
68+
) {
69+
NKikimrSchemeOp::TIndexCreationConfig serializableRepresentation;
70+
71+
for (const auto& description : info.ImplTableDescriptions) {
72+
*serializableRepresentation.AddIndexImplTableDescriptions() = description;
73+
}
74+
75+
std::visit([&]<typename T>(const T& specializedDescription) {
76+
if constexpr (std::is_same_v<T, NKikimrSchemeOp::TVectorIndexKmeansTreeDescription>) {
77+
*serializableRepresentation.MutableVectorIndexKmeansTreeDescription() = specializedDescription;
78+
}
79+
}, info.SpecializedIndexDescription);
80+
81+
persistedBuildIndex.Update(
82+
NIceDb::TUpdate<Schema::IndexBuild::CreationConfig>(serializableRepresentation.SerializeAsString())
83+
);
84+
}
6585

6686
ui32 columnNo = 0;
6787
for (ui32 i = 0; i < info.IndexColumns.size(); ++i, ++columnNo) {

ydb/core/tx/schemeshard/schemeshard_info_types.h

+22-3
Original file line numberDiff line numberDiff line change
@@ -2991,7 +2991,7 @@ struct TIndexBuildInfo: public TSimpleRefCount<TIndexBuildInfo> {
29912991
// TODO(mbkkt) move to TVectorIndexKmeansTreeDescription
29922992
ui32 K = 4;
29932993
ui32 Levels = 5;
2994-
2994+
29952995
// progress
29962996
enum EState : ui32 {
29972997
Sample = 0,
@@ -3007,7 +3007,7 @@ struct TIndexBuildInfo: public TSimpleRefCount<TIndexBuildInfo> {
30073007
EState State = Sample;
30083008

30093009
ui32 ChildBegin = 1; // included
3010-
3010+
30113011
static ui32 BinPow(ui32 k, ui32 l) {
30123012
ui32 r = 1;
30133013
while (l != 0) {
@@ -3282,7 +3282,26 @@ struct TIndexBuildInfo: public TSimpleRefCount<TIndexBuildInfo> {
32823282
indexInfo->IndexName = row.template GetValue<Schema::IndexBuild::IndexName>();
32833283
indexInfo->IndexType = row.template GetValue<Schema::IndexBuild::IndexType>();
32843284

3285-
// TODO load indexInfo->ImplTableDescriptions
3285+
// Restore the operation details: ImplTableDescriptions and SpecializedIndexDescription.
3286+
if (row.template HaveValue<Schema::IndexBuild::CreationConfig>()) {
3287+
NKikimrSchemeOp::TIndexCreationConfig creationConfig;
3288+
Y_ABORT_UNLESS(creationConfig.ParseFromString(row.template GetValue<Schema::IndexBuild::CreationConfig>()));
3289+
3290+
auto& descriptions = *creationConfig.MutableIndexImplTableDescriptions();
3291+
indexInfo->ImplTableDescriptions.reserve(descriptions.size());
3292+
for (auto& description : descriptions) {
3293+
indexInfo->ImplTableDescriptions.emplace_back(std::move(description));
3294+
}
3295+
3296+
switch (creationConfig.GetSpecializedIndexDescriptionCase()) {
3297+
case NKikimrSchemeOp::TIndexCreationConfig::kVectorIndexKmeansTreeDescription:
3298+
indexInfo->SpecializedIndexDescription = std::move(*creationConfig.MutableVectorIndexKmeansTreeDescription());
3299+
break;
3300+
case NKikimrSchemeOp::TIndexCreationConfig::SPECIALIZEDINDEXDESCRIPTION_NOT_SET:
3301+
/* do nothing */
3302+
break;
3303+
}
3304+
}
32863305

32873306
indexInfo->State = TIndexBuildInfo::EState(
32883307
row.template GetValue<Schema::IndexBuild::State>());

ydb/core/tx/schemeshard/schemeshard_schema.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,9 @@ struct Schema : NIceDb::Schema {
13251325
struct AlterMainTableTxStatus : Column<32, NScheme::NTypeIds::Uint32> { using Type = NKikimrScheme::EStatus; };
13261326
struct AlterMainTableTxDone : Column<33, NScheme::NTypeIds::Bool> {};
13271327

1328+
// Serialized as string NKikimrSchemeOp::TIndexCreationConfig protobuf.
1329+
struct CreationConfig : Column<34, NScheme::NTypeIds::String> { using Type = TString; };
1330+
13281331
using TKey = TableKey<Id>;
13291332
using TColumns = TableColumns<
13301333
Id,
@@ -1359,7 +1362,8 @@ struct Schema : NIceDb::Schema {
13591362
BuildKind,
13601363
AlterMainTableTxId,
13611364
AlterMainTableTxStatus,
1362-
AlterMainTableTxDone
1365+
AlterMainTableTxDone,
1366+
CreationConfig
13631367
>;
13641368
};
13651369

ydb/tests/functional/scheme_tests/canondata/tablet_scheme_tests.TestTabletSchemes.test_tablet_schemes_flat_schemeshard_/flat_schemeshard.schema

+7-1
Original file line numberDiff line numberDiff line change
@@ -4800,6 +4800,11 @@
48004800
"ColumnId": 33,
48014801
"ColumnName": "AlterMainTableTxDone",
48024802
"ColumnType": "Bool"
4803+
},
4804+
{
4805+
"ColumnId": 34,
4806+
"ColumnName": "CreationConfig",
4807+
"ColumnType": "String"
48034808
}
48044809
],
48054810
"ColumnsDropped": [],
@@ -4838,7 +4843,8 @@
48384843
30,
48394844
31,
48404845
32,
4841-
33
4846+
33,
4847+
34
48424848
],
48434849
"RoomID": 0,
48444850
"Codec": 0,

0 commit comments

Comments
 (0)