src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
0 / 31
0.0%
Branches:
0 / 48
0.0%
Functions:
0 / 5
0.0%

storage/kv_engine/engine_petkv.h
Line Branch Exec Source
1 #pragma once
2 #include <algorithm>
3 #include <memory>
4 #include <string>
5 #include <vector>
6
7 #include "base/factory.h"
8 #include "base_kv.h"
9 #include "storage/nvm/pet_kv/pet_kv.h"
10
11 DECLARE_int32(prefetch_method);
12
13 class KVEnginePetKV : public BaseKV {
14 public:
15 ✗ explicit KVEnginePetKV(const BaseKVConfig& config) : BaseKV(config) {
16
0/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ const std::string shm_path = config.json_config_["path"];
17
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ const int shard_num = config.json_config_.value("shard_num", 16);
18
0/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ const int value_size = config.json_config_.at("value_size").get<int>();
19
0/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ const int capacity = config.json_config_.at("capacity").get<int>();
20 ✗ constexpr int64_t kMinShardMemory = 2LL * 1024 * 1024;
21 const int64_t value_capacity =
22
0/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ config.json_config_.at("value_capacity").get<int64_t>();
23 const int shard_capacity =
24 ✗ std::max(1, (capacity + shard_num - 1) / shard_num);
25 const int64_t shard_memory =
26 ✗ std::max<int64_t>(kMinShardMemory, value_capacity / shard_num);
27
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ shm_kv = std::make_unique<base::PetMultiKV>(
28 ✗ shm_path, shard_num, shard_memory, shard_capacity, value_size);
29 ✗ }
30
31 ✗ void Get(const uint64_t key, std::string& value, unsigned t) override {
32
0/2
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ auto kv_data = shm_kv->Get(key);
33
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if (kv_data.data)
34
0/2
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ value = std::string(kv_data.data, kv_data.size);
35 ✗ }
36
37 ✗ void BatchGet(base::ConstArray<uint64> keys,
38 std::vector<base::ConstArray<float>>* values,
39 unsigned t) override {
40 ✗ values->clear();
41
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if (FLAGS_prefetch_method == 0) {
42
0/2
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ for (auto k : keys) {
43
0/2
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ auto kv_data = shm_kv->Get(k);
44 #ifdef RPC_DEBUG
45 CHECK_NE(kv_data.size, 0) << "empty kv, key is " << k;
46 #endif
47 ✗ values->emplace_back(
48
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ (float*)kv_data.data, kv_data.size / sizeof(float));
49 }
50
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ } else if (FLAGS_prefetch_method == 1) {
51 ✗ shm_kv->BatchGet(keys, values);
52 }
53 ✗ }
54
55 void
56 ✗ Put(const uint64_t key, const std::string_view& value, unsigned t) override {
57
0/12
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ CHECK(shm_kv->Update(key, value.data(), value.size()));
58 ✗ }
59
60 std::pair<uint64_t, uint64_t> RegisterPMAddr() const {
61 return base::PMMmapRegisterCenter::GetInstance()->ForRDMAMemoryRegion();
62 }
63
64 ✗ void DebugInfo() const override { shm_kv->GetInfo(); }
65
66 private:
67 base::ScopedTempDir dir;
68 std::unique_ptr<base::PetMultiKV> shm_kv;
69 };
70
71 FACTORY_REGISTER(BaseKV, KVEnginePetKV, KVEnginePetKV, const BaseKVConfig&);
72