18
18
#include < util/random/shuffle.h>
19
19
#include < util/string/printf.h>
20
20
21
+ #include < google/protobuf/arena.h>
22
+
21
23
#include < contrib/libs/ftxui/include/ftxui/component/component.hpp>
22
24
#include < contrib/libs/ftxui/include/ftxui/component/component_base.hpp>
23
25
#include < contrib/libs/ftxui/include/ftxui/component/screen_interactive.hpp>
@@ -120,10 +122,15 @@ int GetRandomCount(int warehouseId, int customerId, int districtId) {
120
122
121
123
// -----------------------------------------------------------------------------
122
124
123
- NTable::TBulkUpsertResult LoadItems (NTable::TTableClient& client, const TString& tableFullPath, TLog* Log) {
125
+ NTable::TBulkUpsertResult LoadItems (
126
+ NTable::TTableClient& client,
127
+ const TString& tableFullPath,
128
+ google::protobuf::Arena& arena,
129
+ TLog* Log)
130
+ {
124
131
LOG_T (" Loading " << ITEM_COUNT << " items..." );
125
132
126
- auto valueBuilder = TValueBuilder ();
133
+ auto valueBuilder = TValueBuilder (&arena );
127
134
valueBuilder.BeginList ();
128
135
129
136
for (int i = 1 ; i <= ITEM_COUNT; ++i) {
@@ -151,7 +158,12 @@ NTable::TBulkUpsertResult LoadItems(NTable::TTableClient& client, const TString&
151
158
}
152
159
153
160
valueBuilder.EndList ();
154
- return client.BulkUpsert (tableFullPath, valueBuilder.Build ()).ExtractValueSync ();
161
+
162
+ NTable::TBulkUpsertSettings bulkSettings;
163
+ bulkSettings.Arena (&arena);
164
+ auto result = client.BulkUpsert (tableFullPath, valueBuilder.Build (), bulkSettings).ExtractValueSync ();
165
+ arena.Reset ();
166
+ return result;
155
167
}
156
168
157
169
// -----------------------------------------------------------------------------
@@ -161,11 +173,12 @@ NTable::TBulkUpsertResult LoadWarehouses(
161
173
const TString& tableFullPath,
162
174
int startId,
163
175
int lastId,
176
+ google::protobuf::Arena& arena,
164
177
TLog* Log)
165
178
{
166
179
LOG_T (" Loading warehouses " << startId << " to " << lastId);
167
180
168
- auto valueBuilder = TValueBuilder ();
181
+ auto valueBuilder = TValueBuilder (&arena );
169
182
valueBuilder.BeginList ();
170
183
171
184
for (int warehouseId = startId; warehouseId <= lastId; ++warehouseId) {
@@ -184,7 +197,12 @@ NTable::TBulkUpsertResult LoadWarehouses(
184
197
}
185
198
186
199
valueBuilder.EndList ();
187
- return client.BulkUpsert (tableFullPath, valueBuilder.Build ()).ExtractValueSync ();
200
+
201
+ NTable::TBulkUpsertSettings bulkSettings;
202
+ bulkSettings.Arena (&arena);
203
+ auto result = client.BulkUpsert (tableFullPath, valueBuilder.Build (), bulkSettings).ExtractValueSync ();
204
+ arena.Reset ();
205
+ return result;
188
206
}
189
207
190
208
// -----------------------------------------------------------------------------
@@ -195,11 +213,12 @@ NTable::TBulkUpsertResult LoadStock(
195
213
int wh,
196
214
int itemId,
197
215
int itemsToLoad,
216
+ google::protobuf::Arena& arena,
198
217
TLog* Log)
199
218
{
200
219
LOG_T (" Loading stock for warehouse " << wh << " items " << itemId << " to " << (itemId + itemsToLoad - 1 ));
201
220
202
- auto valueBuilder = TValueBuilder ();
221
+ auto valueBuilder = TValueBuilder (&arena );
203
222
valueBuilder.BeginList ();
204
223
205
224
for (int i = 0 ; i < itemsToLoad; ++i) {
@@ -242,7 +261,12 @@ NTable::TBulkUpsertResult LoadStock(
242
261
}
243
262
244
263
valueBuilder.EndList ();
245
- return client.BulkUpsert (tableFullPath, valueBuilder.Build ()).ExtractValueSync ();
264
+
265
+ NTable::TBulkUpsertSettings bulkSettings;
266
+ bulkSettings.Arena (&arena);
267
+ auto result = client.BulkUpsert (tableFullPath, valueBuilder.Build (), bulkSettings).ExtractValueSync ();
268
+ arena.Reset ();
269
+ return result;
246
270
}
247
271
248
272
// -----------------------------------------------------------------------------
@@ -252,11 +276,12 @@ NTable::TBulkUpsertResult LoadDistricts(
252
276
const TString& tableFullPath,
253
277
int startId,
254
278
int lastId,
279
+ google::protobuf::Arena& arena,
255
280
TLog* Log)
256
281
{
257
282
LOG_T (" Loading districts for warehouses " << startId << " to " << lastId);
258
283
259
- auto valueBuilder = TValueBuilder ();
284
+ auto valueBuilder = TValueBuilder (&arena );
260
285
valueBuilder.BeginList ();
261
286
262
287
for (int warehouseId = startId; warehouseId <= lastId; ++warehouseId) {
@@ -279,7 +304,12 @@ NTable::TBulkUpsertResult LoadDistricts(
279
304
}
280
305
281
306
valueBuilder.EndList ();
282
- return client.BulkUpsert (tableFullPath, valueBuilder.Build ()).ExtractValueSync ();
307
+
308
+ NTable::TBulkUpsertSettings bulkSettings;
309
+ bulkSettings.Arena (&arena);
310
+ auto result = client.BulkUpsert (tableFullPath, valueBuilder.Build (), bulkSettings).ExtractValueSync ();
311
+ arena.Reset ();
312
+ return result;
283
313
}
284
314
285
315
// -----------------------------------------------------------------------------
@@ -289,11 +319,12 @@ NTable::TBulkUpsertResult LoadCustomers(
289
319
const TString& tableFullPath,
290
320
int wh,
291
321
int district,
322
+ google::protobuf::Arena& arena,
292
323
TLog* Log)
293
324
{
294
325
LOG_T (" Loading customers for warehouse " << wh << " district " << district);
295
326
296
- auto valueBuilder = TValueBuilder ();
327
+ auto valueBuilder = TValueBuilder (&arena );
297
328
valueBuilder.BeginList ();
298
329
299
330
for (int customerId = 1 ; customerId <= CUSTOMERS_PER_DISTRICT; ++customerId) {
@@ -333,7 +364,12 @@ NTable::TBulkUpsertResult LoadCustomers(
333
364
}
334
365
335
366
valueBuilder.EndList ();
336
- return client.BulkUpsert (tableFullPath, valueBuilder.Build ()).ExtractValueSync ();
367
+
368
+ NTable::TBulkUpsertSettings bulkSettings;
369
+ bulkSettings.Arena (&arena);
370
+ auto result = client.BulkUpsert (tableFullPath, valueBuilder.Build (), bulkSettings).ExtractValueSync ();
371
+ arena.Reset ();
372
+ return result;
337
373
}
338
374
339
375
// -----------------------------------------------------------------------------
@@ -343,11 +379,12 @@ NTable::TBulkUpsertResult LoadCustomerHistory(
343
379
const TString& tableFullPath,
344
380
int wh,
345
381
int district,
382
+ google::protobuf::Arena& arena,
346
383
TLog* Log)
347
384
{
348
385
LOG_T (" Loading customer history for warehouse " << wh << " district " << district);
349
386
350
- auto valueBuilder = TValueBuilder ();
387
+ auto valueBuilder = TValueBuilder (&arena );
351
388
valueBuilder.BeginList ();
352
389
353
390
i64 prevTs = 0 ;
@@ -375,7 +412,12 @@ NTable::TBulkUpsertResult LoadCustomerHistory(
375
412
}
376
413
377
414
valueBuilder.EndList ();
378
- return client.BulkUpsert (tableFullPath, valueBuilder.Build ()).ExtractValueSync ();
415
+
416
+ NTable::TBulkUpsertSettings bulkSettings;
417
+ bulkSettings.Arena (&arena);
418
+ auto result = client.BulkUpsert (tableFullPath, valueBuilder.Build (), bulkSettings).ExtractValueSync ();
419
+ arena.Reset ();
420
+ return result;
379
421
}
380
422
381
423
// -----------------------------------------------------------------------------
@@ -385,11 +427,12 @@ NTable::TBulkUpsertResult LoadOpenOrders(
385
427
const TString& tableFullPath,
386
428
int wh,
387
429
int district,
430
+ google::protobuf::Arena& arena,
388
431
TLog* Log)
389
432
{
390
433
LOG_T (" Loading open orders for warehouse " << wh << " district " << district);
391
434
392
- auto valueBuilder = TValueBuilder ();
435
+ auto valueBuilder = TValueBuilder (&arena );
393
436
valueBuilder.BeginList ();
394
437
395
438
// TPC-C 4.3.3.1: o_c_id must be a permutation of [1, customersPerDistrict]
@@ -419,7 +462,12 @@ NTable::TBulkUpsertResult LoadOpenOrders(
419
462
}
420
463
421
464
valueBuilder.EndList ();
422
- return client.BulkUpsert (tableFullPath, valueBuilder.Build ()).ExtractValueSync ();
465
+
466
+ NTable::TBulkUpsertSettings bulkSettings;
467
+ bulkSettings.Arena (&arena);
468
+ auto result = client.BulkUpsert (tableFullPath, valueBuilder.Build (), bulkSettings).ExtractValueSync ();
469
+ arena.Reset ();
470
+ return result;
423
471
}
424
472
425
473
// -----------------------------------------------------------------------------
@@ -429,11 +477,12 @@ NTable::TBulkUpsertResult LoadNewOrders(
429
477
const TString& tableFullPath,
430
478
int wh,
431
479
int district,
480
+ google::protobuf::Arena& arena,
432
481
TLog* Log)
433
482
{
434
483
LOG_T (" Loading new orders for warehouse " << wh << " district " << district);
435
484
436
- auto valueBuilder = TValueBuilder ();
485
+ auto valueBuilder = TValueBuilder (&arena );
437
486
valueBuilder.BeginList ();
438
487
439
488
static_assert (FIRST_UNPROCESSED_O_ID < CUSTOMERS_PER_DISTRICT,
@@ -450,7 +499,12 @@ NTable::TBulkUpsertResult LoadNewOrders(
450
499
}
451
500
452
501
valueBuilder.EndList ();
453
- return client.BulkUpsert (tableFullPath, valueBuilder.Build ()).ExtractValueSync ();
502
+
503
+ NTable::TBulkUpsertSettings bulkSettings;
504
+ bulkSettings.Arena (&arena);
505
+ auto result = client.BulkUpsert (tableFullPath, valueBuilder.Build (), bulkSettings).ExtractValueSync ();
506
+ arena.Reset ();
507
+ return result;
454
508
}
455
509
456
510
// -----------------------------------------------------------------------------
@@ -460,11 +514,12 @@ NTable::TBulkUpsertResult LoadOrderLines(
460
514
const TString& tableFullPath,
461
515
int wh,
462
516
int district,
517
+ google::protobuf::Arena& arena,
463
518
TLog* Log)
464
519
{
465
520
LOG_T (" Loading order lines for warehouse " << wh << " district " << district);
466
521
467
- auto valueBuilder = TValueBuilder ();
522
+ auto valueBuilder = TValueBuilder (&arena );
468
523
valueBuilder.BeginList ();
469
524
470
525
for (int orderId = 1 ; orderId <= CUSTOMERS_PER_DISTRICT; ++orderId) {
@@ -503,7 +558,12 @@ NTable::TBulkUpsertResult LoadOrderLines(
503
558
}
504
559
505
560
valueBuilder.EndList ();
506
- return client.BulkUpsert (tableFullPath, valueBuilder.Build ()).ExtractValueSync ();
561
+
562
+ NTable::TBulkUpsertSettings bulkSettings;
563
+ bulkSettings.Arena (&arena);
564
+ auto result = client.BulkUpsert (tableFullPath, valueBuilder.Build (), bulkSettings).ExtractValueSync ();
565
+ arena.Reset ();
566
+ return result;
507
567
}
508
568
509
569
// -----------------------------------------------------------------------------
@@ -545,21 +605,27 @@ void ExecuteWithRetry(const TString& operationName, LoadFunc loadFunc, TLog* Log
545
605
546
606
// -----------------------------------------------------------------------------
547
607
548
- void LoadSmallTables (TDriver& driver, const TString& path, int warehouseCount, TLog* Log) {
608
+ void LoadSmallTables (
609
+ TDriver& driver,
610
+ const TString& path,
611
+ int warehouseCount,
612
+ google::protobuf::Arena& arena,
613
+ TLog* Log)
614
+ {
549
615
NTable::TTableClient tableClient (driver);
550
616
551
617
TString itemTablePath = path + " /" + TABLE_ITEM;
552
618
TString warehouseTablePath = path + " /" + TABLE_WAREHOUSE;
553
619
TString districtTablePath = path + " /" + TABLE_DISTRICT;
554
620
555
621
ExecuteWithRetry (" LoadItems" , [&]() {
556
- return LoadItems (tableClient, itemTablePath, Log);
622
+ return LoadItems (tableClient, itemTablePath, arena, Log);
557
623
}, Log);
558
624
ExecuteWithRetry (" LoadWarehouses" , [&]() {
559
- return LoadWarehouses (tableClient, warehouseTablePath, 1 , warehouseCount, Log);
625
+ return LoadWarehouses (tableClient, warehouseTablePath, 1 , warehouseCount, arena, Log);
560
626
}, Log);
561
627
ExecuteWithRetry (" LoadDistricts" , [&]() {
562
- return LoadDistricts (tableClient, districtTablePath, 1 , warehouseCount, Log);
628
+ return LoadDistricts (tableClient, districtTablePath, 1 , warehouseCount, arena, Log);
563
629
}, Log);
564
630
}
565
631
@@ -609,7 +675,15 @@ struct TLoadState {
609
675
610
676
// -----------------------------------------------------------------------------
611
677
612
- void LoadRange (TDriver& driver, const TString& path, int whStart, int whEnd, TLoadState& state, TLog* Log) {
678
+ void LoadRange (
679
+ TDriver& driver,
680
+ const TString& path,
681
+ int whStart,
682
+ int whEnd,
683
+ TLoadState& state,
684
+ google::protobuf::Arena& arena,
685
+ TLog* Log)
686
+ {
613
687
NTable::TTableClient tableClient (driver);
614
688
615
689
static_assert (ITEM_COUNT % 10 == 0 , " ITEM_COUNT must be divisible by 10" );
@@ -638,10 +712,10 @@ void LoadRange(TDriver& driver, const TString& path, int whStart, int whEnd, TLo
638
712
639
713
for (int district = DISTRICT_LOW_ID; district <= DISTRICT_HIGH_ID; ++district) {
640
714
ExecuteWithRetry (" LoadCustomers" , [&]() {
641
- return LoadCustomers (tableClient, customerTablePath, wh, district, Log);
715
+ return LoadCustomers (tableClient, customerTablePath, wh, district, arena, Log);
642
716
}, Log);
643
717
ExecuteWithRetry (" LoadOpenOrders" , [&]() {
644
- return LoadOpenOrders (tableClient, oorderTablePath, wh, district, Log);
718
+ return LoadOpenOrders (tableClient, oorderTablePath, wh, district, arena, Log);
645
719
}, Log);
646
720
}
647
721
state.DataSizeLoaded .fetch_add (indexedPerWh, std::memory_order_relaxed);
@@ -661,19 +735,19 @@ void LoadRange(TDriver& driver, const TString& path, int whStart, int whEnd, TLo
661
735
int startItemId = batch * itemBatchSize + 1 ;
662
736
int itemsToLoad = itemBatchSize;
663
737
ExecuteWithRetry (" LoadStock" , [&]() {
664
- return LoadStock (tableClient, stockTablePath, wh, startItemId, itemsToLoad, Log);
738
+ return LoadStock (tableClient, stockTablePath, wh, startItemId, itemsToLoad, arena, Log);
665
739
}, Log);
666
740
}
667
741
668
742
for (int district = DISTRICT_LOW_ID; district <= DISTRICT_HIGH_ID; ++district) {
669
743
ExecuteWithRetry (" LoadOrderLines" , [&]() {
670
- return LoadOrderLines (tableClient, orderLineTablePath, wh, district, Log);
744
+ return LoadOrderLines (tableClient, orderLineTablePath, wh, district, arena, Log);
671
745
}, Log);
672
746
ExecuteWithRetry (" LoadCustomerHistory" , [&]() {
673
- return LoadCustomerHistory (tableClient, historyTablePath, wh, district, Log);
747
+ return LoadCustomerHistory (tableClient, historyTablePath, wh, district, arena, Log);
674
748
}, Log);
675
749
ExecuteWithRetry (" LoadNewOrders" , [&]() {
676
- return LoadNewOrders (tableClient, newOrderTablePath, wh, district, Log);
750
+ return LoadNewOrders (tableClient, newOrderTablePath, wh, district, arena, Log);
677
751
}, Log);
678
752
}
679
753
@@ -856,13 +930,14 @@ class TPCCLoader {
856
930
int whEnd = (threadId + 1 ) * Config.WarehouseCount / threadCount;
857
931
858
932
threads.emplace_back ([threadId, &drivers, driverCount, this , whStart, whEnd]() {
933
+ google::protobuf::Arena arena;
859
934
auto & driver = drivers[threadId % driverCount];
860
935
if (threadId == 0 ) {
861
- LoadSmallTables (driver, Config.Path , Config.WarehouseCount , Log.get ());
936
+ LoadSmallTables (driver, Config.Path , Config.WarehouseCount , arena, Log.get ());
862
937
} else {
863
938
std::this_thread::sleep_for (std::chrono::milliseconds (threadId));
864
939
}
865
- LoadRange (driver, Config.Path , whStart, whEnd, LoadState, Log.get ());
940
+ LoadRange (driver, Config.Path , whStart, whEnd, LoadState, arena, Log.get ());
866
941
});
867
942
}
868
943
0 commit comments