22 #ifndef Hyperspace_Master_h
23 #define Hyperspace_Master_h
56 #include <unordered_map>
91 void mkdir(
ResponseCallback *cb, uint64_t session_id,
const char *name,
const std::vector<Attribute>& init_attrs);
92 void mkdirs(
ResponseCallback *cb, uint64_t session_id,
const char *name,
const std::vector<Attribute>& init_attrs);
95 uint32_t flags, uint32_t event_mask,
96 std::vector<Attribute> &init_attrs);
99 const char *name, uint32_t oflags,
const std::vector<Attribute> &attrs);
101 uint64_t handle,
const char *name,
const std::vector<String> &attrs);
103 uint64_t handle,
const char *name,
const char *attr);
107 const char *name,
const char *attr);
109 uint64_t session_id, uint64_t handle);
115 uint64_t handle,
const char *name,
const char *attr,
116 bool include_sub_entries);
118 uint64_t handle,
const char *name,
const char *attr);
122 uint32_t mode,
bool try_lock);
158 std::chrono::steady_clock::time_point now);
200 : persisted_notifications(false) {}
203 : event(_event), persisted_notifications(false) {}
207 notifications.clear();
208 persisted_notifications =
false;
217 std::vector<EventContext>
evts;
223 : friendly_name(_friendly_name), session_id(_session_id), txn(0),
224 aborted(false), error(
Error::
OK) {}
226 void set_error(
int _error,
const char *_error_msg,
bool abort=
true) {
228 error_msg = _error_msg;
234 error_msg = _error_msg;
252 void mkdir(CommandContext &ctx,
const char *name);
253 void unlink(CommandContext &ctx,
const char *name);
254 void open(CommandContext &ctx,
const char *name,
255 uint32_t flags, uint32_t event_mask,
256 std::vector<Attribute> &init_attrs, uint64_t& handle,
257 bool& created, uint64_t& lock_generation);
258 void close(CommandContext &ctx, uint64_t handle);
259 void attr_set(CommandContext &ctx, uint64_t handle,
260 const char *name,
const std::vector<Attribute> &attrs);
261 void attr_get(CommandContext &ctx, uint64_t handle,
263 void attr_get(CommandContext &ctx, uint64_t handle,
264 const char *name,
const std::vector<String> &attrs,
265 std::vector<DynamicBufferPtr> &dbufs);
266 void attr_incr(CommandContext &ctx, uint64_t handle,
267 const char *name,
const char *attr, uint64_t& attr_val);
268 void attr_del(CommandContext &ctx, uint64_t handle,
const char *name);
269 void attr_exists(CommandContext& ctx, uint64_t handle,
270 const char *name,
const char *attr,
bool&
exists);
271 void attr_list(CommandContext& ctx, uint64_t handle, std::vector<String>& attributes);
272 void exists(CommandContext& ctx,
const char *name,
bool& file_exists);
273 void readdir(CommandContext& ctx, uint64_t handle, std::vector<DirEntry>& listing);
274 void readdir_attr(CommandContext& ctx, uint64_t handle,
const char *name,
const char *attr,
275 bool include_sub_entries, std::vector<DirEntryAttr>& listing);
276 void readpath_attr(CommandContext& ctx, uint64_t handle,
const char *name,
const char *attr,
277 std::vector<DirEntryAttr>& listing);
279 bool get_named_node(CommandContext &ctx,
const char *name,
const char* attr,
String &node,
bool *is_dir=0);
281 uint32_t event_mask,
const String &name);
311 std::string &parent_name, std::string &child_name);
313 bool wait_for_notify=
true);
319 bool wait_for_notify=
true);
325 typedef std::unordered_map<uint64_t, SessionDataPtr>
SessionMap;
366 #endif // Hyperspace_Master_h
bool validate_and_create_node_data(BDbTxn &txn, const String &node)
Declarations for ResponseCallbackAttrExists.
bool next_expired_session(SessionDataPtr &, std::chrono::steady_clock::time_point now)
void close(ResponseCallback *cb, uint64_t session_id, uint64_t handle)
std::chrono::steady_clock::time_point m_last_tick
std::shared_ptr< MetricsHandler > MetricsHandlerPtr
Smart pointer to MetricsHandler.
void attr_set(ResponseCallback *cb, uint64_t session_id, uint64_t handle, const char *name, uint32_t oflags, const std::vector< Attribute > &attrs)
Holds Nagios-style program status information.
bool persisted_notifications
std::string String
A String is simply a typedef to std::string.
uint64_t m_next_handle_number
String get_current_master()
Returns hostname of currently elected master.
std::unordered_map< uint64_t, SessionDataPtr > SessionMap
void release_lock(BDbTxn &txn, uint64_t handle, const String &node, HyperspaceEventPtr &release_event, NotificationMap &release_notifications)
void lock_handle(BDbTxn &txn, uint64_t handle, uint32_t mode, String &node)
void status(ResponseCallbackStatus *cb)
Declarations for Protocol.
Manages transaction state.
void unlink(ResponseCallback *cb, uint64_t session_id, const char *name)
struct sockaddr_in m_local_addr
bool m_maintenance_outstanding
void open(ResponseCallbackOpen *cb, uint64_t session_id, const char *name, uint32_t flags, uint32_t event_mask, std::vector< Attribute > &init_attrs)
Program options handling.
bool get_session(uint64_t session_id, SessionDataPtr &session_data)
std::shared_ptr< SessionData > SessionDataPtr
std::shared_ptr< Master > MasterPtr
SessionDataVec m_session_heap
std::vector< SessionDataPtr > SessionDataVec
Declarations for BerkeleyDbFilesystem.
void initialize_session(uint64_t session_id, const String &name)
std::shared_ptr< Event > HyperspaceEventPtr
std::vector< EventContext > evts
void attr_incr(ResponseCallbackAttrIncr *cb, uint64_t session_id, uint64_t handle, const char *name, const char *attr)
Declarations for ResponseCallbackAttrGet.
A dynamic, resizable and reference counted memory buffer.
void attr_del(ResponseCallback *cb, uint64_t session_id, uint64_t handle, const char *name)
void remove_expired_sessions()
std::mutex m_session_map_mutex
void destroy_session(uint64_t session_id)
void grant_pending_lock_reqs(BDbTxn &txn, const String &node, HyperspaceEventPtr &lock_granted_event, NotificationMap &lock_granted_notifications, HyperspaceEventPtr &lock_acquired_event, NotificationMap &lock_acquired_notifications)
void readdir(ResponseCallbackReaddir *cb, uint64_t session_id, uint64_t handle)
void get_datagram_send_address(struct sockaddr_in *addr)
void shutdown(ResponseCallback *cb, uint64_t session_id)
void handle_wakeup()
Handle wakeup event (e.g.
std::unordered_map< uint64_t, uint64_t > NotificationMap
Hash map from Node handle ID to Session ID.
Master(ConnectionManagerPtr &, PropertiesPtr &, ServerKeepaliveHandlerPtr &, ApplicationQueuePtr &app_queue_ptr)
NotificationMap notifications
Sends back result of an attr_exists request.
std::shared_ptr< Properties > PropertiesPtr
void readpath_attr(ResponseCallbackReadpathAttr *cb, uint64_t session_id, uint64_t handle, const char *name, const char *attr)
void lock_handle_with_notification(uint64_t handle, uint32_t mode, bool wait_for_notify=true)
uint32_t m_maintenance_interval
Status m_status
Program status tracker.
void normalize_name(std::string name, std::string &normal)
std::shared_ptr< ServerKeepaliveHandler > ServerKeepaliveHandlerPtr
Sends back result of an attr_get request.
Time related declarations.
BerkeleyDbFilesystem * m_bdb_fs
Declarations for SockAddrMap.
CommandContext(const char *_friendly_name, uint64_t _session_id)
EventContext(HyperspaceEventPtr _event)
Hyperspace filesystem implementation on top of BerkeleyDB.
This class is used to generate and deliver standard responses back to a client.
void get_generation_number()
bool is_master()
Check if we're the current master.
std::chrono::steady_clock::time_point m_sleep_time
Suspension time recorded by handle_sleep()
uint64_t m_next_session_id
void set_error(int _error, const String &_error_msg, bool abort=true)
void attr_exists(ResponseCallbackAttrExists *cb, uint64_t session_id, uint64_t handle, const char *name, const char *attr)
void deliver_event_notifications(CommandContext &ctx, bool wait_for_notify=true)
void mkdir(ResponseCallback *cb, uint64_t session_id, const char *name, const std::vector< Attribute > &init_attrs)
void attr_list(ResponseCallbackAttrList *cb, uint64_t session_id, uint64_t handle)
void attr_get(ResponseCallbackAttrGet *cb, uint64_t session_id, uint64_t handle, const char *name, const std::vector< String > &attrs)
Declarations for ConnectionManager.
void lock(ResponseCallbackLock *cb, uint64_t session_id, uint64_t handle, uint32_t mode, bool try_lock)
std::mutex m_maintenance_mutex
bool find_parent_node(const std::string &normal_name, std::string &parent_name, std::string &child_name)
uint64_t create_session(struct sockaddr_in &addr)
void readdir_attr(ResponseCallbackReaddirAttr *cb, uint64_t session_id, uint64_t handle, const char *name, const char *attr, bool include_sub_entries)
int renew_session_lease(uint64_t session_id)
bool get_named_node(CommandContext &ctx, const char *name, const char *attr, String &node, bool *is_dir=0)
uint32_t m_lease_interval
uint32_t m_keep_alive_interval
std::mutex m_last_tick_mutex
void create_event(CommandContext &ctx, const String &node, uint32_t event_mask, const String &name)
String get_current_master()
void set_error(int _error, const char *_error_msg, bool abort=true)
void release(ResponseCallback *cb, uint64_t session_id, uint64_t handle)
ServerKeepaliveHandlerPtr m_keepalive_handler_ptr
Declarations for MetricsHandler.
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
Declarations for ResponseCallback.
std::shared_ptr< ApplicationQueue > ApplicationQueuePtr
Shared smart pointer to ApplicationQueue object.
MetricsHandlerPtr m_metrics_handler
String extensions and helpers: sets, maps, append operators etc.
void exists(ResponseCallbackExists *cb, uint64_t session_id, const char *name)
SessionDataPtr session_data
bool get_handle_node(CommandContext &ctx, uint64_t handle, const char *attr, String &node)
void handle_sleep()
Handle sleep event (e.g.
bool destroy_handle(uint64_t handle, int &error, String &errmsg, bool wait_for_notify=true)
void mkdirs(ResponseCallback *cb, uint64_t session_id, const char *name, const std::vector< Attribute > &init_attrs)
const char * friendly_name
void persist_event_notifications(BDbTxn &txn, uint64_t event_id, NotificationMap &handles_to_sessions)