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

Commit 3a32398

Browse files
Formating + comments
1 parent 42c4c48 commit 3a32398

File tree

6 files changed

+43
-37
lines changed

6 files changed

+43
-37
lines changed

src/common/container/cuckoo_map.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ CUCKOO_MAP_TEMPLATE_ARGUMENTS
3636
CUCKOO_MAP_TYPE::CuckooMap() {}
3737

3838
CUCKOO_MAP_TEMPLATE_ARGUMENTS
39-
CUCKOO_MAP_TYPE::CuckooMap(size_t initial_size)
40-
: cuckoo_map(initial_size) {}
39+
CUCKOO_MAP_TYPE::CuckooMap(size_t initial_size) : cuckoo_map(initial_size) {}
4140

4241
CUCKOO_MAP_TEMPLATE_ARGUMENTS
4342
CUCKOO_MAP_TYPE::~CuckooMap() {}
@@ -89,9 +88,14 @@ CUCKOO_MAP_ITERATOR_TYPE
8988
CUCKOO_MAP_TYPE::GetIterator() { return cuckoo_map.lock_table(); }
9089

9190
CUCKOO_MAP_TEMPLATE_ARGUMENTS
92-
CUCKOO_MAP_ITERATOR_TYPE
91+
CUCKOO_MAP_ITERATOR_TYPE
9392
CUCKOO_MAP_TYPE::GetConstIterator() const {
94-
auto locked_table = const_cast<CuckooMap*>(this)->cuckoo_map.lock_table();
93+
// WARNING: This is a compiler hack and should never be used elsewhere
94+
// If you are considering using this, please ask Marcel first
95+
// We need the const iterator on the const object and the cuckoohash
96+
// library returns a lock_table object. The other option would be to
97+
// Modify the cuckoohash library which is not neat.
98+
auto locked_table = const_cast<CuckooMap *>(this)->cuckoo_map.lock_table();
9599
return locked_table;
96100
}
97101

@@ -115,7 +119,7 @@ template class CuckooMap<std::shared_ptr<oid_t>, std::shared_ptr<oid_t>>;
115119
template class CuckooMap<StatementCache *, StatementCache *>;
116120

117121
// Used in InternalTypes
118-
template class CuckooMap<ItemPointer, RWType, ItemPointerHasher,
119-
ItemPointerComparator>;
122+
template class CuckooMap<ItemPointer, RWType, ItemPointerHasher,
123+
ItemPointerComparator>;
120124

121125
} // namespace peloton

src/concurrency/timestamp_ordering_transaction_manager.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,7 @@ ResultType TimestampOrderingTransactionManager::CommitTransaction(
781781
if (!rw_set.IsEmpty()) {
782782
auto rw_set_iterator = rw_set.GetConstIterator();
783783
const auto tile_group_id = rw_set_iterator.begin()->first.block;
784-
database_id =
785-
manager.GetTileGroup(tile_group_id)->GetDatabaseId();
784+
database_id = manager.GetTileGroup(tile_group_id)->GetDatabaseId();
786785
}
787786
}
788787

@@ -798,7 +797,6 @@ ResultType TimestampOrderingTransactionManager::CommitTransaction(
798797
// TODO: This might be inefficient since we will have to get the
799798
// tile_group_header for each entry. Check if this needs to be consolidated
800799
for (const auto &tuple_entry : rw_set_lt) {
801-
802800
ItemPointer item_ptr = tuple_entry.first;
803801
oid_t tile_group_id = item_ptr.block;
804802
oid_t tuple_slot = item_ptr.offset;
@@ -809,7 +807,7 @@ ResultType TimestampOrderingTransactionManager::CommitTransaction(
809807
// A read operation has acquired ownership but hasn't done any further
810808
// update/delete yet
811809
// Yield the ownership
812-
YieldOwnership(current_txn, tile_group_header, tuple_slot);
810+
YieldOwnership(current_txn, tile_group_header, tuple_slot);
813811
} else if (tuple_entry.second == RWType::UPDATE) {
814812
// we must guarantee that, at any time point, only one version is
815813
// visible.
@@ -960,8 +958,7 @@ ResultType TimestampOrderingTransactionManager::AbortTransaction(
960958
if (!rw_set.IsEmpty()) {
961959
auto rw_set_iterator = rw_set.GetConstIterator();
962960
const auto tile_group_id = rw_set_iterator.begin()->first.block;
963-
database_id =
964-
manager.GetTileGroup(tile_group_id)->GetDatabaseId();
961+
database_id = manager.GetTileGroup(tile_group_id)->GetDatabaseId();
965962
}
966963
}
967964

@@ -973,7 +970,6 @@ ResultType TimestampOrderingTransactionManager::AbortTransaction(
973970
// TODO: This might be inefficient since we will have to get the
974971
// tile_group_header for each entry. Check if this needs to be consolidated
975972
for (const auto &tuple_entry : rw_set_lt) {
976-
977973
ItemPointer item_ptr = tuple_entry.first;
978974
oid_t tile_group_id = item_ptr.block;
979975
oid_t tuple_slot = item_ptr.offset;
@@ -985,9 +981,9 @@ ResultType TimestampOrderingTransactionManager::AbortTransaction(
985981
// Yield the ownership
986982
YieldOwnership(current_txn, tile_group_header, tuple_slot);
987983
} else if (tuple_entry.second == RWType::UPDATE) {
988-
ItemPointer new_version =
984+
ItemPointer new_version =
989985
tile_group_header->GetPrevItemPointer(tuple_slot);
990-
auto new_tile_group_header =
986+
auto new_tile_group_header =
991987
manager.GetTileGroup(new_version.block)->GetHeader();
992988
// these two fields can be set at any time.
993989
new_tile_group_header->SetBeginCommitId(new_version.offset, MAX_CID);

src/concurrency/transaction_context.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,26 @@ namespace concurrency {
4949
*/
5050

5151
TransactionContext::TransactionContext(const size_t thread_id,
52-
const IsolationLevelType isolation,
53-
const cid_t &read_id)
54-
: rw_set_(INTITIAL_RW_SET_SIZE) {
52+
const IsolationLevelType isolation,
53+
const cid_t &read_id)
54+
: rw_set_(INTITIAL_RW_SET_SIZE) {
5555
Init(thread_id, isolation, read_id);
5656
}
5757

5858
TransactionContext::TransactionContext(const size_t thread_id,
59-
const IsolationLevelType isolation,
60-
const cid_t &read_id, const cid_t &commit_id)
61-
: rw_set_(INTITIAL_RW_SET_SIZE) {
59+
const IsolationLevelType isolation,
60+
const cid_t &read_id,
61+
const cid_t &commit_id)
62+
: rw_set_(INTITIAL_RW_SET_SIZE) {
6263
Init(thread_id, isolation, read_id, commit_id);
6364
}
6465

6566
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) {
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) {
7072
Init(thread_id, isolation, read_id, commit_id);
7173
}
7274

src/include/common/container/cuckoo_map.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,22 @@
2323
namespace peloton {
2424

2525
// CUCKOO_MAP_TEMPLATE_ARGUMENTS
26-
#define CUCKOO_MAP_TEMPLATE_ARGUMENTS template <typename KeyType, \
27-
typename ValueType, typename HashType, typename PredType>
26+
#define CUCKOO_MAP_TEMPLATE_ARGUMENTS \
27+
template <typename KeyType, typename ValueType, typename HashType, \
28+
typename PredType>
2829

2930
// CUCKOO_MAP_DEFAULT_ARGUMENTS
30-
#define CUCKOO_MAP_DEFAULT_ARGUMENTS template <typename KeyType, \
31-
typename ValueType, typename HashType = DefaultHasher<KeyType>, \
32-
typename PredType = std::equal_to<KeyType>>
31+
#define CUCKOO_MAP_DEFAULT_ARGUMENTS \
32+
template <typename KeyType, typename ValueType, \
33+
typename HashType = DefaultHasher<KeyType>, \
34+
typename PredType = std::equal_to<KeyType>>
3335

3436
// CUCKOO_MAP_TYPE
3537
#define CUCKOO_MAP_TYPE CuckooMap<KeyType, ValueType, HashType, PredType>
3638

3739
// Iterator type
3840
#define CUCKOO_MAP_ITERATOR_TYPE \
39-
typename cuckoohash_map<KeyType, ValueType, HashType, PredType>::locked_table
41+
typename cuckoohash_map<KeyType, ValueType, HashType, PredType>::locked_table
4042

4143
CUCKOO_MAP_DEFAULT_ARGUMENTS
4244
class CuckooMap {
@@ -82,8 +84,7 @@ class CuckooMap {
8284
private:
8385

8486
// cuckoo map
85-
typedef cuckoohash_map<KeyType, ValueType, HashType, PredType>
86-
cuckoo_map_t;
87+
typedef cuckoohash_map<KeyType, ValueType, HashType, PredType> cuckoo_map_t;
8788

8889
cuckoo_map_t cuckoo_map;
8990
};

src/include/common/item_pointer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include <cstdint>
2020

21-
#include "common/internal_types.h"
21+
#include "internal_types.h"
2222

2323
namespace peloton {
2424

@@ -67,8 +67,10 @@ class ItemPointerComparator {
6767

6868
struct ItemPointerHasher {
6969
size_t operator()(const ItemPointer &item) const {
70-
// This constant is found in the CityHash code
70+
// This constant is found in the CityHash code
7171
// [Source libcuckoo/default_hasher.hh]
72+
// std::hash returns the same number for unsigned int which causes
73+
// too many collisions in the Cuckoohash leading to too many collisions
7274
return (std::hash<oid_t>()(item.block)*0x9ddfea08eb382d69ULL) ^
7375
std::hash<oid_t>()(item.offset);
7476
}
@@ -77,7 +79,8 @@ struct ItemPointerHasher {
7779
class ItemPointerHashFunc {
7880
public:
7981
size_t operator()(ItemPointer *const &p) const {
80-
return std::hash<oid_t>()(p->block) ^ std::hash<oid_t>()(p->offset);
82+
return (std::hash<oid_t>()(p->block)*0x9ddfea08eb382d69ULL) ^
83+
std::hash<oid_t>()(p->offset);
8184
}
8285

8386
ItemPointerHashFunc(const ItemPointerHashFunc &) {}

src/include/concurrency/transaction_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class TransactionContext : public Printable {
189189
// timestamp when the transaction began
190190
uint64_t timestamp_;
191191

192-
ReadWriteSet rw_set_;
192+
ReadWriteSet rw_set_;
193193
CreateDropSet rw_object_set_;
194194

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

0 commit comments

Comments
 (0)