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 ) {
@@ -168,8 +103,8 @@ void TestDSProxyAndVDiskEqualCost(const TBlobStorageGroupInfo::TTopology& topolo
168
103
TStringStream str;
169
104
double proportion = 1 . * dsproxyCost / vdiskCost;
170
105
i64 diff = (i64)dsproxyCost - vdiskCost;
171
- str << " OKs# " << actor->OKs << " , Fails # " << actor->Fails << " , Cost on dsproxy# "
172
- << dsproxyCost << " , Cost on vdisks# " << vdiskCost << " , proportion# " << proportion
106
+ str << " OKs# " << actor->ResponsesByStatus [NKikimrProto::OK] << " , Errors # " << actor->ResponsesByStatus [NKikimrProto::ERROR]
107
+ << " , Cost on dsproxy# " << dsproxyCost << " , Cost on vdisks# " << vdiskCost << " , proportion# " << proportion
173
108
<< " diff# " << diff;
174
109
175
110
if constexpr (VERBOSE) {
@@ -179,43 +114,6 @@ void TestDSProxyAndVDiskEqualCost(const TBlobStorageGroupInfo::TTopology& topolo
179
114
UNIT_ASSERT_VALUES_EQUAL_C (dsproxyCost, vdiskCost, str.Str ());
180
115
}
181
116
182
- class TInflightActorPut : public TInflightActor <TInflightActorPut> {
183
- public:
184
- TInflightActorPut (TSettings settings, ui32 dataSize = 1024 )
185
- : TInflightActor(settings)
186
- , DataSize(dataSize)
187
- {}
188
-
189
- STRICT_STFUNC (StateWork,
190
- cFunc (TEvBlobStorage::TEvStatusResult::EventType, ScheduleRequests);
191
- cFunc (TEvents::TEvWakeup::EventType, ScheduleRequests);
192
- hFunc (TEvBlobStorage::TEvPutResult, Handle );
193
- )
194
-
195
- virtual void BootstrapImpl (const TActorContext&/* ctx*/ ) override {
196
- // dummy request to establish the session
197
- auto ev = new TEvBlobStorage::TEvStatus (TInstant::Max ());
198
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
199
- Become (&TInflightActorPut::StateWork);
200
- }
201
-
202
- protected:
203
- virtual void SendRequest () override {
204
- TString data = MakeData (DataSize);
205
- auto ev = new TEvBlobStorage::TEvPut (TLogoBlobID (1 , 1 , 1 , 10 , DataSize, RequestsToSend + 1 ),
206
- data, TInstant::Max (), NKikimrBlobStorage::UserData);
207
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
208
- }
209
-
210
- void Handle (TEvBlobStorage::TEvPutResult::TPtr res) {
211
- HandleReply (res->Get ()->Status );
212
- }
213
-
214
- private:
215
- std::string Data;
216
- ui32 DataSize;
217
- };
218
-
219
117
#define MAKE_TEST (erasure, requestType, requests, inflight ) \
220
118
Y_UNIT_TEST (Test##requestType##erasure##Requests##requests##Inflight##inflight) { \
221
119
auto groupType = TBlobStorageGroupType::Erasure##erasure; \
@@ -236,99 +134,6 @@ Y_UNIT_TEST(Test##requestType##erasure##Requests##requests##Inflight##inflight##
236
134
TestDSProxyAndVDiskEqualCost (topology, actor); \
237
135
}
238
136
239
- class TInflightActorGet : public TInflightActor <TInflightActorGet> {
240
- public:
241
- TInflightActorGet (TSettings settings, ui32 dataSize = 1024 )
242
- : TInflightActor(settings)
243
- , DataSize(dataSize)
244
- {}
245
-
246
- STRICT_STFUNC (StateWork,
247
- cFunc (TEvBlobStorage::TEvPutResult::EventType, ScheduleRequests);
248
- cFunc (TEvents::TEvWakeup::EventType, ScheduleRequests);
249
- hFunc (TEvBlobStorage::TEvGetResult, Handle );
250
- )
251
-
252
- virtual void BootstrapImpl (const TActorContext&/* ctx*/ ) override {
253
- TString data = MakeData (DataSize);
254
- BlobId = TLogoBlobID (1 , 1 , 1 , 10 , DataSize, 1 );
255
- auto ev = new TEvBlobStorage::TEvPut (BlobId, data, TInstant::Max ());
256
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
257
- Become (&TInflightActorGet::StateWork);
258
- }
259
-
260
- protected:
261
- virtual void SendRequest () override {
262
- auto ev = new TEvBlobStorage::TEvGet (BlobId, 0 , 10 , TInstant::Max (), NKikimrBlobStorage::EGetHandleClass::FastRead);
263
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
264
- }
265
-
266
- void Handle (TEvBlobStorage::TEvGetResult::TPtr res) {
267
- HandleReply (res->Get ()->Status );
268
- }
269
-
270
- private:
271
- TLogoBlobID BlobId;
272
- std::string Data;
273
- ui32 DataSize;
274
- };
275
-
276
- class TInflightActorPatch : public TInflightActor <TInflightActorPatch> {
277
- public:
278
- TInflightActorPatch (TSettings settings, ui32 dataSize = 1024 )
279
- : TInflightActor(settings)
280
- , DataSize(dataSize)
281
- {}
282
-
283
- STRICT_STFUNC (StateWork,
284
- hFunc (TEvBlobStorage::TEvPatchResult, Handle );
285
- hFunc (TEvBlobStorage::TEvPutResult, Handle );
286
- )
287
-
288
- virtual void BootstrapImpl (const TActorContext&/* ctx*/ ) override {
289
- TString data = MakeData (DataSize);
290
- for (ui32 i = 0 ; i < RequestInFlight; ++i) {
291
- TLogoBlobID blobId (1 , 1 , 1 , 10 , DataSize, 1 + i);
292
- auto ev = new TEvBlobStorage::TEvPut (blobId, data, TInstant::Max ());
293
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
294
- }
295
- Become (&TInflightActorPatch::StateWork);
296
- }
297
-
298
- protected:
299
- virtual void SendRequest () override {
300
- TLogoBlobID oldId = Blobs.front ();
301
- Blobs.pop_front ();
302
- TLogoBlobID newId (1 , 1 , oldId.Step () + 1 , 10 , DataSize, oldId.Cookie ());
303
- Y_ABORT_UNLESS (TEvBlobStorage::TEvPatch::GetBlobIdWithSamePlacement (oldId, &newId, BlobIdMask, GroupId, GroupId));
304
- TArrayHolder<TEvBlobStorage::TEvPatch::TDiff> diffs (new TEvBlobStorage::TEvPatch::TDiff[1 ]);
305
- char c = ' a' + RequestsToSend % 26 ;
306
- diffs[0 ].Set (TString (DataSize, c), 0 );
307
- auto ev = new TEvBlobStorage::TEvPatch (GroupId, oldId, newId, BlobIdMask, std::move (diffs), 1 , TInstant::Max ());
308
- SendToBSProxy (SelfId (), GroupId, ev, 0 );
309
- }
310
-
311
-
312
- void Handle (TEvBlobStorage::TEvPatchResult::TPtr res) {
313
- Blobs.push_back (res->Get ()->Id );
314
- HandleReply (res->Get ()->Status );
315
- }
316
-
317
- void Handle (TEvBlobStorage::TEvPutResult::TPtr res) {
318
- Blobs.push_back (res->Get ()->Id );
319
- if (++BlobsWritten == RequestInFlight) {
320
- ScheduleRequests ();
321
- }
322
- }
323
-
324
- protected:
325
- std::deque<TLogoBlobID> Blobs;
326
- ui32 BlobIdMask = TLogoBlobID::MaxCookie & 0xfffff000 ;
327
- ui32 BlobsWritten = 0 ;
328
- std::string Data;
329
- ui32 DataSize;
330
- };
331
-
332
137
Y_UNIT_TEST_SUITE (CostMetricsPutMirror3dc) {
333
138
MAKE_TEST_W_DATASIZE (Mirror3dc, Put, 1 , 1 , 1000 );
334
139
MAKE_TEST_W_DATASIZE (Mirror3dc, Put, 10 , 1 , 1000 );
0 commit comments