2021-01-13 10:32:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
|
|
|
#include <Core/Types.h>
|
2022-06-14 22:35:55 +00:00
|
|
|
#include <base/defines.h>
|
2021-10-27 23:10:39 +00:00
|
|
|
#include <libnuraft/log_store.hxx>
|
2021-01-13 10:32:20 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class InMemoryLogStore : public nuraft::log_store
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InMemoryLogStore();
|
|
|
|
|
2021-04-08 14:17:57 +00:00
|
|
|
uint64_t start_index() const override;
|
2021-01-13 10:32:20 +00:00
|
|
|
|
2021-04-08 14:17:57 +00:00
|
|
|
uint64_t next_slot() const override;
|
2021-01-13 10:32:20 +00:00
|
|
|
|
|
|
|
nuraft::ptr<nuraft::log_entry> last_entry() const override;
|
|
|
|
|
2021-04-08 14:17:57 +00:00
|
|
|
uint64_t append(nuraft::ptr<nuraft::log_entry> & entry) override;
|
2021-01-13 10:32:20 +00:00
|
|
|
|
2021-04-08 14:17:57 +00:00
|
|
|
void write_at(uint64_t index, nuraft::ptr<nuraft::log_entry> & entry) override;
|
2021-01-13 10:32:20 +00:00
|
|
|
|
2021-04-08 14:17:57 +00:00
|
|
|
nuraft::ptr<std::vector<nuraft::ptr<nuraft::log_entry>>> log_entries(uint64_t start, uint64_t end) override;
|
2021-01-13 10:32:20 +00:00
|
|
|
|
2021-04-08 14:17:57 +00:00
|
|
|
nuraft::ptr<nuraft::log_entry> entry_at(uint64_t index) override;
|
2021-01-13 10:32:20 +00:00
|
|
|
|
2021-04-08 14:17:57 +00:00
|
|
|
uint64_t term_at(uint64_t index) override;
|
2021-01-13 10:32:20 +00:00
|
|
|
|
2021-04-08 14:17:57 +00:00
|
|
|
nuraft::ptr<nuraft::buffer> pack(uint64_t index, Int32 cnt) override;
|
2021-01-13 10:32:20 +00:00
|
|
|
|
2021-04-08 14:17:57 +00:00
|
|
|
void apply_pack(uint64_t index, nuraft::buffer & pack) override;
|
2021-01-13 10:32:20 +00:00
|
|
|
|
2021-04-08 14:17:57 +00:00
|
|
|
bool compact(uint64_t last_log_index) override;
|
2021-01-13 10:32:20 +00:00
|
|
|
|
|
|
|
bool flush() override { return true; }
|
|
|
|
|
|
|
|
private:
|
2022-06-14 22:35:55 +00:00
|
|
|
std::map<uint64_t, nuraft::ptr<nuraft::log_entry>> logs TSA_GUARDED_BY(logs_lock);
|
2021-01-13 10:32:20 +00:00
|
|
|
mutable std::mutex logs_lock;
|
2021-04-08 14:17:57 +00:00
|
|
|
std::atomic<uint64_t> start_idx;
|
2021-01-13 10:32:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|