2727namespace peloton {
2828namespace concurrency {
2929
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-
4630bool TimestampOrderingTransactionManager::SetLastReaderCommitId (
4731 const storage::TileGroupHeader *const tile_group_header,
4832 const oid_t &tuple_id, const cid_t ¤t_cid, const bool is_owner) {
4933 // 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);
5237
53- GetSpinLatchField (tile_group_header, tuple_id) ->Lock ();
38+ latch ->Lock ();
5439
5540 txn_id_t tuple_txn_id = tile_group_header->GetTransactionId (tuple_id);
5641
5742 if (is_owner == false && tuple_txn_id != INITIAL_TXN_ID) {
5843 // if the write lock has already been acquired by some concurrent
5944 // transactions,
6045 // then return without setting the last_reader_cid.
61- GetSpinLatchField (tile_group_header, tuple_id) ->Unlock ();
46+ latch ->Unlock ();
6247 return false ;
6348 } else {
6449 // if current_cid is larger than the current value of last_reader_cid field,
6550 // 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) ;
6853 }
6954
70- GetSpinLatchField (tile_group_header, tuple_id) ->Unlock ();
55+ latch ->Unlock ();
7156 return true ;
7257 }
7358}
7459
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-
8460TimestampOrderingTransactionManager &
8561TimestampOrderingTransactionManager::GetInstance (
8662 const ProtocolType protocol, const IsolationLevelType isolation,
@@ -138,25 +114,26 @@ bool TimestampOrderingTransactionManager::AcquireOwnership(
138114 // to acquire the ownership,
139115 // we must guarantee that no transaction that has read
140116 // 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 ();
142119 // 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);
144121
145122 // must compare last_reader_cid with a transaction's commit_id
146123 // (rather than read_id).
147124 // consider a transaction that is executed under snapshot isolation.
148125 // in this case, commit_id is not equal to read_id.
149126 if (last_reader_cid > current_txn->GetCommitId ()) {
150- GetSpinLatchField ( tile_group_header, tuple_id)->Unlock ();
127+ tile_group_header-> GetSpinLatch ( tuple_id)->Unlock ();
151128
152129 return false ;
153130 } else {
154131 if (tile_group_header->SetAtomicTransactionId (tuple_id, txn_id) == false ) {
155- GetSpinLatchField (tile_group_header, tuple_id) ->Unlock ();
132+ latch ->Unlock ();
156133
157134 return false ;
158135 } else {
159- GetSpinLatchField (tile_group_header, tuple_id) ->Unlock ();
136+ latch ->Unlock ();
160137
161138 return true ;
162139 }
@@ -328,9 +305,9 @@ bool TimestampOrderingTransactionManager::PerformRead(TransactionContext *const
328305
329306 // if we have already owned the version.
330307 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) ==
332309 current_txn->GetCommitId () ||
333- GetLastReaderCommitId (tile_group_header, tuple_id) == 0 );
310+ tile_group_header-> GetLastReaderCommitId (tuple_id) == 0 );
334311 return true ;
335312
336313 } else {
@@ -352,9 +329,9 @@ bool TimestampOrderingTransactionManager::PerformRead(TransactionContext *const
352329 } else {
353330 // if the current transaction has already owned this tuple,
354331 // then perform read directly.
355- PELOTON_ASSERT (GetLastReaderCommitId (tile_group_header, tuple_id) ==
332+ PELOTON_ASSERT (tile_group_header-> GetLastReaderCommitId (tuple_id) ==
356333 current_txn->GetCommitId () ||
357- GetLastReaderCommitId (tile_group_header, tuple_id) == 0 );
334+ tile_group_header-> GetLastReaderCommitId (tuple_id) == 0 );
358335
359336 // this version must already be in the read/write set.
360337 // so no need to update read set.
@@ -391,8 +368,6 @@ void TimestampOrderingTransactionManager::PerformInsert(
391368 // Add the new tuple into the insert set
392369 current_txn->RecordInsert (location);
393370
394- InitTupleReserved (tile_group_header, tuple_id);
395-
396371 // Write down the head pointer's address in tile group header
397372 tile_group_header->SetIndirection (tuple_id, index_entry_ptr);
398373}
@@ -446,8 +421,6 @@ void TimestampOrderingTransactionManager::PerformUpdate(
446421 // newer version to older version.
447422 COMPILER_MEMORY_FENCE;
448423
449- InitTupleReserved (new_tile_group_header, new_location.offset );
450-
451424 // we must be updating the latest version.
452425 // Set the header information for the new version
453426 ItemPointer *index_entry_ptr =
@@ -520,9 +493,8 @@ void TimestampOrderingTransactionManager::PerformDelete(
520493
521494 auto transaction_id = current_txn->GetTransactionId ();
522495
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 ());
526498
527499 // if we can perform delete, then we must have already locked the older
528500 // version.
@@ -554,8 +526,6 @@ void TimestampOrderingTransactionManager::PerformDelete(
554526 // newer version to older version.
555527 COMPILER_MEMORY_FENCE;
556528
557- InitTupleReserved (new_tile_group_header, new_location.offset );
558-
559529 // we must be deleting the latest version.
560530 // Set the header information for the new version
561531 ItemPointer *index_entry_ptr =
0 commit comments