Skip to content

Commit f8de314

Browse files
authored
Fix TPC-C transactions logic and improve logs (#17333) (#19223)
1 parent 47d7b7c commit f8de314

8 files changed

+197
-123
lines changed

ydb/library/workload/tpcc/common_queries.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "common_queries.h"
2+
#include "constants.h"
23
#include "log.h"
34
#include "transactions.h"
45

@@ -64,11 +65,11 @@ TAsyncExecuteQueryResult GetCustomerById(
6465
SELECT C_FIRST, C_MIDDLE, C_LAST, C_STREET_1, C_STREET_2,
6566
C_CITY, C_STATE, C_ZIP, C_PHONE, C_CREDIT, C_CREDIT_LIM,
6667
C_DISCOUNT, C_BALANCE, C_YTD_PAYMENT, C_PAYMENT_CNT, C_SINCE
67-
FROM `customer`
68+
FROM `{}`
6869
WHERE C_W_ID = $c_w_id
6970
AND C_D_ID = $c_d_id
7071
AND C_ID = $c_id;
71-
)", context.Path.c_str());
72+
)", context.Path.c_str(), TABLE_CUSTOMER);
7273

7374
auto params = TParamsBuilder()
7475
.AddParam("$c_w_id").Int32(warehouseID).Build()
@@ -108,12 +109,12 @@ TAsyncExecuteQueryResult GetCustomersByLastName(
108109
SELECT C_FIRST, C_MIDDLE, C_ID, C_STREET_1, C_STREET_2, C_CITY,
109110
C_STATE, C_ZIP, C_PHONE, C_CREDIT, C_CREDIT_LIM, C_DISCOUNT,
110111
C_BALANCE, C_YTD_PAYMENT, C_PAYMENT_CNT, C_SINCE
111-
FROM `customer` VIEW idx_customer_name AS idx
112+
FROM `{}` VIEW `{}` AS idx
112113
WHERE idx.C_W_ID = $c_w_id
113114
AND idx.C_D_ID = $c_d_id
114115
AND idx.C_LAST = $c_last
115116
ORDER BY idx.C_FIRST;
116-
)", context.Path.c_str());
117+
)", context.Path.c_str(), TABLE_CUSTOMER, INDEX_CUSTOMER_NAME);
117118

118119
auto params = TParamsBuilder()
119120
.AddParam("$c_w_id").Int32(warehouseID).Build()

ydb/library/workload/tpcc/constants.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,19 @@ constexpr std::chrono::seconds STOCK_LEVEL_THINK_TIME{5};
5252
// thinking and keying times and number of terminals per warehouse
5353
constexpr double MAX_TPMC_PER_WAREHOUSE = 12.86;
5454

55+
// Table names
56+
constexpr const char* TABLE_CUSTOMER = "customer";
57+
constexpr const char* TABLE_WAREHOUSE = "warehouse";
58+
constexpr const char* TABLE_DISTRICT = "district";
59+
constexpr const char* TABLE_NEW_ORDER = "new_order";
60+
constexpr const char* TABLE_OORDER = "oorder";
61+
constexpr const char* TABLE_ITEM = "item";
62+
constexpr const char* TABLE_STOCK = "stock";
63+
constexpr const char* TABLE_ORDER_LINE = "order_line";
64+
constexpr const char* TABLE_HISTORY = "history";
65+
66+
// Index/View names
67+
constexpr const char* INDEX_CUSTOMER_NAME = "idx_customer_name";
68+
constexpr const char* INDEX_ORDER = "idx_order";
69+
5570
} // namespace NYdb::NTPCC

ydb/library/workload/tpcc/transaction_delivery.cpp

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ TAsyncExecuteQueryResult GetNewOrder(
4848
DECLARE $no_d_id AS Int32;
4949
DECLARE $no_w_id AS Int32;
5050
51-
SELECT NO_W_ID, NO_D_ID, NO_O_ID FROM `new_order`
51+
SELECT NO_W_ID, NO_D_ID, NO_O_ID FROM `{}`
5252
WHERE NO_D_ID = $no_d_id
5353
AND NO_W_ID = $no_w_id
5454
ORDER BY NO_W_ID ASC, NO_D_ID ASC, NO_O_ID ASC
5555
LIMIT 1;
56-
)", context.Path.c_str());
56+
)", context.Path.c_str(), TABLE_NEW_ORDER);
5757

5858
auto params = TParamsBuilder()
5959
.AddParam("$no_d_id").Int32(districtID).Build()
@@ -84,11 +84,11 @@ TAsyncExecuteQueryResult DeleteNewOrder(
8484
DECLARE $no_d_id AS Int32;
8585
DECLARE $no_w_id AS Int32;
8686
87-
DELETE FROM `new_order`
87+
DELETE FROM `{}`
8888
WHERE NO_O_ID = $no_o_id
8989
AND NO_D_ID = $no_d_id
9090
AND NO_W_ID = $no_w_id;
91-
)", context.Path.c_str());
91+
)", context.Path.c_str(), TABLE_NEW_ORDER);
9292

9393
auto params = TParamsBuilder()
9494
.AddParam("$no_o_id").Int32(orderID).Build()
@@ -120,11 +120,11 @@ TAsyncExecuteQueryResult GetCustomerID(
120120
DECLARE $o_w_id AS Int32;
121121
122122
SELECT O_C_ID
123-
FROM `oorder`
123+
FROM `{}`
124124
WHERE O_ID = $o_id
125125
AND O_D_ID = $o_d_id
126126
AND O_W_ID = $o_w_id;
127-
)", context.Path.c_str());
127+
)", context.Path.c_str(), TABLE_OORDER);
128128

129129
auto params = TParamsBuilder()
130130
.AddParam("$o_id").Int32(orderID).Build()
@@ -156,9 +156,9 @@ TAsyncExecuteQueryResult UpdateCarrierID(
156156
DECLARE $o_w_id AS Int32;
157157
DECLARE $o_carrier_id AS Int32;
158158
159-
UPSERT INTO `oorder` (O_W_ID, O_D_ID, O_ID, O_CARRIER_ID)
159+
UPSERT INTO `{}` (O_W_ID, O_D_ID, O_ID, O_CARRIER_ID)
160160
VALUES ($o_w_id, $o_d_id, $o_id, $o_carrier_id);
161-
)", context.Path.c_str());
161+
)", context.Path.c_str(), TABLE_OORDER);
162162

163163
auto params = TParamsBuilder()
164164
.AddParam("$o_w_id").Int32(warehouseID).Build()
@@ -188,8 +188,8 @@ TAsyncExecuteQueryResult UpdateDeliveryDate(
188188
$mapper = ($row) -> (AsStruct(
189189
$row.p1 as OL_W_ID, $row.p2 as OL_D_ID, $row.p3 as OL_O_ID,
190190
$row.p4 as OL_NUMBER, $row.p5 as OL_DELIVERY_D));
191-
UPSERT INTO `order_line` SELECT * FROM as_table(ListMap($values, $mapper));
192-
)", context.Path.c_str());
191+
UPSERT INTO `{}` SELECT * FROM as_table(ListMap($values, $mapper));
192+
)", context.Path.c_str(), TABLE_ORDER_LINE);
193193

194194
auto paramsBuilder = TParamsBuilder();
195195
auto& listBuilder = paramsBuilder.AddParam("$values").BeginList();
@@ -229,11 +229,11 @@ TAsyncExecuteQueryResult GetOrderLines(
229229
DECLARE $ol_w_id AS Int32;
230230
231231
SELECT OL_NUMBER, OL_AMOUNT
232-
FROM `order_line`
232+
FROM `{}`
233233
WHERE OL_O_ID = $ol_o_id
234234
AND OL_D_ID = $ol_d_id
235235
AND OL_W_ID = $ol_w_id;
236-
)", context.Path.c_str());
236+
)", context.Path.c_str(), TABLE_ORDER_LINE);
237237

238238
auto params = TParamsBuilder()
239239
.AddParam("$ol_o_id").Int32(orderID).Build()
@@ -265,11 +265,11 @@ TAsyncExecuteQueryResult GetCustomerData(
265265
DECLARE $c_id AS Int32;
266266
267267
SELECT C_BALANCE, C_DELIVERY_CNT
268-
FROM `customer`
268+
FROM `{}`
269269
WHERE C_W_ID = $c_w_id
270270
AND C_D_ID = $c_d_id
271271
AND C_ID = $c_id;
272-
)", context.Path.c_str());
272+
)", context.Path.c_str(), TABLE_CUSTOMER);
273273

274274
auto params = TParamsBuilder()
275275
.AddParam("$c_w_id").Int32(warehouseID).Build()
@@ -302,9 +302,9 @@ TAsyncExecuteQueryResult UpdateCustomerBalanceAndDeliveryCount(
302302
DECLARE $c_balance AS Double;
303303
DECLARE $c_delivery_cnt AS Int32;
304304
305-
UPSERT INTO `customer` (C_W_ID, C_D_ID, C_ID, C_BALANCE, C_DELIVERY_CNT)
305+
UPSERT INTO `{}` (C_W_ID, C_D_ID, C_ID, C_BALANCE, C_DELIVERY_CNT)
306306
VALUES ($c_w_id, $c_d_id, $c_id, $c_balance, $c_delivery_cnt);
307-
)", context.Path.c_str());
307+
)", context.Path.c_str(), TABLE_CUSTOMER);
308308

309309
auto params = TParamsBuilder()
310310
.AddParam("$c_w_id").Int32(warehouseID).Build()
@@ -342,7 +342,8 @@ NThreading::TFuture<TStatus> GetDeliveryTask(
342342
const int warehouseID = context.WarehouseID;
343343
const int carrierID = RandomNumber(1, 10);
344344

345-
LOG_T("Terminal " << context.TerminalID << " started Delivery transaction in " << warehouseID);
345+
LOG_T("Terminal " << context.TerminalID << " started Delivery transaction in " << warehouseID
346+
<< ", session: " << session.GetId());
346347

347348
size_t processedOrderCount = 0;
348349
std::optional<TTransaction> tx;
@@ -356,9 +357,11 @@ NThreading::TFuture<TStatus> GetDeliveryTask(
356357
if (!newOrderResult.IsSuccess()) {
357358
if (ShouldExit(newOrderResult)) {
358359
LOG_E("Terminal " << context.TerminalID << " new order query failed: "
359-
<< newOrderResult.GetIssues().ToOneLineString());
360+
<< newOrderResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
360361
std::quick_exit(1);
361362
}
363+
LOG_T("Terminal " << context.TerminalID << " new order query failed: "
364+
<< newOrderResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
362365
co_return newOrderResult;
363366
}
364367

@@ -383,9 +386,11 @@ NThreading::TFuture<TStatus> GetDeliveryTask(
383386
if (!customerIdResult.IsSuccess()) {
384387
if (ShouldExit(customerIdResult)) {
385388
LOG_E("Terminal " << context.TerminalID << " get customer ID failed: "
386-
<< customerIdResult.GetIssues().ToOneLineString());
389+
<< customerIdResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
387390
std::quick_exit(1);
388391
}
392+
LOG_T("Terminal " << context.TerminalID << " get customer ID failed: "
393+
<< customerIdResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
389394
co_return customerIdResult;
390395
}
391396

@@ -403,9 +408,11 @@ NThreading::TFuture<TStatus> GetDeliveryTask(
403408
if (!customerDataResult.IsSuccess()) {
404409
if (ShouldExit(customerDataResult)) {
405410
LOG_E("Terminal " << context.TerminalID << " get customer data failed: "
406-
<< customerDataResult.GetIssues().ToOneLineString());
411+
<< customerDataResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
407412
std::quick_exit(1);
408413
}
414+
LOG_T("Terminal " << context.TerminalID << " get customer data failed: "
415+
<< customerDataResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
409416
co_return customerDataResult;
410417
}
411418

@@ -425,9 +432,11 @@ NThreading::TFuture<TStatus> GetDeliveryTask(
425432
if (!orderLinesResult.IsSuccess()) {
426433
if (ShouldExit(orderLinesResult)) {
427434
LOG_E("Terminal " << context.TerminalID << " get order lines failed: "
428-
<< orderLinesResult.GetIssues().ToOneLineString());
435+
<< orderLinesResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
429436
std::quick_exit(1);
430437
}
438+
LOG_T("Terminal " << context.TerminalID << " get order lines failed: "
439+
<< orderLinesResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
431440
co_return orderLinesResult;
432441
}
433442

@@ -463,9 +472,11 @@ NThreading::TFuture<TStatus> GetDeliveryTask(
463472
if (!deleteOrderResult.IsSuccess()) {
464473
if (ShouldExit(deleteOrderResult)) {
465474
LOG_E("Terminal " << context.TerminalID << " delete order failed: "
466-
<< deleteOrderResult.GetIssues().ToOneLineString());
475+
<< deleteOrderResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
467476
std::quick_exit(1);
468477
}
478+
LOG_T("Terminal " << context.TerminalID << " delete order failed: "
479+
<< deleteOrderResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
469480
co_return deleteOrderResult;
470481
}
471482

@@ -475,9 +486,11 @@ NThreading::TFuture<TStatus> GetDeliveryTask(
475486
if (!updateCarrierResult.IsSuccess()) {
476487
if (ShouldExit(updateCarrierResult)) {
477488
LOG_E("Terminal " << context.TerminalID << " update carrier ID failed: "
478-
<< updateCarrierResult.GetIssues().ToOneLineString());
489+
<< updateCarrierResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
479490
std::quick_exit(1);
480491
}
492+
LOG_T("Terminal " << context.TerminalID << " update carrier ID failed: "
493+
<< updateCarrierResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
481494
co_return updateCarrierResult;
482495
}
483496

@@ -489,9 +502,11 @@ NThreading::TFuture<TStatus> GetDeliveryTask(
489502
if (!updateDeliveryResult.IsSuccess()) {
490503
if (ShouldExit(updateDeliveryResult)) {
491504
LOG_E("Terminal " << context.TerminalID << " update delivery date failed: "
492-
<< updateDeliveryResult.GetIssues().ToOneLineString());
505+
<< updateDeliveryResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
493506
std::quick_exit(1);
494507
}
508+
LOG_T("Terminal " << context.TerminalID << " update delivery date failed: "
509+
<< updateDeliveryResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
495510
co_return updateDeliveryResult;
496511
}
497512

@@ -501,9 +516,11 @@ NThreading::TFuture<TStatus> GetDeliveryTask(
501516
if (!updateCustomerResult.IsSuccess()) {
502517
if (ShouldExit(updateCustomerResult)) {
503518
LOG_E("Terminal " << context.TerminalID << " update customer failed: "
504-
<< updateCustomerResult.GetIssues().ToOneLineString());
519+
<< updateCustomerResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
505520
std::quick_exit(1);
506521
}
522+
LOG_T("Terminal " << context.TerminalID << " update customer failed: "
523+
<< updateCustomerResult.GetIssues().ToOneLineString() << ", session: " << session.GetId());
507524
co_return updateCustomerResult;
508525
}
509526

@@ -512,7 +529,7 @@ NThreading::TFuture<TStatus> GetDeliveryTask(
512529
}
513530

514531
LOG_T("Terminal " << context.TerminalID
515-
<< " is committing Delivery transaction, processed " << processedOrderCount << " districts");
532+
<< " is committing Delivery transaction, processed " << processedOrderCount << " districts, session: " << session.GetId());
516533

517534
auto commitFuture = tx->Commit();
518535
auto commitResult = co_await TSuspendWithFuture(commitFuture, context.TaskQueue, context.TerminalID);

0 commit comments

Comments
 (0)