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

Commit 9cca1b7

Browse files
mbutrovichtli2
authored andcommitted
Inline tuple SpinLatch after TileGroupHeader refactor (#1423) moved it out. (#1426)
1 parent 29f92eb commit 9cca1b7

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/concurrency/timestamp_ordering_transaction_manager.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ bool TimestampOrderingTransactionManager::SetLastReaderCommitId(
3333
// get the pointer to the last_reader_cid field.
3434
cid_t read_ts = tile_group_header->GetLastReaderCommitId(tuple_id);
3535

36-
auto latch = tile_group_header->GetSpinLatch(tuple_id);
36+
auto &latch = tile_group_header->GetSpinLatch(tuple_id);
3737

38-
latch->Lock();
38+
latch.Lock();
3939

4040
txn_id_t tuple_txn_id = tile_group_header->GetTransactionId(tuple_id);
4141

4242
if (is_owner == false && tuple_txn_id != INITIAL_TXN_ID) {
4343
// if the write lock has already been acquired by some concurrent
4444
// transactions,
4545
// then return without setting the last_reader_cid.
46-
latch->Unlock();
46+
latch.Unlock();
4747
return false;
4848
} else {
4949
// if current_cid is larger than the current value of last_reader_cid field,
@@ -52,7 +52,7 @@ bool TimestampOrderingTransactionManager::SetLastReaderCommitId(
5252
tile_group_header->SetLastReaderCommitId(tuple_id, current_cid);
5353
}
5454

55-
latch->Unlock();
55+
latch.Unlock();
5656
return true;
5757
}
5858
}
@@ -114,8 +114,8 @@ bool TimestampOrderingTransactionManager::AcquireOwnership(
114114
// to acquire the ownership,
115115
// we must guarantee that no transaction that has read
116116
// the tuple has a larger timestamp than the current transaction.
117-
auto latch = tile_group_header->GetSpinLatch(tuple_id);
118-
latch->Lock();
117+
auto &latch = tile_group_header->GetSpinLatch(tuple_id);
118+
latch.Lock();
119119
// change timestamp
120120
cid_t last_reader_cid = tile_group_header->GetLastReaderCommitId(tuple_id);
121121

@@ -124,16 +124,16 @@ bool TimestampOrderingTransactionManager::AcquireOwnership(
124124
// consider a transaction that is executed under snapshot isolation.
125125
// in this case, commit_id is not equal to read_id.
126126
if (last_reader_cid > current_txn->GetCommitId()) {
127-
tile_group_header->GetSpinLatch(tuple_id)->Unlock();
127+
latch.Unlock();
128128

129129
return false;
130130
} else {
131131
if (tile_group_header->SetAtomicTransactionId(tuple_id, txn_id) == false) {
132-
latch->Unlock();
132+
latch.Unlock();
133133

134134
return false;
135135
} else {
136-
latch->Unlock();
136+
latch.Unlock();
137137

138138
return true;
139139
}

src/include/storage/tile_group_header.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TileGroup;
3333
//===--------------------------------------------------------------------===//
3434

3535
struct TupleHeader {
36-
std::unique_ptr<common::synchronization::SpinLatch> latch;
36+
common::synchronization::SpinLatch latch;
3737
std::atomic<txn_id_t> txn_id;
3838
cid_t read_ts;
3939
cid_t begin_ts;
@@ -92,8 +92,6 @@ class TileGroupHeader : public Printable {
9292
// copy tuple header values
9393
for (oid_t tuple_slot_id = START_OID; tuple_slot_id < num_tuple_slots;
9494
tuple_slot_id++) {
95-
tuple_headers_[tuple_slot_id].latch.reset(
96-
new common::synchronization::SpinLatch);
9795
SetTransactionId(tuple_slot_id, other.GetTransactionId(tuple_slot_id));
9896
SetLastReaderCommitId(tuple_slot_id,
9997
other.GetLastReaderCommitId(tuple_slot_id));
@@ -166,9 +164,9 @@ class TileGroupHeader : public Printable {
166164
return tile_group;
167165
}
168166

169-
inline common::synchronization::SpinLatch *GetSpinLatch(
167+
inline common::synchronization::SpinLatch &GetSpinLatch(
170168
const oid_t &tuple_slot_id) const {
171-
return tuple_headers_[tuple_slot_id].latch.get();
169+
return tuple_headers_[tuple_slot_id].latch;
172170
}
173171

174172
inline txn_id_t GetTransactionId(const oid_t &tuple_slot_id) const {

src/storage/tile_group_header.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ TileGroupHeader::TileGroupHeader(const BackendType &backend_type,
4242
// Set MVCC Initial Value
4343
for (oid_t tuple_slot_id = START_OID; tuple_slot_id < num_tuple_slots;
4444
tuple_slot_id++) {
45-
tuple_headers_[tuple_slot_id].latch.reset(
46-
new common::synchronization::SpinLatch);
4745
SetTransactionId(tuple_slot_id, INVALID_TXN_ID);
4846
SetLastReaderCommitId(tuple_slot_id, INVALID_CID);
4947
SetBeginCommitId(tuple_slot_id, MAX_CID);

0 commit comments

Comments
 (0)