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

Commit 42c4c48

Browse files
make check FINALLY passes
1 parent 313e989 commit 42c4c48

File tree

7 files changed

+283
-270
lines changed

7 files changed

+283
-270
lines changed

src/common/container/cuckoo_map.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ CUCKOO_MAP_TEMPLATE_ARGUMENTS
8888
CUCKOO_MAP_ITERATOR_TYPE
8989
CUCKOO_MAP_TYPE::GetIterator() { return cuckoo_map.lock_table(); }
9090

91+
CUCKOO_MAP_TEMPLATE_ARGUMENTS
92+
CUCKOO_MAP_ITERATOR_TYPE
93+
CUCKOO_MAP_TYPE::GetConstIterator() const {
94+
auto locked_table = const_cast<CuckooMap*>(this)->cuckoo_map.lock_table();
95+
return locked_table;
96+
}
97+
9198
// Explicit template instantiation
9299
template class CuckooMap<uint32_t, uint32_t>;
93100

@@ -107,4 +114,8 @@ template class CuckooMap<std::shared_ptr<oid_t>, std::shared_ptr<oid_t>>;
107114
// Used in StatementCacheManager
108115
template class CuckooMap<StatementCache *, StatementCache *>;
109116

117+
// Used in InternalTypes
118+
template class CuckooMap<ItemPointer, RWType, ItemPointerHasher,
119+
ItemPointerComparator>;
120+
110121
} // namespace peloton

src/concurrency/timestamp_ordering_transaction_manager.cpp

Lines changed: 205 additions & 190 deletions
Large diffs are not rendered by default.

src/concurrency/transaction_context.cpp

Lines changed: 47 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,23 @@ namespace concurrency {
5050

5151
TransactionContext::TransactionContext(const size_t thread_id,
5252
const IsolationLevelType isolation,
53-
const cid_t &read_id) {
53+
const cid_t &read_id)
54+
: rw_set_(INTITIAL_RW_SET_SIZE) {
5455
Init(thread_id, isolation, read_id);
5556
}
5657

5758
TransactionContext::TransactionContext(const size_t thread_id,
5859
const IsolationLevelType isolation,
59-
const cid_t &read_id, const cid_t &commit_id) {
60+
const cid_t &read_id, const cid_t &commit_id)
61+
: rw_set_(INTITIAL_RW_SET_SIZE) {
62+
Init(thread_id, isolation, read_id, commit_id);
63+
}
64+
65+
TransactionContext::TransactionContext(const size_t thread_id,
66+
const IsolationLevelType isolation,
67+
const cid_t &read_id, const cid_t &commit_id,
68+
const size_t rw_set_size)
69+
: rw_set_(rw_set_size) {
6070
Init(thread_id, isolation, read_id, commit_id);
6171
}
6272

@@ -90,124 +100,98 @@ void TransactionContext::Init(const size_t thread_id,
90100
}
91101

92102
RWType TransactionContext::GetRWType(const ItemPointer &location) {
93-
oid_t tile_group_id = location.block;
94-
oid_t tuple_id = location.offset;
95-
auto itr = rw_set_.find(tile_group_id);
96-
if (itr == rw_set_.end()) {
97-
return RWType::INVALID;
98-
}
103+
RWType rw_type;
99104

100-
auto inner_itr = itr->second.find(tuple_id);
101-
if (inner_itr == itr->second.end()) {
102-
return RWType::INVALID;
105+
if (!rw_set_.Find(location, rw_type)) {
106+
rw_type = RWType::INVALID;
103107
}
104-
105-
return inner_itr->second;
108+
return rw_type;
106109
}
107110

108111
void TransactionContext::RecordRead(const ItemPointer &location) {
109-
oid_t tile_group_id = location.block;
110-
oid_t tuple_id = location.offset;
112+
RWType rw_type;
111113

112-
if (IsInRWSet(location)) {
113-
PL_ASSERT(rw_set_.at(tile_group_id).at(tuple_id) != RWType::DELETE &&
114-
rw_set_.at(tile_group_id).at(tuple_id) != RWType::INS_DEL);
114+
if (rw_set_.Find(location, rw_type)) {
115+
PL_ASSERT(rw_type != RWType::DELETE && rw_type != RWType::INS_DEL);
115116
return;
116117
} else {
117-
rw_set_[tile_group_id][tuple_id] = RWType::READ;
118+
rw_set_.Insert(location, RWType::READ);
118119
}
119120
}
120121

121122
void TransactionContext::RecordReadOwn(const ItemPointer &location) {
122-
oid_t tile_group_id = location.block;
123-
oid_t tuple_id = location.offset;
123+
RWType rw_type;
124124

125-
if (IsInRWSet(location)) {
126-
RWType &type = rw_set_.at(tile_group_id).at(tuple_id);
127-
if (type == RWType::READ) {
128-
type = RWType::READ_OWN;
129-
// record write.
130-
return;
131-
}
132-
PL_ASSERT(type != RWType::DELETE && type != RWType::INS_DEL);
125+
if (rw_set_.Find(location, rw_type)) {
126+
PL_ASSERT(rw_type != RWType::DELETE && rw_type != RWType::INS_DEL);
127+
if (rw_type == RWType::READ) {
128+
rw_set_.Update(location, RWType::READ_OWN);
129+
}
133130
} else {
134-
rw_set_[tile_group_id][tuple_id] = RWType::READ_OWN;
131+
rw_set_.Insert(location, RWType::READ_OWN);
135132
}
136133
}
137134

138135
void TransactionContext::RecordUpdate(const ItemPointer &location) {
139-
oid_t tile_group_id = location.block;
140-
oid_t tuple_id = location.offset;
136+
RWType rw_type;
141137

142-
if (IsInRWSet(location)) {
143-
RWType &type = rw_set_.at(tile_group_id).at(tuple_id);
144-
if (type == RWType::READ || type == RWType::READ_OWN) {
145-
type = RWType::UPDATE;
146-
// record write.
138+
if (rw_set_.Find(location, rw_type)) {
139+
if (rw_type == RWType::READ || rw_type == RWType::READ_OWN) {
147140
is_written_ = true;
148-
141+
rw_set_.Update(location, RWType::UPDATE);
149142
return;
150143
}
151-
if (type == RWType::UPDATE) {
144+
if (rw_type == RWType::UPDATE) {
152145
return;
153146
}
154-
if (type == RWType::INSERT) {
147+
if (rw_type == RWType::INSERT) {
155148
return;
156149
}
157-
if (type == RWType::DELETE) {
150+
if (rw_type == RWType::DELETE) {
158151
PL_ASSERT(false);
159152
return;
160153
}
161154
PL_ASSERT(false);
162155
} else {
163-
// consider select_for_udpate case.
164-
rw_set_[tile_group_id][tuple_id] = RWType::UPDATE;
156+
rw_set_.Insert(location, RWType::UPDATE);
165157
}
166158
}
167159

168160
void TransactionContext::RecordInsert(const ItemPointer &location) {
169-
oid_t tile_group_id = location.block;
170-
oid_t tuple_id = location.offset;
171-
172161
if (IsInRWSet(location)) {
173162
PL_ASSERT(false);
174163
} else {
175-
rw_set_[tile_group_id][tuple_id] = RWType::INSERT;
164+
rw_set_.Insert(location, RWType::INSERT);
176165
++insert_count_;
177166
}
178167
}
179168

180169
bool TransactionContext::RecordDelete(const ItemPointer &location) {
181-
oid_t tile_group_id = location.block;
182-
oid_t tuple_id = location.offset;
170+
RWType rw_type;
183171

184-
if (IsInRWSet(location)) {
185-
RWType &type = rw_set_.at(tile_group_id).at(tuple_id);
186-
if (type == RWType::READ || type == RWType::READ_OWN) {
187-
type = RWType::DELETE;
188-
// record write.
172+
if (rw_set_.Find(location, rw_type)) {
173+
if (rw_type == RWType::READ || rw_type == RWType::READ_OWN) {
174+
rw_set_.Update(location, RWType::DELETE);
175+
// record write
189176
is_written_ = true;
190-
191177
return false;
192178
}
193-
if (type == RWType::UPDATE) {
194-
type = RWType::DELETE;
195-
179+
if (rw_type == RWType::UPDATE) {
180+
rw_set_.Update(location, RWType::DELETE);
196181
return false;
197182
}
198-
if (type == RWType::INSERT) {
199-
type = RWType::INS_DEL;
183+
if (rw_type == RWType::INSERT) {
184+
rw_set_.Update(location, RWType::INS_DEL);
200185
--insert_count_;
201-
202186
return true;
203187
}
204-
if (type == RWType::DELETE) {
188+
if(rw_type == RWType::DELETE) {
205189
PL_ASSERT(false);
206190
return false;
207191
}
208192
PL_ASSERT(false);
209193
} else {
210-
rw_set_[tile_group_id][tuple_id] = RWType::DELETE;
194+
rw_set_.Insert(location, RWType::DELETE);
211195
}
212196
return false;
213197
}

src/include/common/container/cuckoo_map.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class CuckooMap {
7676
CUCKOO_MAP_ITERATOR_TYPE
7777
GetIterator();
7878

79+
CUCKOO_MAP_ITERATOR_TYPE
80+
GetConstIterator() const;
81+
7982
private:
8083

8184
// cuckoo map

src/include/common/internal_types.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,13 +1203,9 @@ std::string RWTypeToString(RWType type);
12031203
RWType StringToRWType(const std::string &str);
12041204
std::ostream &operator<<(std::ostream &os, const RWType &type);
12051205

1206-
// block -> offset -> type
1207-
typedef std::unordered_map<oid_t, std::unordered_map<oid_t, RWType>>
1208-
ReadWriteSet;
1209-
12101206
// ItemPointer -> type
12111207
typedef CuckooMap<ItemPointer, RWType, ItemPointerHasher, ItemPointerComparator>
1212-
CuckooReadWriteSet;
1208+
ReadWriteSet;
12131209

12141210
// this enum is to identify why the version should be GC'd.
12151211
enum class GCVersionType {

src/include/common/item_pointer.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,20 @@ class ItemPointerComparator {
5757
return (p1->block == p2->block) && (p1->offset == p2->offset);
5858
}
5959

60+
bool operator()(ItemPointer const &p1, ItemPointer const &p2) const {
61+
return (p1.block == p2.block) && (p1.offset == p2.offset);
62+
}
63+
6064
ItemPointerComparator(const ItemPointerComparator &) {}
6165
ItemPointerComparator() {}
6266
};
6367

6468
struct ItemPointerHasher {
6569
size_t operator()(const ItemPointer &item) const {
66-
return std::hash<oid_t>()(item.block) ^ std::hash<oid_t>()(item.offset);
70+
// This constant is found in the CityHash code
71+
// [Source libcuckoo/default_hasher.hh]
72+
return (std::hash<oid_t>()(item.block)*0x9ddfea08eb382d69ULL) ^
73+
std::hash<oid_t>()(item.offset);
6774
}
6875
};
6976

src/include/concurrency/transaction_context.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "common/printable.h"
2525
#include "common/internal_types.h"
2626

27+
#define INTITIAL_RW_SET_SIZE 64
28+
2729
namespace peloton {
2830

2931
namespace trigger {
@@ -46,6 +48,10 @@ class TransactionContext : public Printable {
4648

4749
TransactionContext(const size_t thread_id, const IsolationLevelType isolation,
4850
const cid_t &read_id, const cid_t &commit_id);
51+
52+
TransactionContext(const size_t thread_id, const IsolationLevelType isolation,
53+
const cid_t &read_id, const cid_t &commit_id,
54+
const size_t read_write_set_size);
4955

5056
~TransactionContext();
5157

@@ -116,16 +122,7 @@ class TransactionContext : public Printable {
116122
void ExecOnCommitTriggers();
117123

118124
bool IsInRWSet(const ItemPointer &location) {
119-
oid_t tile_group_id = location.block;
120-
oid_t tuple_id = location.offset;
121-
122-
if (rw_set_.find(tile_group_id) != rw_set_.end() &&
123-
rw_set_.at(tile_group_id).find(tuple_id) !=
124-
rw_set_.at(tile_group_id).end()) {
125-
return true;
126-
} else {
127-
return false;
128-
}
125+
return rw_set_.Contains(location);
129126
}
130127

131128
inline const ReadWriteSet &GetReadWriteSet() { return rw_set_; }
@@ -192,7 +189,7 @@ class TransactionContext : public Printable {
192189
// timestamp when the transaction began
193190
uint64_t timestamp_;
194191

195-
ReadWriteSet rw_set_;
192+
ReadWriteSet rw_set_;
196193
CreateDropSet rw_object_set_;
197194

198195
// this set contains data location that needs to be gc'd in the transaction.

0 commit comments

Comments
 (0)