blob: 69d92a7b381e452cfed2a83827296d8a22c098e2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#pragma once
#include <atomic>
#include <map>
#include <mutex>
#include <Core/Types.h>
#include <base/defines.h>
#error #include <libnuraft/log_store.hxx>
namespace DB
{
class InMemoryLogStore : public nuraft::log_store
{
public:
InMemoryLogStore();
uint64_t start_index() const override;
uint64_t next_slot() const override;
nuraft::ptr<nuraft::log_entry> last_entry() const override;
uint64_t append(nuraft::ptr<nuraft::log_entry> & entry) override;
void write_at(uint64_t index, nuraft::ptr<nuraft::log_entry> & entry) override;
nuraft::ptr<std::vector<nuraft::ptr<nuraft::log_entry>>> log_entries(uint64_t start, uint64_t end) override;
nuraft::ptr<nuraft::log_entry> entry_at(uint64_t index) override;
uint64_t term_at(uint64_t index) override;
nuraft::ptr<nuraft::buffer> pack(uint64_t index, Int32 cnt) override;
void apply_pack(uint64_t index, nuraft::buffer & pack) override;
bool compact(uint64_t last_log_index) override;
bool flush() override { return true; }
private:
std::map<uint64_t, nuraft::ptr<nuraft::log_entry>> logs TSA_GUARDED_BY(logs_lock);
mutable std::mutex logs_lock;
std::atomic<uint64_t> start_idx;
};
}
|