Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
Inline tuple SpinLatch after TileGroupHeader refactor (#1423) moved i…
Browse files Browse the repository at this point in the history
…t out. (#1426)
  • Loading branch information
mbutrovich authored and tli2 committed Jun 25, 2018
1 parent 29f92eb commit 9cca1b7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/concurrency/timestamp_ordering_transaction_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ 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);

if (is_owner == false && tuple_txn_id != INITIAL_TXN_ID) {
// 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,
Expand All @@ -52,7 +52,7 @@ bool TimestampOrderingTransactionManager::SetLastReaderCommitId(
tile_group_header->SetLastReaderCommitId(tuple_id, current_cid);
}

latch->Unlock();
latch.Unlock();
return true;
}
}
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions src/include/storage/tile_group_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TileGroup;
//===--------------------------------------------------------------------===//

struct TupleHeader {
std::unique_ptr<common::synchronization::SpinLatch> latch;
common::synchronization::SpinLatch latch;
std::atomic<txn_id_t> txn_id;
cid_t read_ts;
cid_t begin_ts;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions src/storage/tile_group_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9cca1b7

Please sign in to comment.