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::ProxyMap Class Reference

Maps a set of proxy names to their associated IP addresses. More...

#include <ProxyMap.h>

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

Public Member Functions

void update_mapping (const String &proxy, const String &hostname, const InetAddr &addr, ProxyMapT &invalidated_map, ProxyMapT &new_map)
 Updates a proxy name mapping. More...
 
void update_mappings (String &mappings, ProxyMapT &invalidated_map, ProxyMapT &new_map)
 Update mappings from proxy map update message string. More...
 
void remove_mapping (const String &proxy, ProxyMapT &remove_map)
 Removes a mapping. More...
 
bool get_mapping (const String &proxy, String &hostname, InetAddr &addr)
 Returns proxy map data for proxy. More...
 
String get_proxy (InetAddr &addr)
 Returns proxy name for addr. More...
 
void get_map (ProxyMapT &map)
 Returns the forward map (proxy name to ProxyAddressInfo) More...
 
CommBufPtr create_update_message ()
 Creates a proxy map update message. More...
 
String to_str ()
 

Private Member Functions

void invalidate_old_mapping (const String &proxy, const InetAddr &addr, ProxyMapT &invalidated_mappings)
 Invalidates (removes) mapping, if changed, from forward and reverse maps. More...
 
void invalidate (const String &proxy, ProxyMapT &invalidated_mappings)
 Invalidates (removes) mapping from forward and reverse maps. More...
 

Private Attributes

std::mutex m_mutex
 Mutex for serializing concurrent access More...
 
ProxyMapT m_forward_map
 Forward map from proxy name to ProxyAddressInfo. More...
 
SockAddrMap< Stringm_reverse_map
 Reverse map from IP address to proxy name. More...
 

Detailed Description

Maps a set of proxy names to their associated IP addresses.

Hypertable uses proxy names (e.g. "rs1") to refer to servers so that the system can continue to operate properly even when servers are reassigned IP addresses, such as starting and stopping Hypertable running on EBS volumes in AWS EC2. There is a single ProxyMap associated with each Comm layer and one of the connected participants is designated as the proxy master by setting the global variable ReactorFactory::proxy_master to true. In Hypertable, the Master is designated as the proxy master. The proxy master is responsible for assigning proxy names which are just mnemonic strings (e.g. "rs1"). Whenever a server connects to the proxy master, the proxy master will either assign the newly connected server a proxy name or obtain it via a handshake and should then update the proxy map with the {proxy name, IP address} association and will propagate the new proxy map information to all connected participants. Once this is complete, all connected participants and send and receive messages to any participant using its proxy name. The CommAddress class is an abstraction that can hold either a proxy name or an IP address and used to identify the destination of a message.

Definition at line 79 of file ProxyMap.h.

Member Function Documentation

CommBufPtr ProxyMap::create_update_message ( )

Creates a proxy map update message.

This method is called by the proxy master to create a proxy map update message to be sent to all connected processes. The proxy map update message consists of a list of proxy mappings in the following format:

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

The forward map is traversed to generate the list of mappings which are added to a newly allocated CommBuf object. The CommBuf object is initialized with a CommHeader that has the CommHeader::FLAGS_BIT_PROXY_MAP_UPDATE bit set in its flags member.

Returns
CommBuf object holding the proxy map update message (to be freed by caller).

Definition at line 127 of file ProxyMap.cc.

void Hypertable::ProxyMap::get_map ( ProxyMapT map)
inline

Returns the forward map (proxy name to ProxyAddressInfo)

Parameters
mapReference to return forward map

Definition at line 164 of file ProxyMap.h.

bool ProxyMap::get_mapping ( const String proxy,
String hostname,
InetAddr addr 
)

Returns proxy map data for proxy.

This method looks up proxy in the forward map and returns the associated hostname and address information, if found.

Parameters
proxyProxy name for which to fetch mapping information
hostnameReference to returned hostname
addrReference to returned address
Returns
true if mapping found, false otherwise.

Definition at line 108 of file ProxyMap.cc.

String ProxyMap::get_proxy ( InetAddr addr)

Returns proxy name for addr.

This method looks up addr in the reverse map and returns the proxy name, if found.

Parameters
addrAddress for which to fetch proxy name
Returns
Proxy name of addr if found in reverse map, otherwise the empty string.

Definition at line 118 of file ProxyMap.cc.

void ProxyMap::invalidate ( const String proxy,
ProxyMapT invalidated_mappings 
)
private

Invalidates (removes) mapping from forward and reverse maps.

This method looks up proxy in the forward map and removes it, if it exists. If mapping found in forward map, the corresponding mapping is also removed from the reverse map. The removed mapping is added to invalidated_mappings with the hostname set to "--DELETED--".

Parameters
proxyProxy name to invalidate
invalidated_mappingsReference to ProxyMapT object to hold invalidated mapping.

Definition at line 167 of file ProxyMap.cc.

void ProxyMap::invalidate_old_mapping ( const String proxy,
const InetAddr addr,
ProxyMapT invalidated_mappings 
)
private

Invalidates (removes) mapping, if changed, from forward and reverse maps.

This method looks up proxy in the forward map and removes it if it exists but maps to an address different from addr. It also looks up addr in the reverse map and removes it if it exists and it maps to a proxy different than proxy. The removed mappings are added to invalidated_mappings.

Parameters
proxyProxy name to invalidate
addrIP address to invalidate
invalidated_mappingsReference to ProxyMapT object to hold invalidated mappings.

Definition at line 142 of file ProxyMap.cc.

void ProxyMap::remove_mapping ( const String proxy,
ProxyMapT remove_map 
)

Removes a mapping.

This method removes the mapping for proxy and adds the removed mapping to remove_map with the hostname set to –DELETED– (see update_mappings). The proxy master calls this method to remove a mapping and then propagates remove_map to all connections.

Parameters
proxyProxy for which mapping is to be removed
remove_mapReference to return map to hold removed mappings

Definition at line 100 of file ProxyMap.cc.

String ProxyMap::to_str ( )

Definition at line 189 of file ProxyMap.cc.

void ProxyMap::update_mapping ( const String proxy,
const String hostname,
const InetAddr addr,
ProxyMapT invalidated_map,
ProxyMapT new_map 
)

Updates a proxy name mapping.

This method first checks to see if there is already a mapping from proxy to addr in the forawrd map. If so, then it updates the hostname. Otherwise, it invalidates proxy from the forward map and addr from the reverse map and adds entries to the forward and reverse maps for the new mapping. Any invalidated mappings are added to invalidated_map and the new forward mapping from proxy to ProxyAddressInfo is added to new_map.

Parameters
proxyProxy name of new/updated mapping
hostnameHostname of new/updated mapping
addrInetAddr of new/updated mapping
invalidated_mapReference to return map to hold invalidated mappings
new_mapReference to return map to hold new forward mapping

Definition at line 38 of file ProxyMap.cc.

void ProxyMap::update_mappings ( String mappings,
ProxyMapT invalidated_map,
ProxyMapT new_map 
)

Update mappings from proxy map update message string.

One process in the system is designated as the proxy master and is responsible for updating the proxy mappings for all connected processes. This method is called by connected processes to update their proxy maps from a proxy map update message received by the proxy master. The proxy map update message consists of a list of mappings in the following format:

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

For each mapping in mappings this method first checks to see if there is already a mapping from proxy to addr in the forawrd map. If so, then it updates the hostname. Otherwise, it invalidates proxy from the forward map and addr from the reverse map and adds entries to the forward and reverse maps for the new mapping. Any invalidated mappings are added to invalidated_map and the new forward mapping from proxy to ProxyAddressInfo is added to new_map. A hostname entry of –DELETED– means that the entry is to be removed. In this situation, this method invalidates proxy from the forward map and addr from the reverse map and the invalidated mappings are added to invalidated_map.

Parameters
mappingsProxy map update message string
invalidated_mapReference to return map to hold invalidated mappings
new_mapReference to return map to hold new forward mapping

Definition at line 55 of file ProxyMap.cc.

Member Data Documentation

ProxyMapT Hypertable::ProxyMap::m_forward_map
private

Forward map from proxy name to ProxyAddressInfo.

Definition at line 217 of file ProxyMap.h.

std::mutex Hypertable::ProxyMap::m_mutex
private

Mutex for serializing concurrent access

Definition at line 214 of file ProxyMap.h.

SockAddrMap<String> Hypertable::ProxyMap::m_reverse_map
private

Reverse map from IP address to proxy name.

Definition at line 220 of file ProxyMap.h.


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