Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
|
#include <thrift-server.h>
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 ConnectionContext * | GetThreadConnectionContext () |
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< Thread > | server_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_ |
ConnectionHandlerIf * | connection_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... | |
IntGauge * | num_current_connections_metric_ |
Number of currently active connections. More... | |
IntCounter * | total_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... | |
AuthProvider * | auth_provider_ |
Not owned by us, owned by the AuthManager. More... | |
Friends | |
class | ThriftServerEventProcessor |
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.
|
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.
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.
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.
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_.
|
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_.
|
static |
Returns a pointer to a struct that contains information about the current connection. This includes:
Definition at line 201 of file thrift-server.cc.
References impala::__connection_context__.
|
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().
|
inline |
Definition at line 92 of file thrift-server.h.
References port_.
Referenced by impala::WaitForLocalServer().
|
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().
|
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().
|
friend |
Definition at line 200 of file thrift-server.h.
|
private |
Not owned by us, owned by the AuthManager.
Definition at line 196 of file thrift-server.h.
Referenced by Start(), and ThriftServer().
|
private |
Path to certificate file in .PEM format.
Definition at line 149 of file thrift-server.h.
Referenced by CreateSocket(), and EnableSsl().
|
private |
Definition at line 181 of file thrift-server.h.
|
private |
Protects connection_contexts_.
Definition at line 175 of file thrift-server.h.
|
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().
|
static |
Definition at line 64 of file thrift-server.h.
|
private |
True if metrics are enabled.
Definition at line 184 of file thrift-server.h.
Referenced by ThriftServer().
|
private |
User-specified identifier that shows up in logs.
Definition at line 162 of file thrift-server.h.
Referenced by Start().
|
private |
Number of currently active connections.
Definition at line 187 of file thrift-server.h.
Referenced by ThriftServer().
|
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().
|
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().
|
private |
Path to private key file in .PEM format.
Definition at line 152 of file thrift-server.h.
Referenced by CreateSocket(), and EnableSsl().
|
private |
Definition at line 169 of file thrift-server.h.
Referenced by Start().
|
private |
Thrift housekeeping.
Definition at line 168 of file thrift-server.h.
Referenced by Start(), and StopForTesting().
|
private |
Thread that runs ThriftServerEventProcessor::Supervise() in a separate loop.
Definition at line 165 of file thrift-server.h.
Referenced by Join(), and StopForTesting().
|
private |
ThreadPool or Threaded server.
Definition at line 159 of file thrift-server.h.
Referenced by Start(), and StopForTesting().
|
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().
|
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().
|
private |
Total connections made over the lifetime of this server.
Definition at line 190 of file thrift-server.h.
Referenced by ThriftServer().
|
private |
Used to generate a unique connection id for every connection.
Definition at line 193 of file thrift-server.h.