2011-11-18 20:17:27 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2014-03-21 17:23:09 +00:00
|
|
|
|
#include <DB/IO/ReadBufferFromHTTP.h>
|
|
|
|
|
#include "ReadHelpers.h"
|
2011-11-18 20:17:27 +00:00
|
|
|
|
|
2014-12-18 11:39:55 +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
|
|
|
|
|
{
|
|
|
|
|
|
2014-03-21 17:23:09 +00:00
|
|
|
|
/** Позволяет читать файл с удалённого сервера через riod.
|
2011-11-18 20:17:27 +00:00
|
|
|
|
*/
|
|
|
|
|
class RemoteReadBuffer : public ReadBuffer
|
|
|
|
|
{
|
|
|
|
|
private:
|
2014-03-21 17:23:09 +00:00
|
|
|
|
Poco::SharedPtr<ReadBufferFromHTTP> impl;
|
2011-11-18 20:17:27 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2012-01-30 19:18:25 +00:00
|
|
|
|
RemoteReadBuffer(
|
2014-03-21 17:23:09 +00:00
|
|
|
|
const std::string & host,
|
|
|
|
|
int port,
|
|
|
|
|
const std::string & path,
|
|
|
|
|
bool compress = true,
|
2014-12-18 11:39:55 +00:00
|
|
|
|
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
|
|
|
|
|
2014-12-18 11:39:55 +00:00
|
|
|
|
impl = new 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;
|
|
|
|
|
}
|
2013-12-13 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
/// Вернуть список имен файлов в директории.
|
|
|
|
|
static std::vector<std::string> listFiles(
|
|
|
|
|
const std::string & host,
|
|
|
|
|
int port,
|
|
|
|
|
const std::string & path,
|
2014-03-21 17:23:09 +00:00
|
|
|
|
size_t timeout = 0)
|
2013-12-13 12:53:17 +00:00
|
|
|
|
{
|
2014-04-02 13:45:39 +00:00
|
|
|
|
ReadBufferFromHTTP::Params params = {
|
|
|
|
|
std::make_pair("action", "list"),
|
|
|
|
|
std::make_pair("path", path)};
|
2013-12-13 12:53:17 +00:00
|
|
|
|
|
2014-04-02 13:45:39 +00:00
|
|
|
|
ReadBufferFromHTTP in(host, port, params, timeout);
|
2013-12-13 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
std::vector<std::string> files;
|
2014-03-21 17:23:09 +00:00
|
|
|
|
while (!in.eof())
|
|
|
|
|
{
|
|
|
|
|
std::string s;
|
|
|
|
|
readString(s, in);
|
|
|
|
|
skipWhitespaceIfAny(in);
|
2013-12-13 12:53:17 +00:00
|
|
|
|
files.push_back(s);
|
2014-03-21 17:23:09 +00:00
|
|
|
|
}
|
2013-12-13 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
return files;
|
|
|
|
|
}
|
2011-11-18 20:17:27 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|