2021-06-09 02:03:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/BackgroundSchedulePool.h>
|
|
|
|
#include <Core/Names.h>
|
|
|
|
#include <IO/ReadBuffer.h>
|
2021-07-03 17:14:56 +00:00
|
|
|
#include <Storages/FileLog/FileLogDirectoryWatcher.h>
|
2021-06-09 02:03:36 +00:00
|
|
|
#include <common/types.h>
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <mutex>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
class Logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
class ReadBufferFromFileLog : public ReadBuffer
|
|
|
|
{
|
|
|
|
public:
|
2021-07-03 17:14:56 +00:00
|
|
|
ReadBufferFromFileLog(const String & path_, Poco::Logger * log_, size_t max_batch_size, size_t poll_timeout_, ContextPtr context_);
|
2021-06-09 02:03:36 +00:00
|
|
|
|
|
|
|
~ReadBufferFromFileLog() override = default;
|
|
|
|
|
|
|
|
void open();
|
2021-07-11 06:18:03 +00:00
|
|
|
void close();
|
2021-06-09 02:03:36 +00:00
|
|
|
|
|
|
|
auto pollTimeout() const { return poll_timeout; }
|
|
|
|
|
|
|
|
inline bool hasMorePolledRecords() const { return current != records.end(); }
|
|
|
|
|
|
|
|
bool poll();
|
|
|
|
|
2021-09-04 17:04:35 +00:00
|
|
|
bool noRecords() { return buffer_status == BufferStatus::NO_RECORD_RETURNED; }
|
2021-07-04 06:16:40 +00:00
|
|
|
|
2021-06-09 02:03:36 +00:00
|
|
|
private:
|
2021-07-04 06:16:40 +00:00
|
|
|
enum class BufferStatus
|
|
|
|
{
|
|
|
|
NO_RECORD_RETURNED,
|
2021-09-04 17:04:35 +00:00
|
|
|
POLLED_OK,
|
2021-06-09 02:03:36 +00:00
|
|
|
};
|
|
|
|
|
2021-07-04 06:16:40 +00:00
|
|
|
BufferStatus buffer_status;
|
|
|
|
|
2021-07-03 17:14:56 +00:00
|
|
|
const String path;
|
|
|
|
|
2021-07-04 06:16:40 +00:00
|
|
|
bool path_is_directory = false;
|
|
|
|
|
2021-06-09 02:03:36 +00:00
|
|
|
Poco::Logger * log;
|
|
|
|
const size_t batch_size = 1;
|
|
|
|
const size_t poll_timeout = 0;
|
|
|
|
|
|
|
|
bool time_out = false;
|
|
|
|
|
2021-07-03 17:14:56 +00:00
|
|
|
|
2021-06-09 02:03:36 +00:00
|
|
|
ContextPtr context;
|
|
|
|
|
|
|
|
bool allowed = true;
|
|
|
|
|
|
|
|
using Record = std::string;
|
|
|
|
using Records = std::vector<Record>;
|
|
|
|
|
|
|
|
Records records;
|
|
|
|
Records::const_iterator current;
|
|
|
|
|
|
|
|
using TaskThread = BackgroundSchedulePool::TaskHolder;
|
|
|
|
|
|
|
|
TaskThread wait_task;
|
|
|
|
|
|
|
|
Records pollBatch(size_t batch_size_);
|
|
|
|
|
|
|
|
void readNewRecords(Records & new_records, size_t batch_size_);
|
|
|
|
|
|
|
|
void cleanUnprocessed();
|
|
|
|
|
|
|
|
bool nextImpl() override;
|
|
|
|
|
|
|
|
void waitFunc();
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|