Skip to content

Commit bbd0161

Browse files
committed
Vector index build preparation in SchemeShard
1 parent 5ff39ba commit bbd0161

9 files changed

+51
-19
lines changed

ydb/core/base/table_index.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,9 @@ bool IsCompatibleIndex(const NKikimrSchemeOp::EIndexType indexType, const TTable
140140
return true;
141141
}
142142

143+
bool IsImplTable(std::string_view tableName) {
144+
return std::find(std::begin(ImplTables), std::end(ImplTables), tableName) != std::end(ImplTables);
145+
}
146+
143147
}
144148
}

ydb/core/base/table_index.h

+5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ struct TIndexColumns {
2121
TVector<TString> DataColumns;
2222
};
2323

24+
inline constexpr const char* ImplTable = "indexImplTable";
25+
inline constexpr std::string_view ImplTables[] = {ImplTable, NTableVectorKmeansTreeIndex::LevelTable, NTableVectorKmeansTreeIndex::PostingTable};
26+
2427
bool IsCompatibleIndex(const NKikimrSchemeOp::EIndexType indexType, const TTableColumns& table, const TIndexColumns& index, TString& explain);
2528
TTableColumns CalcTableImplDescription(const NKikimrSchemeOp::EIndexType indexType, const TTableColumns& table, const TIndexColumns& index);
2629

30+
bool IsImplTable(std::string_view tableName);
31+
2732
}
2833
}

ydb/core/tx/schemeshard/schemeshard__operation_apply_build_index.cpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,25 @@ TVector<ISubOperation::TPtr> ApplyBuildIndex(TOperationId nextId, const TTxTrans
5252

5353
if (!indexName.empty())
5454
{
55+
auto alterImplTableTransactionTemplate = [] (TPath index, TPath implIndexTable, TTableInfo::TPtr implIndexTableInfo) {
56+
auto indexImplTableAltering = TransactionTemplate(index.PathString(), NKikimrSchemeOp::EOperationType::ESchemeOpFinalizeBuildIndexImplTable);
57+
auto alterTable = indexImplTableAltering.MutableAlterTable();
58+
alterTable->SetName(implIndexTable.LeafName());
59+
alterTable->MutablePartitionConfig()->MutableCompactionPolicy()->CopyFrom(implIndexTableInfo->PartitionConfig().GetCompactionPolicy());
60+
alterTable->MutablePartitionConfig()->MutableCompactionPolicy()->SetKeepEraseMarkers(false);
61+
alterTable->MutablePartitionConfig()->SetShadowData(false);
62+
return indexImplTableAltering;
63+
};
64+
5565
TPath index = table.Child(indexName);
56-
TPath implIndexTable = index.Child("indexImplTable");
57-
TTableInfo::TPtr implIndexTableInfo = context.SS->Tables.at(implIndexTable.Base()->PathId);
58-
auto indexImplTableAltering = TransactionTemplate(index.PathString(), NKikimrSchemeOp::EOperationType::ESchemeOpFinalizeBuildIndexImplTable);
59-
auto alterTable = indexImplTableAltering.MutableAlterTable();
60-
alterTable->SetName(implIndexTable.LeafName());
61-
alterTable->MutablePartitionConfig()->MutableCompactionPolicy()->CopyFrom(implIndexTableInfo->PartitionConfig().GetCompactionPolicy());
62-
alterTable->MutablePartitionConfig()->MutableCompactionPolicy()->SetKeepEraseMarkers(false);
63-
alterTable->MutablePartitionConfig()->SetShadowData(false);
64-
65-
result.push_back(CreateFinalizeBuildIndexImplTable(NextPartId(nextId, result), indexImplTableAltering));
66+
for (const std::string_view implTable : NTableIndex::ImplTables) {
67+
TPath implIndexTable = index.Child(implTable.data());
68+
if (!implIndexTable.IsResolved()) {
69+
continue;
70+
}
71+
TTableInfo::TPtr implIndexTableInfo = context.SS->Tables.at(implIndexTable.Base()->PathId);
72+
result.push_back(CreateFinalizeBuildIndexImplTable(NextPartId(nextId, result), alterImplTableTransactionTemplate(index, implIndexTable, implIndexTableInfo)));
73+
}
6674
}
6775

6876
return result;
@@ -109,7 +117,7 @@ TVector<ISubOperation::TPtr> CancelBuildIndex(TOperationId nextId, const TTxTran
109117
Y_ABORT_UNLESS(index.Base()->GetChildren().size() == 1);
110118
for (auto& indexChildItems: index.Base()->GetChildren()) {
111119
const TString& implTableName = indexChildItems.first;
112-
Y_ABORT_UNLESS(implTableName == "indexImplTable", "unexpected name %s", implTableName.c_str());
120+
Y_ABORT_UNLESS(NTableIndex::IsImplTable(implTableName), "unexpected name %s", implTableName.c_str());
113121

114122
TPath implTable = index.Child(implTableName);
115123
{

ydb/core/tx/schemeshard/schemeshard__operation_drop_indexed_table.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,8 @@ TVector<ISubOperation::TPtr> CreateDropIndexedTable(TOperationId nextId, const T
495495
}
496496

497497
for (auto& [implName, implPathId] : child.Base()->GetChildren()) {
498-
Y_ABORT_UNLESS(implName == "indexImplTable"
498+
Y_ABORT_UNLESS(NTableIndex::IsImplTable(implName)
499499
|| implName == "streamImpl"
500-
|| implName == NTableIndex::NTableVectorKmeansTreeIndex::LevelTable
501-
|| implName == NTableIndex::NTableVectorKmeansTreeIndex::PostingTable
502500
, "unexpected name %s", implName.c_str());
503501

504502
TPath implPath = child.Child(implName);

ydb/core/tx/schemeshard/schemeshard_build_index__create.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,13 @@ class TSchemeShard::TIndexBuilder::TTxCreate: public TSchemeShard::TIndexBuilder
226226
case Ydb::Table::TableIndex::TypeCase::kGlobalUniqueIndex:
227227
explain = "unsupported index type to build";
228228
return false;
229-
case Ydb::Table::TableIndex::TypeCase::kGlobalVectorKmeansTreeIndex:
230-
explain = "unsupported vector index type to build";
231-
return false;
229+
case Ydb::Table::TableIndex::TypeCase::kGlobalVectorKmeansTreeIndex: {
230+
buildInfo->IndexType = NKikimrSchemeOp::EIndexType::EIndexTypeGlobalVectorKmeansTree;
231+
NKikimrSchemeOp::TVectorIndexKmeansTreeDescription vectorIndexKmeansTreeDescription;
232+
*vectorIndexKmeansTreeDescription.MutableSettings() = index.global_vector_kmeans_tree_index().vector_settings();
233+
buildInfo->SpecializedIndexDescription = vectorIndexKmeansTreeDescription;
234+
break;
235+
}
232236
case Ydb::Table::TableIndex::TypeCase::TYPE_NOT_SET:
233237
explain = "invalid or unset index type";
234238
return false;

ydb/core/tx/schemeshard/schemeshard_build_index__progress.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
253253
} else if (!buildInfo->InitiateTxDone) {
254254
Send(Self->SelfId(), MakeHolder<TEvSchemeShard::TEvNotifyTxCompletion>(ui64(buildInfo->InitiateTxId)));
255255
} else {
256+
// TODO add vector index filling
257+
if (buildInfo->IndexType == NKikimrSchemeOp::EIndexType::EIndexTypeGlobalVectorKmeansTree) {
258+
ChangeState(BuildId, TIndexBuildInfo::EState::Applying);
259+
Progress(BuildId);
260+
break;
261+
}
262+
256263
ChangeState(BuildId, TIndexBuildInfo::EState::Filling);
257264
Progress(BuildId);
258265
}

ydb/core/tx/schemeshard/schemeshard_info_types.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,10 @@ void TIndexBuildInfo::SerializeToProto(TSchemeShard* ss, NKikimrSchemeOp::TIndex
21222122
for (const auto& implTableDescription : ImplTableDescriptions) {
21232123
*index.AddIndexImplTableDescriptions() = implTableDescription;
21242124
}
2125+
2126+
if (IndexType == NKikimrSchemeOp::EIndexType::EIndexTypeGlobalVectorKmeansTree) {
2127+
*index.MutableVectorIndexKmeansTreeDescription() = std::get<NKikimrSchemeOp::TVectorIndexKmeansTreeDescription>(SpecializedIndexDescription);
2128+
}
21252129
}
21262130

21272131
void TIndexBuildInfo::SerializeToProto(TSchemeShard* ss, NKikimrIndexBuilder::TColumnBuildSettings* result) const {

ydb/core/tx/schemeshard/schemeshard_info_types.h

+2
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,8 @@ struct TIndexBuildInfo: public TSimpleRefCount<TIndexBuildInfo> {
29272927
NTableIndex::TTableColumns ImplTableColumns;
29282928
TVector<NKikimrSchemeOp::TTableDescription> ImplTableDescriptions;
29292929

2930+
std::variant<std::monostate, NKikimrSchemeOp::TVectorIndexKmeansTreeDescription> SpecializedIndexDescription;
2931+
29302932
EState State = EState::Invalid;
29312933
TString Issue;
29322934

ydb/core/tx/schemeshard/schemeshard_utils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ NKikimrSchemeOp::TTableDescription CalcImplTableDesc(
451451
{
452452
NKikimrSchemeOp::TTableDescription implTableDesc;
453453

454-
implTableDesc.SetName("indexImplTable");
454+
implTableDesc.SetName(NTableIndex::ImplTable);
455455

456456
SetImplTablePartitionConfig(baseTableInfo->PartitionConfig(), indexTableDesc, implTableDesc);
457457

@@ -467,7 +467,7 @@ NKikimrSchemeOp::TTableDescription CalcImplTableDesc(
467467
{
468468
NKikimrSchemeOp::TTableDescription implTableDesc;
469469

470-
implTableDesc.SetName("indexImplTable");
470+
implTableDesc.SetName(NTableIndex::ImplTable);
471471

472472
SetImplTablePartitionConfig(baseTableDescr.GetPartitionConfig(), indexTableDesc, implTableDesc);
473473

0 commit comments

Comments
 (0)