|
| 1 | +#include <ydb/public/lib/deprecated/kicli/kicli.h> |
1 | 2 | #include <ydb/core/base/table_index.h> |
2 | 3 | #include <ydb/core/protos/schemeshard/operations.pb.h> |
3 | 4 | #include <ydb/core/tx/schemeshard/ut_helpers/helpers.h> |
@@ -1577,4 +1578,92 @@ Y_UNIT_TEST_SUITE(VectorIndexBuildTest) { |
1577 | 1578 | UNIT_ASSERT_STRING_CONTAINS(buildIndexOperation.DebugString(), "Processed: UploadRows: 0 UploadBytes: 0 ReadRows: 0 ReadBytes: 0"); |
1578 | 1579 | } |
1579 | 1580 | } |
| 1581 | + |
| 1582 | + Y_UNIT_TEST(CreateBuildProposeReject) { |
| 1583 | + TTestBasicRuntime runtime; |
| 1584 | + TTestEnv env(runtime); |
| 1585 | + ui64 txId = 100; |
| 1586 | + |
| 1587 | + runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE); |
| 1588 | + runtime.SetLogPriority(NKikimrServices::BUILD_INDEX, NLog::PRI_TRACE); |
| 1589 | + |
| 1590 | + TestCreateTable(runtime, ++txId, "/MyRoot", R"( |
| 1591 | + Name: "vectors" |
| 1592 | + Columns { Name: "id" Type: "Uint64" } |
| 1593 | + Columns { Name: "embedding" Type: "String" } |
| 1594 | + KeyColumnNames: [ "id" ] |
| 1595 | + )"); |
| 1596 | + env.TestWaitNotification(runtime, txId); |
| 1597 | + |
| 1598 | + NYdb::NTable::TGlobalIndexSettings globalIndexSettings; |
| 1599 | + |
| 1600 | + std::unique_ptr<NYdb::NTable::TKMeansTreeSettings> kmeansTreeSettings; |
| 1601 | + { |
| 1602 | + Ydb::Table::KMeansTreeSettings proto; |
| 1603 | + UNIT_ASSERT(google::protobuf::TextFormat::ParseFromString(R"( |
| 1604 | + settings { |
| 1605 | + metric: DISTANCE_COSINE |
| 1606 | + vector_type: VECTOR_TYPE_FLOAT |
| 1607 | + vector_dimension: 1024 |
| 1608 | + } |
| 1609 | + levels: 5 |
| 1610 | + clusters: 4 |
| 1611 | + )", &proto)); |
| 1612 | + using T = NYdb::NTable::TKMeansTreeSettings; |
| 1613 | + kmeansTreeSettings = std::make_unique<T>(T::FromProto(proto)); |
| 1614 | + } |
| 1615 | + |
| 1616 | + const auto maxShards = DescribePath(runtime, TTestTxConfig::SchemeShard, "/MyRoot/vectors") |
| 1617 | + .GetPathDescription().GetDomainDescription().GetSchemeLimits().GetMaxShardsInPath(); |
| 1618 | + |
| 1619 | + TBlockEvents<TEvSchemeShard::TEvModifySchemeTransaction> blocker(runtime, [&](auto& ev) { |
| 1620 | + auto& modifyScheme = *ev->Get()->Record.MutableTransaction(0); |
| 1621 | + if (modifyScheme.GetOperationType() == NKikimrSchemeOp::ESchemeOpInitiateBuildIndexImplTable) { |
| 1622 | + auto& op = *modifyScheme.MutableCreateTable(); |
| 1623 | + // make shard count exceed the limit to fail the operation |
| 1624 | + op.SetUniformPartitionsCount(maxShards+1); |
| 1625 | + } |
| 1626 | + return false; |
| 1627 | + }); |
| 1628 | + |
| 1629 | + const ui64 buildIndexTx = ++txId; |
| 1630 | + AsyncBuildVectorIndex(runtime, buildIndexTx, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/vectors", "index1", {"embedding"}); |
| 1631 | + |
| 1632 | + env.TestWaitNotification(runtime, buildIndexTx); |
| 1633 | + |
| 1634 | + { |
| 1635 | + auto buildIndexOperation = TestGetBuildIndex(runtime, TTestTxConfig::SchemeShard, "/MyRoot", buildIndexTx); |
| 1636 | + Cout << "BuildIndex 1 " << buildIndexOperation.DebugString() << Endl; |
| 1637 | + UNIT_ASSERT_VALUES_EQUAL_C( |
| 1638 | + buildIndexOperation.GetIndexBuild().GetState(), Ydb::Table::IndexBuildState::STATE_REJECTED, |
| 1639 | + buildIndexOperation.DebugString() |
| 1640 | + ); |
| 1641 | + UNIT_ASSERT_STRING_CONTAINS(buildIndexOperation.DebugString(), "Invalid partition count specified"); |
| 1642 | + } |
| 1643 | + |
| 1644 | + blocker.Stop().Unblock(); |
| 1645 | + |
| 1646 | + { |
| 1647 | + auto result = ReadSystemTable(runtime, TTestTxConfig::SchemeShard, "SnapshotTables", {"Id", "TableOwnerId", "TableLocalId"}, {"Id"}); |
| 1648 | + auto value = NClient::TValue::Create(result); |
| 1649 | + auto rowCount = value["Result"]["List"].Size(); |
| 1650 | + UNIT_ASSERT_VALUES_EQUAL_C(rowCount, 0, "Snapshot is not removed after rejecting index build"); |
| 1651 | + } |
| 1652 | + |
| 1653 | + // The next index build should succeed |
| 1654 | + |
| 1655 | + const ui64 buildIndexTx2 = ++txId; |
| 1656 | + AsyncBuildVectorIndex(runtime, buildIndexTx2, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/vectors", "index1", {"embedding"}); |
| 1657 | + env.TestWaitNotification(runtime, buildIndexTx2); |
| 1658 | + |
| 1659 | + { |
| 1660 | + auto buildIndexOperation = TestGetBuildIndex(runtime, TTestTxConfig::SchemeShard, "/MyRoot", buildIndexTx2); |
| 1661 | + Cout << "BuildIndex 2 " << buildIndexOperation.DebugString() << Endl; |
| 1662 | + UNIT_ASSERT_VALUES_EQUAL_C( |
| 1663 | + buildIndexOperation.GetIndexBuild().GetState(), Ydb::Table::IndexBuildState::STATE_DONE, |
| 1664 | + buildIndexOperation.DebugString() |
| 1665 | + ); |
| 1666 | + } |
| 1667 | + |
| 1668 | + } |
1580 | 1669 | } |
0 commit comments