48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
//
|
|
// Created by Kirill Zhukov on 20.04.2025.
|
|
//
|
|
|
|
#ifndef COMPACTOR_H
|
|
#define COMPACTOR_H
|
|
|
|
#include <atomic>
|
|
#include <vector>
|
|
#include <string>
|
|
#include "utils/datastructures/LFSkipList.h"
|
|
#include "utils/datastructures/LFCircullarBuffer.h"
|
|
#include "utils/io/SSTableIO.h"
|
|
#include "utils/hash/Hash128.h"
|
|
|
|
namespace usub::utils
|
|
{
|
|
class Compactor
|
|
{
|
|
public:
|
|
explicit Compactor(VersionManager& vm);
|
|
~Compactor();
|
|
|
|
void add_sstable_l0(const std::string& filename);
|
|
void run();
|
|
|
|
private:
|
|
void background_worker();
|
|
void compact_level(std::vector<std::string>& source_files, std::vector<std::string>& dest_files, int level);
|
|
|
|
private:
|
|
VersionManager& version_manager_;
|
|
std::atomic<bool> running_;
|
|
std::thread worker_thread_;
|
|
LockFreeRingBuffer<std::string> l0_queue_{1024};
|
|
std::vector<std::string> level0_files_;
|
|
std::vector<std::string> level1_files_;
|
|
std::vector<std::string> level2_files_;
|
|
std::atomic<size_t> level0_size_{0};
|
|
std::atomic<size_t> level1_size_{0};
|
|
std::atomic<size_t> level2_size_{0};
|
|
std::mutex levels_mutex_;
|
|
};
|
|
} // usub
|
|
|
|
|
|
#endif //COMPACTOR_H
|