28 #ifndef Hyperspace_BerkeleyDbFilesystem_h
29 #define Hyperspace_BerkeleyDbFilesystem_h
49 #include <condition_variable>
54 #include <unordered_map>
162 catch(DbException &e) {
231 const std::vector<Thread::id> &thread_ids,
232 bool force_recover=
false);
279 const String &aname, uint32_t *valuep);
281 const String &aname, uint32_t value);
283 const String &aname, uint64_t *valuep);
285 const String &aname, uint64_t value);
287 const String &aname,
const void *value,
size_t value_len);
300 std::vector<DirEntry> &listing);
302 bool include_sub_entries,
303 std::vector<DirEntryAttr> &listing);
305 std::vector<DirEntryAttr> &listing);
320 void create_event(
BDbTxn &txn, uint32_t type, uint64_t
id, uint32_t mask, uint32_t mode);
322 uint32_t mode, uint64_t generation);
340 const std::vector<uint64_t> &handles);
448 uint32_t open_flags, uint32_t event_mask, uint64_t session_id,
449 bool locked, uint32_t del_state);
579 uint64_t lock_generation=0, uint32_t cur_lock_mode=0, uint64_t exclusive_handle=0);
644 uint64_t exclusive_lock_handle);
738 NotificationMap &handles_to_sessions);
797 const String &aname, Dbt &key);
799 static void db_err_callback(
const DbEnv *dbenv,
const char *errpfx,
const char *msg);
822 #endif // Hyperspace_BerkeleyDbFilesystem_h
uint32_t get_handle_del_state(BDbTxn &txn, uint64_t id)
uint64_t handle
Node handle ID.
void set_session_name(BDbTxn &txn, uint64_t id, const String &name)
Manages namespace and transient state database handles.
void set_handle_open_flags(BDbTxn &txn, uint64_t id, uint32_t open_flags)
void add_node_pending_lock_request(BDbTxn &txn, const String &name, LockRequest &request)
Adds a lock request.
BDbHandlesPtr get_db_handles()
bool node_has_shared_lock_handles(BDbTxn &txn, const String &name)
std::chrono::steady_clock::duration m_log_gc_interval
static void db_msg_callback(const DbEnv *dbenv, const char *msg)
std::string String
A String is simply a typedef to std::string.
static void db_err_callback(const DbEnv *dbenv, const char *errpfx, const char *msg)
void delete_node_shared_lock_handle(BDbTxn &txn, const String &name, uint64_t handle_id)
bool get_xattr_i32(BDbTxn &txn, const String &fname, const String &aname, uint32_t *valuep)
String get_current_master()
Returns hostname of currently elected master.
LockRequest(uint64_t h=0, int m=0)
Constructor.
void finish_election()
Finish master election.
Db * handle_namespace_db
Filesystem namespace database handle.
void get_handle_node(BDbTxn &txn, uint64_t id, String &node_name)
void add_node_handle(BDbTxn &txn, const String &name, uint64_t handle)
Manages transaction state.
bool incr_attr(BDbTxn &txn, const String &fname, const String &aname, uint64_t *valuep)
std::mutex m_election_mutex
Mutex for serializing access to m_election_done
void create_handle(BDbTxn &txn, uint64_t id, String node_name, uint32_t open_flags, uint32_t event_mask, uint64_t session_id, bool locked, uint32_t del_state)
void create_node(BDbTxn &txn, const String &name, bool ephemeral=false, uint64_t lock_generation=0, uint32_t cur_lock_mode=0, uint64_t exclusive_handle=0)
Program options handling.
void create(BDbTxn &txn, const String &fname, bool temp)
std::shared_ptr< BDbHandles > BDbHandlesPtr
Smart pointer to BDbHandles.
Db * handle_state_db
Database handle transient state.
void delete_session(BDbTxn &txn, uint64_t id)
bool node_is_ephemeral(BDbTxn &txn, const String &name)
void set_node_cur_lock_mode(BDbTxn &txn, const String &name, uint32_t lock_mode)
BerkeleyDbFilesystem(PropertiesPtr &props, const String &basedir, const std::vector< Thread::id > &thread_ids, bool force_recover=false)
Constructor.
ThreadHandleMap m_thread_handle_map
bool node_has_pending_lock_request(BDbTxn &txn, const String &name)
Encapsulates replication state.
void add_node_shared_lock_handle(BDbTxn &txn, const String &name, uint64_t handle)
A dynamic, resizable and reference counted memory buffer.
void close()
Closes and destroys database handles Closes and destroys handle_namespace_db and handle_state_db and ...
void set_handle_event_mask(BDbTxn &txn, uint64_t id, uint32_t event_mask)
void get_session_handles(BDbTxn &txn, uint64_t id, std::vector< uint64_t > &handles)
static const char NODE_ATTR_DELIM
uint32_t m_max_unused_logs
bool election_finished()
Check if master election is finished.
bool exists(BDbTxn &txn, String fname, bool *is_dir_p=0)
bool m_election_done
Indicates if master election has finished.
File system utility functions.
bool open
Indicates if database handles have been opened.
void get_all_names(BDbTxn &txn, std::vector< String > &names)
A dynamic, resizable memory buffer.
std::unordered_map< uint64_t, uint64_t > NotificationMap
Hash map from Node handle ID to Session ID.
bool node_has_open_handles(BDbTxn &txn, const String &name)
void set_node_ephemeral(BDbTxn &txn, const String &name, bool ephemeral)
void do_checkpoint()
Checkpoints the BerkeleyDB database.
bool handle_is_locked(BDbTxn &txn, uint64_t id)
bool delete_session_handle(BDbTxn &txn, uint64_t id, uint64_t handle_id)
bool delete_node(BDbTxn &txn, const String &name)
std::shared_ptr< Properties > PropertiesPtr
bool get_node_event_notification_map(BDbTxn &txn, const String &name, uint32_t event_mask, NotificationMap &handles_to_sessions)
bool get_node_pending_lock_request(BDbTxn &txn, const String &name, LockRequest &front_req)
Check if a node has any pending lock requests from non-expired handles.
static void db_event_callback(DbEnv *dbenv, uint32_t which, void *info)
uint64_t get_node_exclusive_lock_handle(BDbTxn &txn, const String &name)
void start_transaction(BDbTxn &txn)
Creates a new BerkeleyDB transaction.
void set_handle_locked(BDbTxn &txn, uint64_t id, bool locked)
Compatibility Macros for C/C++.
bool get_xattr(BDbTxn &txn, const String &fname, const String &aname, Hypertable::DynamicBuffer &vbuf)
void delete_node_handle(BDbTxn &txn, const String &name, uint64_t handle)
void set_handle_del_state(BDbTxn &txn, uint64_t id, uint32_t del_state)
uint32_t get_handle_event_mask(BDbTxn &txn, uint64_t id)
Importing boost::thread and boost::thread_group into the Hypertable namespace.
Db * handle_state_db
Transient state database handle.
std::unordered_map< int, String > replica_map
void init_db_handles(const std::vector< Thread::id > &thread_ids)
DbTxn * db_txn
BerkeleyDB transaction object.
bool exists_xattr(BDbTxn &txn, const String &fname, const String &aname)
void create_event(BDbTxn &txn, uint32_t type, uint64_t id, uint32_t mask)
void mkdir(BDbTxn &txn, const String &name)
Hyperspace filesystem implementation on top of BerkeleyDB.
Db * handle_namespace_db
Database handle for persistent filesystem namespace.
void add_session_handle(BDbTxn &txn, uint64_t id, uint64_t handle_id)
uint32_t get_node_cur_lock_mode(BDbTxn &txn, const String &name)
bool is_master()
Check if we're the current master.
bool event_exists(BDbTxn &txn, uint64_t id)
void set_xattr(BDbTxn &txn, const String &fname, const String &aname, const void *value, size_t value_len)
std::ostream & operator<<(std::ostream &out, const BDbTxn &txn)
Writes human-readable version of txn to an ostream.
ReplicationInfo()
Constructor.
void expire_session(BDbTxn &txn, uint64_t id)
bool handle_exists(BDbTxn &txn, uint64_t id)
std::condition_variable m_election_cond
Condition variable for signaling change to m_election_done.
void delete_node_pending_lock_request(BDbTxn &txn, const String &name, uint64_t handle)
void delete_event(BDbTxn &txn, uint64_t id)
uint32_t m_checkpoint_size_kb
Checkpoint size threshold in kilobytes.
void set_node_lock_generation(BDbTxn &txn, const String &name, uint64_t lock_generation)
~BerkeleyDbFilesystem()
Destructor.
Internet address wrapper classes and utility functions.
uint64_t get_handle_session(BDbTxn &txn, uint64_t id)
void set_xattr_i32(BDbTxn &txn, const String &fname, const String &aname, uint32_t value)
uint64_t get_next_id_i64(BDbTxn &txn, IdentifierType id_type, bool increment=false)
Encapsulates a lock request for a file node.
void set_handle_node(BDbTxn &txn, uint64_t id, const String &node_name)
bool list_xattr(BDbTxn &txn, const String &fname, std::vector< String > &anames)
bool session_exists(BDbTxn &txn, uint64_t id)
A String class based on std::string.
void set_event_notification_handles(BDbTxn &txn, uint64_t id, const std::vector< uint64_t > &handles)
void create_session(BDbTxn &txn, uint64_t id, const String &addr)
String get_session_name(BDbTxn &txn, uint64_t id)
void abort()
Abort transaction.
bool get_xattr_i64(BDbTxn &txn, const String &fname, const String &aname, uint64_t *valuep)
void unlink(BDbTxn &txn, const String &name)
static const char * ms_name_state_db
std::chrono::steady_clock::time_point m_last_log_gc_time
void delete_handle(BDbTxn &txn, uint64_t id)
void del_xattr(BDbTxn &txn, const String &fname, const String &aname)
void commit(int flag=0)
Commit transaction.
ReplicationInfo m_replication_info
bool node_exists(BDbTxn &txn, const String &name)
String extensions and helpers: sets, maps, append operators etc.
void get_directory_listing(BDbTxn &txn, String fname, std::vector< DirEntry > &listing)
uint32_t get_handle_open_flags(BDbTxn &txn, uint64_t id)
void get_node_handles(BDbTxn &txn, const String &name, std::vector< uint64_t > &handles)
IdentifierType
Enumeration for object identifier types.
void wait_for_election()
Waits for master election to finish.
std::map< Thread::id, BDbHandlesPtr > ThreadHandleMap
uint64_t incr_node_lock_generation(BDbTxn &txn, const String &name)
void get_directory_attr_listing(BDbTxn &txn, String fname, const String &aname, bool include_sub_entries, std::vector< DirEntryAttr > &listing)
void set_xattr_i64(BDbTxn &txn, const String &fname, const String &aname, uint64_t value)
void build_attr_key(BDbTxn &, String &keystr, const String &aname, Dbt &key)
static const char * ms_name_namespace_db
void set_node_exclusive_lock_handle(BDbTxn &txn, const String &name, uint64_t exclusive_lock_handle)