0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Hyperspace::Master Class Reference

#include <Master.h>

Collaboration diagram for Hyperspace::Master:
Collaboration graph
[legend]

Classes

struct  CommandContext
 
struct  EventContext
 

Public Types

enum  { TIMER_INTERVAL_MS =1000 }
 
enum  { HANDLE_NOT_DEL = 1, HANDLE_MARKED_FOR_DEL = 2 }
 

Public Member Functions

 Master (ConnectionManagerPtr &, PropertiesPtr &, ServerKeepaliveHandlerPtr &, ApplicationQueuePtr &app_queue_ptr)
 
 ~Master ()
 
bool is_master ()
 
String get_current_master ()
 
void mkdir (ResponseCallback *cb, uint64_t session_id, const char *name, const std::vector< Attribute > &init_attrs)
 
void mkdirs (ResponseCallback *cb, uint64_t session_id, const char *name, const std::vector< Attribute > &init_attrs)
 
void unlink (ResponseCallback *cb, uint64_t session_id, const char *name)
 
void open (ResponseCallbackOpen *cb, uint64_t session_id, const char *name, uint32_t flags, uint32_t event_mask, std::vector< Attribute > &init_attrs)
 
void close (ResponseCallback *cb, uint64_t session_id, uint64_t handle)
 
void attr_set (ResponseCallback *cb, uint64_t session_id, uint64_t handle, const char *name, uint32_t oflags, const std::vector< Attribute > &attrs)
 
void attr_get (ResponseCallbackAttrGet *cb, uint64_t session_id, uint64_t handle, const char *name, const std::vector< String > &attrs)
 
void attr_incr (ResponseCallbackAttrIncr *cb, uint64_t session_id, uint64_t handle, const char *name, const char *attr)
 
void attr_del (ResponseCallback *cb, uint64_t session_id, uint64_t handle, const char *name)
 
void attr_exists (ResponseCallbackAttrExists *cb, uint64_t session_id, uint64_t handle, const char *name, const char *attr)
 
void attr_list (ResponseCallbackAttrList *cb, uint64_t session_id, uint64_t handle)
 
void exists (ResponseCallbackExists *cb, uint64_t session_id, const char *name)
 
void readdir (ResponseCallbackReaddir *cb, uint64_t session_id, uint64_t handle)
 
void readdir_attr (ResponseCallbackReaddirAttr *cb, uint64_t session_id, uint64_t handle, const char *name, const char *attr, bool include_sub_entries)
 
void readpath_attr (ResponseCallbackReadpathAttr *cb, uint64_t session_id, uint64_t handle, const char *name, const char *attr)
 
void shutdown (ResponseCallback *cb, uint64_t session_id)
 
void status (ResponseCallbackStatus *cb)
 
void lock (ResponseCallbackLock *cb, uint64_t session_id, uint64_t handle, uint32_t mode, bool try_lock)
 
void release (ResponseCallback *cb, uint64_t session_id, uint64_t handle)
 
uint64_t create_session (struct sockaddr_in &addr)
 
bool get_session (uint64_t session_id, SessionDataPtr &session_data)
 
void destroy_session (uint64_t session_id)
 
void initialize_session (uint64_t session_id, const String &name)
 
int renew_session_lease (uint64_t session_id)
 
bool next_expired_session (SessionDataPtr &, std::chrono::steady_clock::time_point now)
 
void remove_expired_sessions ()
 
void get_datagram_send_address (struct sockaddr_in *addr)
 
void tick ()
 
void handle_sleep ()
 Handle sleep event (e.g. More...
 
void handle_wakeup ()
 Handle wakeup event (e.g. More...
 
void do_maintenance ()
 

Private Types

typedef std::vector
< SessionDataPtr
SessionDataVec
 
typedef std::unordered_map
< uint64_t, SessionDataPtr
SessionMap
 

Private Member Functions

void mkdir (CommandContext &ctx, const char *name)
 
void unlink (CommandContext &ctx, const char *name)
 
void open (CommandContext &ctx, const char *name, uint32_t flags, uint32_t event_mask, std::vector< Attribute > &init_attrs, uint64_t &handle, bool &created, uint64_t &lock_generation)
 
void close (CommandContext &ctx, uint64_t handle)
 
void attr_set (CommandContext &ctx, uint64_t handle, const char *name, const std::vector< Attribute > &attrs)
 
void attr_get (CommandContext &ctx, uint64_t handle, const char *name, const char *attr, DynamicBuffer &dbuf)
 
void attr_get (CommandContext &ctx, uint64_t handle, const char *name, const std::vector< String > &attrs, std::vector< DynamicBufferPtr > &dbufs)
 
void attr_incr (CommandContext &ctx, uint64_t handle, const char *name, const char *attr, uint64_t &attr_val)
 
void attr_del (CommandContext &ctx, uint64_t handle, const char *name)
 
void attr_exists (CommandContext &ctx, uint64_t handle, const char *name, const char *attr, bool &exists)
 
void attr_list (CommandContext &ctx, uint64_t handle, std::vector< String > &attributes)
 
void exists (CommandContext &ctx, const char *name, bool &file_exists)
 
void readdir (CommandContext &ctx, uint64_t handle, std::vector< DirEntry > &listing)
 
void readdir_attr (CommandContext &ctx, uint64_t handle, const char *name, const char *attr, bool include_sub_entries, std::vector< DirEntryAttr > &listing)
 
void readpath_attr (CommandContext &ctx, uint64_t handle, const char *name, const char *attr, std::vector< DirEntryAttr > &listing)
 
bool get_handle_node (CommandContext &ctx, uint64_t handle, const char *attr, String &node)
 
bool get_named_node (CommandContext &ctx, const char *name, const char *attr, String &node, bool *is_dir=0)
 
void create_event (CommandContext &ctx, const String &node, uint32_t event_mask, const String &name)
 
void deliver_event_notifications (CommandContext &ctx, bool wait_for_notify=true)
 
void deliver_event_notifications (EventContext &evt, bool wait_for_notify=true)
 
void get_generation_number ()
 
void normalize_name (std::string name, std::string &normal)
 
void deliver_event_notifications (HyperspaceEventPtr &event_ptr, NotificationMap &handles_to_sessions, bool wait_for_notify=true)
 
void persist_event_notifications (BDbTxn &txn, uint64_t event_id, NotificationMap &handles_to_sessions)
 
void persist_event_notifications (BDbTxn &txn, uint64_t event_id, uint64_t handle)
 
bool validate_and_create_node_data (BDbTxn &txn, const String &node)
 
bool find_parent_node (const std::string &normal_name, std::string &parent_name, std::string &child_name)
 
bool destroy_handle (uint64_t handle, int &error, String &errmsg, bool wait_for_notify=true)
 
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 lock_handle (BDbTxn &txn, uint64_t handle, uint32_t mode, const String &node)
 
void lock_handle_with_notification (uint64_t handle, uint32_t mode, bool wait_for_notify=true)
 
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)
 

Private Attributes

bool m_verbose
 
uint32_t m_lease_interval
 
uint32_t m_keep_alive_interval
 
uint32_t m_maintenance_interval
 
std::string m_base_dir
 
std::string m_lock_file
 
int m_lock_fd
 
uint32_t m_generation
 
uint64_t m_next_handle_number
 
uint64_t m_next_session_id
 
ServerKeepaliveHandlerPtr m_keepalive_handler_ptr
 
struct sockaddr_in m_local_addr
 
SessionDataVec m_session_heap
 
SessionMap m_session_map
 
MetricsHandlerPtr m_metrics_handler
 
std::mutex m_session_map_mutex
 
std::mutex m_last_tick_mutex
 
std::mutex m_maintenance_mutex
 
bool m_maintenance_outstanding
 
std::chrono::steady_clock::time_point m_last_tick
 
std::chrono::steady_clock::time_point m_sleep_time
 Suspension time recorded by handle_sleep() More...
 
bool m_shutdown {}
 
BerkeleyDbFilesystemm_bdb_fs
 
Status m_status
 Program status tracker. More...
 

Detailed Description

Definition at line 61 of file Master.h.

Member Typedef Documentation

typedef std::vector<SessionDataPtr> Hyperspace::Master::SessionDataVec
private

Definition at line 324 of file Master.h.

typedef std::unordered_map<uint64_t, SessionDataPtr> Hyperspace::Master::SessionMap
private

Definition at line 325 of file Master.h.

Member Enumeration Documentation

anonymous enum
Enumerator
TIMER_INTERVAL_MS 

Definition at line 64 of file Master.h.

anonymous enum
Enumerator
HANDLE_NOT_DEL 
HANDLE_MARKED_FOR_DEL 

Definition at line 70 of file Master.h.

Constructor & Destructor Documentation

Hyperspace::Master::Master ( ConnectionManagerPtr conn_mgr,
PropertiesPtr props,
ServerKeepaliveHandlerPtr keepalive_handler,
ApplicationQueuePtr app_queue_ptr 
)

Definition at line 133 of file Master.cc.

Hyperspace::Master::~Master ( )

Definition at line 250 of file Master.cc.

Member Function Documentation

void Hyperspace::Master::attr_del ( ResponseCallback cb,
uint64_t  session_id,
uint64_t  handle,
const char *  name 
)

Definition at line 922 of file Master.cc.

void Hyperspace::Master::attr_del ( CommandContext ctx,
uint64_t  handle,
const char *  name 
)
private

Definition at line 2240 of file Master.cc.

void Hyperspace::Master::attr_exists ( ResponseCallbackAttrExists cb,
uint64_t  session_id,
uint64_t  handle,
const char *  name,
const char *  attr 
)

Definition at line 956 of file Master.cc.

void Hyperspace::Master::attr_exists ( CommandContext ctx,
uint64_t  handle,
const char *  name,
const char *  attr,
bool &  exists 
)
private

Definition at line 2253 of file Master.cc.

void Hyperspace::Master::attr_get ( ResponseCallbackAttrGet cb,
uint64_t  session_id,
uint64_t  handle,
const char *  name,
const std::vector< String > &  attrs 
)

Definition at line 831 of file Master.cc.

void Hyperspace::Master::attr_get ( CommandContext ctx,
uint64_t  handle,
const char *  name,
const char *  attr,
DynamicBuffer dbuf 
)
private

Definition at line 2176 of file Master.cc.

void Hyperspace::Master::attr_get ( CommandContext ctx,
uint64_t  handle,
const char *  name,
const std::vector< String > &  attrs,
std::vector< DynamicBufferPtr > &  dbufs 
)
private

Definition at line 2196 of file Master.cc.

void Hyperspace::Master::attr_incr ( ResponseCallbackAttrIncr cb,
uint64_t  session_id,
uint64_t  handle,
const char *  name,
const char *  attr 
)

Definition at line 883 of file Master.cc.

void Hyperspace::Master::attr_incr ( CommandContext ctx,
uint64_t  handle,
const char *  name,
const char *  attr,
uint64_t &  attr_val 
)
private

Definition at line 2220 of file Master.cc.

void Hyperspace::Master::attr_list ( ResponseCallbackAttrList cb,
uint64_t  session_id,
uint64_t  handle 
)

Definition at line 983 of file Master.cc.

void Hyperspace::Master::attr_list ( CommandContext ctx,
uint64_t  handle,
std::vector< String > &  attributes 
)
private

Definition at line 2273 of file Master.cc.

void Hyperspace::Master::attr_set ( ResponseCallback cb,
uint64_t  session_id,
uint64_t  handle,
const char *  name,
uint32_t  oflags,
const std::vector< Attribute > &  attrs 
)

Definition at line 758 of file Master.cc.

void Hyperspace::Master::attr_set ( CommandContext ctx,
uint64_t  handle,
const char *  name,
const std::vector< Attribute > &  attrs 
)
private

Definition at line 2139 of file Master.cc.

void Hyperspace::Master::close ( ResponseCallback cb,
uint64_t  session_id,
uint64_t  handle 
)

Definition at line 686 of file Master.cc.

void Hyperspace::Master::close ( CommandContext ctx,
uint64_t  handle 
)
private

Definition at line 718 of file Master.cc.

void Hyperspace::Master::create_event ( CommandContext ctx,
const String node,
uint32_t  event_mask,
const String name 
)
private

Definition at line 2474 of file Master.cc.

uint64_t Hyperspace::Master::create_session ( struct sockaddr_in &  addr)

Definition at line 263 of file Master.cc.

void Hyperspace::Master::deliver_event_notifications ( CommandContext ctx,
bool  wait_for_notify = true 
)
private

Definition at line 2495 of file Master.cc.

void Hyperspace::Master::deliver_event_notifications ( EventContext evt,
bool  wait_for_notify = true 
)
private

Definition at line 2501 of file Master.cc.

void Hyperspace::Master::deliver_event_notifications ( HyperspaceEventPtr event_ptr,
NotificationMap handles_to_sessions,
bool  wait_for_notify = true 
)
private

Definition at line 1651 of file Master.cc.

bool Hyperspace::Master::destroy_handle ( uint64_t  handle,
int &  error,
String errmsg,
bool  wait_for_notify = true 
)
private

Definition at line 1734 of file Master.cc.

void Hyperspace::Master::destroy_session ( uint64_t  session_id)

Definition at line 305 of file Master.cc.

void Hyperspace::Master::do_maintenance ( )

Definition at line 1856 of file Master.cc.

void Hyperspace::Master::exists ( ResponseCallbackExists cb,
uint64_t  session_id,
const char *  name 
)

Definition at line 1017 of file Master.cc.

void Hyperspace::Master::exists ( CommandContext ctx,
const char *  name,
bool &  file_exists 
)
private

Definition at line 2290 of file Master.cc.

bool Hyperspace::Master::find_parent_node ( const std::string &  normal_name,
std::string &  parent_name,
std::string &  child_name 
)
private

Definition at line 1695 of file Master.cc.

String Hyperspace::Master::get_current_master ( )
inline

Definition at line 84 of file Master.h.

void Hyperspace::Master::get_datagram_send_address ( struct sockaddr_in *  addr)
inline

Definition at line 162 of file Master.h.

void Hyperspace::Master::get_generation_number ( )
private

Definition at line 2507 of file Master.cc.

bool Hyperspace::Master::get_handle_node ( CommandContext ctx,
uint64_t  handle,
const char *  attr,
String node 
)
private

Definition at line 2391 of file Master.cc.

bool Hyperspace::Master::get_named_node ( CommandContext ctx,
const char *  name,
const char *  attr,
String node,
bool *  is_dir = 0 
)
private

Definition at line 2430 of file Master.cc.

bool Hyperspace::Master::get_session ( uint64_t  session_id,
SessionDataPtr session_data 
)

Definition at line 291 of file Master.cc.

void Hyperspace::Master::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 
)
private

Definition at line 1554 of file Master.cc.

void Hyperspace::Master::handle_sleep ( )

Handle sleep event (e.g.

laptop close). This method works in conjunction with handle_wakeup() to allow Hyperspace to continue working after the machine on which it is running has been suspended and resumed, for example when the laptop is closed and then reopened. It records the current time in m_sleep_time, which is then used by handle_wakeup() to extend session leases.

Definition at line 1829 of file Master.cc.

void Hyperspace::Master::handle_wakeup ( )

Handle wakeup event (e.g.

laptop open). This method works in conjunction with handle_sleep() to allow Hyperspace to continue working after the machine on which it is running has been suspended and resumed, for example when the laptop is closed and then reopened. It extends all session leases by an amount computed as follows:

(now - m_sleep_time) + lease_interval

Definition at line 1835 of file Master.cc.

void Hyperspace::Master::initialize_session ( uint64_t  session_id,
const String name 
)

Definition at line 323 of file Master.cc.

bool Hyperspace::Master::is_master ( )
inline

Definition at line 78 of file Master.h.

void Hyperspace::Master::lock ( ResponseCallbackLock cb,
uint64_t  session_id,
uint64_t  handle,
uint32_t  mode,
bool  try_lock 
)

Definition at line 1203 of file Master.cc.

void Hyperspace::Master::lock_handle ( BDbTxn txn,
uint64_t  handle,
uint32_t  mode,
String node 
)
private

Definition at line 1379 of file Master.cc.

void Hyperspace::Master::lock_handle ( BDbTxn txn,
uint64_t  handle,
uint32_t  mode,
const String node 
)
private

Definition at line 1399 of file Master.cc.

void Hyperspace::Master::lock_handle_with_notification ( uint64_t  handle,
uint32_t  mode,
bool  wait_for_notify = true 
)
private
void Hyperspace::Master::mkdir ( ResponseCallback cb,
uint64_t  session_id,
const char *  name,
const std::vector< Attribute > &  init_attrs 
)

Definition at line 484 of file Master.cc.

void Hyperspace::Master::mkdir ( CommandContext ctx,
const char *  name 
)
private

Definition at line 1874 of file Master.cc.

void Hyperspace::Master::mkdirs ( ResponseCallback cb,
uint64_t  session_id,
const char *  name,
const std::vector< Attribute > &  init_attrs 
)

Definition at line 524 of file Master.cc.

bool Hyperspace::Master::next_expired_session ( SessionDataPtr session_data,
std::chrono::steady_clock::time_point  now 
)

Definition at line 397 of file Master.cc.

void Hyperspace::Master::normalize_name ( std::string  name,
std::string &  normal 
)
private
void Hyperspace::Master::open ( ResponseCallbackOpen cb,
uint64_t  session_id,
const char *  name,
uint32_t  flags,
uint32_t  event_mask,
std::vector< Attribute > &  init_attrs 
)

Definition at line 638 of file Master.cc.

void Hyperspace::Master::open ( CommandContext ctx,
const char *  name,
uint32_t  flags,
uint32_t  event_mask,
std::vector< Attribute > &  init_attrs,
uint64_t &  handle,
bool &  created,
uint64_t &  lock_generation 
)
private

Definition at line 1924 of file Master.cc.

void Hyperspace::Master::persist_event_notifications ( BDbTxn txn,
uint64_t  event_id,
NotificationMap handles_to_sessions 
)
private

Definition at line 1621 of file Master.cc.

void Hyperspace::Master::persist_event_notifications ( BDbTxn txn,
uint64_t  event_id,
uint64_t  handle 
)
private

Definition at line 1640 of file Master.cc.

void Hyperspace::Master::readdir ( ResponseCallbackReaddir cb,
uint64_t  session_id,
uint64_t  handle 
)

Definition at line 1054 of file Master.cc.

void Hyperspace::Master::readdir ( CommandContext ctx,
uint64_t  handle,
std::vector< DirEntry > &  listing 
)
private

Definition at line 2306 of file Master.cc.

void Hyperspace::Master::readdir_attr ( ResponseCallbackReaddirAttr cb,
uint64_t  session_id,
uint64_t  handle,
const char *  name,
const char *  attr,
bool  include_sub_entries 
)

Definition at line 1090 of file Master.cc.

void Hyperspace::Master::readdir_attr ( CommandContext ctx,
uint64_t  handle,
const char *  name,
const char *  attr,
bool  include_sub_entries,
std::vector< DirEntryAttr > &  listing 
)
private

Definition at line 2319 of file Master.cc.

void Hyperspace::Master::readpath_attr ( ResponseCallbackReadpathAttr cb,
uint64_t  session_id,
uint64_t  handle,
const char *  name,
const char *  attr 
)

Definition at line 1129 of file Master.cc.

void Hyperspace::Master::readpath_attr ( CommandContext ctx,
uint64_t  handle,
const char *  name,
const char *  attr,
std::vector< DirEntryAttr > &  listing 
)
private

Definition at line 2338 of file Master.cc.

void Hyperspace::Master::release ( ResponseCallback cb,
uint64_t  session_id,
uint64_t  handle 
)

Definition at line 1416 of file Master.cc.

void Hyperspace::Master::release_lock ( BDbTxn txn,
uint64_t  handle,
const String node,
HyperspaceEventPtr release_event,
NotificationMap release_notifications 
)
private

Definition at line 1509 of file Master.cc.

void Hyperspace::Master::remove_expired_sessions ( )

Definition at line 423 of file Master.cc.

int Hyperspace::Master::renew_session_lease ( uint64_t  session_id)

Definition at line 354 of file Master.cc.

void Hyperspace::Master::shutdown ( ResponseCallback cb,
uint64_t  session_id 
)

Definition at line 1160 of file Master.cc.

void Hyperspace::Master::status ( ResponseCallbackStatus cb)

Definition at line 1194 of file Master.cc.

void Hyperspace::Master::tick ( )
inline

Definition at line 166 of file Master.h.

void Hyperspace::Master::unlink ( ResponseCallback cb,
uint64_t  session_id,
const char *  name 
)

Definition at line 600 of file Master.cc.

void Hyperspace::Master::unlink ( CommandContext ctx,
const char *  name 
)
private

Definition at line 2080 of file Master.cc.

bool Hyperspace::Master::validate_and_create_node_data ( BDbTxn txn,
const String node 
)
private

Definition at line 2526 of file Master.cc.

Member Data Documentation

std::string Hyperspace::Master::m_base_dir
private

Definition at line 331 of file Master.h.

BerkeleyDbFilesystem* Hyperspace::Master::m_bdb_fs
private

Definition at line 355 of file Master.h.

uint32_t Hyperspace::Master::m_generation
private

Definition at line 334 of file Master.h.

uint32_t Hyperspace::Master::m_keep_alive_interval
private

Definition at line 329 of file Master.h.

ServerKeepaliveHandlerPtr Hyperspace::Master::m_keepalive_handler_ptr
private

Definition at line 337 of file Master.h.

std::chrono::steady_clock::time_point Hyperspace::Master::m_last_tick
private

Definition at line 347 of file Master.h.

std::mutex Hyperspace::Master::m_last_tick_mutex
private

Definition at line 344 of file Master.h.

uint32_t Hyperspace::Master::m_lease_interval
private

Definition at line 328 of file Master.h.

struct sockaddr_in Hyperspace::Master::m_local_addr
private

Definition at line 338 of file Master.h.

int Hyperspace::Master::m_lock_fd
private

Definition at line 333 of file Master.h.

std::string Hyperspace::Master::m_lock_file
private

Definition at line 332 of file Master.h.

uint32_t Hyperspace::Master::m_maintenance_interval
private

Definition at line 330 of file Master.h.

std::mutex Hyperspace::Master::m_maintenance_mutex
private

Definition at line 345 of file Master.h.

bool Hyperspace::Master::m_maintenance_outstanding
private

Definition at line 346 of file Master.h.

MetricsHandlerPtr Hyperspace::Master::m_metrics_handler
private

Definition at line 341 of file Master.h.

uint64_t Hyperspace::Master::m_next_handle_number
private

Definition at line 335 of file Master.h.

uint64_t Hyperspace::Master::m_next_session_id
private

Definition at line 336 of file Master.h.

SessionDataVec Hyperspace::Master::m_session_heap
private

Definition at line 339 of file Master.h.

SessionMap Hyperspace::Master::m_session_map
private

Definition at line 340 of file Master.h.

std::mutex Hyperspace::Master::m_session_map_mutex
private

Definition at line 343 of file Master.h.

bool Hyperspace::Master::m_shutdown {}
private

Definition at line 352 of file Master.h.

std::chrono::steady_clock::time_point Hyperspace::Master::m_sleep_time
private

Suspension time recorded by handle_sleep()

Definition at line 350 of file Master.h.

Status Hyperspace::Master::m_status
private

Program status tracker.

Definition at line 358 of file Master.h.

bool Hyperspace::Master::m_verbose
private

Definition at line 327 of file Master.h.


The documentation for this class was generated from the following files: