|
| 1 | +#include <ydb/core/testlib/tablet_helpers.h> |
| 2 | + |
| 3 | +#include <ydb/core/base/tablet_resolver.h> |
| 4 | +#include <ydb/core/base/statestorage_impl.h> |
| 5 | +#include <ydb/core/blobstorage/nodewarden/node_warden.h> |
| 6 | +#include <ydb/core/blobstorage/nodewarden/node_warden_impl.h> |
| 7 | +#include <ydb/core/blobstorage/base/blobstorage_events.h> |
| 8 | +#include <ydb/core/blobstorage/pdisk/blobstorage_pdisk_tools.h> |
| 9 | +#include <ydb/core/blobstorage/pdisk/blobstorage_pdisk_ut_http_request.h> |
| 10 | +#include <ydb/core/mind/bscontroller/bsc.h> |
| 11 | +#include <ydb/core/util/actorsys_test/testactorsys.h> |
| 12 | + |
| 13 | +#include <ydb/library/pdisk_io/sector_map.h> |
| 14 | +#include <ydb/core/util/random.h> |
| 15 | + |
| 16 | +#include <google/protobuf/text_format.h> |
| 17 | +#include <library/cpp/testing/unittest/registar.h> |
| 18 | + |
| 19 | +#include <ydb/core/blobstorage/nodewarden/distconf.h> |
| 20 | + |
| 21 | +namespace NKikimr { |
| 22 | +namespace NBlobStorageNodeWardenTest{ |
| 23 | + |
| 24 | +Y_UNIT_TEST_SUITE(TDistconfGenerateConfigTest) { |
| 25 | + |
| 26 | + NKikimrConfig::TDomainsConfig::TStateStorage GenerateSimpleStateStorage(ui32 nodes) { |
| 27 | + NKikimrConfig::TDomainsConfig::TStateStorage ss; |
| 28 | + NKikimrBlobStorage::TStorageConfig config; |
| 29 | + for (ui32 i : xrange(nodes)) { |
| 30 | + auto *node = config.AddAllNodes(); |
| 31 | + node->SetNodeId(i + 1); |
| 32 | + } |
| 33 | + NKikimr::NStorage::TDistributedConfigKeeper keeper(nullptr, config, true); |
| 34 | + keeper.GenerateStateStorageConfig(&ss, config); |
| 35 | + return ss; |
| 36 | + } |
| 37 | + |
| 38 | + NKikimrConfig::TDomainsConfig::TStateStorage GenerateDCStateStorage(ui32 dcCnt, ui32 racksCnt, ui32 nodesInRack) { |
| 39 | + NKikimrBlobStorage::TStorageConfig config; |
| 40 | + ui32 nodeId = 1; |
| 41 | + for (ui32 dc : xrange(dcCnt)) { |
| 42 | + for (ui32 rack : xrange(racksCnt)) { |
| 43 | + for (auto _ : xrange(nodesInRack)) { |
| 44 | + auto *node = config.AddAllNodes(); |
| 45 | + node->SetNodeId(nodeId++); |
| 46 | + node->MutableLocation()->SetDataCenter("dc-" + std::to_string(dc)); |
| 47 | + node->MutableLocation()->SetRack(std::to_string(rack)); |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + NKikimrConfig::TDomainsConfig::TStateStorage ss; |
| 52 | + NKikimr::NStorage::TDistributedConfigKeeper keeper(nullptr, config, true); |
| 53 | + keeper.GenerateStateStorageConfig(&ss, config); |
| 54 | + return ss; |
| 55 | + } |
| 56 | + |
| 57 | + void CheckStateStorage(const NKikimrConfig::TDomainsConfig::TStateStorage& ss, ui32 nToSelect, const std::unordered_set<ui32>& nodes) { |
| 58 | + auto &rg = ss.GetRing(); |
| 59 | + Cerr << "Actual: " << ss << " Expected: NToSelect: " << nToSelect << Endl; |
| 60 | + UNIT_ASSERT_EQUAL(rg.GetNToSelect(), nToSelect); |
| 61 | + UNIT_ASSERT_EQUAL(rg.NodeSize(), nodes.size()); |
| 62 | + std::unordered_set<ui32> usedNodes; |
| 63 | + for (ui32 i : xrange(nodes.size())) { |
| 64 | + auto n = rg.GetNode(i); |
| 65 | + UNIT_ASSERT(nodes.contains(n)); |
| 66 | + UNIT_ASSERT(usedNodes.insert(n).second); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + Y_UNIT_TEST(GenerateConfigSimpleCases) { |
| 71 | + CheckStateStorage(GenerateSimpleStateStorage(1), 1, {1}); |
| 72 | + CheckStateStorage(GenerateSimpleStateStorage(2), 1, {1, 2}); |
| 73 | + CheckStateStorage(GenerateSimpleStateStorage(3), 3, {1, 2, 3}); |
| 74 | + CheckStateStorage(GenerateSimpleStateStorage(8), 5, {1, 2, 3, 4, 5, 6, 7, 8}); |
| 75 | + CheckStateStorage(GenerateSimpleStateStorage(9), 5, {1, 2, 3, 4, 5, 6, 7, 8}); |
| 76 | + CheckStateStorage(GenerateDCStateStorage(1, 1, 20), 5, {1, 2, 3, 4, 5, 6, 7, 8}); |
| 77 | + CheckStateStorage(GenerateDCStateStorage(1, 10, 5), 5, {1, 6, 11, 16, 21, 26, 31, 36}); |
| 78 | + } |
| 79 | + |
| 80 | + Y_UNIT_TEST(GenerateConfig3DCCases) { |
| 81 | + CheckStateStorage(GenerateDCStateStorage(3, 1, 1), 3, {1, 2, 3}); |
| 82 | + CheckStateStorage(GenerateDCStateStorage(3, 1, 2), 3, {1, 3, 5}); |
| 83 | + CheckStateStorage(GenerateDCStateStorage(3, 1, 3), 9, {1, 2, 3, 4, 5, 6, 7, 8, 9}); |
| 84 | + CheckStateStorage(GenerateDCStateStorage(3, 1, 18), 9, {1, 2, 3, 19, 20, 21, 37, 38, 39}); |
| 85 | + CheckStateStorage(GenerateDCStateStorage(3, 3, 3), 9, {1, 4, 7, 10, 13, 16, 19, 22, 25}); |
| 86 | + } |
| 87 | +} |
| 88 | +} |
| 89 | +} |
0 commit comments