@@ -80,10 +80,6 @@ void TransactionContext::Init(const size_t thread_id,
80
80
81
81
isolation_level_ = isolation;
82
82
83
- is_written_ = false ;
84
-
85
- insert_count_ = 0 ;
86
-
87
83
gc_set_.reset (new GCSet ());
88
84
gc_object_set_.reset (new GCObjectSet ());
89
85
@@ -93,89 +89,48 @@ void TransactionContext::Init(const size_t thread_id,
93
89
RWType TransactionContext::GetRWType (const ItemPointer &location) {
94
90
RWType rw_type = RWType::INVALID;
95
91
96
- auto rw_set_it = rw_set_.find (location);
92
+ const auto rw_set_it = rw_set_.find (location);
97
93
if (rw_set_it != rw_set_.end ()) {
98
- return rw_set_it->second ;
94
+ rw_type = rw_set_it->second ;
99
95
}
100
96
return rw_type;
101
97
}
102
98
103
99
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));
104
102
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;
110
105
}
111
- rw_set_.insert (rw_set_it, std::make_pair (location, RWType::READ));
112
106
}
113
107
114
108
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;
125
112
}
126
113
127
114
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;
143
118
}
144
119
145
120
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;
153
123
}
154
124
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;
179
134
}
180
135
}
181
136
0 commit comments