GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 91.7% 33 / 0 / 36
Functions: 75.0% 6 / 0 / 8
Branches: 64.7% 22 / 0 / 34

storage/index/dram/pet_hash_index.h
Line Branch Exec Source
1 #pragma once
2
3 #include <memory>
4 #include <new>
5
6 #include "base/factory.h"
7 #include "storage/index/index.h"
8 #include "storage/nvm/pet_kv/pet_hash.h"
9
10 class DramPetHashIndex : public Index {
11 public:
12 366 explicit DramPetHashIndex(const BaseKVConfig& config) : Index(config) {
13 const uint64_t capacity =
14
2/4
✓ Branch 1 taken 366 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 366 times.
✗ Branch 5 not taken.
366 config.json_config_.at("capacity").get<uint64_t>();
15 const size_t bytes =
16
1/2
✓ Branch 1 taken 366 times.
✗ Branch 2 not taken.
366 base::PetHash<Key_t, Value_t, false>::MemorySize(capacity);
17 366 void* mem = nullptr;
18
3/6
✓ Branch 0 taken 366 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 366 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 366 times.
366 if (posix_memalign(&mem, 64, bytes) != 0 || mem == nullptr) {
19 throw std::bad_alloc();
20 }
21 366 impl_ = new (mem) base::PetHash<Key_t, Value_t, false>();
22
1/2
✓ Branch 1 taken 366 times.
✗ Branch 2 not taken.
366 impl_->Initialize(capacity);
23 366 }
24
25 732 ~DramPetHashIndex() override {
26
1/2
✓ Branch 0 taken 366 times.
✗ Branch 1 not taken.
366 if (impl_ != nullptr) {
27 366 impl_->~PetHash<Key_t, Value_t, false>();
28 366 std::free(impl_);
29 366 impl_ = nullptr;
30 }
31 732 }
32
33 80056 void Get(Key_t key, Value_t& pointer, unsigned tid) override {
34 (void)tid;
35
1/2
✓ Branch 1 taken 80056 times.
✗ Branch 2 not taken.
80056 auto [value, exists] = impl_->Get(key);
36
2/2
✓ Branch 0 taken 77642 times.
✓ Branch 1 taken 2414 times.
80056 pointer = exists ? value : NONE;
37 80056 }
38
39 138438 Value_t Put(Key_t key, Value_t pointer, unsigned tid) override {
40 (void)tid;
41 138438 Value_t old_handle = kValueHandleNone;
42
1/2
✓ Branch 2 taken 138438 times.
✗ Branch 3 not taken.
138438 impl_->Set(key, pointer, nullptr, false, &old_handle);
43 138438 return old_handle;
44 }
45
46 630 void BatchGet(base::ConstArray<Key_t> keys,
47 Value_t* pointers,
48 unsigned tid) override {
49 (void)tid;
50
2/2
✓ Branch 1 taken 23352 times.
✓ Branch 2 taken 630 times.
23982 for (int i = 0; i < keys.Size(); ++i) {
51
2/2
✓ Branch 1 taken 22722 times.
✓ Branch 2 taken 630 times.
23352 if (i + 1 < keys.Size()) {
52
1/2
✓ Branch 2 taken 22722 times.
✗ Branch 3 not taken.
22722 impl_->HintPrefetch(keys[i + 1]);
53 }
54
1/2
✓ Branch 2 taken 23352 times.
✗ Branch 3 not taken.
23352 auto [value, exists] = impl_->Get(keys[i]);
55
2/2
✓ Branch 0 taken 23220 times.
✓ Branch 1 taken 132 times.
23352 pointers[i] = exists ? value : NONE;
56 }
57 630 }
58
59 18 void BatchPut(base::ConstArray<Key_t> keys,
60 Value_t* pointers,
61 unsigned tid) override {
62
2/2
✓ Branch 1 taken 144 times.
✓ Branch 2 taken 18 times.
162 for (int i = 0; i < keys.Size(); ++i) {
63 144 Put(keys[i], pointers[i], tid);
64 }
65 18 }
66
67 bool Delete(Key_t& key) override { return impl_->Delete(key); }
68 size_t Capacity() override { return impl_->Capacity(); }
69
70 private:
71 base::PetHash<Key_t, Value_t, false>* impl_ = nullptr;
72 };
73
74 FACTORY_REGISTER(Index, DRAM_PET_HASH, DramPetHashIndex, const BaseKVConfig&);
75