Maps a set of proxy names to their associated IP addresses. More...
#include <ProxyMap.h>
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< String > | m_reverse_map |
Reverse map from IP address to proxy name. More... | |
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.
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.
Definition at line 127 of file ProxyMap.cc.
|
inline |
Returns the forward map (proxy name to ProxyAddressInfo)
map | Reference to return forward map |
Definition at line 164 of file ProxyMap.h.
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.
proxy | Proxy name for which to fetch mapping information |
hostname | Reference to returned hostname |
addr | Reference to returned address |
Definition at line 108 of file ProxyMap.cc.
Returns proxy name for addr
.
This method looks up addr
in the reverse map and returns the proxy name, if found.
addr | Address for which to fetch proxy name |
addr
if found in reverse map, otherwise the empty string. Definition at line 118 of file ProxyMap.cc.
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--".
proxy | Proxy name to invalidate |
invalidated_mappings | Reference to ProxyMapT object to hold invalidated mapping. |
Definition at line 167 of file ProxyMap.cc.
|
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
.
proxy | Proxy name to invalidate |
addr | IP address to invalidate |
invalidated_mappings | Reference to ProxyMapT object to hold invalidated mappings. |
Definition at line 142 of file ProxyMap.cc.
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.
proxy | Proxy for which mapping is to be removed |
remove_map | Reference 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
.
proxy | Proxy name of new/updated mapping |
hostname | Hostname of new/updated mapping |
addr | InetAddr of new/updated mapping |
invalidated_map | Reference to return map to hold invalidated mappings |
new_map | Reference 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
.
mappings | Proxy map update message string |
invalidated_map | Reference to return map to hold invalidated mappings |
new_map | Reference to return map to hold new forward mapping |
Definition at line 55 of file ProxyMap.cc.
|
private |
Forward map from proxy name to ProxyAddressInfo.
Definition at line 217 of file ProxyMap.h.
|
private |
Mutex for serializing concurrent access
Definition at line 214 of file ProxyMap.h.
|
private |
Reverse map from IP address to proxy name.
Definition at line 220 of file ProxyMap.h.