13#include <nlohmann/json.hpp>
15#include <unordered_map>
16#include <unordered_set>
32 return std::tuple_size_v<T> * serialised_size<typename T::value_type>();
45 if constexpr (std::is_integral_v<typename T::value_type>)
48 data, size, (
const uint8_t*)v.data(), serialised_size<T>());
52 for (
const auto& e : v)
65 void read_value(T& v,
const uint8_t*& data,
size_t& size)
69 if constexpr (std::is_integral_v<typename T::value_type>)
71 constexpr auto n = serialised_size<T>();
72 memcpy(v.data(), data, n);
85 v = serialized::read<T>(data, size);
89#pragma clang diagnostic push
90#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
91#define ADD_SERIALIZED_SIZE_FOR_JSON_NEXT(TYPE, FIELD) \
92 +serialised_size<decltype(TYPE::FIELD)>()
93#define ADD_SERIALIZED_SIZE_FOR_JSON_FINAL(TYPE, FIELD) \
94 ADD_SERIALIZED_SIZE_FOR_JSON_NEXT(TYPE, FIELD)
96#define WRITE_VALUE_FOR_JSON_NEXT(TYPE, FIELD) write_value(t.FIELD, data, size);
97#define WRITE_VALUE_FOR_JSON_FINAL(TYPE, FIELD) \
98 WRITE_VALUE_FOR_JSON_NEXT(TYPE, FIELD)
100#define READ_VALUE_FOR_JSON_NEXT(TYPE, FIELD) read_value(t.FIELD, data, size);
101#define READ_VALUE_FOR_JSON_FINAL(TYPE, FIELD) \
102 READ_VALUE_FOR_JSON_NEXT(TYPE, FIELD)
104#define DECLARE_TPCC_TYPE(TYPE)
105#define DECLARE_TPCC_REQUIRED_FIELDS(TYPE, ...) \
106 _Pragma("clang diagnostic push"); \
107 _Pragma("clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\""); \
109 ccf::kv::serialisers::SerialisedEntry tpcc_serialise(const TYPE& t) \
111 ccf::kv::serialisers::SerialisedEntry rep; \
112 constexpr size_t required_size = 0 _FOR_JSON_COUNT_NN(__VA_ARGS__)(POP1)( \
113 ADD_SERIALIZED_SIZE, TYPE, ##__VA_ARGS__); \
114 rep.resize(required_size); \
115 auto data = rep.data(); \
116 auto size = rep.size(); \
117 _FOR_JSON_COUNT_NN(__VA_ARGS__)(POP1)(WRITE_VALUE, TYPE, ##__VA_ARGS__); \
121 TYPE tpcc_deserialise(const ccf::kv::serialisers::SerialisedEntry& rep) \
123 auto data = rep.data(); \
124 auto size = rep.size(); \
126 _FOR_JSON_COUNT_NN(__VA_ARGS__)(POP1)(READ_VALUE, TYPE, ##__VA_ARGS__); \
129 _Pragma("clang diagnostic pop");
130#pragma clang diagnostic pop
132 template <
typename T>
142 return tpcc_deserialise<T>(rep);
148 static const int MIN_STREET = 10;
149 static const int MAX_STREET = 20;
150 static const int MIN_CITY = 10;
151 static const int MAX_CITY = 20;
152 static const int STATE = 2;
153 static const int ZIP = 9;
181 std::array<char, MAX_NAME + 1>
name = {0};
182 std::array<char, MAX_DATA + 1>
data = {0};
212 std::array<char, MAX_NAME + 1>
name = {0};
213 std::array<char, Address::MAX_STREET + 1>
street_1 = {0};
214 std::array<char, Address::MAX_STREET + 1>
street_2 = {0};
215 std::array<char, Address::MAX_STREET + 1>
city = {0};
216 std::array<char, Address::STATE + 1>
state = {0};
217 std::array<char, Address::ZIP + 1>
zip = {0};
223 Warehouse,
id, tax, ytd, name, street_1, street_2, city, state, zip);
246 std::array<char, MAX_NAME + 1>
name = {0};
247 std::array<char, Address::MAX_STREET + 1>
street_1 = {0};
248 std::array<char, Address::MAX_STREET + 1>
street_2 = {0};
249 std::array<char, Address::MAX_CITY + 1>
city = {0};
250 std::array<char, Address::STATE + 1>
state = {0};
251 std::array<char, Address::ZIP + 1>
zip = {0};
293 std::array<char, MAX_DATA + 1>
data = {0};
310 Stock, i_id, w_id, quantity, ytd, order_cnt, remote_cnt, dist, data);
352 std::array<char, MAX_FIRST + 1>
first = {0};
353 std::array<char, MIDDLE + 1>
middle = {0};
354 std::array<char, MAX_LAST + 1>
last = {0};
355 std::array<char, Address::MAX_STREET + 1>
street_1 = {0};
356 std::array<char, Address::MAX_STREET + 1>
street_2 = {0};
357 std::array<char, Address::MAX_CITY + 1>
city = {0};
358 std::array<char, Address::STATE + 1>
state = {0};
359 std::array<char, Address::ZIP + 1>
zip = {0};
360 std::array<char, PHONE + 1>
phone = {0};
361 std::array<char, DATETIME_SIZE + 1>
since = {0};
362 std::array<char, CREDIT + 1>
credit = {0};
363 std::array<char, MAX_DATA + 1>
data = {0};
423 std::array<char, DATETIME_SIZE + 1>
entry_d = {0};
429 Order,
id, c_id, d_id, w_id, carrier_id, ol_cnt, all_local, entry_d);
532 std::array<char, DATETIME_SIZE + 1>
date = {0};
533 std::array<char, MAX_DATA + 1>
data = {0};
539 History, c_id, c_d_id, c_w_id, d_id, w_id, amount, date, data);
541 template <
typename K,
typename V>
557 "Distribute key is the wrong size");
563 static std::unordered_map<uint64_t, TpccMap<Customer::Key, Customer>>
565 static std::unordered_map<uint64_t, TpccMap<Order::Key, Order>>
orders;
567 static std::unordered_map<uint64_t, TpccMap<NewOrder::Key, NewOrder>>
ccf::ByteVector SerialisedEntry
Definition serialised_entry.h:8
void write(uint8_t *&data, size_t &size, const T &v)
Definition serialized.h:106
void skip(const uint8_t *&data, size_t &size, size_t skip)
Definition serialized.h:166
Definition tpcc_common.h:8
void write_value(const T &v, uint8_t *&data, size_t &size)
Definition tpcc_tables.h:41
T tpcc_deserialise(const ccf::kv::serialisers::SerialisedEntry &rep)
void read_value(T &v, const uint8_t *&data, size_t &size)
Definition tpcc_tables.h:65
ccf::kv::serialisers::SerialisedEntry tpcc_serialise(const T &t)
constexpr size_t serialised_size()
Definition tpcc_tables.h:28
Definition tpcc_tables.h:334
int32_t id
Definition tpcc_tables.h:335
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 const int MAX_LAST
Definition tpcc_tables.h:324
static constexpr float INITIAL_CREDIT_LIM
Definition tpcc_tables.h:314
int32_t w_id
Definition tpcc_tables.h:345
static const int NUM_PER_DISTRICT
Definition tpcc_tables.h:329
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
static const int CREDIT
Definition tpcc_tables.h:326
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 MIDDLE
Definition tpcc_tables.h:323
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:236
int32_t id
Definition tpcc_tables.h:237
int32_t w_id
Definition tpcc_tables.h:238
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 const int INITIAL_NEXT_O_ID
Definition tpcc_tables.h:230
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:513
int32_t w_id
Definition tpcc_tables.h:518
int32_t c_id
Definition tpcc_tables.h:514
int32_t d_id
Definition tpcc_tables.h:517
int32_t c_w_id
Definition tpcc_tables.h:516
int32_t c_d_id
Definition tpcc_tables.h:515
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:169
int32_t id
Definition tpcc_tables.h:170
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 NUM_ITEMS
Definition tpcc_tables.h:166
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:486
int32_t w_id
Definition tpcc_tables.h:487
int32_t d_id
Definition tpcc_tables.h:488
int32_t o_id
Definition tpcc_tables.h:489
Definition tpcc_tables.h:482
int32_t w_id
Definition tpcc_tables.h:497
Key get_key()
Definition tpcc_tables.h:492
static const int INITIAL_NUM_PER_DISTRICT
Definition tpcc_tables.h:483
int32_t o_id
Definition tpcc_tables.h:499
int32_t d_id
Definition tpcc_tables.h:498
Definition tpcc_tables.h:441
int32_t w_id
Definition tpcc_tables.h:444
int32_t number
Definition tpcc_tables.h:445
int32_t d_id
Definition tpcc_tables.h:443
int32_t o_id
Definition tpcc_tables.h:442
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
static const int REMOTE_PROBABILITY_MILLIS
Definition tpcc_tables.h:438
Definition tpcc_tables.h:407
int32_t id
Definition tpcc_tables.h:408
Definition tpcc_tables.h:394
Key get_key()
Definition tpcc_tables.h:411
static const int MAX_ORDER_ID
Definition tpcc_tables.h:404
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
static const int INITIAL_ORDERS_PER_DISTRICT
Definition tpcc_tables.h:402
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
static const int NULL_CARRIER_LOWER_BOUND
Definition tpcc_tables.h:398
int32_t ol_cnt
Definition tpcc_tables.h:421
static const int INITIAL_ALL_LOCAL
Definition tpcc_tables.h:401
Definition tpcc_tables.h:296
int32_t w_id
Definition tpcc_tables.h:298
int32_t i_id
Definition tpcc_tables.h:297
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
static const int NUM_STOCK_PER_WAREHOUSE
Definition tpcc_tables.h:283
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 DIST
Definition tpcc_tables.h:280
static const int MIN_DATA
Definition tpcc_tables.h:281
int32_t w_id
Definition tpcc_tables.h:286
Definition tpcc_tables.h:134
static ccf::kv::serialisers::SerialisedEntry to_serialised(const T &t)
Definition tpcc_tables.h:135
static T from_serialised(const ccf::kv::serialisers::SerialisedEntry &rep)
Definition tpcc_tables.h:140
Definition tpcc_tables.h:545
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:200
int32_t id
Definition tpcc_tables.h:201
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
static const int MAX_WAREHOUSE_ID
Definition tpcc_tables.h:198
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
#define DECLARE_TPCC_REQUIRED_FIELDS(TYPE,...)
Definition tpcc_tables.h:105
#define DECLARE_TPCC_TYPE(TYPE)
Definition tpcc_tables.h:104
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