19 int32_t new_orders_per_district;
20 std::mt19937 rand_generator;
22 float random_float(
float min,
float max)
24 return tpcc::random_float(min, max, rand_generator);
27 uint32_t random_int(uint32_t min, uint32_t max)
29 return tpcc::random_int(min, max, rand_generator);
32 int32_t random_int_excluding(
int lower,
int upper,
int excluding)
34 return tpcc::random_int_excluding(
35 lower, upper, excluding, rand_generator);
39 void create_random_string(
40 std::array<char, T>& str, uint32_t min, uint32_t max)
49 rand = random_int(min, max);
52 create_random_string(str, rand);
56 void create_random_string(std::array<char, T>& str, uint32_t length)
58 for (uint32_t i = 0; i < length - 1; ++i)
60 str[i] = 97 + random_int(0, 26);
62 str[length - 1] =
'\0';
66 void create_random_int(std::array<char, T>& str, uint32_t length)
68 for (uint32_t i = 0; i < length - 1; ++i)
70 str[i] = 48 + random_int(0, 10);
72 str[length - 1] =
'\0';
75 std::unordered_set<uint32_t> select_unique_ids(
76 uint32_t num_items_, uint32_t num_unique)
78 std::unordered_set<uint32_t> r;
79 for (uint32_t i = 0; i < num_items_; ++i)
84 while (r.size() > num_unique)
92 void set_original(std::array<char, T>& s)
94 int position = random_int(0, T - 8);
95 memcpy(s.data() + position,
"ORIGINAL", 8);
98 Stock generate_stock(uint32_t item_id, uint32_t wh_id,
bool is_original)
109 create_random_string(s.
dist[i],
sizeof(s.
dist[i]));
114 set_original(s.
data);
118 create_random_string(
124 void make_stock(uint32_t wh_id)
127 std::unordered_set<uint32_t> selected_rows =
128 select_unique_ids(num_items, num_items / 10);
130 for (uint32_t i = 1; i <= num_items; ++i)
132 bool is_original = selected_rows.find(i) != selected_rows.end();
133 Stock s = generate_stock(i, wh_id, is_original);
139 void generate_warehouse(int32_t
id,
Warehouse* warehouse)
144 create_random_string(
146 create_random_string(
148 random_int(Address::MIN_STREET, Address::MAX_STREET));
149 create_random_string(
151 random_int(Address::MIN_STREET, Address::MAX_STREET));
152 create_random_string(
153 warehouse->
city, random_int(Address::MIN_CITY, Address::MAX_CITY));
154 create_random_string(warehouse->
state, Address::STATE, Address::STATE);
155 create_random_string(warehouse->
zip, Address::ZIP);
158 void generate_district(int32_t
id, int32_t w_id,
District* district)
161 district->
w_id = w_id;
164 district->
next_o_id = customers_per_district + 1;
165 create_random_string(
167 create_random_string(
168 district->
street_1, Address::MIN_STREET, Address::MAX_STREET);
169 create_random_string(
170 district->
street_2, Address::MIN_STREET, Address::MAX_STREET);
171 create_random_string(
172 district->
city, Address::MIN_CITY, Address::MAX_CITY);
173 create_random_string(district->
state, Address::STATE, Address::STATE);
174 create_random_string(district->
zip, Address::ZIP);
177 void generate_customer(
185 customer->
d_id = d_id;
186 customer->
w_id = w_id;
194 create_random_string(
196 std::copy_n(
"OE", 2, customer->
middle.begin());
200 make_last_name(
id - 1, customer->
last.data());
204 make_last_name(random_int(0, 1000), customer->
last.data());
207 create_random_string(
208 customer->
street_1, Address::MIN_STREET, Address::MAX_STREET);
209 create_random_string(
210 customer->
street_2, Address::MIN_STREET, Address::MAX_STREET);
211 create_random_string(
212 customer->
city, Address::MIN_CITY, Address::MAX_CITY);
213 create_random_string(customer->
state, Address::STATE, Address::STATE);
214 create_random_string(customer->
zip, Address::ZIP);
216 customer->
since = tx_time;
231 create_random_string(
235 void generate_history(
236 int32_t c_id, int32_t d_id, int32_t w_id,
History* history)
238 history->
c_id = c_id;
240 history->
d_id = d_id;
242 history->
w_id = w_id;
244 history->
date = tx_time;
248 std::vector<int> make_permutation(
int lower,
int upper)
250 std::vector<int> array;
252 for (
int i = 0; i <= upper - lower; ++i)
254 array[i] = lower + i;
257 for (
int i = 0; i < upper - lower; ++i)
259 int index = random_int(i, upper - lower);
261 array[i] = array[index];
294 void generate_order_line(
302 orderline->
o_id = o_id;
303 orderline->
d_id = d_id;
304 orderline->
w_id = w_id;
305 orderline->
number = number;
320 create_random_string(
326 void make_warehouse_without_stock(int32_t w_id)
329 generate_warehouse(w_id, &w);
331 warehouses->put(w.
get_key(), w);
333 for (int32_t d_id = 1; d_id <= districts_per_warehouse; ++d_id)
336 generate_district(d_id, w_id, &d);
338 districts->put(d.
get_key(), d);
341 std::unordered_set<uint32_t> selected_rows = select_unique_ids(
342 customers_per_district / 10, customers_per_district);
343 for (int32_t c_id = 1; c_id <= customers_per_district; ++c_id)
346 bool bad_credit = selected_rows.find(c_id) != selected_rows.end();
347 generate_customer(c_id, d_id, w_id, bad_credit, &c);
350 table_key.
v.
w_id = w_id;
351 table_key.
v.
d_id = d_id;
355 std::string tbl_name = fmt::format(
"customer_{}_{}", w_id, d_id);
362 auto customers = args.
tx.
rw(it->second);
363 customers->put(c.
get_key(), c);
366 generate_history(c_id, d_id, w_id, &h);
375 std::vector<int> permutation =
376 make_permutation(1, customers_per_district);
377 for (int32_t o_id = 1; o_id <= customers_per_district; ++o_id)
381 customers_per_district - new_orders_per_district < o_id;
384 o_id, permutation[o_id - 1], d_id, w_id, new_order, &o);
387 table_key.
v.
w_id = w_id;
388 table_key.
v.
d_id = d_id;
392 std::string tbl_name = fmt::format(
"orders_{}_{}", w_id, d_id);
398 auto order = args.
tx.
rw(it->second);
402 for (int32_t ol_number = 1; ol_number <= o.
ol_cnt; ++ol_number)
405 generate_order_line(ol_number, o_id, d_id, w_id, new_order, &line);
407 order_lines->put(line.
get_key(), line);
412 table_key_.
v.
w_id = w_id;
413 table_key_.
v.
d_id = d_id;
417 std::string tbl_name =
418 fmt::format(
"new_orders_{}_{}", w_id, d_id);
430 auto new_orders = args.
tx.
rw(it_->second);
431 new_orders->put(no.
get_key(), no);
438 void generate_item(int32_t
id,
bool original)
449 set_original(item.
data);
452 items_table->put(item.
get_key(), item);
459 auto original_rows = select_unique_ids(num_items, num_items / 10);
461 for (uint32_t i = 1; i <= num_items; ++i)
463 bool is_original = original_rows.find(i) != original_rows.end();
464 generate_item(i, is_original);
471 int32_t new_orders_per_district_,
475 new_orders_per_district(new_orders_per_district_)
477 rand_generator.seed(seed);
485 throw std::logic_error(
"Can only create the database 1 time");
490 for (uint32_t i = 0; i < num_warehouses; ++i)
493 make_warehouse_without_stock(i);
M::Handle * rw(M &m)
Definition tx.h:213
Definition tpcc_setup.h:15
SetupDb(ccf::endpoints::EndpointContext &args_, int32_t new_orders_per_district_, uint32_t seed)
Definition tpcc_setup.h:469
void run()
Definition tpcc_setup.h:480
#define LOG_INFO_FMT
Definition logger.h:395
Definition tpcc_common.h:8
Definition endpoint_context.h:55
ccf::kv::Tx & tx
Definition endpoint_context.h:61
Definition tpcc_tables.h:313
float balance
Definition tpcc_tables.h:348
std::array< char, CREDIT+1 > credit
Definition tpcc_tables.h:362
int32_t id
Definition tpcc_tables.h:343
static const int INITIAL_PAYMENT_CNT
Definition tpcc_tables.h:319
Key get_key()
Definition tpcc_tables.h:338
std::array< char, MIDDLE+1 > middle
Definition tpcc_tables.h:353
std::array< char, MAX_DATA+1 > data
Definition tpcc_tables.h:363
static const int MAX_FIRST
Definition tpcc_tables.h:322
float ytd_payment
Definition tpcc_tables.h:349
static constexpr float INITIAL_BALANCE
Definition tpcc_tables.h:317
static constexpr float INITIAL_CREDIT_LIM
Definition tpcc_tables.h:314
int32_t w_id
Definition tpcc_tables.h:345
static constexpr float MIN_DISCOUNT
Definition tpcc_tables.h:315
int32_t payment_cnt
Definition tpcc_tables.h:350
static const int MIN_FIRST
Definition tpcc_tables.h:321
std::array< char, Address::ZIP+1 > zip
Definition tpcc_tables.h:359
static constexpr char BAD_CREDIT[]
Definition tpcc_tables.h:331
static constexpr float MAX_DISCOUNT
Definition tpcc_tables.h:316
std::array< char, Address::MAX_STREET+1 > street_1
Definition tpcc_tables.h:355
int32_t delivery_cnt
Definition tpcc_tables.h:351
std::array< char, Address::STATE+1 > state
Definition tpcc_tables.h:358
static const int MIN_DATA
Definition tpcc_tables.h:327
float credit_lim
Definition tpcc_tables.h:346
static constexpr float INITIAL_YTD_PAYMENT
Definition tpcc_tables.h:318
std::array< char, PHONE+1 > phone
Definition tpcc_tables.h:360
std::array< char, Address::MAX_CITY+1 > city
Definition tpcc_tables.h:357
float discount
Definition tpcc_tables.h:347
std::array< char, Address::MAX_STREET+1 > street_2
Definition tpcc_tables.h:356
std::array< char, DATETIME_SIZE+1 > since
Definition tpcc_tables.h:361
static constexpr char GOOD_CREDIT[]
Definition tpcc_tables.h:330
static const int MAX_DATA
Definition tpcc_tables.h:328
static const int INITIAL_DELIVERY_CNT
Definition tpcc_tables.h:320
std::array< char, MAX_FIRST+1 > first
Definition tpcc_tables.h:352
std::array< char, MAX_LAST+1 > last
Definition tpcc_tables.h:354
int32_t d_id
Definition tpcc_tables.h:344
static const int PHONE
Definition tpcc_tables.h:325
Definition tpcc_tables.h:226
std::array< char, Address::MAX_STREET+1 > street_1
Definition tpcc_tables.h:247
static const int NUM_PER_WAREHOUSE
Definition tpcc_tables.h:233
Key get_key()
Definition tpcc_tables.h:253
std::array< char, Address::ZIP+1 > zip
Definition tpcc_tables.h:251
float tax
Definition tpcc_tables.h:243
int32_t next_o_id
Definition tpcc_tables.h:245
float ytd
Definition tpcc_tables.h:244
std::array< char, Address::STATE+1 > state
Definition tpcc_tables.h:250
static const int MAX_NAME
Definition tpcc_tables.h:232
int32_t w_id
Definition tpcc_tables.h:242
static constexpr float MIN_TAX
Definition tpcc_tables.h:227
static const int MIN_NAME
Definition tpcc_tables.h:231
static constexpr float INITIAL_YTD
Definition tpcc_tables.h:229
static constexpr float MAX_TAX
Definition tpcc_tables.h:228
std::array< char, Address::MAX_STREET+1 > street_2
Definition tpcc_tables.h:248
std::array< char, MAX_NAME+1 > name
Definition tpcc_tables.h:246
std::array< char, Address::MAX_CITY+1 > city
Definition tpcc_tables.h:249
int32_t id
Definition tpcc_tables.h:241
Definition tpcc_tables.h:507
static constexpr float INITIAL_AMOUNT
Definition tpcc_tables.h:510
int32_t w_id
Definition tpcc_tables.h:530
Key get_key()
Definition tpcc_tables.h:521
int32_t c_id
Definition tpcc_tables.h:526
static const int MAX_DATA
Definition tpcc_tables.h:509
int32_t c_w_id
Definition tpcc_tables.h:528
int32_t d_id
Definition tpcc_tables.h:529
int32_t c_d_id
Definition tpcc_tables.h:527
static const int MIN_DATA
Definition tpcc_tables.h:508
std::array< char, MAX_DATA+1 > data
Definition tpcc_tables.h:533
std::array< char, DATETIME_SIZE+1 > date
Definition tpcc_tables.h:532
float amount
Definition tpcc_tables.h:531
Definition tpcc_tables.h:157
float price
Definition tpcc_tables.h:180
int32_t im_id
Definition tpcc_tables.h:179
std::array< char, MAX_DATA+1 > data
Definition tpcc_tables.h:182
static const int MIN_DATA
Definition tpcc_tables.h:164
static constexpr float MAX_PRICE
Definition tpcc_tables.h:161
int32_t id
Definition tpcc_tables.h:178
Key get_key()
Definition tpcc_tables.h:173
static const int MAX_NAME
Definition tpcc_tables.h:163
static const int MIN_NAME
Definition tpcc_tables.h:162
static constexpr float MIN_PRICE
Definition tpcc_tables.h:160
static const int MAX_DATA
Definition tpcc_tables.h:165
static const int MIN_IM
Definition tpcc_tables.h:158
static const int MAX_IM
Definition tpcc_tables.h:159
std::array< char, MAX_NAME+1 > name
Definition tpcc_tables.h:181
Definition tpcc_tables.h:482
int32_t w_id
Definition tpcc_tables.h:497
Key get_key()
Definition tpcc_tables.h:492
int32_t o_id
Definition tpcc_tables.h:499
int32_t d_id
Definition tpcc_tables.h:498
Definition tpcc_tables.h:432
int32_t supply_w_id
Definition tpcc_tables.h:458
Key get_key()
Definition tpcc_tables.h:448
static const int MAX_I_ID
Definition tpcc_tables.h:434
std::array< char, Stock::DIST+1 > dist_info
Definition tpcc_tables.h:462
static constexpr float MIN_AMOUNT
Definition tpcc_tables.h:436
int32_t o_id
Definition tpcc_tables.h:453
int32_t number
Definition tpcc_tables.h:456
std::array< char, DATETIME_SIZE+1 > delivery_d
Definition tpcc_tables.h:461
int32_t quantity
Definition tpcc_tables.h:459
int32_t d_id
Definition tpcc_tables.h:454
float amount
Definition tpcc_tables.h:460
int32_t i_id
Definition tpcc_tables.h:457
static const int MIN_I_ID
Definition tpcc_tables.h:433
static constexpr float MAX_AMOUNT
Definition tpcc_tables.h:437
int32_t w_id
Definition tpcc_tables.h:455
static const int INITIAL_QUANTITY
Definition tpcc_tables.h:435
Definition tpcc_tables.h:394
Key get_key()
Definition tpcc_tables.h:411
int32_t w_id
Definition tpcc_tables.h:419
int32_t carrier_id
Definition tpcc_tables.h:420
int32_t c_id
Definition tpcc_tables.h:417
static const int MAX_OL_CNT
Definition tpcc_tables.h:400
int32_t id
Definition tpcc_tables.h:416
std::array< char, DATETIME_SIZE+1 > entry_d
Definition tpcc_tables.h:423
static const int MAX_CARRIER_ID
Definition tpcc_tables.h:396
int32_t d_id
Definition tpcc_tables.h:418
int32_t all_local
Definition tpcc_tables.h:422
static const int MIN_CARRIER_ID
Definition tpcc_tables.h:395
static const int MIN_OL_CNT
Definition tpcc_tables.h:399
static const int NULL_CARRIER_ID
Definition tpcc_tables.h:397
int32_t ol_cnt
Definition tpcc_tables.h:421
static const int INITIAL_ALL_LOCAL
Definition tpcc_tables.h:401
Definition tpcc_tables.h:277
int32_t ytd
Definition tpcc_tables.h:288
int32_t order_cnt
Definition tpcc_tables.h:289
int32_t quantity
Definition tpcc_tables.h:287
static const int MAX_DATA
Definition tpcc_tables.h:282
std::array< std::array< char, DIST+1 >, District::NUM_PER_WAREHOUSE > dist
Definition tpcc_tables.h:291
int32_t i_id
Definition tpcc_tables.h:285
Key get_key()
Definition tpcc_tables.h:301
static const int MAX_QUANTITY
Definition tpcc_tables.h:279
static const int MIN_QUANTITY
Definition tpcc_tables.h:278
int32_t remote_cnt
Definition tpcc_tables.h:290
std::array< char, MAX_DATA+1 > data
Definition tpcc_tables.h:293
static const int MIN_DATA
Definition tpcc_tables.h:281
int32_t w_id
Definition tpcc_tables.h:286
static std::unordered_map< uint64_t, TpccMap< Order::Key, Order > > orders
Definition tpcc_tables.h:565
static TpccMap< Stock::Key, Stock > stocks
Definition tpcc_tables.h:559
static std::unordered_map< uint64_t, TpccMap< NewOrder::Key, NewOrder > > new_orders
Definition tpcc_tables.h:568
static TpccMap< District::Key, District > districts
Definition tpcc_tables.h:561
static TpccMap< OrderLine::Key, OrderLine > order_lines
Definition tpcc_tables.h:566
static TpccMap< History::Key, History > histories
Definition tpcc_tables.h:562
static TpccMap< Warehouse::Key, Warehouse > warehouses
Definition tpcc_tables.h:560
static std::unordered_map< uint64_t, TpccMap< Customer::Key, Customer > > customers
Definition tpcc_tables.h:564
static TpccMap< Item::Key, Item > items
Definition tpcc_tables.h:569
Definition tpcc_tables.h:190
std::array< char, Address::ZIP+1 > zip
Definition tpcc_tables.h:217
std::array< char, MAX_NAME+1 > name
Definition tpcc_tables.h:212
Key get_key()
Definition tpcc_tables.h:204
static constexpr float MAX_TAX
Definition tpcc_tables.h:192
static const int MAX_NAME
Definition tpcc_tables.h:195
float ytd
Definition tpcc_tables.h:211
std::array< char, Address::MAX_STREET+1 > city
Definition tpcc_tables.h:215
std::array< char, Address::MAX_STREET+1 > street_2
Definition tpcc_tables.h:214
static constexpr float MIN_TAX
Definition tpcc_tables.h:191
std::array< char, Address::STATE+1 > state
Definition tpcc_tables.h:216
int32_t id
Definition tpcc_tables.h:209
static const int MIN_NAME
Definition tpcc_tables.h:194
float tax
Definition tpcc_tables.h:210
static constexpr float INITIAL_YTD
Definition tpcc_tables.h:193
std::array< char, Address::MAX_STREET+1 > street_1
Definition tpcc_tables.h:213
Definition tpcc_tables.h:547
int32_t d_id
Definition tpcc_tables.h:551
int32_t w_id
Definition tpcc_tables.h:550
struct tpcc::TpccTables::DistributeKey::@2 v
uint64_t k
Definition tpcc_tables.h:553