forked from readablesystems/sto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHT_txns.hh
327 lines (285 loc) · 10.5 KB
/
HT_txns.hh
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#pragma once
#include <set>
#include "HT_bench.hh"
namespace htbench {
static constexpr uint64_t max_txns = 200000;
/*
template <typename DBParams>
void htbench_runner<DBParams>::gen_workload(int txn_size) {
dist_init();
for (uint64_t i = 0; i < max_txns; ++i) {
htbench_txn_t txn {};
txn.ops.reserve(txn_size);
std::set<uint32_t> key_set;
for (int j = 0; j < txn_size; ++j) {
uint32_t key;
do {
key = dd->sample();
} while (key_set.find(key) != key_set.end());
key_set.insert(key);
}
bool any_write = false;
for (auto it = key_set.begin(); it != key_set.end(); ++it) {
bool is_write = ud->sample() < write_threshold;
ht_op_t op {};
op.is_write = is_write;
op.key = *it;
if (is_write) {
any_write = true;
ig.random_ht_col_value_inplace(&op.value);
}
txn.ops.push_back(std::move(op));
}
txn.rw_txn = any_write;
workload.push_back(std::move(txn));
}
}
*/
template <typename DBParams>
void htbench_runner<DBParams>::gen_workload(uint64_t read_txn_size) {
bool is_write = write_threshold > 0;
const uint64_t txn_size = is_write ? 1 : read_txn_size;
dist_init();
for (uint64_t i = 0; i < max_txns; i += txn_size) {
htbench_txn_t txn {};
txn.ops.reserve(txn_size);
for (uint64_t j = 0; j < txn_size; j++) {
uint32_t key = dd->sample();
bool any_write = is_write;
ht_op_t op {};
op.is_write = is_write;
op.key = key;
if (is_write) {
any_write = true;
ig.random_ht_col_value_inplace(&op.value);
}
txn.ops.push_back(std::move(op));
txn.rw_txn |= any_write;
}
workload.push_back(std::move(txn));
}
}
using bench::RowAccess;
template <typename DBParams>
typename htbench_runner<DBParams>::txn_type htbench_runner<DBParams>::run_txn(
const htbench_txn_t& txn) {
ht_value::col_type output;
//uint64_t op_start_tick = 0;
//uint64_t op_end_tick = 0;
if (!nontrans || !txn.ops[0].is_write) {
//uint64_t txn_start_tick = read_tsc();
TRANSACTION {
//bool success, result;
bool failure, result;
uintptr_t row;
const void* value;
if (DBParams::MVCC && txn.rw_txn) {
Sto::mvcc_rw_upgrade();
}
for (auto& op : txn.ops) {
//op_start_tick = read_tsc();
if (op.is_write) {
ht_key key(op.key);
/*
std::tie(success, result, row, value)
= table.table().select_row(key,
Commute ? RowAccess::None : RowAccess::ObserveValue
);
*/
std::tie(failure, result, row, value)
= table.table().transGet(
key, table_type::ReadOnlyAccess).to_tuple();
//op_end_tick = read_tsc();
//TSC_ACCOUNT(tc_txn_write, op_end_tick - op_start_tick);
//TXN_DO(success);
TXN_DO(!failure);
assert(result);
//op_start_tick = read_tsc();
if (Commute) {
/*
commutators::Commutator<ht_value> comm(op.value);
table.table().update_row(row, comm);
*/
} else {
auto old_val = reinterpret_cast<const ht_value*>(value);
auto new_val = Sto::tx_alloc(old_val);
new_val->value = op.value;
//table.table().update_row(row, new_val);
table.table().transUpdate(row, new_val);
}
//op_end_tick = read_tsc();
//TSC_ACCOUNT(tc_txn_write, op_end_tick - op_start_tick);
} else {
//auto key_start_t = read_tsc();
ht_key key(op.key);
//TSC_ACCOUNT(tc_keygen, read_tsc() - key_start_t);
//auto table_start_t = read_tsc();
auto& tbl = table.table();
//TSC_ACCOUNT(tc_table, read_tsc() - table_start_t);
//auto sel_start_t = read_tsc();
/*
auto res
= tbl.select_row(key,
RowAccess::ObserveValue
);
*/
auto res = tbl.transGet(
key, table_type::ReadOnlyAccess).to_tuple();
//TSC_ACCOUNT(tc_select_call, read_tsc() - sel_start_t);
//auto untie_start_t = read_tsc();
//std::tie(success, result, row, value) = res;
std::tie(failure, result, row, value) = res;
//TSC_ACCOUNT(tc_untie, read_tsc() - untie_start_t);
//op_end_tick = read_tsc();
//TSC_ACCOUNT(tc_txn_read, op_end_tick - op_start_tick);
//TXN_DO(success);
TXN_DO(!failure);
assert(result);
//op_start_tick = read_tsc();
output = reinterpret_cast<const ht_value*>(value)->value;
//op_end_tick = read_tsc();
//TSC_ACCOUNT(tc_txn_read, op_end_tick - op_start_tick);
}
}
} RETRY(true);
//uint64_t txn_end_tick = read_tsc();
//TSC_ACCOUNT(tc_txn_total, txn_end_tick - txn_start_tick);
} else {
//uint64_t txn_start_tick = read_tsc();
//op_start_tick = read_tsc();
ht_key key(txn.ops[0].key);
auto* value_p = table.table().nontrans_get(key);
if (value_p) {
output = value_p->value;
}
//op_end_tick = read_tsc();
//TSC_ACCOUNT(tc_txn_read, op_end_tick - op_start_tick);
/*
for (auto& op : txn.ops) {
op_start_tick = read_tsc();
if (op.is_write) {
ht_key key(op.key);
ht_value* value_p = table.table().nontrans_get(key);
if (value_p) {
value_p->value = op.value;
table.table().nontrans_put(key, *value_p);
} else {
ht_value value;
value.value = op.value;
table.table().nontrans_put(key, value);
}
op_end_tick = read_tsc();
write_ticks += op_end_tick - op_start_tick;
} else {
ht_key key(op.key);
auto* value_p = table.table().nontrans_get(key);
if (value_p) {
output = value_p->value;
}
op_end_tick = read_tsc();
read_ticks += op_end_tick - op_start_tick;
}
}
*/
//uint64_t txn_end_tick = read_tsc();
//TSC_ACCOUNT(tc_txn_total, txn_end_tick - txn_start_tick);
}
(void)output;
}
template <typename DBParams>
void htbench_barerunner<DBParams>::gen_workload(uint64_t read_txn_size) {
bool is_write = write_threshold > 0;
const uint64_t txn_size = is_write ? 1 : read_txn_size;
dist_init();
for (uint64_t i = 0; i < max_txns; i += txn_size) {
htbench_txn_t txn {};
txn.ops.reserve(txn_size);
for (uint64_t j = 0; j < txn_size; j++) {
uint32_t key = dd->sample();
bool any_write = is_write;
ht_op_t op {};
op.is_write = is_write;
op.key = key;
if (is_write) {
any_write = true;
ig.random_ht_col_value_inplace(&op.value);
}
txn.ops.push_back(std::move(op));
txn.rw_txn |= any_write;
}
workload.push_back(std::move(txn));
}
}
using bench::RowAccess;
template <typename DBParams>
typename htbench_barerunner<DBParams>::txn_type
htbench_barerunner<DBParams>::run_txn(
const htbench_txn_t&) {
ht_value::col_type output;
if (!nontrans) {
TRANSACTION {
//auto start_tick = read_tsc();
/*
bool success, result;
uintptr_t row;
const void* value;
if (DBParams::MVCC && txn.rw_txn) {
Sto::mvcc_rw_upgrade();
}
for (auto& op : txn.ops) {
if (op.is_write) {
ht_key key(op.key);
std::tie(success, result, row, value)
= table.table().select_row(key,
Commute ? RowAccess::None : RowAccess::ObserveValue
);
TXN_DO(success);
assert(result);
if (Commute) {
commutators::Commutator<ht_value> comm(op.value);
table.table().update_row(row, comm);
} else {
auto old_val = reinterpret_cast<const ht_value*>(value);
auto new_val = Sto::tx_alloc(old_val);
new_val->value = op.value;
table.table().update_row(row, new_val);
}
} else {
ht_key key(op.key);
auto& tbl = table.table();
auto res
= tbl.select_row(key,
RowAccess::ObserveValue
);
std::tie(success, result, row, value) = res;
TXN_DO(success);
assert(result);
output = reinterpret_cast<const ht_value*>(value)->value;
}
}
*/
int foo = 0;
(void) foo;
TXN_DO(true);
/*
for (char foo = 0; foo >= 0; foo++) {
(void) foo;
}
*/
//TSC_ACCOUNT(tc_txn_read, read_tsc() - start_tick);
} RETRY(true);
} else {
do {
TransactionLoopGuard __txn_guard;
int foo = 0;
(void) foo;
/*
for (char foo = 0; foo >= 0; foo++) {
(void) foo;
}
*/
} while (false);
}
(void)output;
}
};