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

Commit a9847aa

Browse files
committed
Refactor of transaction_context to reduce lookups.
1 parent 91d9525 commit a9847aa

File tree

2 files changed

+24
-74
lines changed

2 files changed

+24
-74
lines changed

src/concurrency/transaction_context.cpp

Lines changed: 23 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ void TransactionContext::Init(const size_t thread_id,
8080

8181
isolation_level_ = isolation;
8282

83-
is_written_ = false;
84-
85-
insert_count_ = 0;
86-
8783
gc_set_.reset(new GCSet());
8884
gc_object_set_.reset(new GCObjectSet());
8985

@@ -93,89 +89,48 @@ void TransactionContext::Init(const size_t thread_id,
9389
RWType TransactionContext::GetRWType(const ItemPointer &location) {
9490
RWType rw_type = RWType::INVALID;
9591

96-
auto rw_set_it = rw_set_.find(location);
92+
const auto rw_set_it = rw_set_.find(location);
9793
if (rw_set_it != rw_set_.end()) {
98-
return rw_set_it->second;
94+
rw_type = rw_set_it->second;
9995
}
10096
return rw_type;
10197
}
10298

10399
void TransactionContext::RecordRead(const ItemPointer &location) {
100+
PELOTON_ASSERT(rw_set_.count(location) == 0 ||
101+
(rw_set_[location] != RWType::DELETE && rw_set_[location] != RWType::INS_DEL));
104102

105-
auto rw_set_it = rw_set_.find(location);
106-
if (rw_set_it != rw_set_.end()) {
107-
UNUSED_ATTRIBUTE RWType rw_type = rw_set_it->second;
108-
PELOTON_ASSERT(rw_type != RWType::DELETE && rw_type != RWType::INS_DEL);
109-
return;
103+
if (rw_set_.count(location) == 0) {
104+
rw_set_[location] = RWType::READ;
110105
}
111-
rw_set_.insert(rw_set_it, std::make_pair(location, RWType::READ));
112106
}
113107

114108
void TransactionContext::RecordReadOwn(const ItemPointer &location) {
115-
auto rw_set_it = rw_set_.find(location);
116-
if (rw_set_it != rw_set_.end()) {
117-
RWType rw_type = rw_set_it->second;
118-
PELOTON_ASSERT(rw_type != RWType::DELETE && rw_type != RWType::INS_DEL);
119-
if (rw_type == RWType::READ) {
120-
rw_set_it->second = RWType::READ_OWN;
121-
}
122-
} else {
123-
rw_set_.insert(rw_set_it, std::make_pair(location, RWType::READ_OWN));
124-
}
109+
PELOTON_ASSERT(rw_set_.count(location) == 0 ||
110+
(rw_set_[location] != RWType::DELETE && rw_set_[location] != RWType::INS_DEL));
111+
rw_set_[location] = RWType::READ_OWN;
125112
}
126113

127114
void TransactionContext::RecordUpdate(const ItemPointer &location) {
128-
auto rw_set_it = rw_set_.find(location);
129-
if (rw_set_it != rw_set_.end()) {
130-
RWType rw_type = rw_set_it->second;
131-
if (rw_type == RWType::READ || rw_type == RWType::READ_OWN) {
132-
is_written_ = true;
133-
rw_set_it->second = RWType::UPDATE;
134-
} else if (rw_type == RWType::UPDATE || rw_type == RWType::INSERT) {
135-
return;
136-
} else {
137-
// DELETE or INS_DELETE
138-
PELOTON_ASSERT(false);
139-
}
140-
} else {
141-
rw_set_.insert(rw_set_it, std::make_pair(location, RWType::UPDATE));
142-
}
115+
PELOTON_ASSERT(rw_set_.count(location) == 0 ||
116+
(rw_set_[location] != RWType::DELETE && rw_set_[location] != RWType::INS_DEL));
117+
rw_set_[location] = RWType::UPDATE;
143118
}
144119

145120
void TransactionContext::RecordInsert(const ItemPointer &location) {
146-
auto rw_set_it = rw_set_.find(location);
147-
if (rw_set_it != rw_set_.end()) {
148-
PELOTON_ASSERT(false);
149-
return;
150-
}
151-
rw_set_.insert(rw_set_it, std::make_pair(location, RWType::INSERT));
152-
++insert_count_;
121+
PELOTON_ASSERT(rw_set_.count(location) == 0);
122+
rw_set_[location] = RWType::INSERT;
153123
}
154124

155-
bool TransactionContext::RecordDelete(const ItemPointer &location) {
156-
auto rw_set_it = rw_set_.find(location);
157-
if (rw_set_it != rw_set_.end()) {
158-
RWType rw_type = rw_set_it->second;
159-
160-
if (rw_type == RWType::READ || rw_type == RWType::READ_OWN) {
161-
rw_set_it->second = RWType::DELETE;
162-
is_written_ = true;
163-
return false;
164-
} else if (rw_type == RWType::UPDATE) {
165-
rw_set_it->second = RWType::DELETE;
166-
return false;
167-
} else if (rw_type == RWType::INSERT) {
168-
rw_set_it->second = RWType::INS_DEL;
169-
--insert_count_;
170-
return true;
171-
} else {
172-
// DELETE and INS_DEL
173-
PELOTON_ASSERT(false);
174-
return false;
175-
}
176-
} else {
177-
rw_set_.insert(rw_set_it, std::make_pair(location, RWType::DELETE));
178-
return false;
125+
void TransactionContext::RecordDelete(const ItemPointer &location) {
126+
PELOTON_ASSERT(rw_set_.count(location) == 0 ||
127+
(rw_set_[location] != RWType::DELETE && rw_set_[location] != RWType::INS_DEL));
128+
if (rw_set_[location] == RWType::INSERT) {
129+
rw_set_[location] = RWType::INS_DEL;
130+
}
131+
else {
132+
// READ, READ_OWN, UPDATE
133+
rw_set_[location] = RWType::DELETE;
179134
}
180135
}
181136

src/include/concurrency/transaction_context.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,8 @@ class TransactionContext : public Printable {
171171
* @brief Delete the record.
172172
*
173173
* @param[in] <unnamed> The logical physical location of the record
174-
*
175-
* @return Return true if we detect INS_DEL.
176174
*/
177-
bool RecordDelete(const ItemPointer &);
175+
void RecordDelete(const ItemPointer &);
178176

179177
RWType GetRWType(const ItemPointer &);
180178

@@ -337,9 +335,6 @@ class TransactionContext : public Printable {
337335
/** result of the transaction */
338336
ResultType result_ = ResultType::SUCCESS;
339337

340-
bool is_written_;
341-
size_t insert_count_;
342-
343338
IsolationLevelType isolation_level_;
344339

345340
std::unique_ptr<trigger::TriggerSet> on_commit_triggers_;

0 commit comments

Comments
 (0)