From 9cca1b7f1291c4f655dd21909a8f5a22bac384bc Mon Sep 17 00:00:00 2001 From: Matt Butrovich Date: Mon, 25 Jun 2018 13:08:58 -0400 Subject: [PATCH] Inline tuple SpinLatch after TileGroupHeader refactor (#1423) moved it out. (#1426) --- .../timestamp_ordering_transaction_manager.cpp | 18 +++++++++--------- src/include/storage/tile_group_header.h | 8 +++----- src/storage/tile_group_header.cpp | 2 -- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/concurrency/timestamp_ordering_transaction_manager.cpp b/src/concurrency/timestamp_ordering_transaction_manager.cpp index 3adf5dc69b4..3a39ccc8877 100644 --- a/src/concurrency/timestamp_ordering_transaction_manager.cpp +++ b/src/concurrency/timestamp_ordering_transaction_manager.cpp @@ -33,9 +33,9 @@ bool TimestampOrderingTransactionManager::SetLastReaderCommitId( // get the pointer to the last_reader_cid field. cid_t read_ts = tile_group_header->GetLastReaderCommitId(tuple_id); - auto latch = tile_group_header->GetSpinLatch(tuple_id); + auto &latch = tile_group_header->GetSpinLatch(tuple_id); - latch->Lock(); + latch.Lock(); txn_id_t tuple_txn_id = tile_group_header->GetTransactionId(tuple_id); @@ -43,7 +43,7 @@ bool TimestampOrderingTransactionManager::SetLastReaderCommitId( // if the write lock has already been acquired by some concurrent // transactions, // then return without setting the last_reader_cid. - latch->Unlock(); + latch.Unlock(); return false; } else { // if current_cid is larger than the current value of last_reader_cid field, @@ -52,7 +52,7 @@ bool TimestampOrderingTransactionManager::SetLastReaderCommitId( tile_group_header->SetLastReaderCommitId(tuple_id, current_cid); } - latch->Unlock(); + latch.Unlock(); return true; } } @@ -114,8 +114,8 @@ bool TimestampOrderingTransactionManager::AcquireOwnership( // to acquire the ownership, // we must guarantee that no transaction that has read // the tuple has a larger timestamp than the current transaction. - auto latch = tile_group_header->GetSpinLatch(tuple_id); - latch->Lock(); + auto &latch = tile_group_header->GetSpinLatch(tuple_id); + latch.Lock(); // change timestamp cid_t last_reader_cid = tile_group_header->GetLastReaderCommitId(tuple_id); @@ -124,16 +124,16 @@ bool TimestampOrderingTransactionManager::AcquireOwnership( // consider a transaction that is executed under snapshot isolation. // in this case, commit_id is not equal to read_id. if (last_reader_cid > current_txn->GetCommitId()) { - tile_group_header->GetSpinLatch(tuple_id)->Unlock(); + latch.Unlock(); return false; } else { if (tile_group_header->SetAtomicTransactionId(tuple_id, txn_id) == false) { - latch->Unlock(); + latch.Unlock(); return false; } else { - latch->Unlock(); + latch.Unlock(); return true; } diff --git a/src/include/storage/tile_group_header.h b/src/include/storage/tile_group_header.h index 0c851ee1414..12ede331232 100644 --- a/src/include/storage/tile_group_header.h +++ b/src/include/storage/tile_group_header.h @@ -33,7 +33,7 @@ class TileGroup; //===--------------------------------------------------------------------===// struct TupleHeader { - std::unique_ptr latch; + common::synchronization::SpinLatch latch; std::atomic txn_id; cid_t read_ts; cid_t begin_ts; @@ -92,8 +92,6 @@ class TileGroupHeader : public Printable { // copy tuple header values for (oid_t tuple_slot_id = START_OID; tuple_slot_id < num_tuple_slots; tuple_slot_id++) { - tuple_headers_[tuple_slot_id].latch.reset( - new common::synchronization::SpinLatch); SetTransactionId(tuple_slot_id, other.GetTransactionId(tuple_slot_id)); SetLastReaderCommitId(tuple_slot_id, other.GetLastReaderCommitId(tuple_slot_id)); @@ -166,9 +164,9 @@ class TileGroupHeader : public Printable { return tile_group; } - inline common::synchronization::SpinLatch *GetSpinLatch( + inline common::synchronization::SpinLatch &GetSpinLatch( const oid_t &tuple_slot_id) const { - return tuple_headers_[tuple_slot_id].latch.get(); + return tuple_headers_[tuple_slot_id].latch; } inline txn_id_t GetTransactionId(const oid_t &tuple_slot_id) const { diff --git a/src/storage/tile_group_header.cpp b/src/storage/tile_group_header.cpp index ee30fe82dff..4ff67e670f9 100644 --- a/src/storage/tile_group_header.cpp +++ b/src/storage/tile_group_header.cpp @@ -42,8 +42,6 @@ TileGroupHeader::TileGroupHeader(const BackendType &backend_type, // Set MVCC Initial Value for (oid_t tuple_slot_id = START_OID; tuple_slot_id < num_tuple_slots; tuple_slot_id++) { - tuple_headers_[tuple_slot_id].latch.reset( - new common::synchronization::SpinLatch); SetTransactionId(tuple_slot_id, INVALID_TXN_ID); SetLastReaderCommitId(tuple_slot_id, INVALID_CID); SetBeginCommitId(tuple_slot_id, MAX_CID);