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

Commit 881a8e6

Browse files
tcm-marcelpervazea
authored andcommitted
Performance Fixes: pass TileGroupHeader*, avoid RW set lookups (#1380)
* Performance Fixes * add TileGroupHeader* as argument to ReadRecord to avoid lookup with GetTileGroup() * rewrite access to RW set in TransactionContext::Record* functions to avoid duplicated lookups * Change RW set find to return non-const iterator It also worked with const iterators, but it violates the const correctness. It seems this is not done correctly in tbb.
1 parent 36e880e commit 881a8e6

9 files changed

+56
-47
lines changed

src/codegen/transaction_runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ uint32_t TransactionRuntime::PerformVectorizedRead(
5656
ItemPointer location{tile_group_idx, selection_vector[idx]};
5757

5858
// Perform the read
59-
bool can_read = txn_manager.PerformRead(&txn, location);
59+
bool can_read = txn_manager.PerformRead(&txn, location, tile_group_header, false);
6060

6161
// Update the selection vector and output position
6262
selection_vector[out_idx] = selection_vector[idx];

src/concurrency/timestamp_ordering_transaction_manager.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ void TimestampOrderingTransactionManager::YieldOwnership(
170170
tile_group_header->SetTransactionId(tuple_id, INITIAL_TXN_ID);
171171
}
172172

173-
bool TimestampOrderingTransactionManager::PerformRead(
174-
TransactionContext *const current_txn, const ItemPointer &read_location,
175-
bool acquire_ownership) {
173+
bool TimestampOrderingTransactionManager::PerformRead(TransactionContext *const current_txn,
174+
const ItemPointer &read_location,
175+
storage::TileGroupHeader *tile_group_header,
176+
bool acquire_ownership) {
176177
ItemPointer location = read_location;
177178

178179
//////////////////////////////////////////////////////////
@@ -189,24 +190,18 @@ bool TimestampOrderingTransactionManager::PerformRead(
189190

190191
// TODO: what if we want to read a version that we write?
191192
else if (current_txn->GetIsolationLevel() == IsolationLevelType::SNAPSHOT) {
192-
oid_t tile_group_id = location.block;
193193
oid_t tuple_id = location.offset;
194194

195195
LOG_TRACE("PerformRead (%u, %u)\n", location.block, location.offset);
196-
auto &manager = catalog::Manager::GetInstance();
197-
auto tile_group_header = manager.GetTileGroup(tile_group_id)->GetHeader();
198196

199197
// Check if it's select for update before we check the ownership
200198
// and modify the last reader cid
201199
if (acquire_ownership == true) {
202200
// get the latest version of this tuple.
203201
location = *(tile_group_header->GetIndirection(location.offset));
204202

205-
tile_group_id = location.block;
206203
tuple_id = location.offset;
207204

208-
tile_group_header = manager.GetTileGroup(tile_group_id)->GetHeader();
209-
210205
if (IsOwner(current_txn, tile_group_header, tuple_id) == false) {
211206
// Acquire ownership if we haven't
212207
if (IsOwnable(current_txn, tile_group_header, tuple_id) == false) {
@@ -240,12 +235,9 @@ bool TimestampOrderingTransactionManager::PerformRead(
240235
//////////////////////////////////////////////////////////
241236
else if (current_txn->GetIsolationLevel() ==
242237
IsolationLevelType::READ_COMMITTED) {
243-
oid_t tile_group_id = location.block;
244238
oid_t tuple_id = location.offset;
245239

246240
LOG_TRACE("PerformRead (%u, %u)\n", location.block, location.offset);
247-
auto &manager = catalog::Manager::GetInstance();
248-
auto tile_group_header = manager.GetTileGroup(tile_group_id)->GetHeader();
249241

250242
// Check if it's select for update before we check the ownership.
251243
if (acquire_ownership == true) {
@@ -301,13 +293,9 @@ bool TimestampOrderingTransactionManager::PerformRead(
301293
current_txn->GetIsolationLevel() ==
302294
IsolationLevelType::REPEATABLE_READS);
303295

304-
oid_t tile_group_id = location.block;
305296
oid_t tuple_id = location.offset;
306297

307298
LOG_TRACE("PerformRead (%u, %u)\n", location.block, location.offset);
308-
auto &manager = catalog::Manager::GetInstance();
309-
auto tile_group_header = manager.GetTileGroup(tile_group_id)->GetHeader();
310-
311299
// Check if it's select for update before we check the ownership
312300
// and modify the last reader cid.
313301
if (acquire_ownership == true) {

src/concurrency/transaction_context.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void TransactionContext::Init(const size_t thread_id,
9393
RWType TransactionContext::GetRWType(const ItemPointer &location) {
9494
RWType rw_type = RWType::INVALID;
9595

96-
const auto rw_set_it = rw_set_.find(location);
96+
auto rw_set_it = rw_set_.find(location);
9797
if (rw_set_it != rw_set_.end()) {
9898
return rw_set_it->second;
9999
}
@@ -102,78 +102,81 @@ RWType TransactionContext::GetRWType(const ItemPointer &location) {
102102

103103
void TransactionContext::RecordRead(const ItemPointer &location) {
104104

105-
const auto rw_set_it = rw_set_.find(location);
105+
auto rw_set_it = rw_set_.find(location);
106106
if (rw_set_it != rw_set_.end()) {
107107
UNUSED_ATTRIBUTE RWType rw_type = rw_set_it->second;
108108
PELOTON_ASSERT(rw_type != RWType::DELETE && rw_type != RWType::INS_DEL);
109109
return;
110110
}
111-
rw_set_[location] = RWType::READ;
111+
rw_set_.insert(rw_set_it, std::make_pair(location, RWType::READ));
112112
}
113113

114114
void TransactionContext::RecordReadOwn(const ItemPointer &location) {
115-
const auto rw_set_it = rw_set_.find(location);
115+
auto rw_set_it = rw_set_.find(location);
116116
if (rw_set_it != rw_set_.end()) {
117117
RWType rw_type = rw_set_it->second;
118118
PELOTON_ASSERT(rw_type != RWType::DELETE && rw_type != RWType::INS_DEL);
119-
if (rw_type != RWType::READ) {
120-
return;
119+
if (rw_type == RWType::READ) {
120+
rw_set_it->second = RWType::READ_OWN;
121121
}
122+
} else {
123+
rw_set_.insert(rw_set_it, std::make_pair(location, RWType::READ_OWN));
122124
}
123-
rw_set_[location] = RWType::READ_OWN;
124125
}
125126

126127
void TransactionContext::RecordUpdate(const ItemPointer &location) {
127-
const auto rw_set_it = rw_set_.find(location);
128+
auto rw_set_it = rw_set_.find(location);
128129
if (rw_set_it != rw_set_.end()) {
129130
RWType rw_type = rw_set_it->second;
130131
if (rw_type == RWType::READ || rw_type == RWType::READ_OWN) {
131132
is_written_ = true;
133+
rw_set_it->second = RWType::UPDATE;
132134
} else if (rw_type == RWType::UPDATE || rw_type == RWType::INSERT) {
133135
return;
134136
} else {
135137
// DELETE or INS_DELETE
136138
PELOTON_ASSERT(false);
137-
return;
138139
}
140+
} else {
141+
rw_set_.insert(rw_set_it, std::make_pair(location, RWType::UPDATE));
139142
}
140-
rw_set_[location] = RWType::UPDATE;
141143
}
142144

143145
void TransactionContext::RecordInsert(const ItemPointer &location) {
144-
const auto rw_set_it = rw_set_.find(location);
146+
auto rw_set_it = rw_set_.find(location);
145147
if (rw_set_it != rw_set_.end()) {
146148
PELOTON_ASSERT(false);
147149
return;
148150
}
149-
rw_set_[location] = RWType::INSERT;
151+
rw_set_.insert(rw_set_it, std::make_pair(location, RWType::INSERT));
150152
++insert_count_;
151153
}
152154

153155
bool TransactionContext::RecordDelete(const ItemPointer &location) {
154-
const auto rw_set_it = rw_set_.find(location);
156+
auto rw_set_it = rw_set_.find(location);
155157
if (rw_set_it != rw_set_.end()) {
156158
RWType rw_type = rw_set_it->second;
157159

158160
if (rw_type == RWType::READ || rw_type == RWType::READ_OWN) {
159-
rw_set_[location] = RWType::DELETE;
161+
rw_set_it->second = RWType::DELETE;
160162
is_written_ = true;
161163
return false;
162164
} else if (rw_type == RWType::UPDATE) {
163-
rw_set_[location] = RWType::DELETE;
165+
rw_set_it->second = RWType::DELETE;
164166
return false;
165167
} else if (rw_type == RWType::INSERT) {
166-
rw_set_[location] = RWType::INS_DEL;
168+
rw_set_it->second = RWType::INS_DEL;
167169
--insert_count_;
168170
return true;
169171
} else {
170172
// DELETE and INS_DEL
171173
PELOTON_ASSERT(false);
172174
return false;
173175
}
176+
} else {
177+
rw_set_.insert(rw_set_it, std::make_pair(location, RWType::DELETE));
178+
return false;
174179
}
175-
rw_set_[location] = RWType::DELETE;
176-
return false;
177180
}
178181

179182
const std::string TransactionContext::GetInfo() const {

src/executor/hybrid_scan_executor.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ bool HybridScanExecutor::SeqScanUtil() {
230230
predicate_->Evaluate(&tuple, nullptr, executor_context_).IsTrue();
231231
if (eval == true) {
232232
position_list.push_back(tuple_id);
233-
auto res = transaction_manager.PerformRead(current_txn, location,
233+
auto res = transaction_manager.PerformRead(current_txn,
234+
location,
235+
tile_group_header,
234236
acquire_owner);
235237
if (!res) {
236238
transaction_manager.SetTransactionResult(current_txn,
@@ -389,7 +391,9 @@ bool HybridScanExecutor::ExecPrimaryIndexLookup() {
389391

390392
if (visibility == VisibilityType::OK) {
391393
visible_tuples[tuple_location.block].push_back(tuple_location.offset);
392-
auto res = transaction_manager.PerformRead(current_txn, tuple_location,
394+
auto res = transaction_manager.PerformRead(current_txn,
395+
tuple_location,
396+
tile_group_header,
393397
acquire_owner);
394398
if (!res) {
395399
transaction_manager.SetTransactionResult(current_txn,

src/executor/index_scan_executor.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,10 @@ bool IndexScanExecutor::ExecPrimaryIndexLookup() {
254254
// if passed evaluation, then perform write.
255255
if (eval == true) {
256256
LOG_TRACE("perform read operation");
257-
auto res = transaction_manager.PerformRead(
258-
current_txn, tuple_location, acquire_owner);
257+
auto res = transaction_manager.PerformRead(current_txn,
258+
tuple_location,
259+
tile_group_header,
260+
acquire_owner);
259261
if (!res) {
260262
LOG_TRACE("read nothing");
261263
transaction_manager.SetTransactionResult(current_txn,
@@ -519,8 +521,10 @@ bool IndexScanExecutor::ExecSecondaryIndexLookup() {
519521
}
520522
// if passed evaluation, then perform write.
521523
if (eval == true) {
522-
auto res = transaction_manager.PerformRead(
523-
current_txn, tuple_location, acquire_owner);
524+
auto res = transaction_manager.PerformRead(current_txn,
525+
tuple_location,
526+
tile_group_header,
527+
acquire_owner);
524528
if (!res) {
525529
transaction_manager.SetTransactionResult(current_txn,
526530
ResultType::FAILURE);

src/executor/seq_scan_executor.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ bool SeqScanExecutor::DExecute() {
172172
// if the tuple is visible, then perform predicate evaluation.
173173
if (predicate_ == nullptr) {
174174
position_list.push_back(tuple_id);
175-
auto res = transaction_manager.PerformRead(current_txn, location,
175+
auto res = transaction_manager.PerformRead(current_txn,
176+
location,
177+
tile_group_header,
176178
acquire_owner);
177179
if (!res) {
178180
transaction_manager.SetTransactionResult(current_txn,
@@ -188,7 +190,9 @@ bool SeqScanExecutor::DExecute() {
188190
LOG_TRACE("Evaluation result: %s", eval.GetInfo().c_str());
189191
if (eval.IsTrue()) {
190192
position_list.push_back(tuple_id);
191-
auto res = transaction_manager.PerformRead(current_txn, location,
193+
auto res = transaction_manager.PerformRead(current_txn,
194+
location,
195+
tile_group_header,
192196
acquire_owner);
193197
if (!res) {
194198
transaction_manager.SetTransactionResult(current_txn,

src/include/concurrency/timestamp_ordering_transaction_manager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,13 @@ class TimestampOrderingTransactionManager : public TransactionManager {
170170
*
171171
* @param current_txn The current transaction
172172
* @param[in] location The location of the tuple to be read
173+
* @param[in] tile_group_header Pointer to the tile group header
173174
* @param[in] acquire_ownership The acquire ownership
174175
*/
175176
virtual bool PerformRead(TransactionContext *const current_txn,
176177
const ItemPointer &location,
177-
bool acquire_ownership = false);
178+
storage::TileGroupHeader *tile_group_header,
179+
bool acquire_ownership);
178180

179181
/**
180182
* @brief Perform an update operation

src/include/concurrency/transaction_manager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ class TransactionManager {
190190
ItemPointer *index_entry_ptr = nullptr) = 0;
191191

192192
virtual bool PerformRead(TransactionContext *const current_txn,
193-
const ItemPointer &location,
194-
bool acquire_ownership = false) = 0;
193+
const ItemPointer &location,
194+
storage::TileGroupHeader *tile_group_header,
195+
bool acquire_ownership) = 0;
195196

196197

197198
virtual void PerformUpdate(TransactionContext *const current_txn,

src/storage/data_table.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,10 @@ bool DataTable::CheckForeignKeySrcAndCascade(
661661
// we can
662662
// delete it later
663663
bool ret =
664-
transaction_manager.PerformRead(current_txn, *ptr, true);
664+
transaction_manager.PerformRead(current_txn,
665+
*ptr,
666+
src_tile_group_header,
667+
true);
665668

666669
if (ret == false) {
667670
if (src_is_owner) {

0 commit comments

Comments
 (0)