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-04-01 07:20:54 +00:00
|
|
|
/// Use max_total_size_ = 0 for unlimited storage
|
|
|
|
MemoryWriteBuffer(
|
|
|
|
size_t max_total_size_ = 0,
|
|
|
|
size_t initial_chunk_size_ = DBMS_DEFAULT_BUFFER_SIZE,
|
|
|
|
double growth_rate_ = 2.0,
|
|
|
|
size_t max_chunk_size_ = 128 * DBMS_DEFAULT_BUFFER_SIZE);
|
2017-02-09 10:10:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void nextImpl() override;
|
2017-02-09 10:10:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
~MemoryWriteBuffer() override;
|
2017-02-09 10:10:13 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::shared_ptr<ReadBuffer> getReadBufferImpl() override;
|
2017-02-28 14:15:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const size_t max_total_size;
|
|
|
|
const size_t initial_chunk_size;
|
|
|
|
const size_t max_chunk_size;
|
|
|
|
const double growth_rate;
|
2017-02-09 10:10:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
using Container = std::forward_list<BufferBase::Buffer>;
|
2017-02-09 10:10:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Container chunk_list;
|
|
|
|
Container::iterator chunk_tail;
|
|
|
|
size_t total_chunks_size = 0;
|
2017-02-09 10:10:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void addChunk();
|
2017-02-09 10:10:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
friend class ReadBufferFromMemoryWriteBuffer;
|
2017-02-09 10:10:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|