Skip to content

Commit c087bd7

Browse files
authored
Fix index feature flags checking on SchemeShard (#23785)
1 parent 83d459f commit c087bd7

File tree

9 files changed

+51
-46
lines changed

9 files changed

+51
-46
lines changed

ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,7 +3713,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
37133713
auto result = db.ExecuteQuery(alterQuery, NYdb::NQuery::TTxControl::NoTx()).ExtractValueSync();
37143714

37153715
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::BAD_REQUEST, result.GetIssues().ToString());
3716-
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "building global unique index is disabled");
3716+
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Adding a unique index to an existing table is disabled");
37173717
}
37183718
}
37193719

@@ -3744,7 +3744,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
37443744
));
37453745
auto op = session.AlterTableLong("/Root/TestTable", settings).ExtractValueSync();
37463746
UNIT_ASSERT_VALUES_EQUAL_C(op.Status().GetStatus(), EStatus::BAD_REQUEST, op.Status().GetIssues().ToString());
3747-
UNIT_ASSERT_STRING_CONTAINS(op.Status().GetIssues().ToString(), "building global unique index is disabled");
3747+
UNIT_ASSERT_STRING_CONTAINS(op.Status().GetIssues().ToString(), "Adding a unique index to an existing table is disabled");
37483748
}
37493749
}
37503750

ydb/core/tx/schemeshard/schemeshard__operation_create_indexed_table.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,29 @@ TVector<ISubOperation::TPtr> CreateIndexedTable(TOperationId nextId, const TTxTr
241241
}
242242

243243
for (auto& indexDescription: indexedTable.GetIndexDescription()) {
244-
245-
if (indexDescription.GetType() == NKikimrSchemeOp::EIndexType::EIndexTypeGlobalVectorKmeansTree && !context.SS->EnableVectorIndex) {
246-
return {CreateReject(nextId, NKikimrScheme::EStatus::StatusPreconditionFailed, "Vector index support is disabled")};
244+
const auto indexType = indexDescription.HasType()
245+
? indexDescription.GetType()
246+
: NKikimrSchemeOp::EIndexTypeGlobal;
247+
248+
switch (indexType) {
249+
case NKikimrSchemeOp::EIndexTypeInvalid:
250+
return {CreateReject(nextId, NKikimrScheme::EStatus::StatusPreconditionFailed, "Invalid index type")};
251+
case NKikimrSchemeOp::EIndexTypeGlobal:
252+
case NKikimrSchemeOp::EIndexTypeGlobalAsync:
253+
// no feature flag, everything is fine
254+
break;
255+
case NKikimrSchemeOp::EIndexTypeGlobalUnique:
256+
if (!context.SS->EnableInitialUniqueIndex) {
257+
return {CreateReject(nextId, NKikimrScheme::EStatus::StatusPreconditionFailed, "Unique constraint feature is disabled")};
258+
}
259+
break;
260+
case NKikimrSchemeOp::EIndexTypeGlobalVectorKmeansTree:
261+
if (!context.SS->EnableVectorIndex) {
262+
return {CreateReject(nextId, NKikimrScheme::EStatus::StatusPreconditionFailed, "Vector index support is disabled")};
263+
}
264+
break;
247265
}
248266

249-
250267
{
251268
auto scheme = TransactionTemplate(
252269
tx.GetWorkingDir() + "/" + baseTableDescription.GetName(),
@@ -256,14 +273,7 @@ TVector<ISubOperation::TPtr> CreateIndexedTable(TOperationId nextId, const TTxTr
256273
scheme.SetInternal(tx.GetInternal());
257274

258275
scheme.MutableCreateTableIndex()->CopyFrom(indexDescription);
259-
if (!indexDescription.HasType()) {
260-
scheme.MutableCreateTableIndex()->SetType(NKikimrSchemeOp::EIndexTypeGlobal);
261-
} else if (!AppData()->FeatureFlags.GetEnableUniqConstraint()) {
262-
if (indexDescription.GetType() == NKikimrSchemeOp::EIndexTypeGlobalUnique) {
263-
TString msg = TStringBuilder() << "Unique constraint feature is disabled";
264-
return {CreateReject(nextId, NKikimrScheme::EStatus::StatusPreconditionFailed, msg)};
265-
}
266-
}
276+
scheme.MutableCreateTableIndex()->SetType(indexType);
267277

268278
result.push_back(CreateNewTableIndex(NextPartId(nextId, result), scheme));
269279
}

ydb/core/tx/schemeshard/schemeshard_build_index__create.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ class TSchemeShard::TIndexBuilder::TTxCreate: public TSchemeShard::TIndexBuilder
223223
const auto& index = settings.index();
224224

225225
switch (index.type_case()) {
226+
case Ydb::Table::TableIndex::TypeCase::TYPE_NOT_SET:
227+
explain = "Invalid or unset index type";
228+
return false;
226229
case Ydb::Table::TableIndex::TypeCase::kGlobalIndex:
227230
buildInfo.BuildKind = TIndexBuildInfo::EBuildKind::BuildSecondaryIndex;
228231
buildInfo.IndexType = NKikimrSchemeOp::EIndexType::EIndexTypeGlobal;
@@ -232,15 +235,18 @@ class TSchemeShard::TIndexBuilder::TTxCreate: public TSchemeShard::TIndexBuilder
232235
buildInfo.IndexType = NKikimrSchemeOp::EIndexType::EIndexTypeGlobalAsync;
233236
break;
234237
case Ydb::Table::TableIndex::TypeCase::kGlobalUniqueIndex:
235-
if (AppData()->FeatureFlags.GetEnableAddUniqueIndex()) {
236-
buildInfo.BuildKind = TIndexBuildInfo::EBuildKind::BuildSecondaryUniqueIndex;
237-
buildInfo.IndexType = NKikimrSchemeOp::EIndexType::EIndexTypeGlobalUnique;
238-
break;
239-
} else {
240-
explain = "building global unique index is disabled";
238+
if (!Self->EnableAddUniqueIndex) {
239+
explain = "Adding a unique index to an existing table is disabled";
241240
return false;
242241
}
242+
buildInfo.BuildKind = TIndexBuildInfo::EBuildKind::BuildSecondaryUniqueIndex;
243+
buildInfo.IndexType = NKikimrSchemeOp::EIndexType::EIndexTypeGlobalUnique;
244+
break;
243245
case Ydb::Table::TableIndex::TypeCase::kGlobalVectorKmeansTreeIndex: {
246+
if (!Self->EnableVectorIndex) {
247+
explain = "Vector index support is disabled";
248+
return false;
249+
}
244250
buildInfo.BuildKind = index.index_columns().size() == 1
245251
? TIndexBuildInfo::EBuildKind::BuildVectorIndex
246252
: TIndexBuildInfo::EBuildKind::BuildPrefixedVectorIndex;
@@ -257,9 +263,6 @@ class TSchemeShard::TIndexBuilder::TTxCreate: public TSchemeShard::TIndexBuilder
257263
}
258264
break;
259265
}
260-
case Ydb::Table::TableIndex::TypeCase::TYPE_NOT_SET:
261-
explain = "invalid or unset index type";
262-
return false;
263266
};
264267

265268
buildInfo.IndexName = index.name();

ydb/core/tx/schemeshard/schemeshard_impl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4950,6 +4950,8 @@ void TSchemeShard::OnActivateExecutor(const TActorContext &ctx) {
49504950
EnableReplaceIfExistsForExternalEntities = appData->FeatureFlags.GetEnableReplaceIfExistsForExternalEntities();
49514951
EnableTempTables = appData->FeatureFlags.GetEnableTempTables();
49524952
EnableVectorIndex = appData->FeatureFlags.GetEnableVectorIndex();
4953+
EnableInitialUniqueIndex = appData->FeatureFlags.GetEnableUniqConstraint();
4954+
EnableAddUniqueIndex = appData->FeatureFlags.GetEnableAddUniqueIndex();
49534955
EnableResourcePoolsOnServerless = appData->FeatureFlags.GetEnableResourcePoolsOnServerless();
49544956
EnableExternalDataSourcesOnServerless = appData->FeatureFlags.GetEnableExternalDataSourcesOnServerless();
49554957
EnableShred = appData->FeatureFlags.GetEnableDataErasure();
@@ -7666,6 +7668,8 @@ void TSchemeShard::ApplyConsoleConfigs(const NKikimrConfig::TFeatureFlags& featu
76667668
EnableReplaceIfExistsForExternalEntities = featureFlags.GetEnableReplaceIfExistsForExternalEntities();
76677669
EnableResourcePoolsOnServerless = featureFlags.GetEnableResourcePoolsOnServerless();
76687670
EnableVectorIndex = featureFlags.GetEnableVectorIndex();
7671+
EnableInitialUniqueIndex = featureFlags.GetEnableUniqConstraint();
7672+
EnableAddUniqueIndex = featureFlags.GetEnableAddUniqueIndex();
76697673
EnableExternalDataSourcesOnServerless = featureFlags.GetEnableExternalDataSourcesOnServerless();
76707674
EnableShred = featureFlags.GetEnableDataErasure();
76717675
EnableExternalSourceSchemaInference = featureFlags.GetEnableExternalSourceSchemaInference();

ydb/core/tx/schemeshard/schemeshard_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ class TSchemeShard
355355
bool EnableTempTables = false;
356356
bool EnableResourcePoolsOnServerless = false;
357357
bool EnableVectorIndex = false;
358+
bool EnableInitialUniqueIndex = false;
359+
bool EnableAddUniqueIndex = false;
358360
bool EnableExternalDataSourcesOnServerless = false;
359361
bool EnableShred = false;
360362
bool EnableExternalSourceSchemaInference = false;

ydb/core/tx/schemeshard/ut_helpers/test_env.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ NSchemeShardUT_Private::TTestEnv::TTestEnv(TTestActorRuntime& runtime, const TTe
594594
app.FeatureFlags.SetEnablePublicApiExternalBlobs(true);
595595
app.FeatureFlags.SetEnableTableDatetime64(true);
596596
app.FeatureFlags.SetEnableVectorIndex(true);
597+
app.FeatureFlags.SetEnableAddUniqueIndex(true);
597598
app.FeatureFlags.SetEnableColumnStore(true);
598599
app.FeatureFlags.SetEnableStrictAclCheck(opts.EnableStrictAclCheck_);
599600
app.SetEnableMoveIndex(opts.EnableMoveIndex_);

ydb/core/tx/schemeshard/ut_index_build/ut_index_build.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
196196
void BaseCase(NKikimrSchemeOp::EIndexType indexType) {
197197
TTestBasicRuntime runtime;
198198
TTestEnv env(runtime);
199-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
200199
ui64 txId = 100;
201200

202201
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
@@ -404,7 +403,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
404403
void CancellationNotEnoughRetries(NKikimrSchemeOp::EIndexType indexType) {
405404
TTestBasicRuntime runtime;
406405
TTestEnv env(runtime);
407-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
408406
ui64 txId = 100;
409407

410408
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
@@ -538,7 +536,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
538536
void CancellationNoTable(NKikimrSchemeOp::EIndexType indexType) {
539537
TTestBasicRuntime runtime;
540538
TTestEnv env(runtime);
541-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
542539
ui64 txId = 100;
543540

544541
TestBuildIndex(runtime, ++txId, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/Table", TBuildIndexConfig{"index1", indexType, {"index"}, {}}, Ydb::StatusIds::BAD_REQUEST);
@@ -559,7 +556,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
559556
void WithFollowers(NKikimrSchemeOp::EIndexType indexType) {
560557
TTestBasicRuntime runtime;
561558
TTestEnv env(runtime);
562-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
563559
ui64 txId = 100;
564560

565561
TestCreateTable(runtime, ++txId, "/MyRoot", R"(
@@ -623,7 +619,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
623619
void RejectsCreate(NKikimrSchemeOp::EIndexType indexType) {
624620
TTestBasicRuntime runtime;
625621
TTestEnv env(runtime, TTestEnvOptions().EnableProtoSourceIdInfo(true));
626-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
627622
ui64 txId = 100;
628623

629624
TestBuildIndex(runtime, ++txId, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/NotExist", TBuildIndexConfig{"index1", indexType, {"index"}, {}}, Ydb::StatusIds::BAD_REQUEST);
@@ -635,7 +630,7 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
635630
TestBuildIndex(runtime, ++txId, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/DIR", TBuildIndexConfig{"index1", indexType, {"index"}, {}}, Ydb::StatusIds::BAD_REQUEST);
636631
env.TestWaitNotification(runtime, txId);
637632

638-
TestCreateIndexedTable(runtime, ++txId, "/MyRoot", R"(
633+
TestCreateIndexedTable(runtime, ++txId, "/MyRoot", Sprintf(R"(
639634
TableDescription {
640635
Name: "Table"
641636
Columns { Name: "key" Type: "Uint64" }
@@ -646,13 +641,15 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
646641
}
647642
IndexDescription {
648643
Name: "UserDefinedIndexByValue0"
644+
Type: %s
649645
KeyColumnNames: ["value0"]
650646
}
651647
IndexDescription {
652648
Name: "UserDefinedIndexByValue1"
649+
Type: %s
653650
KeyColumnNames: ["value1"]
654651
}
655-
)");
652+
)", NKikimrSchemeOp::EIndexType_Name(indexType).c_str(), NKikimrSchemeOp::EIndexType_Name(indexType).c_str()));
656653
env.TestWaitNotification(runtime, txId);
657654

658655
// should not affect index limits
@@ -716,7 +713,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
716713
void CheckLimitWithDroppedIndex(NKikimrSchemeOp::EIndexType indexType) {
717714
TTestBasicRuntime runtime;
718715
TTestEnv env(runtime);
719-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
720716
ui64 txId = 100;
721717

722718
TSchemeLimits lowLimits;
@@ -755,7 +751,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
755751
void Lock(NKikimrSchemeOp::EIndexType indexType) {
756752
TTestBasicRuntime runtime;
757753
TTestEnv env(runtime);
758-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
759754
ui64 txId = 100;
760755

761756
// Just create main table
@@ -846,7 +841,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
846841
opts.EnableBackgroundCompaction(false);
847842
opts.DisableStatsBatching(true);
848843
TTestEnv env(runtime, opts);
849-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
850844

851845
NDataShard::gDbStatsReportInterval = TDuration::Seconds(0);
852846

@@ -1031,7 +1025,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
10311025
void IndexPartitioningIsPersisted(NKikimrSchemeOp::EIndexType indexType) {
10321026
TTestBasicRuntime runtime;
10331027
TTestEnv env(runtime);
1034-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
10351028
ui64 txId = 100;
10361029

10371030
TestCreateTable(runtime, ++txId, "/MyRoot", R"(
@@ -1112,10 +1105,8 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
11121105
void DropIndex(NKikimrSchemeOp::EIndexType indexType) {
11131106
TTestBasicRuntime runtime;
11141107
TTestEnv env(runtime);
1115-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
11161108
ui64 txId = 100;
11171109

1118-
const TString indexTypeStr = (indexType == NKikimrSchemeOp::EIndexType::EIndexTypeGlobal) ? "EIndexTypeGlobal" : "EIndexTypeGlobalUnique";
11191110
TestCreateIndexedTable(runtime, ++txId, "/MyRoot", Sprintf(R"(
11201111
TableDescription {
11211112
Name: "Table"
@@ -1134,7 +1125,7 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
11341125
Type: %s
11351126
KeyColumnNames: ["value1"]
11361127
}
1137-
)", indexTypeStr.c_str(), indexTypeStr.c_str()));
1128+
)", NKikimrSchemeOp::EIndexType_Name(indexType).c_str(), NKikimrSchemeOp::EIndexType_Name(indexType).c_str()));
11381129
env.TestWaitNotification(runtime, txId);
11391130

11401131
TestDescribeResult(DescribePath(runtime, "/MyRoot/Table"),
@@ -1196,10 +1187,8 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
11961187
void RejectsDropIndex(NKikimrSchemeOp::EIndexType indexType) {
11971188
TTestBasicRuntime runtime;
11981189
TTestEnv env(runtime);
1199-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
12001190
ui64 txId = 100;
12011191

1202-
const TString indexTypeStr = (indexType == NKikimrSchemeOp::EIndexType::EIndexTypeGlobal) ? "EIndexTypeGlobal" : "EIndexTypeGlobalUnique";
12031192
TestCreateIndexedTable(runtime, ++txId, "/MyRoot", Sprintf(R"(
12041193
TableDescription {
12051194
Name: "Table"
@@ -1213,7 +1202,7 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
12131202
Type: %s
12141203
KeyColumnNames: ["value0"]
12151204
}
1216-
)", indexTypeStr.c_str()));
1205+
)", NKikimrSchemeOp::EIndexType_Name(indexType).c_str()));
12171206
env.TestWaitNotification(runtime, txId);
12181207

12191208
TestDescribeResult(DescribePath(runtime, "/MyRoot/Table"),
@@ -1281,7 +1270,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
12811270
void CancelBuild(NKikimrSchemeOp::EIndexType indexType) {
12821271
TTestBasicRuntime runtime;
12831272
TTestEnv env(runtime);
1284-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
12851273
ui64 txId = 100;
12861274

12871275
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
@@ -1356,7 +1344,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
13561344
void RejectsCancel(NKikimrSchemeOp::EIndexType indexType) {
13571345
TTestBasicRuntime runtime;
13581346
TTestEnv env(runtime);
1359-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
13601347
ui64 txId = 100;
13611348

13621349
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
@@ -1494,7 +1481,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
14941481
void RejectsOnDuplicatesUniq(bool crossShardDuplicates) {
14951482
TTestBasicRuntime runtime;
14961483
TTestEnv env(runtime);
1497-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
14981484
ui64 txId = 100;
14991485

15001486
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
@@ -1575,7 +1561,6 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
15751561
Y_UNIT_TEST(NullsAreUniq) {
15761562
TTestBasicRuntime runtime;
15771563
TTestEnv env(runtime);
1578-
runtime.GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
15791564
ui64 txId = 100;
15801565

15811566
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);

ydb/services/ydb/backup_ut/ydb_backup_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,7 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
25322532
: Server([&] {
25332533
NKikimrConfig::TAppConfig appConfig;
25342534
appConfig.MutableFeatureFlags()->SetEnableVectorIndex(true);
2535+
appConfig.MutableFeatureFlags()->SetEnableAddUniqueIndex(true);
25352536
return appConfig;
25362537
}())
25372538
, Driver(TDriverConfig().SetEndpoint(Sprintf("localhost:%u", Server.GetPort())))
@@ -2908,7 +2909,6 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
29082909

29092910
void TestTableWithIndexBackupRestore(NKikimrSchemeOp::EIndexType indexType = NKikimrSchemeOp::EIndexTypeGlobal, bool prefix = false) {
29102911
TS3TestEnv testEnv;
2911-
testEnv.GetServer().GetRuntime()->GetAppData().FeatureFlags.SetEnableAddUniqueIndex(true);
29122912
constexpr const char* table = "/Root/table";
29132913
constexpr const char* index = "value_idx";
29142914

ydb/services/ydb/ydb_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ Y_UNIT_TEST_SUITE(TGRpcYdbTest) {
13081308
UNIT_ASSERT(deferred.status() == Ydb::StatusIds::BAD_REQUEST);
13091309
NYdb::NIssue::TIssues issues;
13101310
NYdb::NIssue::IssuesFromMessage(deferred.issues(), issues);
1311-
UNIT_ASSERT(issues.ToString().contains("invalid or unset index type"));
1311+
UNIT_ASSERT(issues.ToString().contains("Invalid or unset index type"));
13121312
}
13131313
}
13141314

0 commit comments

Comments
 (0)