27 #ifndef Hypertable_Master_HyperspaceMasterFile_h
28 #define Hypertable_Master_HyperspaceMasterFile_h
35 #include <condition_variable>
55 : m_props(props), m_hyperspace(hyperspace) {}
85 template<
typename Function>
87 Function set_startup_status) {
93 m_hyperspace->mkdirs(toplevel_dir);
96 if (!m_hyperspace->exists( toplevel_dir +
"/master" )) {
97 handle = m_hyperspace->open( toplevel_dir +
"/master",
99 m_hyperspace->close(handle);
107 bool reported =
false;
108 uint32_t retry_interval = m_props->get_i32(
"Hypertable.Connection.Retry.Interval");
110 m_handle = m_hyperspace->open(toplevel_dir +
"/master", oflags);
115 &lock_status, &sequencer);
119 set_startup_status(
false);
120 HT_INFOF(
"Couldn't obtain lock on '%s/master' due to conflict, entering retry loop ...",
121 toplevel_dir.c_str());
125 unique_lock<mutex>
lock(m_mutex);
126 m_cond.wait_for(lock, std::chrono::milliseconds(retry_interval));
133 set_startup_status(
true);
136 HT_INFOF(
"Obtained lock on '%s/master'", toplevel_dir.c_str());
138 if (!m_hyperspace->attr_exists(m_handle,
"next_server_id"))
139 m_hyperspace->attr_set(m_handle,
"next_server_id",
"1", 2);
142 m_hyperspace->mkdirs(toplevel_dir +
"/servers");
143 m_hyperspace->mkdirs(toplevel_dir +
"/tables");
146 handle = m_hyperspace->open(toplevel_dir +
"/root",
160 void write_master_address();
164 uint64_t next_server_id();
183 uint64_t m_handle {};
196 #endif // HyperspaceMasterFile_h
Lock successfully granted.
Exclusive lock attempt failed because another has it locked.
Program options handling.
#define HT_ON_SCOPE_EXIT(...)
bool lock_acquired()
Returns flag indicating if lock was acquired.
SessionPtr m_hyperspace
Hyperspace session.
HyperspaceMasterFile(PropertiesPtr props, SessionPtr &hyperspace)
Constructor.
std::mutex m_mutex
Mutex for serializing member access
bool obtain_master_lock(const std::string &toplevel_dir, Function set_startup_status)
Acquires lock on toplevel_dir/master file in hyperspace.
void shutdown(ResponseCallback *cb, uint64_t session_id)
std::shared_ptr< Session > SessionPtr
std::shared_ptr< Properties > PropertiesPtr
void close_handle_ptr(SessionPtr hyperspace, uint64_t *handlep)
Facilitates operations on the master file in Hyperspace.
void lock(ResponseCallbackLock *cb, uint64_t session_id, uint64_t handle, uint32_t mode, bool try_lock)
#define HT_INFOF(msg,...)
std::condition_variable m_cond
Condition variable signalling shutdown.
This is a generic exception class for Hypertable.
PropertiesPtr m_props
Properties.
Create file if it does not exist.
Executes user-defined functions when leaving the current scope.