0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Hypertable::HandlerMap Class Reference

Data structure for mapping socket addresses to I/O handlers. More...

#include <HandlerMap.h>

Collaboration diagram for Hypertable::HandlerMap:
Collaboration graph
[legend]

Public Member Functions

 HandlerMap ()
 Constructor. More...
 
void insert_handler (IOHandlerAccept *handler)
 Inserts an accept handler. More...
 
void insert_handler (IOHandlerData *handler, bool checkout=false)
 Inserts a data (TCP) handler. More...
 
void insert_handler (IOHandlerDatagram *handler)
 Inserts a datagram (UDP) handler. More...
 
void insert_handler (IOHandlerRaw *handler)
 Inserts a raw handler. More...
 
int checkout_handler (const CommAddress &addr, IOHandlerAccept **handler)
 Checks out accept I/O handler associated with addr. More...
 
int checkout_handler (const CommAddress &addr, IOHandlerData **handler)
 Checks out data (TCP) I/O handler associated with addr. More...
 
int checkout_handler (const CommAddress &addr, IOHandlerDatagram **handler)
 Checks out datagram (UDP) I/O handler associated with addr. More...
 
int checkout_handler (const CommAddress &addr, IOHandlerRaw **handler)
 Checks out raw I/O handler associated with addr. More...
 
int contains_data_handler (const CommAddress &addr)
 Checks to see if addr is contained in map. More...
 
void decrement_reference_count (IOHandler *handler)
 Decrements the reference count of handler. More...
 
int set_alias (const InetAddr &addr, const InetAddr &alias)
 Sets an alias address for an existing TCP address in map. More...
 
int remove_handler (IOHandler *handler)
 Removes handler from map. More...
 
void decomission_handler_unlocked (IOHandler *handler)
 Decomissions handler. More...
 
void decomission_handler (IOHandler *handler)
 Decomissions handler with m_mutex locked. More...
 
void decomission_all ()
 Decomissions all handlers. More...
 
bool destroy_ok (IOHandler *handler)
 Determines if handler can be destoryed. More...
 
bool translate_proxy_address (const CommAddress &proxy_addr, InetAddr *addr)
 Translates proxy_addr to its corresponding IPV4 address. More...
 
void purge_handler (IOHandler *handler)
 Purges (removes) handler. More...
 
void wait_for_empty ()
 Waits for map to become empty. More...
 
int add_proxy (const String &proxy, const String &hostname, const InetAddr &addr)
 Adds or updates proxy information. More...
 
int remove_proxy (const String &proxy)
 Removes a proxy name from the proxy map. More...
 
void get_proxy_map (ProxyMapT &proxy_map)
 Returns the proxy map. More...
 
void update_proxy_map (const char *message, size_t message_len)
 Updates the proxy map with a proxy map update message received from the proxy master. More...
 
int32_t propagate_proxy_map (IOHandlerData *handler)
 Sends the current proxy map over connection identified by handler. More...
 
bool wait_for_proxy_map (Timer &timer)
 Waits for proxy map to get updated from a proxy map update message received from the master. More...
 

Private Member Functions

int propagate_proxy_map (ProxyMapT &mappings)
 Propagates proxy map information in mappings to all active data (TCP) connections. More...
 
int translate_address (const CommAddress &addr, InetAddr *inet_addr)
 Translates addr to an InetAddr (IP address). More...
 
int remove_handler_unlocked (IOHandler *handler)
 Removes handler from map without locking m_mutex. More...
 
IOHandlerAcceptlookup_accept_handler (const InetAddr &addr)
 Finds accept I/O handler associated with addr. More...
 
IOHandlerDatalookup_data_handler (const InetAddr &addr)
 Finds data (TCP) I/O handler associated with addr. More...
 
IOHandlerDatagramlookup_datagram_handler (const InetAddr &addr)
 Finds datagram I/O handler associated with addr. More...
 
IOHandlerRawlookup_raw_handler (const InetAddr &addr)
 Finds raw I/O handler associated with addr. More...
 

Private Attributes

std::mutex m_mutex
 Mutex for serializing concurrent access More...
 
std::condition_variable m_cond
 Condition variable for signalling empty map. More...
 
std::condition_variable m_cond_proxy
 Condition variable for signalling proxy map load. More...
 
SockAddrMap< IOHandlerAccept * > m_accept_handler_map
 Accept map (InetAddr-to-IOHandlerAccept) More...
 
SockAddrMap< IOHandlerData * > m_data_handler_map
 Data (TCP) map (InetAddr-to-IOHandlerData) More...
 
SockAddrMap< IOHandlerDatagram * > m_datagram_handler_map
 Datagram (UDP) map (InetAddr-to-IOHandlerDatagram) More...
 
SockAddrMap< IOHandlerRaw * > m_raw_handler_map
 Raw map (InetAddr-to-IOHandlerRaw) More...
 
std::set< IOHandler * > m_decomissioned_handlers
 Decomissioned handler set. More...
 
ProxyMap m_proxy_map
 Proxy map. More...
 
bool m_proxies_loaded
 Flag indicating if proxy map has been loaded. More...
 

Detailed Description

Data structure for mapping socket addresses to I/O handlers.

An I/O handler is associated with each socket connection and is used to handle polling events on the socket descriptor. Examples incude writing a message to the socket, reading a message from the socket, or completing a connection request. This class maintains three maps, one for TCP socket connections, UDP socket connections, and one for accept sockets. The Comm methods use this map to locate the I/O handler for a given address.

Definition at line 69 of file HandlerMap.h.

Constructor & Destructor Documentation

Hypertable::HandlerMap::HandlerMap ( )
inline

Constructor.

Definition at line 74 of file HandlerMap.h.

Member Function Documentation

int HandlerMap::add_proxy ( const String proxy,
const String hostname,
const InetAddr addr 
)

Adds or updates proxy information.

This method adds or updates proxy information in m_proxy_map. For the data handler to which addr refers, it updates its proxy name via a call to IOHandler::set_proxy and then calls propagate_proxy_map with the newly added/updated proxy information to update all active data connections with the new proxy information.

Note
This method should only be called by the proxy master.
Parameters
proxyProxy name of new/updated mapping
hostnameHostname of new/updated mapping
addrInetAddr of new/updated mapping
Returns
Error::OK on success, or one of the errors returned by propagate_proxy_map

Definition at line 299 of file HandlerMap.cc.

int HandlerMap::checkout_handler ( const CommAddress addr,
IOHandlerAccept **  handler 
)

Checks out accept I/O handler associated with addr.

Looks up addr in accept map. If an entry is found, then its reference count is incremented and it is returned in handler.

Parameters
addrConnection address
handlerAddress of handler pointer returned
Returns
Error::OK on success, or Error::COMM_NOT_CONNECTED if no mapping found for addr.

Definition at line 70 of file HandlerMap.cc.

int HandlerMap::checkout_handler ( const CommAddress addr,
IOHandlerData **  handler 
)

Checks out data (TCP) I/O handler associated with addr.

First translates addr to socket address and then looks up translated address in data map. If an entry is found, then its reference count is incremented and it is returned in handler.

Parameters
addrConnection address
handlerAddress of handler pointer returned
Returns
Error::OK on success, Error::COMM_INVALID_PROXY if addr is of type CommAddress::PROXY and no translation exists, or Error::COMM_NOT_CONNECTED if no mapping found for translated address.

Definition at line 85 of file HandlerMap.cc.

int HandlerMap::checkout_handler ( const CommAddress addr,
IOHandlerDatagram **  handler 
)

Checks out datagram (UDP) I/O handler associated with addr.

Looks up addr in datagram map. If an entry is found, then its reference count is incremented and it is returned in handler.

Parameters
addrConnection address
handlerAddress of handler pointer returned
Returns
Error::OK on success, or Error::COMM_NOT_CONNECTED if no mapping found for addr.

Definition at line 104 of file HandlerMap.cc.

int HandlerMap::checkout_handler ( const CommAddress addr,
IOHandlerRaw **  handler 
)

Checks out raw I/O handler associated with addr.

Looks up addr in raw map. If an entry is found, then its reference count is incremented and it is returned in handler.

Parameters
addrConnection address
handlerAddress of handler pointer returned
Returns
Error::OK on success, or Error::COMM_NOT_CONNECTED if no mapping found for addr.

Definition at line 118 of file HandlerMap.cc.

int HandlerMap::contains_data_handler ( const CommAddress addr)

Checks to see if addr is contained in map.

First translates addr to socket address and then looks up translated address in data map.

Parameters
addrConnection address
Returns
Error::OK if found, Error::COMM_INVALID_PROXY if addr is of type CommAddress::PROXY and no translation exists, or Error::COMM_NOT_CONNECTED if no mapping found for translated address.

Definition at line 137 of file HandlerMap.cc.

void HandlerMap::decomission_all ( )

Decomissions all handlers.

This method is called by the ~Comm to decomission all of the handlers in the map.

Note
It doesn't look like the Comm object ever gets deleted and therefore this method never gets called. See issue 1031.

Definition at line 223 of file HandlerMap.cc.

void Hypertable::HandlerMap::decomission_handler ( IOHandler handler)
inline

Decomissions handler with m_mutex locked.

This method locks m_mutex and calls decomission_handler_unlocked

Parameters
handlerPointer to IOHandler to decomission

Definition at line 217 of file HandlerMap.h.

void HandlerMap::decomission_handler_unlocked ( IOHandler handler)

Decomissions handler.

Since handler pointers are passed into the polling mechanism and asynchronously referenced by reactor threads, care must be taken to not delete a handler until it has be removed from the polling mechanism. This is accomplished by introducing a two-step removal process. First a handler is decomissioned (by this method) by removing it from the associated map, adding it to the m_decomissioned_handlers set and marking it decomissioned. Once there are no more references to the handler, it may be safely removed. The removal is accomplished via purge_handler which is called by the reactor thread after it has been removed from the polling interface.

Parameters
handlerPointer to IOHandler to decomission

Definition at line 214 of file HandlerMap.cc.

void HandlerMap::decrement_reference_count ( IOHandler handler)

Decrements the reference count of handler.

The decrementing of a handler's reference count is done by this method with m_mutex locked which avoids a race condition between checking out handlers and purging them.

Parameters
handlerPointer to I/O handler for which to decrement reference count

Definition at line 132 of file HandlerMap.cc.

bool HandlerMap::destroy_ok ( IOHandler handler)

Determines if handler can be destoryed.

Returns
true if handler is decomissioned and has a reference count of 0.

Definition at line 263 of file HandlerMap.cc.

void HandlerMap::get_proxy_map ( ProxyMapT proxy_map)

Returns the proxy map.

Parameters
proxy_mapreference to returned proxy map

Definition at line 331 of file HandlerMap.cc.

void HandlerMap::insert_handler ( IOHandlerAccept handler)

Inserts an accept handler.

Uses IOHandler::m_local_addr as the key

Parameters
handlerAccept I/O handler to insert

Definition at line 39 of file HandlerMap.cc.

void HandlerMap::insert_handler ( IOHandlerData handler,
bool  checkout = false 
)

Inserts a data (TCP) handler.

Uses IOHandler::m_addr as the key. If program is the proxy master, a proxy map update message with the new mapping is broadcast to all connections.

Parameters
handlerData (TCP) I/O handler to insert
checkoutAtomically checkout handler

Definition at line 46 of file HandlerMap.cc.

void HandlerMap::insert_handler ( IOHandlerDatagram handler)

Inserts a datagram (UDP) handler.

Uses IOHandler::m_local_addr as the key.

Parameters
handlerDatagram (UDP) I/O handler to insert

Definition at line 55 of file HandlerMap.cc.

void HandlerMap::insert_handler ( IOHandlerRaw handler)

Inserts a raw handler.

Uses IOHandler::m_addr as the key.

Parameters
handlerRaw I/O handler to insert

Definition at line 62 of file HandlerMap.cc.

IOHandlerAccept * HandlerMap::lookup_accept_handler ( const InetAddr addr)
private

Finds accept I/O handler associated with addr.

This method looks up addr in m_accept_handler_map and returns the handler, if found.

Parameters
addrAddress of accept handler to locate
Returns
Pointer to IOHandlerAccept object associated with addr, or 0 if not found.

Definition at line 439 of file HandlerMap.cc.

IOHandlerData * HandlerMap::lookup_data_handler ( const InetAddr addr)
private

Finds data (TCP) I/O handler associated with addr.

This method looks up addr in m_data_handler_map and returns the handler, if found.

Parameters
addrAddress of data handler to locate
Returns
Pointer to IOHandlerData object associated with addr, or 0 if not found.

Definition at line 446 of file HandlerMap.cc.

IOHandlerDatagram * HandlerMap::lookup_datagram_handler ( const InetAddr addr)
private

Finds datagram I/O handler associated with addr.

This method looks up addr in m_datagram_handler_map and returns the handler, if found.

Parameters
addrAddress of datagram handler to locate
Returns
Pointer to IOHandlerDatagram object associated with addr, or 0 if not found.

Definition at line 453 of file HandlerMap.cc.

IOHandlerRaw * HandlerMap::lookup_raw_handler ( const InetAddr addr)
private

Finds raw I/O handler associated with addr.

This method looks up addr in m_raw_handler_map and returns the handler, if found.

Parameters
addrAddress of raw handler to locate
Returns
Pointer to IOHandlerRaw object associated with addr, or nullptr if not found.

Definition at line 460 of file HandlerMap.cc.

int32_t HandlerMap::propagate_proxy_map ( IOHandlerData handler)

Sends the current proxy map over connection identified by handler.

This method must only be called by the proxy master, otherwise it will assert.

Parameters
handlerConnection over which to send proxy map
Returns
Same set of error codes returned by IOHandlerData::send_message

Definition at line 365 of file HandlerMap.cc.

int HandlerMap::propagate_proxy_map ( ProxyMapT mappings)
private

Propagates proxy map information in mappings to all active data (TCP) connections.

This method creates a proxy map update message from the mappings in mappings. The update message is just a list of mapping entries in the following format:

<proxy> '\t' <hostname> '\t' <addr> '\n' 

Then the proxy map update message is sent via each of the handlers in the data (TCP) handler map. If an error is encountered on a handler when trying to send the proxy map, it will be decomissioned.

Parameters
mappingsProxy map information to propagate.
Returns
Error::OK if proxy map update message was successfully sent across all data handlers, otherwise one of the error codes returned by IOHandlerData::send_message

Definition at line 383 of file HandlerMap.cc.

void HandlerMap::purge_handler ( IOHandler handler)

Purges (removes) handler.

This method removes handler from the m_decomissioned_handlers set, signals m_cond if m_decomissioned_handlers becomes empty, calls hander->disconnect(), and then deletes the handler. This method must only be called from a reactor thread after the handler has been removed from the polling interface and destroy_ok returns true for the handler.

Parameters
handlerHandler to purge

Definition at line 286 of file HandlerMap.cc.

int HandlerMap::remove_handler ( IOHandler handler)

Removes handler from map.

This method removes handler from the data, datagram, or accept map, depending on the type of handler. If handler refers to a data handler, then its alias address entry is also removed from the data map.

Parameters
handlerIOHandler to remove
Returns
Error::OK on success, or Error::COMM_NOT_CONNECTED if handler is not found in any of the maps.

Definition at line 209 of file HandlerMap.cc.

int HandlerMap::remove_handler_unlocked ( IOHandler handler)
private

Removes handler from map without locking m_mutex.

This method removes handler from the data, datagram, or accept map, depending on the type of handler. If handler refers to a data handler, then its alias address entry is also removed from the data map.

Parameters
handlerIOHandler to remove
Returns
Error::OK on success, or Error::COMM_NOT_CONNECTED if handler is not found in any of the maps.

Definition at line 168 of file HandlerMap.cc.

int HandlerMap::remove_proxy ( const String proxy)

Removes a proxy name from the proxy map.

This method removes proxy from m_proxy_map and then calls propagate_proxy_map to propagate the removed mapping information to all connections.

Note
This method should only be called by the proxy master.
Parameters
proxyProxy name to remove
Returns
Error::OK if proxy not found in proxy map or if it was successfully removed, or one of the errors returned by propagate_proxy_map

Definition at line 314 of file HandlerMap.cc.

int HandlerMap::set_alias ( const InetAddr addr,
const InetAddr alias 
)

Sets an alias address for an existing TCP address in map.

RangeServers listen on a well-known port defined by the Hypertable.RangeServer.Port configuration property (default = 15865). However, RangeServers connect to the master using an ephemeral port due to a bind conflict with its listen socket. So that the Master can refer to the RangeServer using the well-known port, an alias address can be registered and subsequently used to reference the connection. This method adds an entry to the data (TCP) map for alias which references the IOHandlerData object previously registered under addr.

Parameters
addrAddress of previously registered data handler
aliasAlias address to add
Returns
Error::OK on success, or Error::COMM_CONFLICTING_ADDRESS if alias is already in the data map, or Error::COMM_NOT_CONNECTED if addr is not found in the data map.

Definition at line 152 of file HandlerMap.cc.

int HandlerMap::translate_address ( const CommAddress addr,
InetAddr inet_addr 
)
private

Translates addr to an InetAddr (IP address).

If addr is of type CommAddress::PROXY, then the m_proxy_map is consulted to translate the proxy name to an IP address, otherwise if addr is of type CommAddress::INET, the IP address held in addr is copied to inet_addr.

Parameters
addrAddress to translate
inet_addrPointer to valid InetAddr object to hold translated address
Returns
Error::OK on success, Error::COMM_INVALID_PROXY if addr is of type CommAddress::PROXY and no mapping is found.

Definition at line 424 of file HandlerMap.cc.

bool HandlerMap::translate_proxy_address ( const CommAddress proxy_addr,
InetAddr addr 
)

Translates proxy_addr to its corresponding IPV4 address.

This method fetches the mapping for proxy_addr from m_proxy_map and returns the associated IPV4 address in addr. If addr is NULL, then no translation occurs but the return value can be checked to see if the proxy name contains a mapping.

Parameters
proxy_addrReference to proxy address
addrPointer to return IPV4 address
Returns
true if mapping found, false otherwise

Definition at line 270 of file HandlerMap.cc.

void HandlerMap::update_proxy_map ( const char *  message,
size_t  message_len 
)

Updates the proxy map with a proxy map update message received from the proxy master.

Calls ProxyMap::update_mappings with message to update the proxy map. If any of the proxy names have changed, the corresponding data handlers are updated with a call to IOHandler::set_proxy. For each mapping in message that has the hostname set to –DELETED–, the associated data handler is decomissioned. After the proxy map has been successfuly updated, the m_proxies_loaded flag is set to true and the m_cond_proxy condition variable is signalled.

Parameters
messagePointer to proxy map update message
message_lenLength of proxy map update message

Definition at line 336 of file HandlerMap.cc.

void HandlerMap::wait_for_empty ( )

Waits for map to become empty.

This method assumes that all of the handlers in the map have been decomissioned. It waits for the m_decomissioned_handlers set to become empty, waiting on m_cond until it does.

Definition at line 281 of file HandlerMap.cc.

bool HandlerMap::wait_for_proxy_map ( Timer timer)

Waits for proxy map to get updated from a proxy map update message received from the master.

This method waits on m_cond_proxy for m_proxies_loaded to become true or timer expires.

Parameters
timerDeadline timer
Returns
true if proxy map was loaded, false if timer expired before proxy map was loaded.

Definition at line 374 of file HandlerMap.cc.

Member Data Documentation

SockAddrMap<IOHandlerAccept *> Hypertable::HandlerMap::m_accept_handler_map
private

Accept map (InetAddr-to-IOHandlerAccept)

Definition at line 415 of file HandlerMap.h.

std::condition_variable Hypertable::HandlerMap::m_cond
private

Condition variable for signalling empty map.

Definition at line 409 of file HandlerMap.h.

std::condition_variable Hypertable::HandlerMap::m_cond_proxy
private

Condition variable for signalling proxy map load.

Definition at line 412 of file HandlerMap.h.

SockAddrMap<IOHandlerData *> Hypertable::HandlerMap::m_data_handler_map
private

Data (TCP) map (InetAddr-to-IOHandlerData)

Definition at line 418 of file HandlerMap.h.

SockAddrMap<IOHandlerDatagram *> Hypertable::HandlerMap::m_datagram_handler_map
private

Datagram (UDP) map (InetAddr-to-IOHandlerDatagram)

Definition at line 421 of file HandlerMap.h.

std::set<IOHandler *> Hypertable::HandlerMap::m_decomissioned_handlers
private

Decomissioned handler set.

Definition at line 427 of file HandlerMap.h.

std::mutex Hypertable::HandlerMap::m_mutex
private

Mutex for serializing concurrent access

Definition at line 406 of file HandlerMap.h.

bool Hypertable::HandlerMap::m_proxies_loaded
private

Flag indicating if proxy map has been loaded.

Definition at line 433 of file HandlerMap.h.

ProxyMap Hypertable::HandlerMap::m_proxy_map
private

Proxy map.

Definition at line 430 of file HandlerMap.h.

SockAddrMap<IOHandlerRaw *> Hypertable::HandlerMap::m_raw_handler_map
private

Raw map (InetAddr-to-IOHandlerRaw)

Definition at line 424 of file HandlerMap.h.


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