ClickHouse/dbms/src/Storages/MergeTree/RemoteQueryExecutor.cpp

82 lines
1.4 KiB
C++
Raw Normal View History

2016-01-28 01:00:27 +00:00
#include <DB/Storages/MergeTree/RemoteQueryExecutor.h>
#include <DB/Interpreters/executeQuery.h>
#include <DB/IO/ReadBufferFromHTTP.h>
#include <DB/IO/ReadHelpers.h>
#include <DB/IO/WriteHelpers.h>
namespace DB
{
namespace ErrorCodes
{
extern const int ABORTED;
}
namespace RemoteQueryExecutor
{
namespace
{
std::string getEndpointId(const std::string & node_id)
{
return "RemoteQueryExecutor:" + node_id;
}
}
Service::Service(Context & context_)
2016-03-25 11:48:45 +00:00
: context{context_}
2016-01-28 01:00:27 +00:00
{
}
std::string Service::getId(const std::string & node_id) const
{
return getEndpointId(node_id);
}
2016-03-01 17:47:53 +00:00
void Service::processQuery(const Poco::Net::HTMLForm & params, ReadBuffer & body, WriteBuffer & out)
2016-01-28 01:00:27 +00:00
{
if (is_cancelled)
2016-03-25 11:48:45 +00:00
throw Exception{"RemoteQueryExecutor service terminated", ErrorCodes::ABORTED};
2016-01-28 01:00:27 +00:00
std::string query = params.get("query");
bool flag = true;
try
{
(void) executeQuery(query, context, true);
}
catch (...)
{
2016-03-01 17:47:53 +00:00
tryLogCurrentException(__PRETTY_FUNCTION__);
2016-01-28 01:00:27 +00:00
flag = false;
}
writeBinary(flag, out);
out.next();
}
bool Client::executeQuery(const InterserverIOEndpointLocation & location, const std::string & query)
{
ReadBufferFromHTTP::Params params =
{
{"endpoint", getEndpointId(location.name)},
{"compress", "false"},
{"query", query}
};
2016-03-25 11:48:45 +00:00
ReadBufferFromHTTP in{location.host, location.port, params};
2016-01-28 01:00:27 +00:00
bool flag;
readBinary(flag, in);
assertEOF(in);
return flag;
}
}
}