diff options
author | Ilia Shakhov <pixcc@ydb.tech> | 2024-12-20 13:36:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-20 10:36:31 +0000 |
commit | 0134f44cd5fcd8e83924e2223593eaf51e1259a9 (patch) | |
tree | 89de3b21c7200bb1ef47e9808efb380edd609269 | |
parent | 7c90d7cf0e8c1c62b12b631297e3e3fe9ceb23ea (diff) | |
download | ydb-0134f44cd5fcd8e83924e2223593eaf51e1259a9.tar.gz |
Make `ListNodesCache` persistent between different `ListNodes` batches (#12813)
-rw-r--r-- | ydb/core/mind/dynamic_nameserver.cpp | 2 | ||||
-rw-r--r-- | ydb/core/mind/node_broker_ut.cpp | 50 |
2 files changed, 44 insertions, 8 deletions
diff --git a/ydb/core/mind/dynamic_nameserver.cpp b/ydb/core/mind/dynamic_nameserver.cpp index afd8dd2f16..cc6ccce004 100644 --- a/ydb/core/mind/dynamic_nameserver.cpp +++ b/ydb/core/mind/dynamic_nameserver.cpp @@ -237,7 +237,7 @@ void TDynamicNameserver::SendNodesList(const TActorContext &ctx) auto now = ctx.Now(); if (ListNodesCache->NeedUpdate(now)) { auto newNodes = MakeIntrusive<TIntrusiveVector<TEvInterconnect::TNodeInfo>>(); - auto newExpire = now; + auto newExpire = TInstant::Max(); for (const auto &pr : StaticConfig->StaticNodeTable) { newNodes->emplace_back(pr.first, diff --git a/ydb/core/mind/node_broker_ut.cpp b/ydb/core/mind/node_broker_ut.cpp index 1fa568f205..9330514a5e 100644 --- a/ydb/core/mind/node_broker_ut.cpp +++ b/ydb/core/mind/node_broker_ut.cpp @@ -622,20 +622,25 @@ void CheckResolveUnknownNode(TTestActorRuntime &runtime, UNIT_ASSERT(reply->Addresses.empty()); } +THolder<TEvInterconnect::TEvNodesInfo> GetNameserverNodesListEv(TTestActorRuntime &runtime, TActorId sender) { + runtime.Send(new IEventHandle(GetNameserviceActorId(), sender, new TEvInterconnect::TEvListNodes)); + + TAutoPtr<IEventHandle> handle; + auto reply = runtime.GrabEdgeEventRethrow<TEvInterconnect::TEvNodesInfo>(handle); + UNIT_ASSERT(reply); + + return IEventHandle::Release<TEvInterconnect::TEvNodesInfo>(handle); +} + void GetNameserverNodesList(TTestActorRuntime &runtime, TActorId sender, THashMap<ui32, TEvInterconnect::TNodeInfo> &nodes, bool includeStatic) { ui32 maxStaticNodeId = runtime.GetAppData().DynamicNameserviceConfig->MaxStaticNodeId; - TAutoPtr<TEvInterconnect::TEvListNodes> event = new TEvInterconnect::TEvListNodes; - runtime.Send(new IEventHandle(GetNameserviceActorId(), sender, event.Release())); - - TAutoPtr<IEventHandle> handle; - auto reply = runtime.GrabEdgeEventRethrow<TEvInterconnect::TEvNodesInfo>(handle); - UNIT_ASSERT(reply); + auto ev = GetNameserverNodesListEv(runtime, sender); - for (auto &node : reply->Nodes) + for (auto &node : ev->Nodes) if (includeStatic || node.NodeId > maxStaticNodeId) nodes.emplace(node.NodeId, node); } @@ -1722,6 +1727,37 @@ Y_UNIT_TEST_SUITE(TDynamicNameserverTest) { CheckResolveNode(runtime, sender, NODE2, "1.2.3.5"); UNIT_ASSERT_VALUES_EQUAL(resolveRequests.size(), 3); } + + Y_UNIT_TEST(ListNodesCacheWhenNoChanges) { + TTestBasicRuntime runtime(1, false); + Setup(runtime); + TActorId sender = runtime.AllocateEdgeActor(); + + // Add one dynamic node in addition to one static node + CheckRegistration(runtime, sender, "host1", 1001, "host1.host1.host1", "1.2.3.4", + 1, 2, 3, 4, TStatus::OK, NODE1); + + // Make ListNodes requests that are not batched + auto ev1 = GetNameserverNodesListEv(runtime, sender); + UNIT_ASSERT_VALUES_EQUAL(ev1->Nodes.size(), 2); + + auto ev2 = GetNameserverNodesListEv(runtime, sender); + UNIT_ASSERT_VALUES_EQUAL(ev2->Nodes.size(), 2); + + // No changes, so ListNodesCache must be the same + UNIT_ASSERT_VALUES_EQUAL(ev1->NodesPtr.Get(), ev2->NodesPtr.Get()); + + // Add new dynamic node + CheckRegistration(runtime, sender, "host2", 1001, "host2.host2.host2", "1.2.3.5", + 1, 2, 3, 5, TStatus::OK, NODE2); + + // Make one more ListNodes request + auto ev3 = GetNameserverNodesListEv(runtime, sender); + UNIT_ASSERT_VALUES_EQUAL(ev3->Nodes.size(), 3); + + // When changes are made, a new ListNodesCache is allocated + UNIT_ASSERT_VALUES_UNEQUAL(ev2->NodesPtr.Get(), ev3->NodesPtr.Get()); + } } Y_UNIT_TEST_SUITE(TSlotIndexesPoolTest) { |