Skip to content

Commit 01587a0

Browse files
authored
[25-3] Allow to try to cancel broken index builds (#30931)
2 parents 87f7dab + ac50c52 commit 01587a0

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

ydb/core/tx/schemeshard/schemeshard_build_index__cancel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ struct TSchemeShard::TIndexBuilder::TTxCancel: public TSchemeShard::TIndexBuilde
6565

6666
NIceDb::TNiceDb db(txc.DB);
6767
indexBuildInfo.CancelRequested = true;
68+
indexBuildInfo.IsBroken = false; // allow to recover by cancelling broken index builds
69+
if (indexBuildInfo.State == TIndexBuildInfo::EState::Invalid) {
70+
indexBuildInfo.State = TIndexBuildInfo::EState::Filling;
71+
}
6872
Self->PersistBuildIndexCancelRequest(db, indexBuildInfo);
6973

7074
Progress(indexBuildInfo.Id);

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

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,17 +1504,13 @@ Y_UNIT_TEST_SUITE(VectorIndexBuildTest) {
15041504
auto buildIndexHtml = TestGetBuildIndexHtml(runtime, TTestTxConfig::SchemeShard, buildIndexTx);
15051505
Cout << "BuildIndex 3 " << buildIndexOperation.DebugString() << Endl << buildIndexHtml << Endl;
15061506
UNIT_ASSERT_VALUES_EQUAL_C(
1507-
buildIndexOperation.GetIndexBuild().GetState(), Ydb::Table::IndexBuildState::STATE_TRANSFERING_DATA,
1507+
buildIndexOperation.GetIndexBuild().GetState(), Ydb::Table::IndexBuildState::STATE_CANCELLATION,
15081508
buildIndexOperation.DebugString()
15091509
);
1510-
UNIT_ASSERT_STRING_CONTAINS(buildIndexHtml, "IsBroken: YES");
1510+
UNIT_ASSERT_STRING_CONTAINS(buildIndexHtml, "IsBroken: NO");
15111511
UNIT_ASSERT_STRING_CONTAINS(buildIndexHtml, "CancelRequested: YES");
15121512
}
15131513

1514-
// but we need to turn EnableVectorIndex back to progress:
1515-
runtime.GetAppData().FeatureFlags.SetEnableVectorIndex(true);
1516-
RebootTablet(runtime, TTestTxConfig::SchemeShard, runtime.AllocateEdgeActor());
1517-
15181514
env.TestWaitNotification(runtime, buildIndexTx);
15191515

15201516
{
@@ -1610,14 +1606,7 @@ Y_UNIT_TEST_SUITE(VectorIndexBuildTest) {
16101606
}
16111607
}
16121608

1613-
Y_UNIT_TEST(UnknownState) {
1614-
TTestBasicRuntime runtime;
1615-
TTestEnv env(runtime);
1616-
ui64 txId = 100;
1617-
1618-
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
1619-
runtime.SetLogPriority(NKikimrServices::BUILD_INDEX, NLog::PRI_TRACE);
1620-
1609+
ui64 DoCreateBrokenIndex(TTestBasicRuntime& runtime, TTestEnv& env, ui64& txId) {
16211610
TestCreateTable(runtime, ++txId, "/MyRoot", R"(
16221611
Name: "vectors"
16231612
Columns { Name: "id" Type: "Uint64" }
@@ -1683,6 +1672,19 @@ Y_UNIT_TEST_SUITE(VectorIndexBuildTest) {
16831672
UNIT_ASSERT_STRING_CONTAINS(buildIndexHtml, "IsBroken: YES");
16841673
}
16851674

1675+
return buildIndexTx;
1676+
}
1677+
1678+
Y_UNIT_TEST(UnknownState) {
1679+
TTestBasicRuntime runtime;
1680+
TTestEnv env(runtime);
1681+
ui64 txId = 100;
1682+
1683+
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
1684+
runtime.SetLogPriority(NKikimrServices::BUILD_INDEX, NLog::PRI_TRACE);
1685+
1686+
const ui64 buildIndexTx = DoCreateBrokenIndex(runtime, env, txId);
1687+
16861688
{
16871689
// set a known State but unknown SubState
16881690
TString writeQuery = Sprintf(R"(
@@ -1742,6 +1744,29 @@ Y_UNIT_TEST_SUITE(VectorIndexBuildTest) {
17421744
}
17431745
}
17441746

1747+
Y_UNIT_TEST(CancelBroken) {
1748+
TTestBasicRuntime runtime;
1749+
TTestEnv env(runtime);
1750+
ui64 txId = 100;
1751+
1752+
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
1753+
runtime.SetLogPriority(NKikimrServices::BUILD_INDEX, NLog::PRI_TRACE);
1754+
1755+
const ui64 buildIndexTx = DoCreateBrokenIndex(runtime, env, txId);
1756+
1757+
const ui64 cancelTxId = ++txId;
1758+
TestCancelBuildIndex(runtime, cancelTxId, TTestTxConfig::SchemeShard, "/MyRoot", buildIndexTx);
1759+
env.TestWaitNotification(runtime, buildIndexTx);
1760+
1761+
auto descr = TestGetBuildIndex(runtime, TTestTxConfig::SchemeShard, "/MyRoot", buildIndexTx);
1762+
Y_ASSERT(descr.GetIndexBuild().GetState() == Ydb::Table::IndexBuildState::STATE_CANCELLED);
1763+
1764+
// Check that another index is built successfully (i.e. the table is not left in a locked state)
1765+
const ui64 buildIndex2Tx = ++txId;
1766+
AsyncBuildVectorIndex(runtime, buildIndex2Tx, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/vectors", "index1", {"embedding"});
1767+
env.TestWaitNotification(runtime, buildIndex2Tx);
1768+
}
1769+
17451770
Y_UNIT_TEST(CreateBuildProposeReject) {
17461771
TTestBasicRuntime runtime;
17471772
TTestEnv env(runtime);

0 commit comments

Comments
 (0)