Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::ThriftServer Class Reference

#include <thrift-server.h>

Collaboration diagram for impala::ThriftServer:

Classes

struct  ConnectionContext
 Per-connection information. More...
 
class  ConnectionHandlerIf
 Interface class for receiving connection creation / termination events. More...
 
class  ThriftServerEventProcessor
 

Public Types

enum  ServerType { ThreadPool = 0, Threaded }
 
typedef std::string Username
 Username. More...
 

Public Member Functions

 ThriftServer (const std::string &name, const boost::shared_ptr< apache::thrift::TProcessor > &processor, int port, AuthProvider *auth_provider=NULL, MetricGroup *metrics=NULL, int num_worker_threads=DEFAULT_WORKER_THREADS, ServerType server_type=Threaded)
 
Status EnableSsl (const std::string &certificate, const std::string &private_key)
 
int port () const
 
bool ssl_enabled () const
 
void Join ()
 Blocks until the server stops and exits its main thread. More...
 
void StopForTesting ()
 
Status Start ()
 
void SetConnectionHandler (ConnectionHandlerIf *connection)
 

Static Public Member Functions

static const TUniqueId & GetThreadConnectionId ()
 
static const ConnectionContextGetThreadConnectionContext ()
 

Static Public Attributes

static const int DEFAULT_WORKER_THREADS = 2
 

Private Types

typedef boost::unordered_map
< ConnectionContext
*, boost::shared_ptr
< ConnectionContext > > 
ConnectionContextSet
 

Private Member Functions

Status CreateSocket (boost::shared_ptr< apache::thrift::transport::TServerTransport > *socket)
 

Private Attributes

bool started_
 True if the server has been successfully started, for internal use only. More...
 
int port_
 The port on which the server interface is exposed. More...
 
bool ssl_enabled_
 True if the server socket only accepts SSL connections. More...
 
std::string certificate_path_
 Path to certificate file in .PEM format. More...
 
std::string private_key_path_
 Path to private key file in .PEM format. More...
 
int num_worker_threads_
 
ServerType server_type_
 ThreadPool or Threaded server. More...
 
const std::string name_
 User-specified identifier that shows up in logs. More...
 
boost::scoped_ptr< Threadserver_thread_
 Thread that runs ThriftServerEventProcessor::Supervise() in a separate loop. More...
 
boost::scoped_ptr
< apache::thrift::server::TServer > 
server_
 Thrift housekeeping. More...
 
boost::shared_ptr
< apache::thrift::TProcessor > 
processor_
 
ConnectionHandlerIfconnection_handler_
 If not NULL, called when connection events happen. Not owned by us. More...
 
boost::mutex connection_contexts_lock_
 Protects connection_contexts_. More...
 
ConnectionContextSet connection_contexts_
 
bool metrics_enabled_
 True if metrics are enabled. More...
 
IntGaugenum_current_connections_metric_
 Number of currently active connections. More...
 
IntCountertotal_connections_metric_
 Total connections made over the lifetime of this server. More...
 
boost::uuids::random_generator uuid_generator_
 Used to generate a unique connection id for every connection. More...
 
AuthProviderauth_provider_
 Not owned by us, owned by the AuthManager. More...
 

Friends

class ThriftServerEventProcessor
 

Detailed Description

Utility class for all Thrift servers. Runs a threaded server by default, or a TThreadPoolServer with, by default, 2 worker threads, that exposes the interface described by a user-supplied TProcessor object. If TThreadPoolServer is used, client must use TSocket as transport. TODO: Need a builder to help with the unwieldy constructor

Definition at line 39 of file thrift-server.h.

Member Typedef Documentation

typedef boost::unordered_map<ConnectionContext*, boost::shared_ptr<ConnectionContext> > impala::ThriftServer::ConnectionContextSet
private

Map of active connection context to a shared_ptr containing that context; when an item is removed from the map, it is automatically freed.

Definition at line 180 of file thrift-server.h.

typedef std::string impala::ThriftServer::Username

Username.

Definition at line 42 of file thrift-server.h.

Member Enumeration Documentation

There are 2 servers supported by Thrift with different threading models. ThreadPool – Allocates a fixed number of threads. A thread is used by a connection until it closes. Threaded – Allocates 1 thread per connection, as needed.

Enumerator
ThreadPool 
Threaded 

Definition at line 70 of file thrift-server.h.

Constructor & Destructor Documentation

impala::ThriftServer::ThriftServer ( const std::string &  name,
const boost::shared_ptr< apache::thrift::TProcessor > &  processor,
int  port,
AuthProvider auth_provider = NULL,
MetricGroup metrics = NULL,
int  num_worker_threads = DEFAULT_WORKER_THREADS,
ServerType  server_type = Threaded 
)

Creates, but does not start, a new server on the specified port that exports the supplied interface.

  • name: human-readable name of this server. Should not contain spaces
  • processor: Thrift processor to handle RPCs
  • port: The port the server will listen for connections on
  • auth_provider: Authentication scheme to use. If NULL, use the global default demon<->demon provider.
  • metrics: if not NULL, the server will register metrics on this object
  • num_worker_threads: the number of worker threads to use in any thread pool
  • server_type: the type of IO strategy this server should employ

Definition at line 276 of file thrift-server.cc.

References impala::MetricGroup::AddCounter(), impala::MetricGroup::AddGauge(), auth_provider_, impala::AuthManager::GetInstance(), impala::AuthManager::GetInternalAuthProvider(), metrics_enabled_, num_current_connections_metric_, and total_connections_metric_.

Member Function Documentation

Status impala::ThriftServer::CreateSocket ( boost::shared_ptr< apache::thrift::transport::TServerTransport > *  socket)
private

Creates the server socket on which this server listens. May be SSL enabled. Returns OK unless there was a Thrift error.

Definition at line 306 of file thrift-server.cc.

References certificate_path_, impala::Status::OK, port_, private_key_path_, and ssl_enabled().

Referenced by Start().

Status impala::ThriftServer::EnableSsl ( const std::string &  certificate,
const std::string &  private_key 
)

Enables secure access over SSL. Must be called before Start(). The arguments are paths to certificate and private key files in .PEM format, respectively. If either file does not exist, an error is returned.

Definition at line 327 of file thrift-server.cc.

References certificate_path_, impala::Status::OK, private_key_path_, ssl_enabled_, and started_.

const ThriftServer::ConnectionContext * impala::ThriftServer::GetThreadConnectionContext ( )
static

Returns a pointer to a struct that contains information about the current connection. This includes:

  • A unique identifier for the connection.
  • The username provided by the underlying transport for the current connection, or an empty string if the transport did not provide a username. Currently, only the TSasl transport provides this information.
  • The client connection network address. It is only safe to call this method during a Thrift processor RPC implementation. Otherwise, the result of calling this method is undefined. It is also only safe to reference the returned value during an RPC method.

Definition at line 201 of file thrift-server.cc.

References impala::__connection_context__.

const TUniqueId & impala::ThriftServer::GetThreadConnectionId ( )
static

Returns a unique identifier for the current connection. A connection is identified with the lifetime of a socket connection to this server. It is only safe to call this method during a Thrift processor RPC implementation. Otherwise, the result of calling this method is undefined. It is also only safe to reference the returned value during an RPC method.

Definition at line 197 of file thrift-server.cc.

References impala::__connection_context__, and impala::ThriftServer::ConnectionContext::connection_id.

void impala::ThriftServer::Join ( )

Blocks until the server stops and exits its main thread.

Definition at line 396 of file thrift-server.cc.

References server_thread_, and started_.

Referenced by main(), TestServer::Server(), and StopForTesting().

int impala::ThriftServer::port ( ) const
inline

Definition at line 92 of file thrift-server.h.

References port_.

Referenced by impala::WaitForLocalServer().

void impala::ThriftServer::SetConnectionHandler ( ConnectionHandlerIf connection)
inline

Sets the connection handler which receives events when connections are created or closed.

Definition at line 110 of file thrift-server.h.

References connection_handler_.

Referenced by impala::CreateImpalaServer().

bool impala::ThriftServer::ssl_enabled ( ) const
inline

Definition at line 94 of file thrift-server.h.

References ssl_enabled_.

Referenced by CreateSocket(), and Start().

Status impala::ThriftServer::Start ( )

Starts the main server thread. Once this call returns, clients may connect to this server and issue RPCs. May not be called more than once.

Definition at line 351 of file thrift-server.cc.

References auth_provider_, CreateSocket(), impala::AuthProvider::GetServerTransportFactory(), name_, num_worker_threads_, impala::Status::OK, port_, processor_, RETURN_IF_ERROR, server_, server_type_, ssl_enabled(), started_, and Threaded.

Referenced by main(), and TestServer::Server().

void impala::ThriftServer::StopForTesting ( )

FOR TESTING ONLY; stop the server and block until the server is stopped; use it only if it is a Threaded server.

Definition at line 402 of file thrift-server.cc.

References Join(), server_, server_thread_, server_type_, started_, and Threaded.

Referenced by main().

Friends And Related Function Documentation

friend class ThriftServerEventProcessor
friend

Definition at line 200 of file thrift-server.h.

Member Data Documentation

AuthProvider* impala::ThriftServer::auth_provider_
private

Not owned by us, owned by the AuthManager.

Definition at line 196 of file thrift-server.h.

Referenced by Start(), and ThriftServer().

std::string impala::ThriftServer::certificate_path_
private

Path to certificate file in .PEM format.

Definition at line 149 of file thrift-server.h.

Referenced by CreateSocket(), and EnableSsl().

ConnectionContextSet impala::ThriftServer::connection_contexts_
private

Definition at line 181 of file thrift-server.h.

boost::mutex impala::ThriftServer::connection_contexts_lock_
private

Protects connection_contexts_.

Definition at line 175 of file thrift-server.h.

ConnectionHandlerIf* impala::ThriftServer::connection_handler_
private

If not NULL, called when connection events happen. Not owned by us.

Definition at line 172 of file thrift-server.h.

Referenced by SetConnectionHandler().

const int impala::ThriftServer::DEFAULT_WORKER_THREADS = 2
static

Definition at line 64 of file thrift-server.h.

bool impala::ThriftServer::metrics_enabled_
private

True if metrics are enabled.

Definition at line 184 of file thrift-server.h.

Referenced by ThriftServer().

const std::string impala::ThriftServer::name_
private

User-specified identifier that shows up in logs.

Definition at line 162 of file thrift-server.h.

Referenced by Start().

IntGauge* impala::ThriftServer::num_current_connections_metric_
private

Number of currently active connections.

Definition at line 187 of file thrift-server.h.

Referenced by ThriftServer().

int impala::ThriftServer::num_worker_threads_
private

How many worker threads to use to serve incoming requests (requests are queued if no thread is immediately available)

Definition at line 156 of file thrift-server.h.

Referenced by Start().

int impala::ThriftServer::port_
private

The port on which the server interface is exposed.

Definition at line 143 of file thrift-server.h.

Referenced by CreateSocket(), port(), and Start().

std::string impala::ThriftServer::private_key_path_
private

Path to private key file in .PEM format.

Definition at line 152 of file thrift-server.h.

Referenced by CreateSocket(), and EnableSsl().

boost::shared_ptr<apache::thrift::TProcessor> impala::ThriftServer::processor_
private

Definition at line 169 of file thrift-server.h.

Referenced by Start().

boost::scoped_ptr<apache::thrift::server::TServer> impala::ThriftServer::server_
private

Thrift housekeeping.

Definition at line 168 of file thrift-server.h.

Referenced by Start(), and StopForTesting().

boost::scoped_ptr<Thread> impala::ThriftServer::server_thread_
private

Thread that runs ThriftServerEventProcessor::Supervise() in a separate loop.

Definition at line 165 of file thrift-server.h.

Referenced by Join(), and StopForTesting().

ServerType impala::ThriftServer::server_type_
private

ThreadPool or Threaded server.

Definition at line 159 of file thrift-server.h.

Referenced by Start(), and StopForTesting().

bool impala::ThriftServer::ssl_enabled_
private

True if the server socket only accepts SSL connections.

Definition at line 146 of file thrift-server.h.

Referenced by EnableSsl(), and ssl_enabled().

bool impala::ThriftServer::started_
private

True if the server has been successfully started, for internal use only.

Definition at line 140 of file thrift-server.h.

Referenced by EnableSsl(), Join(), Start(), and StopForTesting().

IntCounter* impala::ThriftServer::total_connections_metric_
private

Total connections made over the lifetime of this server.

Definition at line 190 of file thrift-server.h.

Referenced by ThriftServer().

boost::uuids::random_generator impala::ThriftServer::uuid_generator_
private

Used to generate a unique connection id for every connection.

Definition at line 193 of file thrift-server.h.


The documentation for this class was generated from the following files: