48 lines
935 B
C++
48 lines
935 B
C++
//
|
|
// Created by Kirill Zhukov on 20.04.2025.
|
|
//
|
|
|
|
#ifndef RECOVERYLOG_H
|
|
#define RECOVERYLOG_H
|
|
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <functional>
|
|
#include <filesystem>
|
|
#include "utils/hash/Hash128.h"
|
|
#include "core/Command.h"
|
|
|
|
namespace usub::utils
|
|
{
|
|
class RecoveryLog
|
|
{
|
|
public:
|
|
explicit RecoveryLog(const std::string& dbname);
|
|
|
|
~RecoveryLog();
|
|
|
|
void log_put(const std::string& key, const std::string& value);
|
|
|
|
void log_delete(const std::string& key);
|
|
|
|
void log_command(const core::Command& cmd);
|
|
|
|
void replay(const std::function<void(const core::Command&)>& callback) const;
|
|
|
|
void clear();
|
|
|
|
private:
|
|
void ensure_metadata_dir() const;
|
|
|
|
private:
|
|
std::string db_name_;
|
|
std::string metadata_dir_;
|
|
std::string log_file_;
|
|
std::ofstream log_out_;
|
|
};
|
|
} // utils
|
|
// usub
|
|
|
|
#endif //RECOVERYLOG_H
|