Skip to content

Commit 561068e

Browse files
Test for info collector in Bridge Mode CMS (#20631)
1 parent 6ca983e commit 561068e

File tree

3 files changed

+78
-5
lines changed

3 files changed

+78
-5
lines changed

ydb/core/cms/cms_ut.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,49 @@ Y_UNIT_TEST_SUITE(TCmsTest) {
23532353
// Wall-E soft maintainance task can continue
23542354
env.CheckWalleCheckTask("task-1", TStatus::ALLOW, env.GetNodeId(2));
23552355
}
2356+
2357+
void ChangePileMap(TEvInterconnect::TEvNodesInfo::TPtr* ev) {
2358+
UNIT_ASSERT((*ev)->Get()->PileMap);
2359+
auto nodes = MakeIntrusive<TIntrusiveVector<TEvInterconnect::TNodeInfo>>((*ev)->Get()->Nodes);
2360+
auto pileMap = std::make_shared<TEvInterconnect::TEvNodesInfo::TPileMap>(*(*ev)->Get()->PileMap);
2361+
for (const auto& node : *nodes) {
2362+
pileMap->at(node.NodeId % pileMap->size()).push_back(node.NodeId);
2363+
}
2364+
2365+
auto newEv = IEventHandle::Downcast<TEvInterconnect::TEvNodesInfo>(
2366+
new IEventHandle((*ev)->Recipient, (*ev)->Sender, new TEvInterconnect::TEvNodesInfo(nodes, pileMap))
2367+
);
2368+
ev->Swap(newEv);
2369+
}
2370+
2371+
Y_UNIT_TEST(BridgeModeCollectInfo)
2372+
{
2373+
TTestEnvOpts opts(8);
2374+
TCmsTestEnv env(opts.WithBridgeMode());
2375+
2376+
auto observerFunc = [&](TAutoPtr<IEventHandle>& ev) {
2377+
if (ev->GetTypeRewrite() == TEvInterconnect::EvNodesInfo) {
2378+
auto *x = reinterpret_cast<TEvInterconnect::TEvNodesInfo::TPtr*>(&ev);
2379+
ChangePileMap(x);
2380+
}
2381+
return TTestActorRuntime::EEventAction::PROCESS;
2382+
};
2383+
env.SetObserverFunc(observerFunc);
2384+
2385+
env.Register(CreateInfoCollector(env.GetSender(), TDuration::Minutes(1)));
2386+
2387+
TAutoPtr<IEventHandle> handle;
2388+
auto reply = env.GrabEdgeEventRethrow<TCms::TEvPrivate::TEvClusterInfo>(handle);
2389+
UNIT_ASSERT(reply);
2390+
const auto &info = *reply->Info;
2391+
UNIT_ASSERT(info.IsBridgeMode);
2392+
UNIT_ASSERT(info.NodeIdToPileId.size() == 8);
2393+
2394+
for (const auto [nodeId, pileId] : info.NodeIdToPileId) {
2395+
UNIT_ASSERT(nodeId % opts.PileCount == pileId);
2396+
}
2397+
2398+
}
23562399
}
23572400

23582401
}

ydb/core/cms/cms_ut_common.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ static void SetupServices(TTestBasicRuntime &runtime, const TTestEnvOpts &option
565565
runtime.GetAppData().DynamicNameserviceConfig = dnsConfig;
566566
runtime.GetAppData().DisableCheckingSysNodesCms = true;
567567
runtime.GetAppData().BootstrapConfig = TFakeNodeWhiteboardService::BootstrapConfig;
568+
569+
if (options.IsBridgeMode) {
570+
for (ui32 pileId = 0; pileId < options.PileCount; ++pileId) {
571+
runtime.GetAppData().BridgeConfig->AddPiles()->SetName("r" + ToString(pileId));
572+
}
573+
}
568574

569575
NKikimrCms::TCmsConfig cmsConfig;
570576
cmsConfig.MutableSentinelConfig()->SetEnable(options.EnableSentinel);
@@ -622,11 +628,25 @@ TCmsTestEnv::TCmsTestEnv(const TTestEnvOpts &options)
622628
mallocInfo.SetParam("FillMemoryOnAllocation", "false");
623629
SetupLogging();
624630

625-
for (ui32 nodeIndex = 0; nodeIndex < GetNodeCount(); ++nodeIndex) {
626-
if (options.NRings > 1) {
627-
SetupCustomStateStorage(*this, options.NToSelect, options.NRings, options.RingSize);
628-
} else {
629-
SetupStateStorage(*this, nodeIndex);
631+
if (options.IsBridgeMode) {
632+
TVector<TStateStorageInfo::TRingGroup> ringGroups = {{.State = PRIMARY, .NToSelect = options.NToSelect}};
633+
std::fill_n(
634+
std::back_inserter(ringGroups),
635+
options.PileCount - 1,
636+
TStateStorageInfo::TRingGroup{.State = SYNCHRONIZED, .NToSelect = options.NToSelect}
637+
);
638+
auto setuper = CreateCustomStateStorageSetupper(ringGroups, options.NRings * options.RingSize);
639+
640+
for (ui32 nodeIndex = 0; nodeIndex < GetNodeCount(); ++nodeIndex) {
641+
setuper(*this, nodeIndex);
642+
}
643+
} else {
644+
for (ui32 nodeIndex = 0; nodeIndex < GetNodeCount(); ++nodeIndex) {
645+
if (options.NRings > 1) {
646+
SetupCustomStateStorage(*this, options.NToSelect, options.NRings, options.RingSize);
647+
} else {
648+
SetupStateStorage(*this, nodeIndex);
649+
}
630650
}
631651
}
632652
SetupServices(*this, options);

ydb/core/cms/cms_ut_common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ struct TTestEnvOpts {
8585
ui32 NRings;
8686
ui32 RingSize;
8787
ui32 DataCenterCount;
88+
ui32 PileCount;
8889
TNodeTenantsMap Tenants;
8990
bool UseMirror3dcErasure;
9091
bool AdvanceCurrentTime;
9192
bool EnableSentinel;
9293
bool EnableCMSRequestPriorities;
9394
bool EnableSingleCompositeActionGroup;
9495
bool EnableDynamicGroups;
96+
bool IsBridgeMode;
9597

9698
using TNodeLocationCallback = std::function<TNodeLocation(ui32)>;
9799
TNodeLocationCallback NodeLocationCallback;
@@ -107,13 +109,15 @@ struct TTestEnvOpts {
107109
, NRings(1)
108110
, RingSize(nodeCount)
109111
, DataCenterCount(1)
112+
, PileCount(0)
110113
, Tenants(tenants)
111114
, UseMirror3dcErasure(false)
112115
, AdvanceCurrentTime(false)
113116
, EnableSentinel(false)
114117
, EnableCMSRequestPriorities(true)
115118
, EnableSingleCompositeActionGroup(true)
116119
, EnableDynamicGroups(false)
120+
, IsBridgeMode(false)
117121
{
118122
}
119123

@@ -141,6 +145,12 @@ struct TTestEnvOpts {
141145
EnableDynamicGroups = true;
142146
return *this;
143147
}
148+
149+
TTestEnvOpts& WithBridgeMode(ui32 pileCount = 2) {
150+
IsBridgeMode = true;
151+
PileCount = pileCount;
152+
return *this;
153+
}
144154
};
145155

146156
class TCmsTestEnv : public TTestBasicRuntime {

0 commit comments

Comments
 (0)