15 #ifndef IMPALA_RUNTIME_CLIENT_CACHE_H
16 #define IMPALA_RUNTIME_CLIENT_CACHE_H
21 #include <boost/unordered_map.hpp>
22 #include <boost/thread/mutex.hpp>
23 #include <boost/bind.hpp>
108 int32_t recv_timeout_ms)
145 typedef boost::unordered_map<
156 typedef std::map<ClientKey, boost::shared_ptr<ThriftClientImpl> >
ClientMap;
197 if (status->
ok()) DCHECK(
client_ != NULL);
224 template <
class F,
class Request,
class Response>
225 Status DoRpc(
const F& f,
const Request& request, Response* response) {
226 DCHECK(response != NULL);
228 (
client_->*f)(*response, request);
229 }
catch (
const apache::thrift::TException& e) {
236 (
client_->*f)(*response, request);
237 }
catch (apache::thrift::TException& e) {
239 return Status(TErrorCode::RPC_GENERAL_ERROR, e.what());
267 int32_t recv_timeout_ms = 0,
const std::string& service_name =
"")
270 boost::bind<ThriftClientImpl*>(
315 reinterpret_cast<ClientKey*>(iface));
324 reinterpret_cast<ClientKey*>(client));
334 const std::string service_name) {
335 Client* client =
new Client(address.hostname, address.port, service_name);
344 class ImpalaInternalServiceClient;
348 class CatalogServiceClient;
const uint64_t wait_ms_
Time to wait between failed connection attempts.
Status ReopenClient(ClientFactory factory_method, ClientKey *client_key)
boost::function< ThriftClientImpl *(const TNetworkAddress &address, ClientKey *client_key)> ClientFactory
Status GetClient(const TNetworkAddress &address, T **iface)
boost::mutex lock
Protects clients.
void TestShutdown()
For testing only: shutdown all clients.
std::map< ClientKey, boost::shared_ptr< ThriftClientImpl > > ClientMap
void InitMetrics(MetricGroup *metrics, const std::string &key_prefix)
ClientConnection< CatalogServiceClient > CatalogServiceConnection
void ReleaseClient(ClientKey *client_key)
#define RETURN_IF_ERROR(stmt)
some generally useful macros
InterfaceType * iface()
Returns the object used to actually make RPCs against the remote server.
MetricGroups may be organised hierarchically as a tree.
const uint32_t num_tries_
Number of attempts to make to open a connection. 0 means retry indefinitely.
ThriftClientImpl * MakeClient(const TNetworkAddress &address, ClientKey *client_key, const std::string service_name)
Factory method to produce a new ThriftClient<T> for the wrapped cache.
boost::mutex client_map_lock_
Protects client_map_.
IntGauge * total_clients_metric_
Total clients in the cache, including those in use.
ClientCacheHelper client_cache_helper_
Status GetClient(const TNetworkAddress &address, ClientFactory factory_method, ClientKey *client_key)
If there is an error creating the new client, *client_key will be NULL.
ClientCache< CatalogServiceClient > CatalogServiceClientCache
std::string DebugString()
Helper method which returns a debug string.
IntGauge * clients_in_use_metric_
Number of clients 'checked-out' from the cache.
Status DoRpc(const F &f, const Request &request, Response *response)
ClientCache(const std::string &service_name="")
ClientCacheHelper::ClientFactory client_factory_
Function pointer, bound to MakeClient, which produces clients when the cache is empty.
bool IsTimeoutTException(const TException &e)
Super class for templatized thrift clients.
PerHostCacheMap per_host_caches_
ClientCache(uint32_t num_tries, uint64_t wait_ms, int32_t send_timeout_ms=0, int32_t recv_timeout_ms=0, const std::string &service_name="")
void ReleaseClient(T **client)
Return the client to the cache and set *client to NULL.
const int32_t send_timeout_ms_
Time to wait for the underlying socket to send data, e.g., for an RPC.
std::string DebugString()
Return a debug representation of the contents of this cache.
void TestShutdown()
Closes every connection in the cache. Used only for testing.
std::list< ClientKey > clients
List of client keys for this entry's host.
void CloseConnections(const TNetworkAddress &address)
Status CreateClient(const TNetworkAddress &address, ClientFactory factory_method, ClientKey *client_key)
Create a new client for specific address in 'client' and put it in client_map_.
void CloseConnections(const TNetworkAddress &address)
ClientConnection< ImpalaInternalServiceClient > ImpalaInternalServiceConnection
boost::mutex cache_lock_
Protects per_host_caches_.
Status ReopenClient(T **client)
This class is thread-safe.
ClientCacheHelper(uint32_t num_tries, uint64_t wait_ms, int32_t send_timeout_ms, int32_t recv_timeout_ms)
Private constructor so that only ClientCache can instantiate this class.
void InitMetrics(MetricGroup *metrics, const std::string &key_prefix)
boost::unordered_map< TNetworkAddress, boost::shared_ptr< PerHostCache > > PerHostCacheMap
ClientCache< T > * client_cache_
ClientConnection(ClientCache< T > *client_cache, TNetworkAddress address, Status *status)
ClientCache< ImpalaInternalServiceClient > ImpalaInternalServiceClientCache
const int32_t recv_timeout_ms_
Time to wait for the underlying socket to receive data, e.g., for an RPC response.