|
| 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> |
@@ -1710,4 +1711,92 @@ Y_UNIT_TEST_SUITE(VectorIndexBuildTest) { |
1710 | 1711 | } |
1711 | 1712 | } |
1712 | 1713 |
|
| 1714 | + Y_UNIT_TEST(CreateBuildProposeReject) { |
| 1715 | + TTestBasicRuntime runtime; |
| 1716 | + TTestEnv env(runtime); |
| 1717 | + ui64 txId = 100; |
| 1718 | + |
| 1719 | + runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE); |
| 1720 | + runtime.SetLogPriority(NKikimrServices::BUILD_INDEX, NLog::PRI_TRACE); |
| 1721 | + |
| 1722 | + TestCreateTable(runtime, ++txId, "/MyRoot", R"( |
| 1723 | + Name: "vectors" |
| 1724 | + Columns { Name: "id" Type: "Uint64" } |
| 1725 | + Columns { Name: "embedding" Type: "String" } |
| 1726 | + KeyColumnNames: [ "id" ] |
| 1727 | + )"); |
| 1728 | + env.TestWaitNotification(runtime, txId); |
| 1729 | + |
| 1730 | + NYdb::NTable::TGlobalIndexSettings globalIndexSettings; |
| 1731 | + |
| 1732 | + std::unique_ptr<NYdb::NTable::TKMeansTreeSettings> kmeansTreeSettings; |
| 1733 | + { |
| 1734 | + Ydb::Table::KMeansTreeSettings proto; |
| 1735 | + UNIT_ASSERT(google::protobuf::TextFormat::ParseFromString(R"( |
| 1736 | + settings { |
| 1737 | + metric: DISTANCE_COSINE |
| 1738 | + vector_type: VECTOR_TYPE_FLOAT |
| 1739 | + vector_dimension: 1024 |
| 1740 | + } |
| 1741 | + levels: 5 |
| 1742 | + clusters: 4 |
| 1743 | + )", &proto)); |
| 1744 | + using T = NYdb::NTable::TKMeansTreeSettings; |
| 1745 | + kmeansTreeSettings = std::make_unique<T>(T::FromProto(proto)); |
| 1746 | + } |
| 1747 | + |
| 1748 | + const auto maxShards = DescribePath(runtime, TTestTxConfig::SchemeShard, "/MyRoot/vectors") |
| 1749 | + .GetPathDescription().GetDomainDescription().GetSchemeLimits().GetMaxShardsInPath(); |
| 1750 | + |
| 1751 | + TBlockEvents<TEvSchemeShard::TEvModifySchemeTransaction> blocker(runtime, [&](auto& ev) { |
| 1752 | + auto& modifyScheme = *ev->Get()->Record.MutableTransaction(0); |
| 1753 | + if (modifyScheme.GetOperationType() == NKikimrSchemeOp::ESchemeOpInitiateBuildIndexImplTable) { |
| 1754 | + auto& op = *modifyScheme.MutableCreateTable(); |
| 1755 | + // make shard count exceed the limit to fail the operation |
| 1756 | + op.SetUniformPartitionsCount(maxShards+1); |
| 1757 | + } |
| 1758 | + return false; |
| 1759 | + }); |
| 1760 | + |
| 1761 | + const ui64 buildIndexTx = ++txId; |
| 1762 | + AsyncBuildVectorIndex(runtime, buildIndexTx, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/vectors", "index1", {"embedding"}); |
| 1763 | + |
| 1764 | + env.TestWaitNotification(runtime, buildIndexTx); |
| 1765 | + |
| 1766 | + { |
| 1767 | + auto buildIndexOperation = TestGetBuildIndex(runtime, TTestTxConfig::SchemeShard, "/MyRoot", buildIndexTx); |
| 1768 | + Cout << "BuildIndex 1 " << buildIndexOperation.DebugString() << Endl; |
| 1769 | + UNIT_ASSERT_VALUES_EQUAL_C( |
| 1770 | + buildIndexOperation.GetIndexBuild().GetState(), Ydb::Table::IndexBuildState::STATE_REJECTED, |
| 1771 | + buildIndexOperation.DebugString() |
| 1772 | + ); |
| 1773 | + UNIT_ASSERT_STRING_CONTAINS(buildIndexOperation.DebugString(), "Invalid partition count specified"); |
| 1774 | + } |
| 1775 | + |
| 1776 | + blocker.Stop().Unblock(); |
| 1777 | + |
| 1778 | + { |
| 1779 | + auto result = ReadSystemTable(runtime, TTestTxConfig::SchemeShard, "SnapshotTables", {"Id", "TableOwnerId", "TableLocalId"}, {"Id"}); |
| 1780 | + auto value = NClient::TValue::Create(result); |
| 1781 | + auto rowCount = value["Result"]["List"].Size(); |
| 1782 | + UNIT_ASSERT_VALUES_EQUAL_C(rowCount, 0, "Snapshot is not removed after rejecting index build"); |
| 1783 | + } |
| 1784 | + |
| 1785 | + // The next index build should succeed |
| 1786 | + |
| 1787 | + const ui64 buildIndexTx2 = ++txId; |
| 1788 | + AsyncBuildVectorIndex(runtime, buildIndexTx2, TTestTxConfig::SchemeShard, "/MyRoot", "/MyRoot/vectors", "index1", {"embedding"}); |
| 1789 | + env.TestWaitNotification(runtime, buildIndexTx2); |
| 1790 | + |
| 1791 | + { |
| 1792 | + auto buildIndexOperation = TestGetBuildIndex(runtime, TTestTxConfig::SchemeShard, "/MyRoot", buildIndexTx2); |
| 1793 | + Cout << "BuildIndex 2 " << buildIndexOperation.DebugString() << Endl; |
| 1794 | + UNIT_ASSERT_VALUES_EQUAL_C( |
| 1795 | + buildIndexOperation.GetIndexBuild().GetState(), Ydb::Table::IndexBuildState::STATE_DONE, |
| 1796 | + buildIndexOperation.DebugString() |
| 1797 | + ); |
| 1798 | + } |
| 1799 | + |
| 1800 | + } |
| 1801 | + |
1713 | 1802 | } |
0 commit comments