Provides access to the cluster ID. More...
#include <ClusterId.h>
Public Types | |
enum | { GENERATE_IF_NOT_FOUND =1 } |
Flag to signal constructor to generate cluster ID if not found. More... | |
Public Member Functions | |
ClusterId (Hyperspace::SessionPtr &hyperspace, bool generate_if_not_found=false) | |
Constructor. More... | |
Static Public Member Functions | |
static uint64_t | get () |
Gets the cluster ID. More... | |
Static Private Attributes | |
static uint64_t | id |
Cluster ID. More... | |
Provides access to the cluster ID.
Each cluster is assigned a unique identifier, which is a 64-bit unsigned integer. This cluster ID is generated once by the Master and is stored in Hyperspace. This class provides access to the cluster ID and can also be used to generate the cluster ID if it does not exist.
Definition at line 45 of file ClusterId.h.
ClusterId::ClusterId | ( | Hyperspace::SessionPtr & | hyperspace, |
bool | generate_if_not_found = false |
||
) |
Constructor.
This method attempts to read the cluster ID from the cluster_id attribute of the /hypertable/master
file in Hyperspace. If found, the cluster ID will be stored to a static member variable and can be obtained via a call to the static member function get(). If the cluster_id attribute does not exist and the generate_if_not_found
is true, then the method will generate a cluster ID by taking the first 64-bits of the MD5 hash value of the string formed by concatenating the IP address of the primary interface with the master listen port and the current time. The exact format is as follows:
<primary-ip> + ':' + <master-listen-port> + <current-time>
Once the ID is generated, it will get written to the cluster_id attribute of the /hypertable/master
file in Hyperspace and stored to a static member variable that can be returned by get(). If any errors are encountered, or if the cluster_id attrbute is not found and generate_if_not_found
is false, then an exception will be thrown.
hyperspace | Reference to hyperspace session |
generate_if_not_found | Flag to control whether or not the ID should be generated if it is not found |
Definition at line 48 of file ClusterId.cc.
|
inlinestatic |
|
staticprivate |
Cluster ID.
Definition at line 90 of file ClusterId.h.