2020-04-14 19:47:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DataStreams/NativeBlockInputStream.h>
|
|
|
|
#include <DataStreams/NativeBlockOutputStream.h>
|
|
|
|
#include <Storages/MergeTree/IMergeTreeDataPart.h>
|
|
|
|
#include <Disks/IDisk.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class MergeTreeData;
|
|
|
|
|
|
|
|
class MergeTreeWriteAheadLog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
constexpr static auto WAL_FILE_NAME = "wal";
|
|
|
|
constexpr static auto WAL_FILE_EXTENSION = ".bin";
|
2020-05-05 15:06:16 +00:00
|
|
|
constexpr static size_t MAX_WAL_BYTES = 1024 * 1024 * 1024;
|
2020-04-14 19:47:19 +00:00
|
|
|
|
|
|
|
MergeTreeWriteAheadLog(const MergeTreeData & storage_, const DiskPtr & disk_,
|
|
|
|
const String & name = String(WAL_FILE_NAME) + WAL_FILE_EXTENSION);
|
|
|
|
|
|
|
|
void write(const Block & block, const String & part_name);
|
2020-05-05 15:06:16 +00:00
|
|
|
std::vector<MergeTreeMutableDataPartPtr> restore();
|
2020-04-14 19:47:19 +00:00
|
|
|
|
|
|
|
private:
|
2020-04-30 15:27:39 +00:00
|
|
|
void init();
|
|
|
|
void rotate();
|
2020-04-14 19:47:19 +00:00
|
|
|
|
|
|
|
const MergeTreeData & storage;
|
|
|
|
DiskPtr disk;
|
|
|
|
String path;
|
|
|
|
|
|
|
|
std::unique_ptr<WriteBuffer> out;
|
|
|
|
std::unique_ptr<NativeBlockOutputStream> block_out;
|
|
|
|
|
|
|
|
Int64 min_block_number = std::numeric_limits<Int64>::max();
|
2020-04-29 17:14:49 +00:00
|
|
|
Int64 max_block_number = std::numeric_limits<Int64>::min();
|
2020-04-14 19:47:19 +00:00
|
|
|
|
|
|
|
mutable std::mutex write_mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|