27
27
namespace peloton {
28
28
namespace concurrency {
29
29
30
- common::synchronization::SpinLatch *
31
- TimestampOrderingTransactionManager::GetSpinLatchField (
32
- const storage::TileGroupHeader *const tile_group_header,
33
- const oid_t &tuple_id) {
34
- return (
35
- common::synchronization::SpinLatch
36
- *)(tile_group_header->GetReservedFieldRef (tuple_id) + LOCK_OFFSET);
37
- }
38
-
39
- cid_t TimestampOrderingTransactionManager::GetLastReaderCommitId (
40
- const storage::TileGroupHeader *const tile_group_header,
41
- const oid_t &tuple_id) {
42
- return *(cid_t *)(tile_group_header->GetReservedFieldRef (tuple_id) +
43
- LAST_READER_OFFSET);
44
- }
45
-
46
30
bool TimestampOrderingTransactionManager::SetLastReaderCommitId (
47
31
const storage::TileGroupHeader *const tile_group_header,
48
32
const oid_t &tuple_id, const cid_t ¤t_cid, const bool is_owner) {
49
33
// get the pointer to the last_reader_cid field.
50
- cid_t *ts_ptr = (cid_t *)(tile_group_header->GetReservedFieldRef (tuple_id) +
51
- LAST_READER_OFFSET);
34
+ cid_t read_ts = tile_group_header->GetLastReaderCommitId (tuple_id);
35
+
36
+ auto latch = tile_group_header->GetSpinLatch (tuple_id);
52
37
53
- GetSpinLatchField (tile_group_header, tuple_id) ->Lock ();
38
+ latch ->Lock ();
54
39
55
40
txn_id_t tuple_txn_id = tile_group_header->GetTransactionId (tuple_id);
56
41
57
42
if (is_owner == false && tuple_txn_id != INITIAL_TXN_ID) {
58
43
// if the write lock has already been acquired by some concurrent
59
44
// transactions,
60
45
// then return without setting the last_reader_cid.
61
- GetSpinLatchField (tile_group_header, tuple_id) ->Unlock ();
46
+ latch ->Unlock ();
62
47
return false ;
63
48
} else {
64
49
// if current_cid is larger than the current value of last_reader_cid field,
65
50
// then set last_reader_cid to current_cid.
66
- if (*ts_ptr < current_cid) {
67
- *ts_ptr = current_cid;
51
+ if (read_ts < current_cid) {
52
+ tile_group_header-> SetLastReaderCommitId (tuple_id, current_cid) ;
68
53
}
69
54
70
- GetSpinLatchField (tile_group_header, tuple_id) ->Unlock ();
55
+ latch ->Unlock ();
71
56
return true ;
72
57
}
73
58
}
74
59
75
- void TimestampOrderingTransactionManager::InitTupleReserved (
76
- const storage::TileGroupHeader *const tile_group_header,
77
- const oid_t tuple_id) {
78
- auto reserved_area = tile_group_header->GetReservedFieldRef (tuple_id);
79
-
80
- new ((reserved_area + LOCK_OFFSET)) common::synchronization::SpinLatch ();
81
- *(cid_t *)(reserved_area + LAST_READER_OFFSET) = 0 ;
82
- }
83
-
84
60
TimestampOrderingTransactionManager &
85
61
TimestampOrderingTransactionManager::GetInstance (
86
62
const ProtocolType protocol, const IsolationLevelType isolation,
@@ -138,25 +114,26 @@ bool TimestampOrderingTransactionManager::AcquireOwnership(
138
114
// to acquire the ownership,
139
115
// we must guarantee that no transaction that has read
140
116
// the tuple has a larger timestamp than the current transaction.
141
- GetSpinLatchField (tile_group_header, tuple_id)->Lock ();
117
+ auto latch = tile_group_header->GetSpinLatch (tuple_id);
118
+ latch->Lock ();
142
119
// change timestamp
143
- cid_t last_reader_cid = GetLastReaderCommitId (tile_group_header, tuple_id);
120
+ cid_t last_reader_cid = tile_group_header-> GetLastReaderCommitId (tuple_id);
144
121
145
122
// must compare last_reader_cid with a transaction's commit_id
146
123
// (rather than read_id).
147
124
// consider a transaction that is executed under snapshot isolation.
148
125
// in this case, commit_id is not equal to read_id.
149
126
if (last_reader_cid > current_txn->GetCommitId ()) {
150
- GetSpinLatchField ( tile_group_header, tuple_id)->Unlock ();
127
+ tile_group_header-> GetSpinLatch ( tuple_id)->Unlock ();
151
128
152
129
return false ;
153
130
} else {
154
131
if (tile_group_header->SetAtomicTransactionId (tuple_id, txn_id) == false ) {
155
- GetSpinLatchField (tile_group_header, tuple_id) ->Unlock ();
132
+ latch ->Unlock ();
156
133
157
134
return false ;
158
135
} else {
159
- GetSpinLatchField (tile_group_header, tuple_id) ->Unlock ();
136
+ latch ->Unlock ();
160
137
161
138
return true ;
162
139
}
@@ -328,9 +305,9 @@ bool TimestampOrderingTransactionManager::PerformRead(TransactionContext *const
328
305
329
306
// if we have already owned the version.
330
307
PELOTON_ASSERT (IsOwner (current_txn, tile_group_header, tuple_id) == true );
331
- PELOTON_ASSERT (GetLastReaderCommitId (tile_group_header, tuple_id) ==
308
+ PELOTON_ASSERT (tile_group_header-> GetLastReaderCommitId (tuple_id) ==
332
309
current_txn->GetCommitId () ||
333
- GetLastReaderCommitId (tile_group_header, tuple_id) == 0 );
310
+ tile_group_header-> GetLastReaderCommitId (tuple_id) == 0 );
334
311
return true ;
335
312
336
313
} else {
@@ -352,9 +329,9 @@ bool TimestampOrderingTransactionManager::PerformRead(TransactionContext *const
352
329
} else {
353
330
// if the current transaction has already owned this tuple,
354
331
// then perform read directly.
355
- PELOTON_ASSERT (GetLastReaderCommitId (tile_group_header, tuple_id) ==
332
+ PELOTON_ASSERT (tile_group_header-> GetLastReaderCommitId (tuple_id) ==
356
333
current_txn->GetCommitId () ||
357
- GetLastReaderCommitId (tile_group_header, tuple_id) == 0 );
334
+ tile_group_header-> GetLastReaderCommitId (tuple_id) == 0 );
358
335
359
336
// this version must already be in the read/write set.
360
337
// so no need to update read set.
@@ -391,8 +368,6 @@ void TimestampOrderingTransactionManager::PerformInsert(
391
368
// Add the new tuple into the insert set
392
369
current_txn->RecordInsert (location);
393
370
394
- InitTupleReserved (tile_group_header, tuple_id);
395
-
396
371
// Write down the head pointer's address in tile group header
397
372
tile_group_header->SetIndirection (tuple_id, index_entry_ptr);
398
373
}
@@ -446,8 +421,6 @@ void TimestampOrderingTransactionManager::PerformUpdate(
446
421
// newer version to older version.
447
422
COMPILER_MEMORY_FENCE;
448
423
449
- InitTupleReserved (new_tile_group_header, new_location.offset );
450
-
451
424
// we must be updating the latest version.
452
425
// Set the header information for the new version
453
426
ItemPointer *index_entry_ptr =
@@ -520,9 +493,8 @@ void TimestampOrderingTransactionManager::PerformDelete(
520
493
521
494
auto transaction_id = current_txn->GetTransactionId ();
522
495
523
- PELOTON_ASSERT (
524
- GetLastReaderCommitId (tile_group_header, old_location.offset ) ==
525
- current_txn->GetCommitId ());
496
+ PELOTON_ASSERT (tile_group_header->GetLastReaderCommitId (
497
+ old_location.offset ) == current_txn->GetCommitId ());
526
498
527
499
// if we can perform delete, then we must have already locked the older
528
500
// version.
@@ -554,8 +526,6 @@ void TimestampOrderingTransactionManager::PerformDelete(
554
526
// newer version to older version.
555
527
COMPILER_MEMORY_FENCE;
556
528
557
- InitTupleReserved (new_tile_group_header, new_location.offset );
558
-
559
529
// we must be deleting the latest version.
560
530
// Set the header information for the new version
561
531
ItemPointer *index_entry_ptr =
0 commit comments