@@ -50,25 +50,14 @@ namespace concurrency {
5050
5151TransactionContext::TransactionContext (const size_t thread_id,
5252 const IsolationLevelType isolation,
53- const cid_t &read_id)
54- : rw_set_(INTITIAL_RW_SET_SIZE) {
53+ const cid_t &read_id) {
5554 Init (thread_id, isolation, read_id);
5655}
5756
5857TransactionContext::TransactionContext (const size_t thread_id,
5958 const IsolationLevelType isolation,
6059 const cid_t &read_id,
61- const cid_t &commit_id)
62- : rw_set_(INTITIAL_RW_SET_SIZE) {
63- Init (thread_id, isolation, read_id, commit_id);
64- }
65-
66- TransactionContext::TransactionContext (const size_t thread_id,
67- const IsolationLevelType isolation,
68- const cid_t &read_id,
69- const cid_t &commit_id,
70- const size_t rw_set_size)
71- : rw_set_(rw_set_size) {
60+ const cid_t &commit_id) {
7261 Init (thread_id, isolation, read_id, commit_id);
7362}
7463
@@ -95,107 +84,95 @@ void TransactionContext::Init(const size_t thread_id,
9584
9685 insert_count_ = 0 ;
9786
98- rw_set_.Clear ();
9987 gc_set_.reset (new GCSet ());
10088 gc_object_set_.reset (new GCObjectSet ());
10189
10290 on_commit_triggers_.reset ();
10391}
10492
10593RWType TransactionContext::GetRWType (const ItemPointer &location) {
106- RWType rw_type;
94+ RWType rw_type = RWType::INVALID ;
10795
108- if (!rw_set_.Find (location, rw_type)) {
109- rw_type = RWType::INVALID;
96+ const auto rw_set_it = rw_set_.find (location);
97+ if (rw_set_it != rw_set_.end ()) {
98+ return rw_set_it->second ;
11099 }
111100 return rw_type;
112101}
113102
114103void TransactionContext::RecordRead (const ItemPointer &location) {
115- RWType rw_type;
116104
117- if (rw_set_.Find (location, rw_type)) {
105+ const 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 ;
118108 PELOTON_ASSERT (rw_type != RWType::DELETE && rw_type != RWType::INS_DEL);
119109 return ;
120- } else {
121- rw_set_.Insert (location, RWType::READ);
122110 }
111+ rw_set_[location] = RWType::READ;
123112}
124113
125114void TransactionContext::RecordReadOwn (const ItemPointer &location) {
126- RWType rw_type ;
127-
128- if (rw_set_. Find (location, rw_type)) {
115+ const auto rw_set_it = rw_set_. find (location) ;
116+ if (rw_set_it != rw_set_. end ()) {
117+ RWType rw_type = rw_set_it-> second ;
129118 PELOTON_ASSERT (rw_type != RWType::DELETE && rw_type != RWType::INS_DEL);
130- if (rw_type = = RWType::READ) {
131- rw_set_. Update (location, RWType::READ_OWN) ;
119+ if (rw_type ! = RWType::READ) {
120+ return ;
132121 }
133- } else {
134- rw_set_.Insert (location, RWType::READ_OWN);
135122 }
123+ rw_set_[location] = RWType::READ_OWN;
136124}
137125
138126void TransactionContext::RecordUpdate (const ItemPointer &location) {
139- RWType rw_type ;
140-
141- if (rw_set_. Find (location, rw_type)) {
127+ const auto rw_set_it = rw_set_. find (location) ;
128+ if (rw_set_it != rw_set_. end ()) {
129+ RWType rw_type = rw_set_it-> second ;
142130 if (rw_type == RWType::READ || rw_type == RWType::READ_OWN) {
143131 is_written_ = true ;
144- rw_set_.Update (location, RWType::UPDATE);
145- return ;
146- }
147- if (rw_type == RWType::UPDATE) {
148- return ;
149- }
150- if (rw_type == RWType::INSERT) {
132+ } else if (rw_type == RWType::UPDATE || rw_type == RWType::INSERT) {
151133 return ;
152- }
153- if (rw_type == RWType:: DELETE) {
134+ } else {
135+ // DELETE or INS_DELETE
154136 PELOTON_ASSERT (false );
155137 return ;
156138 }
157- PELOTON_ASSERT (false );
158- } else {
159- rw_set_.Insert (location, RWType::UPDATE);
160139 }
140+ rw_set_[location] = RWType::UPDATE;
161141}
162142
163143void TransactionContext::RecordInsert (const ItemPointer &location) {
164- if (IsInRWSet (location)) {
144+ const auto rw_set_it = rw_set_.find (location);
145+ if (rw_set_it != rw_set_.end ()) {
165146 PELOTON_ASSERT (false );
166- } else {
167- rw_set_.Insert (location, RWType::INSERT);
168- ++insert_count_;
147+ return ;
169148 }
149+ rw_set_[location] = RWType::INSERT;
150+ ++insert_count_;
170151}
171152
172153bool TransactionContext::RecordDelete (const ItemPointer &location) {
173- RWType rw_type;
154+ const auto rw_set_it = rw_set_.find (location);
155+ if (rw_set_it != rw_set_.end ()) {
156+ RWType rw_type = rw_set_it->second ;
174157
175- if (rw_set_.Find (location, rw_type)) {
176158 if (rw_type == RWType::READ || rw_type == RWType::READ_OWN) {
177- rw_set_.Update (location, RWType::DELETE);
178- // record write
159+ rw_set_[location] = RWType::DELETE;
179160 is_written_ = true ;
180161 return false ;
181- }
182- if (rw_type == RWType::UPDATE) {
183- rw_set_.Update (location, RWType::DELETE);
162+ } else if (rw_type == RWType::UPDATE) {
163+ rw_set_[location] = RWType::DELETE;
184164 return false ;
185- }
186- if (rw_type == RWType::INSERT) {
187- rw_set_.Update (location, RWType::INS_DEL);
165+ } else if (rw_type == RWType::INSERT) {
166+ rw_set_[location] = RWType::INS_DEL;
188167 --insert_count_;
189168 return true ;
190- }
191- if (rw_type == RWType:: DELETE) {
169+ } else {
170+ // DELETE and INS_DEL
192171 PELOTON_ASSERT (false );
193172 return false ;
194173 }
195- PELOTON_ASSERT (false );
196- } else {
197- rw_set_.Insert (location, RWType::DELETE);
198174 }
175+ rw_set_[location] = RWType::DELETE;
199176 return false ;
200177}
201178
0 commit comments