Skip to content

Commit f7a4f78

Browse files
authored
Merge bf6f316 into 19153a4
2 parents 19153a4 + bf6f316 commit f7a4f78

11 files changed

+57
-23
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/grpc_services/rpc_describe_table.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "service_table.h"
88
#include "rpc_common/rpc_common.h"
9+
#include <ydb/core/base/table_index.h>
910
#include <ydb/core/tx/schemeshard/schemeshard.h>
1011
#include <ydb/core/ydb_convert/table_description.h>
1112
#include <ydb/core/ydb_convert/ydb_convert.h>
@@ -153,7 +154,7 @@ class TDescribeTableRPC : public TRpcSchemeRequestActor<TDescribeTableRPC, TEvDe
153154
record->MutableOptions()->SetReturnPartitionStats(true);
154155
}
155156

156-
if (AppData(ctx)->AllowPrivateTableDescribeForTest || path.EndsWith("/indexImplTable")) {
157+
if (AppData(ctx)->AllowPrivateTableDescribeForTest || path.EndsWith(TStringBuilder() << "/" << NTableIndex::ImplTable)) {
157158
record->MutableOptions()->SetShowPrivateTable(true);
158159
}
159160

ydb/core/kqp/gateway/utils/scheme_helpers.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "scheme_helpers.h"
22

33
#include <ydb/core/base/path.h>
4+
#include <ydb/core/base/table_index.h>
45
#include <ydb/core/protos/external_sources.pb.h>
56

67
namespace NKikimr::NKqp::NSchemeHelpers {
@@ -46,7 +47,7 @@ bool SplitTablePath(const TString& tableName, const TString& database, std::pair
4647
}
4748

4849
TString CreateIndexTablePath(const TString& tableName, const TString& indexName) {
49-
return tableName + "/" + indexName + "/indexImplTable";
50+
return tableName + "/" + indexName + "/" + NTableIndex::ImplTable;
5051
}
5152

5253
bool SetDatabaseForLoginOperation(TString& result, bool getDomainLoginOnly, TMaybe<TString> domainName,

ydb/core/tx/schemeshard/schemeshard__operation_apply_build_index.cpp

+20-12
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;
@@ -106,10 +114,10 @@ TVector<ISubOperation::TPtr> CancelBuildIndex(TOperationId nextId, const TTxTran
106114

107115
if (!indexName.empty()) {
108116
TPath index = table.Child(indexName);
109-
Y_ABORT_UNLESS(index.Base()->GetChildren().size() == 1);
117+
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_part.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,8 @@ ISubOperation::TPtr CascadeDropTableChildren(TVector<ISubOperation::TPtr>& resul
152152
}
153153

154154
for (auto& [implName, implPathId] : child.Base()->GetChildren()) {
155-
Y_ABORT_UNLESS(implName == "indexImplTable"
155+
Y_ABORT_UNLESS(NTableIndex::IsImplTable(implName)
156156
|| implName == "streamImpl"
157-
|| implName == NTableIndex::NTableVectorKmeansTreeIndex::LevelTable
158-
|| implName == NTableIndex::NTableVectorKmeansTreeIndex::PostingTable
159157
, "unexpected name %s", implName.c_str());
160158

161159
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

+8-1
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
}
@@ -314,7 +321,7 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
314321
}
315322

316323
if (buildInfo->ImplTablePath.Empty() && buildInfo->IsBuildIndex()) {
317-
TPath implTable = TPath::Init(buildInfo->TablePathId, Self).Dive(buildInfo->IndexName).Dive("indexImplTable");
324+
TPath implTable = TPath::Init(buildInfo->TablePathId, Self).Dive(buildInfo->IndexName).Dive(NTableIndex::ImplTable);
318325
buildInfo->ImplTablePath = implTable.PathString();
319326

320327
TTableInfo::TPtr implTableInfo = Self->Tables.at(implTable.Base()->PathId);

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)