17 #include <boost/shared_ptr.hpp>
18 #include <boost/thread.hpp>
23 #include "gen-cpp/Types_types.h"
24 #include "gen-cpp/Data_types.h"
32 #define SIGNED_RIGHT_SHIFT_IS 1
33 #define ARITHMETIC_RIGHT_SHIFT 1
38 #pragma clang diagnostic push
39 #pragma clang diagnostic ignored "-Wstring-plus-int"
40 #include <thrift/Thrift.h>
41 #include <thrift/transport/TSocket.h>
42 #include <thrift/transport/TServerSocket.h>
43 #include <thrift/concurrency/ThreadManager.h>
44 #include <thrift/concurrency/PosixThreadFactory.h>
45 #include <thrift/protocol/TCompactProtocol.h>
46 #pragma clang diagnostic pop
50 using namespace apache::thrift;
51 using namespace apache::thrift::transport;
52 using namespace apache::thrift::server;
54 using namespace apache::thrift::concurrency;
58 bool Apache::Hadoop::Hive::Partition::operator<(
59 const Apache::Hadoop::Hive::Partition& x)
const {
60 DCHECK(
false) <<
"This should not get called.";
66 ThriftSerializer::ThriftSerializer(
bool compact,
int initial_buffer_size) :
67 mem_buffer_(new TMemoryBuffer(initial_buffer_size)) {
69 TCompactProtocolFactoryT<TMemoryBuffer> factory;
72 TBinaryProtocolFactoryT<TMemoryBuffer> factory;
78 shared_ptr<TMemoryBuffer> mem,
bool compact) {
80 TCompactProtocolFactoryT<TMemoryBuffer> tproto_factory;
81 return tproto_factory.getProtocol(mem);
83 TBinaryProtocolFactoryT<TMemoryBuffer> tproto_factory;
84 return tproto_factory.getProtocol(mem);
90 bool TNetworkAddress::operator<(
const TNetworkAddress& that)
const {
91 if (this->hostname < that.hostname) {
93 }
else if ((this->hostname == that.hostname) && (this->port < that.port)) {
100 bool TUniqueId::operator<(
const TUniqueId& that)
const {
101 return (hi < that.hi) || (hi == that.hi && lo < that.lo);
104 bool TAccessEvent::operator<(
const TAccessEvent& that)
const {
105 return this->
name < that.name;
117 int retry_interval_ms) {
118 return WaitForServer(
"localhost", server.
port(), num_retries, retry_interval_ms);
122 int retry_interval_ms) {
124 while (retry_count < num_retries) {
126 TSocket socket(host, port);
128 socket.setConnTimeout(500);
132 }
catch (
const TException& e) {
133 VLOG_QUERY <<
"Connection failed: " << e.what();
136 VLOG_QUERY <<
"Waiting " << retry_interval_ms <<
"ms for Thrift server at "
137 << host <<
":" << port
138 <<
" to come up, failed attempt " << retry_count
139 <<
" of " << num_retries;
142 return Status(
"Server did not come up");
145 std::ostream&
operator<<(std::ostream& out,
const TColumnValue& colval) {
146 if (colval.__isset.bool_val) {
147 out << ((colval.bool_val) ?
"true" :
"false");
148 }
else if (colval.__isset.double_val) {
149 out << colval.double_val;
150 }
else if (colval.__isset.byte_val) {
151 out << colval.byte_val;
152 }
else if (colval.__isset.short_val) {
153 out << colval.short_val;
154 }
else if (colval.__isset.int_val) {
155 out << colval.int_val;
156 }
else if (colval.__isset.long_val) {
157 out << colval.long_val;
158 }
else if (colval.__isset.string_val) {
159 out << colval.string_val;
160 }
else if (colval.__isset.binary_val) {
161 out << colval.binary_val;
169 int cmp = a.hostname.compare(b.hostname);
170 if (cmp < 0)
return true;
171 if (cmp == 0)
return a.port < b.port;
177 return strstr(e.what(),
"EAGAIN (timed out)") != NULL;
void InitThriftLogging()
Redirects all Thrift logging to VLOG(1)
const StringSearch UrlParser::protocol_search & protocol
boost::shared_ptr< apache::thrift::protocol::TProtocol > protocol_
void SleepForMs(const int64_t duration_ms)
Sleeps the current thread for at least duration_ms milliseconds.
bool TNetworkAddressComparator(const TNetworkAddress &a, const TNetworkAddress &b)
bool IsTimeoutTException(const TException &e)
Status WaitForServer(const string &host, int port, int num_retries, int retry_interval_ms)
static void ThriftOutputFunction(const char *output)
Status WaitForLocalServer(const ThriftServer &server, int num_retries, int retry_interval_ms)
boost::shared_ptr< apache::thrift::transport::TMemoryBuffer > mem_buffer_
shared_ptr< TProtocol > CreateDeserializeProtocol(shared_ptr< TMemoryBuffer > mem, bool compact)
ostream & operator<<(ostream &os, const map< TNetworkAddress, llama::TAllocatedResource > &resources)