1
1
#include < ydb/core/blobstorage/ut_blobstorage/lib/env.h>
2
2
#include < ydb/core/blobstorage/groupinfo/blobstorage_groupinfo.h>
3
+ #include " ut_helpers.h"
3
4
4
5
constexpr bool VERBOSE = false ;
5
6
@@ -11,72 +12,6 @@ TString MakeData(ui32 dataSize) {
11
12
return data;
12
13
}
13
14
14
- template <typename TDerived>
15
- class TInflightActor : public TActorBootstrapped <TDerived> {
16
- public:
17
- struct TSettings {
18
- ui32 Requests;
19
- ui32 MaxInFlight;
20
- TDuration Delay = TDuration::Zero();
21
- };
22
-
23
- public:
24
- TInflightActor (TSettings settings)
25
- : RequestsToSend(settings.Requests)
26
- , RequestInFlight(settings.MaxInFlight)
27
- , Settings(settings)
28
- {}
29
-
30
- virtual ~TInflightActor () = default ;
31
-
32
- void SetGroupId (ui32 groupId) {
33
- GroupId = groupId;
34
- }
35
- void Bootstrap (const TActorContext &ctx) {
36
- BootstrapImpl (ctx);
37
- }
38
-
39
- protected:
40
- void ScheduleRequests () {
41
- while (RequestInFlight > 0 && RequestsToSend > 0 ) {
42
- TMonotonic now = TMonotonic::Now ();
43
- TDuration timePassed = now - LastTs;
44
- if (timePassed >= Settings.Delay ) {
45
- LastTs = now;
46
- RequestInFlight--;
47
- RequestsToSend--;
48
- SendRequest ();
49
- } else {
50
- TActorBootstrapped<TDerived>::Schedule (Settings.Delay - timePassed, new TEvents::TEvWakeup);
51
- }
52
- }
53
- }
54
-
55
- void HandleReply (NKikimrProto::EReplyStatus status) {
56
- if (status == NKikimrProto::OK) {
57
- OKs++;
58
- } else {
59
- Fails++;
60
- }
61
- ++RequestInFlight;
62
- ScheduleRequests ();
63
- }
64
-
65
- virtual void BootstrapImpl (const TActorContext &ctx) = 0;
66
- virtual void SendRequest () = 0;
67
-
68
- protected:
69
- ui32 RequestsToSend;
70
- ui32 RequestInFlight;
71
- ui32 GroupId;
72
- TMonotonic LastTs;
73
- TSettings Settings;
74
-
75
- public:
76
- ui32 OKs = 0 ;
77
- ui32 Fails = 0 ;
78
- };
79
-
80
15
ui64 AggregateVDiskCounters (std::unique_ptr<TEnvironmentSetup>& env, const NKikimrBlobStorage::TBaseConfig& baseConfig,
81
16
TString storagePool, ui32 groupSize, ui32 groupId, const std::vector<ui32>& pdiskLayout, TString subsystem,
82
17
TString counter, bool derivative = false ) {
@@ -170,8 +105,8 @@ void TestDSProxyAndVDiskEqualCost(const TBlobStorageGroupInfo::TTopology& topolo
170
105
TStringStream str;
171
106
double proportion = 1 . * dsproxyCost / vdiskCost;
172
107
i64 diff = (i64)dsproxyCost - vdiskCost;
173
- str << " OKs# " << actor->OKs << " , Fails # " << actor->Fails << " , Cost on dsproxy# "
174
- << dsproxyCost << " , Cost on vdisks# " << vdiskCost << " , proportion# " << proportion
108
+ str << " OKs# " << actor->ResponsesByStatus [NKikimrProto::OK] << " , Errors # " << actor->ResponsesByStatus [NKikimrProto::ERROR]
109
+ << " , Cost on dsproxy# " << dsproxyCost << " , Cost on vdisks# " << vdiskCost << " , proportion# " << proportion
175
110
<< " diff# " << diff;
176
111
177
112
if constexpr (VERBOSE) {
@@ -181,43 +116,6 @@ void TestDSProxyAndVDiskEqualCost(const TBlobStorageGroupInfo::TTopology& topolo
181
116
UNIT_ASSERT_VALUES_EQUAL_C (dsproxyCost, vdiskCost, str.Str ());
182
117
}
183
118
184
- class TInflightActorPut : public TInflightActor <TInflightActorPut> {
185
- public:
186
- TInflightActorPut (TSettings settings, ui32 dataSize = 1024 )
187
- : TInflightActor(settings)
188
- , DataSize(dataSize)
189
- {}
190
-
191
- STRICT_STFUNC (StateWork,
192
- cFunc (TEvBlobStorage::TEvStatusResult::EventType, ScheduleRequests);
193
- cFunc (TEvents::TEvWakeup::EventType, ScheduleRequests);
194
- hFunc (TEvBlobStorage::TEvPutResult, Handle );
195
- )
196
-
197
- virtual void BootstrapImpl (const TActorContext&/* ctx*/ ) override {
198
- // dummy request to establish the session
199
- auto ev = new TEvBlobStorage::TEvStatus (TInstant::Max ());
200
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
201
- Become (&TInflightActorPut::StateWork);
202
- }
203
-
204
- protected:
205
- virtual void SendRequest () override {
206
- TString data = MakeData (DataSize);
207
- auto ev = new TEvBlobStorage::TEvPut (TLogoBlobID (1 , 1 , 1 , 10 , DataSize, RequestsToSend + 1 ),
208
- data, TInstant::Max (), NKikimrBlobStorage::UserData);
209
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
210
- }
211
-
212
- void Handle (TEvBlobStorage::TEvPutResult::TPtr res) {
213
- HandleReply (res->Get ()->Status );
214
- }
215
-
216
- private:
217
- std::string Data;
218
- ui32 DataSize;
219
- };
220
-
221
119
#define MAKE_TEST (erasure, requestType, requests, inflight ) \
222
120
Y_UNIT_TEST (Test##requestType##erasure##Requests##requests##Inflight##inflight) { \
223
121
auto groupType = TBlobStorageGroupType::Erasure##erasure; \
@@ -238,99 +136,6 @@ Y_UNIT_TEST(Test##requestType##erasure##Requests##requests##Inflight##inflight##
238
136
TestDSProxyAndVDiskEqualCost (topology, actor); \
239
137
}
240
138
241
- class TInflightActorGet : public TInflightActor <TInflightActorGet> {
242
- public:
243
- TInflightActorGet (TSettings settings, ui32 dataSize = 1024 )
244
- : TInflightActor(settings)
245
- , DataSize(dataSize)
246
- {}
247
-
248
- STRICT_STFUNC (StateWork,
249
- cFunc (TEvBlobStorage::TEvPutResult::EventType, ScheduleRequests);
250
- cFunc (TEvents::TEvWakeup::EventType, ScheduleRequests);
251
- hFunc (TEvBlobStorage::TEvGetResult, Handle );
252
- )
253
-
254
- virtual void BootstrapImpl (const TActorContext&/* ctx*/ ) override {
255
- TString data = MakeData (DataSize);
256
- BlobId = TLogoBlobID (1 , 1 , 1 , 10 , DataSize, 1 );
257
- auto ev = new TEvBlobStorage::TEvPut (BlobId, data, TInstant::Max ());
258
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
259
- Become (&TInflightActorGet::StateWork);
260
- }
261
-
262
- protected:
263
- virtual void SendRequest () override {
264
- auto ev = new TEvBlobStorage::TEvGet (BlobId, 0 , 10 , TInstant::Max (), NKikimrBlobStorage::EGetHandleClass::FastRead);
265
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
266
- }
267
-
268
- void Handle (TEvBlobStorage::TEvGetResult::TPtr res) {
269
- HandleReply (res->Get ()->Status );
270
- }
271
-
272
- private:
273
- TLogoBlobID BlobId;
274
- std::string Data;
275
- ui32 DataSize;
276
- };
277
-
278
- class TInflightActorPatch : public TInflightActor <TInflightActorPatch> {
279
- public:
280
- TInflightActorPatch (TSettings settings, ui32 dataSize = 1024 )
281
- : TInflightActor(settings)
282
- , DataSize(dataSize)
283
- {}
284
-
285
- STRICT_STFUNC (StateWork,
286
- hFunc (TEvBlobStorage::TEvPatchResult, Handle );
287
- hFunc (TEvBlobStorage::TEvPutResult, Handle );
288
- )
289
-
290
- virtual void BootstrapImpl (const TActorContext&/* ctx*/ ) override {
291
- TString data = MakeData (DataSize);
292
- for (ui32 i = 0 ; i < RequestInFlight; ++i) {
293
- TLogoBlobID blobId (1 , 1 , 1 , 10 , DataSize, 1 + i);
294
- auto ev = new TEvBlobStorage::TEvPut (blobId, data, TInstant::Max ());
295
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
296
- }
297
- Become (&TInflightActorPatch::StateWork);
298
- }
299
-
300
- protected:
301
- virtual void SendRequest () override {
302
- TLogoBlobID oldId = Blobs.front ();
303
- Blobs.pop_front ();
304
- TLogoBlobID newId (1 , 1 , oldId.Step () + 1 , 10 , DataSize, oldId.Cookie ());
305
- Y_ABORT_UNLESS (TEvBlobStorage::TEvPatch::GetBlobIdWithSamePlacement (oldId, &newId, BlobIdMask, GroupId, GroupId));
306
- TArrayHolder<TEvBlobStorage::TEvPatch::TDiff> diffs (new TEvBlobStorage::TEvPatch::TDiff[1 ]);
307
- char c = ' a' + RequestsToSend % 26 ;
308
- diffs[0 ].Set (TString (DataSize, c), 0 );
309
- auto ev = new TEvBlobStorage::TEvPatch (GroupId, oldId, newId, BlobIdMask, std::move (diffs), 1 , TInstant::Max ());
310
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
311
- }
312
-
313
-
314
- void Handle (TEvBlobStorage::TEvPatchResult::TPtr res) {
315
- Blobs.push_back (res->Get ()->Id );
316
- HandleReply (res->Get ()->Status );
317
- }
318
-
319
- void Handle (TEvBlobStorage::TEvPutResult::TPtr res) {
320
- Blobs.push_back (res->Get ()->Id );
321
- if (++BlobsWritten == RequestInFlight) {
322
- ScheduleRequests ();
323
- }
324
- }
325
-
326
- protected:
327
- std::deque<TLogoBlobID> Blobs;
328
- ui32 BlobIdMask = TLogoBlobID::MaxCookie & 0xfffff000 ;
329
- ui32 BlobsWritten = 0 ;
330
- std::string Data;
331
- ui32 DataSize;
332
- };
333
-
334
139
Y_UNIT_TEST_SUITE (CostMetricsPutMirror3dc) {
335
140
MAKE_TEST_W_DATASIZE (Mirror3dc, Put, 1 , 1 , 1000 );
336
141
MAKE_TEST_W_DATASIZE (Mirror3dc, Put, 10 , 1 , 1000 );
0 commit comments