ClickHouse/dbms/include/DB/IO/RemoteReadBuffer.h

76 lines
2.0 KiB
C++
Raw Normal View History

2011-11-18 20:17:27 +00:00
#pragma once
#include <DB/IO/ReadBufferFromHTTP.h>
#include "ReadHelpers.h"
2011-11-18 20:17:27 +00:00
#define DEFAULT_REMOTE_READ_BUFFER_CONNECTION_TIMEOUT 1
#define DEFAULT_REMOTE_READ_BUFFER_RECEIVE_TIMEOUT 1800
#define DEFAULT_REMOTE_READ_BUFFER_SEND_TIMEOUT 1800
2011-11-18 20:17:27 +00:00
namespace DB
{
/** Позволяет читать файл с удалённого сервера через riod.
2011-11-18 20:17:27 +00:00
*/
class RemoteReadBuffer : public ReadBuffer
{
private:
std::unique_ptr<ReadBufferFromHTTP> impl;
2011-11-18 20:17:27 +00:00
public:
RemoteReadBuffer(
const std::string & host,
int port,
const std::string & path,
bool compress = true,
size_t buffer_size = DBMS_DEFAULT_BUFFER_SIZE,
const Poco::Timespan & connection_timeout = Poco::Timespan(DEFAULT_REMOTE_READ_BUFFER_CONNECTION_TIMEOUT, 0),
const Poco::Timespan & send_timeout = Poco::Timespan(DEFAULT_REMOTE_READ_BUFFER_SEND_TIMEOUT, 0),
const Poco::Timespan & receive_timeout = Poco::Timespan(DEFAULT_REMOTE_READ_BUFFER_RECEIVE_TIMEOUT, 0))
2014-04-08 07:24:21 +00:00
: ReadBuffer(nullptr, 0)
2011-11-18 20:17:27 +00:00
{
2014-04-02 13:45:39 +00:00
ReadBufferFromHTTP::Params params = {
std::make_pair("action", "read"),
std::make_pair("path", path),
std::make_pair("compress", (compress ? "true" : "false"))};
2011-11-18 20:17:27 +00:00
impl = std::make_unique<ReadBufferFromHTTP>(host, port, params, buffer_size, connection_timeout, send_timeout, receive_timeout);
2011-11-18 20:17:27 +00:00
}
bool nextImpl()
{
if (!impl->next())
return false;
internal_buffer = impl->buffer();
working_buffer = internal_buffer;
return true;
}
/// Вернуть список имен файлов в директории.
static std::vector<std::string> listFiles(
const std::string & host,
int port,
const std::string & path,
size_t timeout = 0)
{
2014-04-02 13:45:39 +00:00
ReadBufferFromHTTP::Params params = {
std::make_pair("action", "list"),
std::make_pair("path", path)};
2014-04-02 13:45:39 +00:00
ReadBufferFromHTTP in(host, port, params, timeout);
std::vector<std::string> files;
while (!in.eof())
{
std::string s;
readString(s, in);
skipWhitespaceIfAny(in);
files.push_back(s);
}
return files;
}
2011-11-18 20:17:27 +00:00
};
}