Skip to content

Commit

Permalink
pdisk filter
Browse files Browse the repository at this point in the history
  • Loading branch information
StekPerepolnen committed Apr 12, 2024
1 parent 77c6779 commit e029ee3
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
1 change: 1 addition & 0 deletions ydb/core/viewer/json_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class TJsonStorage : public TJsonStorageBase {
}

void Bootstrap() override {
Cerr << "iiiii Bootstrap" << Endl;
TIntrusivePtr<TDomainsInfo> domains = AppData()->DomainsInfo;
ui64 hiveId = domains->GetHive();
if (hiveId != TDomainsInfo::BadTabletId) {
Expand Down
8 changes: 8 additions & 0 deletions ydb/core/viewer/json_storage_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class TJsonStorageBase : public TViewerPipeClient<TJsonStorageBase> {
}

void Handle(TEvInterconnect::TEvNodesInfo::TPtr& ev) {
Cerr << "iiiiiiiiii TEvNodesInfo 1" << Endl;
ui32 maxAllowedNodeId = std::numeric_limits<ui32>::max();
TIntrusivePtr<TDynamicNameserviceConfig> dynamicNameserviceConfig = AppData()->DynamicNameserviceConfig;
if (dynamicNameserviceConfig) {
Expand All @@ -274,6 +275,7 @@ class TJsonStorageBase : public TViewerPipeClient<TJsonStorageBase> {
SendNodeRequests(ni.NodeId);
}
}
Cerr << "iiiiiiiiii TEvNodesInfo 2" << Endl;
RequestDone();
}

Expand Down Expand Up @@ -312,6 +314,7 @@ class TJsonStorageBase : public TViewerPipeClient<TJsonStorageBase> {
}

void Handle(TEvHive::TEvResponseHiveStorageStats::TPtr& ev) {
Cerr << "iiiii TEvResponseHiveStorageStats" << Endl;
HiveStorageStats[ev->Cookie] = ev->Release();
RequestDone();
}
Expand Down Expand Up @@ -351,7 +354,9 @@ class TJsonStorageBase : public TViewerPipeClient<TJsonStorageBase> {
}

void Handle(TEvWhiteboard::TEvVDiskStateResponse::TPtr& ev) {
Cerr << "iiiii TEvVDiskStateResponse" << Endl;
ui64 nodeId = ev.Get()->Cookie;
Cerr << "iiiii nodeid" << nodeId << Endl;
auto& vDiskInfo = VDiskInfo[nodeId] = std::move(ev->Get()->Record);
for (auto& vDiskStateInfo : *(vDiskInfo.MutableVDiskStateInfo())) {
vDiskStateInfo.SetNodeId(nodeId);
Expand All @@ -368,11 +373,13 @@ class TJsonStorageBase : public TViewerPipeClient<TJsonStorageBase> {

void Handle(TEvWhiteboard::TEvBSGroupStateResponse::TPtr& ev) {
ui64 nodeId = ev.Get()->Cookie;
Cerr << "iiiiiiiiiiiii Cookie " << nodeId << Endl;
for (const auto& info : ev->Get()->Record.GetBSGroupStateInfo()) {
TString storagePoolName = info.GetStoragePoolName();
if (storagePoolName.empty()) {
continue;
}
Cerr << "iiiiiiiiiiiii nodeId " << info.GetNodeId() << Endl;
if (FilterNodeIds.empty() || FilterNodeIds.contains(info.GetNodeId())) {
StoragePoolInfo[storagePoolName].Groups.emplace(ToString(info.GetGroupID()));
TString groupId(ToString(info.GetGroupID()));
Expand All @@ -381,6 +388,7 @@ class TJsonStorageBase : public TViewerPipeClient<TJsonStorageBase> {
}
}
for (const auto& vDiskNodeId : info.GetVDiskNodeIds()) {
Cerr << "iiiiiiiiiiiii vDiskNodeId " << vDiskNodeId << Endl;
Group2NodeId[info.GetGroupID()].push_back(vDiskNodeId);
}
}
Expand Down
121 changes: 121 additions & 0 deletions ydb/core/viewer/viewer_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
nodes.clear();

for (int nodeId = 0; nodeId < nodesTotal; nodeId++) {
sample.NodeId = nodeId;
nodes.emplace_back(sample);
}
}
Expand Down Expand Up @@ -1104,4 +1105,124 @@ Y_UNIT_TEST_SUITE(Viewer) {
}
}
}

void ChangeBSGroupStateResponse(TEvWhiteboard::TEvBSGroupStateResponse::TPtr* ev) {
auto& pbRecord = (*ev)->Get()->Record;
// pbRecord.clear_bsgroupstateinfo();
// auto state = pbRecord.add_bsgroupstateinfo();
Cerr << pbRecord.ShortDebugString() << Endl;
}

void ChangePDiskStateResponse(TEvWhiteboard::TEvPDiskStateResponse::TPtr* ev) {
auto& pbRecord = (*ev)->Get()->Record;
// pbRecord.clear_pdiskstateinfo();
// auto state = pbRecord.add_pdiskstateinfo();
Cerr << pbRecord.ShortDebugString() << Endl;
}


void ChangeVDiskStateOn9NodeResponse(NNodeWhiteboard::TEvWhiteboard::TEvVDiskStateResponse::TPtr* ev) {
ui64 nodeId = (*ev)->Cookie;
auto& pbRecord = (*ev)->Get()->Record;

auto sample = pbRecord.vdiskstateinfo(0);
pbRecord.clear_vdiskstateinfo();

for (int k = 1; k <= 8; k++) {
auto groupId = (nodeId + k) % 9;
ui32 pdisk = k <= 4 ? 0 : 1;
ui32 slotid = k % 4;
auto vdisk = 0;
auto state = pbRecord.add_vdiskstateinfo();
state->CopyFrom(sample);
state->set_pdiskid(pdisk);
state->set_vdiskslotid(slotid);
state->mutable_vdiskid()->set_vdisk(vdisk++);
state->mutable_vdiskid()->set_groupid(groupId);
state->set_vdiskstate(NKikimrWhiteboard::EVDiskState::OK);
state->set_nodeid(nodeId);
}
}

void JsonStorage9NodesListingTest() {
TPortManager tp;
ui16 port = tp.GetPort(2134);
ui16 grpcPort = tp.GetPort(2135);
auto settings = TServerSettings(port);
settings.InitKikimrRunConfig()
.SetNodeCount(1)
.SetUseRealThreads(false)
.SetDomainName("Root");
TServer server(settings);
server.EnableGRpc(grpcPort);
TClient client(settings);
TTestActorRuntime& runtime = *server.GetRuntime();

TActorId sender = runtime.AllocateEdgeActor();
TAutoPtr<IEventHandle> handle;

THttpRequest httpReq(HTTP_METHOD_GET);
httpReq.CgiParameters.emplace("with", "all");
httpReq.CgiParameters.emplace("version", "v2");
// httpReq.CgiParameters.emplace("node_id", "1");
auto page = MakeHolder<TMonPage>("viewer", "title");
TMonService2HttpRequest monReq(nullptr, &httpReq, nullptr, page.Get(), "/json/storage", nullptr);
auto request = MakeHolder<NMon::TEvHttpInfo>(monReq);

auto observerFunc = [&](TAutoPtr<IEventHandle>& ev) {
Y_UNUSED(ev);
switch (ev->GetTypeRewrite()) {
case TEvInterconnect::EvNodesInfo: {
auto *x = reinterpret_cast<TEvInterconnect::TEvNodesInfo::TPtr*>(&ev);
Cerr << "aaaa EvNodesInfo 1" << Endl;
ChangeListNodes(x, 9);
Cerr << "aaaa EvNodesInfo 2" << Endl;
break;
}
case TEvWhiteboard::EvBSGroupStateResponse: {
auto *x = reinterpret_cast<TEvWhiteboard::TEvBSGroupStateResponse::TPtr*>(&ev);
Cerr << "aaaa EvBSGroupStateResponse 1" << Endl;
ChangeBSGroupStateResponse(x);
Cerr << "aaaa EvBSGroupStateResponse 2" << Endl;
break;
}
case TEvWhiteboard::EvVDiskStateResponse: {
auto *x = reinterpret_cast<TEvWhiteboard::TEvVDiskStateResponse::TPtr*>(&ev);
Cerr << "aaaa EvVDiskStateResponse 1" << Endl;
ChangeVDiskStateOn9NodeResponse(x);
Cerr << "aaaa EvVDiskStateResponse 2" << Endl;
break;
}
case TEvWhiteboard::EvPDiskStateResponse: {
auto *x = reinterpret_cast<TEvWhiteboard::TEvPDiskStateResponse::TPtr*>(&ev);
Cerr << "aaaa EvPDiskStateResponse 1" << Endl;
ChangePDiskStateResponse(x);
Cerr << "aaaa EvPDiskStateResponse 2" << Endl;
break;
}
}

return TTestActorRuntime::EEventAction::PROCESS;
};
runtime.SetObserverFunc(observerFunc);

runtime.Send(new IEventHandle(NKikimr::NViewer::MakeViewerID(0), sender, request.Release(), 0));
NMon::TEvHttpInfoRes* result = runtime.GrabEdgeEvent<NMon::TEvHttpInfoRes>(handle);

size_t pos = result->Answer.find('{');
TString jsonResult = result->Answer.substr(pos);
Cerr << "json result: " << jsonResult << Endl;
NJson::TJsonValue json;
try {
NJson::ReadJsonTree(jsonResult, &json, true);
}
catch (yexception ex) {
Ctest << ex.what() << Endl;
}
// UNIT_ASSERT_VALUES_EQUAL(json.GetMap().contains("StorageGroups"), isExpectingGroup);
}

Y_UNIT_TEST(JsonStorage9NodesListingV1NodeIdFilter) {
JsonStorage9NodesListingTest();
}
}

0 comments on commit e029ee3

Please sign in to comment.