-
Notifications
You must be signed in to change notification settings - Fork 117
/
txn_impl.h
643 lines (593 loc) · 23.1 KB
/
txn_impl.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
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
#ifndef _NDB_TXN_IMPL_H_
#define _NDB_TXN_IMPL_H_
#include "txn.h"
#include "lockguard.h"
// base definitions
template <template <typename> class Protocol, typename Traits>
transaction<Protocol, Traits>::transaction(uint64_t flags, string_allocator_type &sa)
: transaction_base(flags), sa(&sa)
{
INVARIANT(rcu::s_instance.in_rcu_region());
#ifdef BTREE_LOCK_OWNERSHIP_CHECKING
concurrent_btree::NodeLockRegionBegin();
#endif
}
template <template <typename> class Protocol, typename Traits>
transaction<Protocol, Traits>::~transaction()
{
// transaction shouldn't fall out of scope w/o resolution
// resolution means TXN_EMBRYO, TXN_COMMITED, and TXN_ABRT
INVARIANT(state != TXN_ACTIVE);
INVARIANT(rcu::s_instance.in_rcu_region());
const unsigned cur_depth = rcu_guard_->sync()->depth();
rcu_guard_.destroy();
if (cur_depth == 1) {
INVARIANT(!rcu::s_instance.in_rcu_region());
cast()->on_post_rcu_region_completion();
}
#ifdef BTREE_LOCK_OWNERSHIP_CHECKING
concurrent_btree::AssertAllNodeLocksReleased();
#endif
}
template <template <typename> class Protocol, typename Traits>
void
transaction<Protocol, Traits>::clear()
{
// it's actually *more* efficient to not call clear explicitly on the
// read/write/absent sets, and let the destructors do the clearing- this is
// because the destructors can take shortcuts since it knows the obj doesn't
// have to end in a valid state
}
template <template <typename> class Protocol, typename Traits>
void
transaction<Protocol, Traits>::abort_impl(abort_reason reason)
{
abort_trap(reason);
switch (state) {
case TXN_EMBRYO:
case TXN_ACTIVE:
break;
case TXN_ABRT:
return;
case TXN_COMMITED:
throw transaction_unusable_exception();
}
state = TXN_ABRT;
this->reason = reason;
// on abort, we need to go over all insert nodes and
// release the locks
typename write_set_map::iterator it = write_set.begin();
typename write_set_map::iterator it_end = write_set.end();
for (; it != it_end; ++it) {
dbtuple * const tuple = it->get_tuple();
if (it->is_insert()) {
INVARIANT(tuple->is_locked());
this->cleanup_inserted_tuple_marker(tuple, it->get_key(), it->get_btree());
tuple->unlock();
}
}
clear();
}
template <template <typename> class Protocol, typename Traits>
void
transaction<Protocol, Traits>::cleanup_inserted_tuple_marker(
dbtuple *marker, const std::string &key, concurrent_btree *btr)
{
// XXX: this code should really live in txn_proto2_impl.h
INVARIANT(marker->version == dbtuple::MAX_TID);
INVARIANT(marker->is_locked());
INVARIANT(marker->is_lock_owner());
typename concurrent_btree::value_type removed = 0;
const bool did_remove = btr->remove(varkey(key), &removed);
if (unlikely(!did_remove)) {
#ifdef CHECK_INVARIANTS
std::cerr << " *** could not remove key: " << util::hexify(key) << std::endl;
#ifdef TUPLE_CHECK_KEY
std::cerr << " *** original key : " << util::hexify(marker->key) << std::endl;
#endif
#endif
ALWAYS_ASSERT(false);
}
INVARIANT(removed == (typename concurrent_btree::value_type) marker);
INVARIANT(marker->is_latest());
marker->clear_latest();
dbtuple::release(marker); // rcu free
}
namespace {
inline const char *
transaction_state_to_cstr(transaction_base::txn_state state)
{
switch (state) {
case transaction_base::TXN_EMBRYO: return "TXN_EMBRYO";
case transaction_base::TXN_ACTIVE: return "TXN_ACTIVE";
case transaction_base::TXN_ABRT: return "TXN_ABRT";
case transaction_base::TXN_COMMITED: return "TXN_COMMITED";
}
ALWAYS_ASSERT(false);
return 0;
}
inline std::string
transaction_flags_to_str(uint64_t flags)
{
bool first = true;
std::ostringstream oss;
if (flags & transaction_base::TXN_FLAG_LOW_LEVEL_SCAN) {
oss << "TXN_FLAG_LOW_LEVEL_SCAN";
first = false;
}
if (flags & transaction_base::TXN_FLAG_READ_ONLY) {
if (first)
oss << "TXN_FLAG_READ_ONLY";
else
oss << " | TXN_FLAG_READ_ONLY";
first = false;
}
return oss.str();
}
}
template <template <typename> class Protocol, typename Traits>
void
transaction<Protocol, Traits>::dump_debug_info() const
{
std::cerr << "Transaction (obj=" << util::hexify(this) << ") -- state "
<< transaction_state_to_cstr(state) << std::endl;
std::cerr << " Abort Reason: " << AbortReasonStr(reason) << std::endl;
std::cerr << " Flags: " << transaction_flags_to_str(flags) << std::endl;
std::cerr << " Read/Write sets:" << std::endl;
std::cerr << " === Read Set ===" << std::endl;
// read-set
for (typename read_set_map::const_iterator rs_it = read_set.begin();
rs_it != read_set.end(); ++rs_it)
std::cerr << *rs_it << std::endl;
std::cerr << " === Write Set ===" << std::endl;
// write-set
for (typename write_set_map::const_iterator ws_it = write_set.begin();
ws_it != write_set.end(); ++ws_it)
std::cerr << *ws_it << std::endl;
std::cerr << " === Absent Set ===" << std::endl;
// absent-set
for (typename absent_set_map::const_iterator as_it = absent_set.begin();
as_it != absent_set.end(); ++as_it)
std::cerr << " B-tree Node " << util::hexify(as_it->first)
<< " : " << as_it->second << std::endl;
}
template <template <typename> class Protocol, typename Traits>
std::map<std::string, uint64_t>
transaction<Protocol, Traits>::get_txn_counters() const
{
std::map<std::string, uint64_t> ret;
// max_read_set_size
ret["read_set_size"] = read_set.size();;
ret["read_set_is_large?"] = !read_set.is_small_type();
// max_absent_set_size
ret["absent_set_size"] = absent_set.size();
ret["absent_set_is_large?"] = !absent_set.is_small_type();
// max_write_set_size
ret["write_set_size"] = write_set.size();
ret["write_set_is_large?"] = !write_set.is_small_type();
return ret;
}
template <template <typename> class Protocol, typename Traits>
bool
transaction<Protocol, Traits>::handle_last_tuple_in_group(
dbtuple_write_info &last,
bool did_group_insert)
{
if (did_group_insert) {
// don't need to lock
if (!last.is_insert())
// we inserted the last run, and then we did 1+ more overwrites
// to it, so we do NOT need to lock the node (again), but we DO
// need to apply the latest write
last.entry->set_do_write();
} else {
dbtuple *tuple = last.get_tuple();
if (unlikely(tuple->version == dbtuple::MAX_TID)) {
// if we race to put/insert w/ another txn which has inserted a new
// record, we *must* abort b/c the other txn could try to put/insert
// into a new record which we hold the lock on, so we must abort
//
// other ideas:
// we could *not* abort if this txn did not insert any new records.
// we could also release our insert locks and try to acquire them
// again in sorted order
return false; // signal abort
}
const dbtuple::version_t v = tuple->lock(true); // lock for write
INVARIANT(dbtuple::IsLatest(v) == tuple->is_latest());
last.mark_locked();
if (unlikely(!dbtuple::IsLatest(v) ||
!cast()->can_read_tid(tuple->version))) {
// XXX(stephentu): overly conservative (with the can_read_tid() check)
return false; // signal abort
}
last.entry->set_do_write();
}
return true;
}
template <template <typename> class Protocol, typename Traits>
bool
transaction<Protocol, Traits>::commit(bool doThrow)
{
#ifdef TUPLE_MAGIC
try {
#endif
PERF_DECL(
static std::string probe0_name(
std::string(__PRETTY_FUNCTION__) + std::string(":total:")));
ANON_REGION(probe0_name.c_str(), &transaction_base::g_txn_commit_probe0_cg);
switch (state) {
case TXN_EMBRYO:
case TXN_ACTIVE:
break;
case TXN_COMMITED:
return true;
case TXN_ABRT:
if (doThrow)
throw transaction_abort_exception(reason);
return false;
}
dbtuple_write_info_vec write_dbtuples;
std::pair<bool, tid_t> commit_tid(false, 0);
// copy write tuples to vector for sorting
if (!write_set.empty()) {
PERF_DECL(
static std::string probe1_name(
std::string(__PRETTY_FUNCTION__) + std::string(":lock_write_nodes:")));
ANON_REGION(probe1_name.c_str(), &transaction_base::g_txn_commit_probe1_cg);
INVARIANT(!is_snapshot());
typename write_set_map::iterator it = write_set.begin();
typename write_set_map::iterator it_end = write_set.end();
for (size_t pos = 0; it != it_end; ++it, ++pos) {
INVARIANT(!it->is_insert() || it->get_tuple()->is_locked());
write_dbtuples.emplace_back(it->get_tuple(), &(*it), it->is_insert(), pos);
}
}
// read_only txns require consistent snapshots
INVARIANT(!is_snapshot() || read_set.empty());
INVARIANT(!is_snapshot() || write_set.empty());
INVARIANT(!is_snapshot() || absent_set.empty());
if (!is_snapshot()) {
// we don't have consistent tids, or not a read-only txn
// lock write nodes
if (!write_dbtuples.empty()) {
PERF_DECL(
static std::string probe2_name(
std::string(__PRETTY_FUNCTION__) + std::string(":lock_write_nodes:")));
ANON_REGION(probe2_name.c_str(), &transaction_base::g_txn_commit_probe2_cg);
// lock the logical nodes in sort order
{
PERF_DECL(
static std::string probe6_name(
std::string(__PRETTY_FUNCTION__) + std::string(":sort_write_nodes:")));
ANON_REGION(probe6_name.c_str(), &transaction_base::g_txn_commit_probe6_cg);
write_dbtuples.sort(); // in-place
}
typename dbtuple_write_info_vec::iterator it = write_dbtuples.begin();
typename dbtuple_write_info_vec::iterator it_end = write_dbtuples.end();
dbtuple_write_info *last_px = nullptr;
bool inserted_last_run = false;
for (; it != it_end; last_px = &(*it), ++it) {
if (likely(last_px && last_px->tuple != it->tuple)) {
// on boundary
if (unlikely(!handle_last_tuple_in_group(*last_px, inserted_last_run))) {
abort_trap((reason = ABORT_REASON_WRITE_NODE_INTERFERENCE));
goto do_abort;
}
inserted_last_run = false;
}
if (it->is_insert()) {
INVARIANT(!last_px || last_px->tuple != it->tuple);
INVARIANT(it->is_locked());
INVARIANT(it->get_tuple()->is_locked());
INVARIANT(it->get_tuple()->is_lock_owner());
it->entry->set_do_write(); // all inserts are marked do-write
inserted_last_run = true;
} else {
INVARIANT(!it->is_locked());
}
}
if (likely(last_px) &&
unlikely(!handle_last_tuple_in_group(*last_px, inserted_last_run))) {
abort_trap((reason = ABORT_REASON_WRITE_NODE_INTERFERENCE));
goto do_abort;
}
commit_tid.first = true;
PERF_DECL(
static std::string probe5_name(
std::string(__PRETTY_FUNCTION__) + std::string(":gen_commit_tid:")));
ANON_REGION(probe5_name.c_str(), &transaction_base::g_txn_commit_probe5_cg);
commit_tid.second = cast()->gen_commit_tid(write_dbtuples);
VERBOSE(std::cerr << "commit tid: " << g_proto_version_str(commit_tid.second) << std::endl);
} else {
VERBOSE(std::cerr << "commit tid: <read-only>" << std::endl);
}
// do read validation
{
PERF_DECL(
static std::string probe3_name(
std::string(__PRETTY_FUNCTION__) + std::string(":read_validation:")));
ANON_REGION(probe3_name.c_str(), &transaction_base::g_txn_commit_probe3_cg);
// check the nodes we actually read are still the latest version
if (!read_set.empty()) {
typename read_set_map::iterator it = read_set.begin();
typename read_set_map::iterator it_end = read_set.end();
for (; it != it_end; ++it) {
VERBOSE(std::cerr << "validating dbtuple " << util::hexify(it->get_tuple())
<< " at snapshot_tid "
<< g_proto_version_str(cast()->snapshot_tid())
<< std::endl);
const bool found = sorted_dbtuples_contains(
write_dbtuples, it->get_tuple());
if (likely(found ?
it->get_tuple()->is_latest_version(it->get_tid()) :
it->get_tuple()->stable_is_latest_version(it->get_tid())))
continue;
VERBOSE(std::cerr << "validating dbtuple " << util::hexify(it->get_tuple()) << " at snapshot_tid "
<< g_proto_version_str(cast()->snapshot_tid()) << " FAILED" << std::endl
<< " txn read version: " << g_proto_version_str(it->get_tid()) << std::endl
<< " tuple=" << *it->get_tuple() << std::endl);
//std::cerr << "failed tuple: " << *it->get_tuple() << std::endl;
abort_trap((reason = ABORT_REASON_READ_NODE_INTEREFERENCE));
goto do_abort;
}
}
// check btree versions have not changed
if (!absent_set.empty()) {
typename absent_set_map::iterator it = absent_set.begin();
typename absent_set_map::iterator it_end = absent_set.end();
for (; it != it_end; ++it) {
const uint64_t v = concurrent_btree::ExtractVersionNumber(it->first);
if (unlikely(v != it->second.version)) {
VERBOSE(std::cerr << "expected node " << util::hexify(it->first) << " at v="
<< it->second.version << ", got v=" << v << std::endl);
abort_trap((reason = ABORT_REASON_NODE_SCAN_READ_VERSION_CHANGED));
goto do_abort;
}
}
}
}
// commit actual records
if (!write_dbtuples.empty()) {
PERF_DECL(
static std::string probe4_name(
std::string(__PRETTY_FUNCTION__) + std::string(":write_records:")));
ANON_REGION(probe4_name.c_str(), &transaction_base::g_txn_commit_probe4_cg);
typename write_set_map::iterator it = write_set.begin();
typename write_set_map::iterator it_end = write_set.end();
for (; it != it_end; ++it) {
if (unlikely(!it->do_write()))
continue;
dbtuple * const tuple = it->get_tuple();
INVARIANT(tuple->is_locked());
VERBOSE(std::cerr << "writing dbtuple " << util::hexify(tuple)
<< " at commit_tid " << g_proto_version_str(commit_tid.second)
<< std::endl);
if (it->is_insert()) {
INVARIANT(tuple->version == dbtuple::MAX_TID);
tuple->version = commit_tid.second; // allows write_record_ret() to succeed
// w/o creating a new chain
} else {
tuple->prefetch();
const dbtuple::write_record_ret ret =
tuple->write_record_at(
cast(), commit_tid.second,
it->get_value(), it->get_writer());
bool unlock_head = false;
if (unlikely(ret.head_ != tuple)) {
// tuple was replaced by ret.head_
INVARIANT(ret.rest_ == tuple);
// XXX: write_record_at() should acquire this lock
ret.head_->lock(true);
unlock_head = true;
// need to unlink tuple from underlying btree, replacing
// with ret.rest_ (atomically)
typename concurrent_btree::value_type old_v = 0;
if (it->get_btree()->insert(
varkey(it->get_key()), (typename concurrent_btree::value_type) ret.head_, &old_v, NULL))
// should already exist in tree
INVARIANT(false);
INVARIANT(old_v == (typename concurrent_btree::value_type) tuple);
// we don't RCU free this, because it is now part of the chain
// (the cleaners will take care of this)
++evt_dbtuple_latest_replacement;
}
if (unlikely(ret.rest_))
// spill happened: schedule GC task
cast()->on_dbtuple_spill(ret.head_, ret.rest_);
if (!it->get_value())
// logical delete happened: schedule GC task
cast()->on_logical_delete(ret.head_, it->get_key(), it->get_btree());
if (unlikely(unlock_head))
ret.head_->unlock();
}
VERBOSE(std::cerr << "dbtuple " << util::hexify(tuple) << " is_locked? " << tuple->is_locked() << std::endl);
}
// unlock
// NB: we can no longer un-lock after doing the writes above
for (typename dbtuple_write_info_vec::iterator it = write_dbtuples.begin();
it != write_dbtuples.end(); ++it) {
if (it->is_locked())
it->tuple->unlock();
else
INVARIANT(!it->is_insert());
}
}
}
state = TXN_COMMITED;
if (commit_tid.first)
cast()->on_tid_finish(commit_tid.second);
clear();
return true;
do_abort:
// XXX: these values are possibly un-initialized
if (this->is_snapshot())
VERBOSE(std::cerr << "aborting txn @ snapshot_tid " << cast()->snapshot_tid() << std::endl);
else
VERBOSE(std::cerr << "aborting txn" << std::endl);
for (typename dbtuple_write_info_vec::iterator it = write_dbtuples.begin();
it != write_dbtuples.end(); ++it) {
if (it->is_locked()) {
if (it->is_insert()) {
INVARIANT(it->entry);
this->cleanup_inserted_tuple_marker(
it->tuple.get(), it->entry->get_key(), it->entry->get_btree());
}
// XXX: potential optimization: on unlock() for abort, we don't
// technically need to change the version number
it->tuple->unlock();
} else {
INVARIANT(!it->is_insert());
}
}
state = TXN_ABRT;
if (commit_tid.first)
cast()->on_tid_finish(commit_tid.second);
clear();
if (doThrow)
throw transaction_abort_exception(reason);
return false;
#ifdef TUPLE_MAGIC
} catch (dbtuple::magic_failed_exception &) {
dump_debug_info();
ALWAYS_ASSERT(false);
}
#endif
}
template <template <typename> class Protocol, typename Traits>
std::pair< dbtuple *, bool >
transaction<Protocol, Traits>::try_insert_new_tuple(
concurrent_btree &btr,
const std::string *key,
const void *value,
dbtuple::tuple_writer_t writer)
{
INVARIANT(key);
const size_t sz =
value ? writer(dbtuple::TUPLE_WRITER_COMPUTE_NEEDED,
value, nullptr, 0) : 0;
// perf: ~900 tsc/alloc on istc11.csail.mit.edu
dbtuple * const tuple = dbtuple::alloc_first(sz, true);
if (value)
writer(dbtuple::TUPLE_WRITER_DO_WRITE,
value, tuple->get_value_start(), 0);
INVARIANT(find_read_set(tuple) == read_set.end());
INVARIANT(tuple->is_latest());
INVARIANT(tuple->version == dbtuple::MAX_TID);
INVARIANT(tuple->is_locked());
INVARIANT(tuple->is_write_intent());
#ifdef TUPLE_CHECK_KEY
tuple->key.assign(key->data(), key->size());
tuple->tree = (void *) &btr;
#endif
// XXX: underlying btree api should return the existing value if insert
// fails- this would allow us to avoid having to do another search
typename concurrent_btree::insert_info_t insert_info;
if (unlikely(!btr.insert_if_absent(
varkey(*key), (typename concurrent_btree::value_type) tuple, &insert_info))) {
VERBOSE(std::cerr << "insert_if_absent failed for key: " << util::hexify(key) << std::endl);
tuple->clear_latest();
tuple->unlock();
dbtuple::release_no_rcu(tuple);
++transaction_base::g_evt_dbtuple_write_insert_failed;
return std::pair< dbtuple *, bool >(nullptr, false);
}
VERBOSE(std::cerr << "insert_if_absent suceeded for key: " << util::hexify(key) << std::endl
<< " new dbtuple is " << util::hexify(tuple) << std::endl);
// update write_set
// too expensive to be practical
// INVARIANT(find_write_set(tuple) == write_set.end());
write_set.emplace_back(tuple, key, value, writer, &btr, true);
// update node #s
INVARIANT(insert_info.node);
if (!absent_set.empty()) {
auto it = absent_set.find(insert_info.node);
if (it != absent_set.end()) {
if (unlikely(it->second.version != insert_info.old_version)) {
abort_trap((reason = ABORT_REASON_WRITE_NODE_INTERFERENCE));
return std::make_pair(tuple, true);
}
VERBOSE(std::cerr << "bump node=" << util::hexify(it->first) << " from v=" << insert_info.old_version
<< " -> v=" << insert_info.new_version << std::endl);
// otherwise, bump the version
it->second.version = insert_info.new_version;
SINGLE_THREADED_INVARIANT(concurrent_btree::ExtractVersionNumber(it->first) == it->second);
}
}
return std::make_pair(tuple, false);
}
template <template <typename> class Protocol, typename Traits>
template <typename ValueReader>
bool
transaction<Protocol, Traits>::do_tuple_read(
const dbtuple *tuple, ValueReader &value_reader)
{
INVARIANT(tuple);
++evt_local_search_lookups;
const bool is_snapshot_txn = is_snapshot();
const transaction_base::tid_t snapshot_tid = is_snapshot_txn ?
cast()->snapshot_tid() : static_cast<transaction_base::tid_t>(dbtuple::MAX_TID);
transaction_base::tid_t start_t = 0;
if (Traits::read_own_writes) {
// this is why read_own_writes is not performant, because we have
// to do linear scan
auto write_set_it = find_write_set(const_cast<dbtuple *>(tuple));
if (unlikely(write_set_it != write_set.end())) {
++evt_local_search_write_set_hits;
if (!write_set_it->get_value())
return false;
const typename ValueReader::value_type * const px =
reinterpret_cast<const typename ValueReader::value_type *>(
write_set_it->get_value());
value_reader.dup(*px, this->string_allocator());
return true;
}
}
// do the actual tuple read
dbtuple::ReadStatus stat;
{
PERF_DECL(static std::string probe0_name(std::string(__PRETTY_FUNCTION__) + std::string(":do_read:")));
ANON_REGION(probe0_name.c_str(), &private_::txn_btree_search_probe0_cg);
tuple->prefetch();
stat = tuple->stable_read(snapshot_tid, start_t, value_reader, this->string_allocator(), is_snapshot_txn);
if (unlikely(stat == dbtuple::READ_FAILED)) {
const transaction_base::abort_reason r = transaction_base::ABORT_REASON_UNSTABLE_READ;
abort_impl(r);
throw transaction_abort_exception(r);
}
}
if (unlikely(!cast()->can_read_tid(start_t))) {
const transaction_base::abort_reason r = transaction_base::ABORT_REASON_FUTURE_TID_READ;
abort_impl(r);
throw transaction_abort_exception(r);
}
INVARIANT(stat == dbtuple::READ_EMPTY ||
stat == dbtuple::READ_RECORD);
const bool v_empty = (stat == dbtuple::READ_EMPTY);
if (v_empty)
++transaction_base::g_evt_read_logical_deleted_node_search;
if (!is_snapshot_txn)
// read-only txns do not need read-set tracking
// (b/c we know the values are consistent)
read_set.emplace_back(tuple, start_t);
return !v_empty;
}
template <template <typename> class Protocol, typename Traits>
void
transaction<Protocol, Traits>::do_node_read(
const typename concurrent_btree::node_opaque_t *n, uint64_t v)
{
INVARIANT(n);
if (is_snapshot())
return;
auto it = absent_set.find(n);
if (it == absent_set.end()) {
absent_set[n].version = v;
} else if (it->second.version != v) {
const transaction_base::abort_reason r =
transaction_base::ABORT_REASON_NODE_SCAN_READ_VERSION_CHANGED;
abort_impl(r);
throw transaction_abort_exception(r);
}
}
#endif /* _NDB_TXN_IMPL_H_ */