49 bool generate_if_not_found) {
51 string toplevel_dir =
properties->get_str(
"Hypertable.Directory");
57 handle = hyperspace->open(toplevel_dir +
"/master",
60 size_t retry_count = 12;
66 hyperspace->attr_get(handle,
"cluster_id", buf);
67 string cluster_id((
const char *)buf.
base, buf.
fill());
68 id = (uint64_t)strtoull(cluster_id.c_str(), 0, 0);
73 if (generate_if_not_found)
76 HT_INFO(
"Problem reading cluster ID from Hyperspace, will retry in 10 seconds ...");
77 this_thread::sleep_for(chrono::milliseconds(10000));
81 HT_THROW2(e.
code(), e,
"Problem reading cluster ID from Hyperspace");
86 uint16_t port =
properties->get_i16(
"Hypertable.Master.Port");
89 id = (uint64_t)
md5_hash(tmp.c_str());
92 HT_INFOF(
"Newly generated cluster ID = %llu", (
Llu)
id);
96 hyperspace->attr_set(handle,
"cluster_id", tmp.c_str(), tmp.length());
99 HT_FATALF(
"Problem writing newly generated cluster ID to Hyperspace - %s"
int64_t md5_hash(const char *input)
Returns a 64-bit hash checksum of a null terminated input buffer.
PropertiesPtr properties
This singleton map stores all options.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
ClusterId(Hyperspace::SessionPtr &hyperspace, bool generate_if_not_found=false)
Constructor.
long long unsigned int Llu
Shortcut for printf formats.
#define HT_ON_SCOPE_EXIT(...)
A dynamic, resizable and reference counted memory buffer.
A dynamic, resizable memory buffer.
std::shared_ptr< Session > SessionPtr
const char * get_text(int error)
Returns a descriptive error message.
Encapsulate an internet address.
static uint64_t id
Cluster ID.
void close_handle_ptr(SessionPtr hyperspace, uint64_t *handlep)
Compatibility Macros for C/C++.
String format(int sep= ':') const
Returns a string with a dotted notation ("127.0.0.1:8080") including the port.
#define HT_FATALF(msg,...)
#define HT_INFOF(msg,...)
uint8_t * base
Pointer to the allocated memory buffer.
size_t fill() const
Returns the size of the used portion.
Internet address wrapper classes and utility functions.
This is a generic exception class for Hypertable.
System information and statistics based on libsigar.
static const NetInfo & net_info()
Retrieves updated Network information (see SystemInfo.h)
Declarations for ClusterId.
int code() const
Returns the error code.
#define HT_THROW2(_code_, _ex_, _msg_)
Executes user-defined functions when leaving the current scope.