-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmocktpccdb.h
210 lines (178 loc) · 6.63 KB
/
mocktpccdb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#ifndef BENCH_MOCKTPCCDB_H__
#define BENCH_MOCKTPCCDB_H__
#include <cassert>
#include <string>
#include <vector>
#include "tpccdb.h"
namespace tpcc {
class MockTPCCDB : public TPCCDB {
public:
MockTPCCDB() : new_order_committed_(true), undo_count_(0) {}
virtual int32_t stockLevel(int32_t warehouse_id, int32_t district_id, int32_t threshold) {
w_id_ = warehouse_id;
d_id_ = district_id;
stock_level_threshold_ = threshold;
return 42;
}
virtual void orderStatus(int32_t warehouse_id, int32_t district_id, int32_t customer_id,
OrderStatusOutput* output) {
w_id_ = warehouse_id;
d_id_ = district_id;
order_status_c_id_ = customer_id;
setOrderOutput(output);
}
virtual void orderStatus(int32_t warehouse_id, int32_t district_id, const char* c_last,
OrderStatusOutput* output) {
w_id_ = warehouse_id;
d_id_ = district_id;
c_last_ = c_last;
setOrderOutput(output);
}
virtual bool newOrder(int32_t warehouse_id, int32_t district_id, int32_t customer_id,
const std::vector<NewOrderItem>& items, const char* now,
NewOrderOutput* output, TPCCUndo** undo) {
return newOrderHome(warehouse_id, district_id, customer_id, items, now, output, undo);
}
virtual bool newOrderHome(int32_t warehouse_id, int32_t district_id, int32_t customer_id,
const std::vector<NewOrderItem>& items, const char* now,
NewOrderOutput* output, TPCCUndo** undo) {
w_id_ = warehouse_id;
d_id_ = district_id;
c_id_ = customer_id;
items_ = items;
now_ = now;
// when newOrder aborts, it doesn't have an undo buffer
if (new_order_committed_) {
setUndo(undo);
}
output->d_tax = 42;
return new_order_committed_;
}
virtual bool newOrderRemote(int32_t home_warehouse, int32_t remote_warehouse,
const std::vector<NewOrderItem>& items, std::vector<int32_t>* out_quantities,
TPCCUndo** undo) {
w_id_ = home_warehouse;
remote_warehouse_ = remote_warehouse;
items_ = items;
// when newOrder aborts, it doesn't have an undo buffer
if (new_order_committed_) {
setUndo(undo);
}
out_quantities->push_back(42);
return new_order_committed_;
}
virtual void payment(int32_t warehouse_id, int32_t district_id, int32_t c_warehouse_id,
int32_t c_district_id, int32_t customer_id, float h_amount, const char* now,
PaymentOutput* output, TPCCUndo** undo) {
paymentHome(warehouse_id, district_id, c_warehouse_id, c_district_id, customer_id, h_amount,
now, output, undo);
}
virtual void payment(int32_t warehouse_id, int32_t district_id, int32_t c_warehouse_id,
int32_t c_district_id, const char* c_last, float h_amount, const char* now,
PaymentOutput* output, TPCCUndo** undo) {
c_last_ = c_last;
paymentHome(warehouse_id, district_id, c_warehouse_id, c_district_id, 0, h_amount,
now, output, undo);
}
virtual void paymentHome(int32_t warehouse_id, int32_t district_id, int32_t c_warehouse_id,
int32_t c_district_id, int32_t c_id, float h_amount, const char* now,
PaymentOutput* output, TPCCUndo** undo) {
w_id_ = warehouse_id;
d_id_ = district_id;
c_w_id_ = c_warehouse_id;
c_d_id_ = c_district_id;
c_id_ = c_id;
h_amount_ = h_amount;
now_ = now;
setPaymentOutput(output);
setUndo(undo);
}
virtual void paymentRemote(int32_t warehouse_id, int32_t district_id, int32_t c_warehouse_id,
int32_t c_district_id, int32_t c_id, float h_amount, PaymentOutput* output,
TPCCUndo** undo) {
paymentRemote(warehouse_id, district_id, c_warehouse_id, c_district_id, "", h_amount,
output, undo);
}
virtual void paymentRemote(int32_t warehouse_id, int32_t district_id, int32_t c_warehouse_id,
int32_t c_district_id, const char* c_last, float h_amount, PaymentOutput* output,
TPCCUndo** undo) {
// NULL terminate everything to avoid valgrind warnings
memset(output, 0, sizeof(*output));
w_id_ = warehouse_id;
setUndo(undo);
}
virtual void delivery(int32_t warehouse_id, int32_t carrier_id, const char* now,
std::vector<DeliveryOrderInfo>* orders, TPCCUndo** undo) {
w_id_ = warehouse_id;
delivery_carrier_id_ = carrier_id;
now_ = now;
orders->resize(1);
(*orders)[0].d_id = 1;
(*orders)[0].o_id = 42;
setUndo(undo);
}
virtual bool hasWarehouse(int32_t warehouse_id) {
return true;
}
virtual void applyUndo(TPCCUndo* undo) {
assert(undo == (TPCCUndo*) this);
assert(undo_count_ > 0);
undo_count_ -= 1;
}
virtual void freeUndo(TPCCUndo* undo) {
applyUndo(undo);
}
int32_t w_id_;
int32_t d_id_;
int32_t stock_level_threshold_;
int32_t order_status_c_id_;
std::string c_last_;
int32_t delivery_carrier_id_;
std::string now_;
int32_t c_w_id_;
int32_t c_d_id_;
int32_t c_id_;
int32_t remote_warehouse_;
float h_amount_;
std::vector<NewOrderItem> items_;
bool new_order_committed_;
int undo_count_;
private:
void setUndo(TPCCUndo** undo) {
if (undo != NULL) {
*undo = (TPCCUndo*) this;
undo_count_ += 1;
}
}
void setOrderOutput(OrderStatusOutput* output) {
output->c_balance = 1.23f;
// Null terminate to avoid uninitialized data warnings
output->c_first[0] = '\0';
output->c_middle[0] = '\0';
output->c_last[0] = '\0';
output->o_entry_d[0] = '\0';
}
#define TERMINATE_ADDRESS(struct, prefix) \
struct->prefix ## street_1[0] = '\0'; \
struct->prefix ## street_2[0] = '\0'; \
struct->prefix ## city[0] = '\0'; \
struct->prefix ## state[0] = '\0'; \
struct->prefix ## zip[0] = '\0'
void setPaymentOutput(PaymentOutput* output) {
output->c_balance = 1.23f;
// Null terminate to avoid uninitialized data warnings
TERMINATE_ADDRESS(output, w_);
TERMINATE_ADDRESS(output, d_);
TERMINATE_ADDRESS(output, c_);
output->c_first[0] = '\0';
output->c_middle[0] = '\0';
output->c_last[0] = '\0';
output->c_phone[0] = '\0';
output->c_since[0] = '\0';
output->c_credit[0] = '\0';
output->c_data[0] = '\0';
}
#undef TERMINATE_ADDRESS
};
} // namespace tpcc
#endif