Skip to content

Commit d6f67f8

Browse files
committed
add rdma endpoint monitoring for cells
1 parent da157a2 commit d6f67f8

17 files changed

Lines changed: 1334 additions & 67 deletions

File tree

cloud/blockstore/libs/daemon/common/bootstrap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ void TBootstrapBase::Init()
264264
Configs->RdmaConfig->GetBlockstoreServerTarget()),
265265
Logging,
266266
GetTraceSerializer(),
267+
Monitoring,
267268
RdmaRequestServer,
268269
Service);
269270
STORAGE_INFO("RDMA Target initialized");

cloud/blockstore/libs/endpoints_rdma/rdma_server.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,34 +81,34 @@ class TRdmaEndpoint final
8181
}
8282

8383
void HandleRequest(
84-
void* context,
84+
NRdma::IServerRequest* context,
8585
TCallContextBasePtr callContext,
8686
TStringBuf in,
8787
TStringBuf out) override;
8888

8989
private:
9090
NProto::TError DoHandleRequest(
91-
void* context,
91+
NRdma::IServerRequest* context,
9292
TCallContextPtr callContext,
9393
TStringBuf in,
9494
TStringBuf out);
9595

9696
NProto::TError HandleReadBlocksRequest(
97-
void* context,
97+
NRdma::IServerRequest* context,
9898
TCallContextPtr callContext,
9999
NProto::TReadBlocksRequest& request,
100100
TStringBuf requestData,
101101
TStringBuf out);
102102

103103
NProto::TError HandleWriteBlocksRequest(
104-
void* context,
104+
NRdma::IServerRequest* context,
105105
TCallContextPtr callContext,
106106
NProto::TWriteBlocksRequest& request,
107107
TStringBuf requestData,
108108
TStringBuf out);
109109

110110
NProto::TError HandleZeroBlocksRequest(
111-
void* context,
111+
NRdma::IServerRequest* context,
112112
TCallContextPtr callContext,
113113
NProto::TZeroBlocksRequest* request,
114114
TStringBuf requestData,
@@ -120,7 +120,7 @@ using TRdmaEndpointPtr = std::shared_ptr<TRdmaEndpoint>;
120120
////////////////////////////////////////////////////////////////////////////////
121121

122122
void TRdmaEndpoint::HandleRequest(
123-
void* context,
123+
NRdma::IServerRequest* context,
124124
TCallContextBasePtr callContext,
125125
TStringBuf in,
126126
TStringBuf out)
@@ -161,7 +161,7 @@ void TRdmaEndpoint::HandleRequest(
161161
}
162162

163163
NProto::TError TRdmaEndpoint::DoHandleRequest(
164-
void* context,
164+
NRdma::IServerRequest* context,
165165
TCallContextPtr callContext,
166166
TStringBuf in,
167167
TStringBuf out)
@@ -204,7 +204,7 @@ NProto::TError TRdmaEndpoint::DoHandleRequest(
204204
}
205205

206206
NProto::TError TRdmaEndpoint::HandleReadBlocksRequest(
207-
void* context,
207+
NRdma::IServerRequest* context,
208208
TCallContextPtr callContext,
209209
NProto::TReadBlocksRequest& request,
210210
TStringBuf requestData,
@@ -261,7 +261,7 @@ NProto::TError TRdmaEndpoint::HandleReadBlocksRequest(
261261
}
262262

263263
NProto::TError TRdmaEndpoint::HandleWriteBlocksRequest(
264-
void* context,
264+
NRdma::IServerRequest* context,
265265
TCallContextPtr callContext,
266266
NProto::TWriteBlocksRequest& request,
267267
TStringBuf requestData,
@@ -315,7 +315,7 @@ NProto::TError TRdmaEndpoint::HandleWriteBlocksRequest(
315315
}
316316

317317
NProto::TError TRdmaEndpoint::HandleZeroBlocksRequest(
318-
void* context,
318+
NRdma::IServerRequest* context,
319319
TCallContextPtr callContext,
320320
NProto::TZeroBlocksRequest* request,
321321
TStringBuf requestData,

cloud/blockstore/libs/rdma_test/server_test_async.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ TString MakeKey(const TString& host, ui32 port)
2929

3030
////////////////////////////////////////////////////////////////////////////////
3131

32-
class IRequestWrapper
32+
class IRequestWrapper: public NCloud::NStorage::NRdma::IServerRequest
3333
{
3434
public:
35-
virtual ~IRequestWrapper() = default;
3635
virtual void SendResponse(size_t responseBytes) = 0;
3736
virtual void SendError(ui32 error, TStringBuf message) = 0;
37+
38+
[[nodiscard]] ui64 GetSessionId() const override
39+
{
40+
return 0;
41+
}
3842
};
3943

4044
template <typename TRequestResponse>
@@ -99,14 +103,19 @@ class TRdmaAsyncTestEndpoint: public NCloud::NStorage::NRdma::IServerEndpoint
99103
: Handler(std::move(handler))
100104
{}
101105

102-
void SendResponse(void* context, size_t responseBytes) override
106+
void SendResponse(
107+
NCloud::NStorage::NRdma::IServerRequest* context,
108+
size_t responseBytes) override
103109
{
104110
std::unique_ptr<IRequestWrapper> wrapper(
105111
static_cast<IRequestWrapper*>(context));
106112
wrapper->SendResponse(responseBytes);
107113
}
108114

109-
void SendError(void* context, ui32 error, TStringBuf message) override
115+
void SendError(
116+
NCloud::NStorage::NRdma::IServerRequest* context,
117+
ui32 error,
118+
TStringBuf message) override
110119
{
111120
std::unique_ptr<IRequestWrapper> wrapper(
112121
static_cast<IRequestWrapper*>(context));
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
#include "mount_registry.h"
2+
3+
#include <cloud/storage/core/libs/common/error.h>
4+
#include <cloud/storage/core/libs/common/task_queue.h>
5+
#include <cloud/storage/core/libs/common/thread_pool.h>
6+
7+
#include <util/generic/algorithm.h>
8+
9+
namespace NCloud::NBlockStore::NStorage {
10+
11+
////////////////////////////////////////////////////////////////////////////////
12+
13+
TMountRegistry::TMountRegistry(TLog log)
14+
: Log(std::move(log))
15+
// a single thread on purpose, see the comment on the class
16+
, Queue(CreateThreadPool("RDMA_REG", 1))
17+
{}
18+
19+
TMountRegistry::~TMountRegistry() = default;
20+
21+
void TMountRegistry::Start()
22+
{
23+
Queue->Start();
24+
}
25+
26+
void TMountRegistry::Stop()
27+
{
28+
Queue->Stop();
29+
}
30+
31+
////////////////////////////////////////////////////////////////////////////////
32+
33+
void TMountRegistry::Enqueue(std::function<void()> update) noexcept
34+
{
35+
auto task = [Log = Log, update = std::move(update)]
36+
{
37+
// the thread pool runs the task in a noexcept context
38+
auto error = SafeExecute<NProto::TError>(
39+
[&]
40+
{
41+
update();
42+
return NProto::TError{};
43+
});
44+
45+
if (HasError(error)) {
46+
STORAGE_WARN(
47+
"Can't update the mount registry: %s",
48+
FormatError(error).c_str());
49+
}
50+
};
51+
52+
// called from the transport threads, nothing may escape into them
53+
auto error = SafeExecute<NProto::TError>(
54+
[&]
55+
{
56+
Queue->ExecuteSimple(std::move(task));
57+
return NProto::TError{};
58+
});
59+
60+
if (HasError(error)) {
61+
STORAGE_WARN(
62+
"Can't enqueue a mount registry update: %s",
63+
FormatError(error).c_str());
64+
}
65+
}
66+
67+
////////////////////////////////////////////////////////////////////////////////
68+
69+
void TMountRegistry::AddConnection(
70+
ui64 sessionId,
71+
TString peer,
72+
TInstant startTs) noexcept
73+
{
74+
Enqueue(
75+
[this, sessionId, peer = std::move(peer), startTs]
76+
{ DoAddConnection(sessionId, peer, startTs); });
77+
}
78+
79+
void TMountRegistry::RemoveConnection(ui64 sessionId) noexcept
80+
{
81+
Enqueue([this, sessionId] { DoRemoveConnection(sessionId); });
82+
}
83+
84+
void TMountRegistry::AddMount(ui64 sessionId, TMountInfo info) noexcept
85+
{
86+
Enqueue(
87+
[this, sessionId, info = std::move(info)]() mutable
88+
{ DoAddMount(sessionId, std::move(info)); });
89+
}
90+
91+
void TMountRegistry::RemoveMount(
92+
ui64 sessionId,
93+
TString diskId,
94+
TString clientId) noexcept
95+
{
96+
Enqueue(
97+
[this,
98+
sessionId,
99+
diskId = std::move(diskId),
100+
clientId = std::move(clientId)]
101+
{ DoRemoveMount(sessionId, diskId, clientId); });
102+
}
103+
104+
////////////////////////////////////////////////////////////////////////////////
105+
106+
void TMountRegistry::DoAddConnection(
107+
ui64 sessionId,
108+
TString peer,
109+
TInstant startTs)
110+
{
111+
with_lock (Lock) {
112+
auto& connection = Connections[sessionId];
113+
connection.SessionId = sessionId;
114+
connection.Peer = std::move(peer);
115+
connection.StartTs = startTs;
116+
}
117+
}
118+
119+
void TMountRegistry::DoRemoveConnection(ui64 sessionId)
120+
{
121+
with_lock (Lock) {
122+
Connections.erase(sessionId);
123+
}
124+
}
125+
126+
void TMountRegistry::DoAddMount(ui64 sessionId, TMountInfo info)
127+
{
128+
with_lock (Lock) {
129+
auto* connection = Connections.FindPtr(sessionId);
130+
if (!connection) {
131+
// the connection is announced before it can serve anything and
132+
// forgotten only after everything it delivered has been answered,
133+
// so there is no mount to record here - and recording one would
134+
// bring a closed connection back for good
135+
return;
136+
}
137+
138+
auto it = FindIf(
139+
connection->Mounts,
140+
[&](const auto& mount)
141+
{
142+
return mount.DiskId == info.DiskId &&
143+
mount.ClientId == info.ClientId;
144+
});
145+
146+
if (it != connection->Mounts.end()) {
147+
*it = std::move(info);
148+
} else {
149+
connection->Mounts.push_back(std::move(info));
150+
}
151+
}
152+
}
153+
154+
void TMountRegistry::DoRemoveMount(
155+
ui64 sessionId,
156+
const TString& diskId,
157+
const TString& clientId)
158+
{
159+
with_lock (Lock) {
160+
auto* connection = Connections.FindPtr(sessionId);
161+
if (!connection) {
162+
return;
163+
}
164+
165+
EraseIf(
166+
connection->Mounts,
167+
[&](const auto& mount)
168+
{
169+
return mount.DiskId == diskId && mount.ClientId == clientId;
170+
});
171+
}
172+
}
173+
174+
TVector<TConnectionInfo> TMountRegistry::GetConnections() const
175+
{
176+
TVector<TConnectionInfo> result;
177+
178+
with_lock (Lock) {
179+
result.reserve(Connections.size());
180+
181+
for (const auto& [sessionId, connection]: Connections) {
182+
result.push_back(connection);
183+
}
184+
}
185+
186+
SortBy(result, [](const auto& connection) { return connection.StartTs; });
187+
188+
return result;
189+
}
190+
191+
////////////////////////////////////////////////////////////////////////////////
192+
193+
TMountRegistryPtr CreateMountRegistry(ILoggingServicePtr logging)
194+
{
195+
return std::make_shared<TMountRegistry>(
196+
logging->CreateLog("BLOCKSTORE_SERVER"));
197+
}
198+
199+
} // namespace NCloud::NBlockStore::NStorage

0 commit comments

Comments
 (0)