2017-02-22 15:29:43 +00:00
|
|
|
#pragma once
|
2017-02-09 10:10:13 +00:00
|
|
|
#include <forward_list>
|
|
|
|
|
|
|
|
#include <DB/IO/WriteBuffer.h>
|
2017-02-22 15:29:43 +00:00
|
|
|
#include <DB/IO/IReadableWriteBuffer.h>
|
2017-03-27 12:40:08 +00:00
|
|
|
#include <DB/Common/Allocator.h>
|
2017-02-09 10:10:13 +00:00
|
|
|
#include <DB/Core/Defines.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-03-02 09:35:17 +00:00
|
|
|
/// Stores data in memory chunks, size of cunks are exponentially increasing during write
|
|
|
|
/// Written data could be reread after write
|
2017-03-27 12:40:08 +00:00
|
|
|
class MemoryWriteBuffer : public WriteBuffer, public IReadableWriteBuffer, boost::noncopyable, private Allocator<false>
|
2017-02-09 10:10:13 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-03-02 09:35:17 +00:00
|
|
|
/// Use max_total_size_ = 0 for unlimited storage
|
2017-02-09 10:10:13 +00:00
|
|
|
MemoryWriteBuffer(
|
|
|
|
size_t max_total_size_ = 0,
|
|
|
|
size_t initial_chunk_size_ = DBMS_DEFAULT_BUFFER_SIZE,
|
2017-03-27 12:40:08 +00:00
|
|
|
double growth_rate_ = 2.0,
|
|
|
|
size_t max_chunk_size_ = 128 * DBMS_DEFAULT_BUFFER_SIZE);
|
2017-02-09 10:10:13 +00:00
|
|
|
|
|
|
|
void nextImpl() override;
|
|
|
|
|
|
|
|
~MemoryWriteBuffer() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2017-02-28 14:15:13 +00:00
|
|
|
std::shared_ptr<ReadBuffer> getReadBufferImpl() override;
|
|
|
|
|
2017-02-09 10:10:13 +00:00
|
|
|
const size_t max_total_size;
|
|
|
|
const size_t initial_chunk_size;
|
2017-03-27 12:40:08 +00:00
|
|
|
const size_t max_chunk_size;
|
2017-02-09 10:10:13 +00:00
|
|
|
const double growth_rate;
|
|
|
|
|
|
|
|
using Container = std::forward_list<BufferBase::Buffer>;
|
|
|
|
|
|
|
|
Container chunk_list;
|
|
|
|
Container::iterator chunk_tail;
|
|
|
|
size_t total_chunks_size = 0;
|
|
|
|
|
|
|
|
void addChunk();
|
|
|
|
|
|
|
|
friend class ReadBufferFromMemoryWriteBuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|