0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BerkeleyDbFilesystem.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 #ifndef Hyperspace_BerkeleyDbFilesystem_h
29 #define Hyperspace_BerkeleyDbFilesystem_h
30 
31 #include <Common/Compat.h>
32 
33 #include <Hyperspace/DirEntry.h>
35 #include <Hyperspace/StateDbKeys.h>
36 
37 #include <Common/DynamicBuffer.h>
38 #include <Common/FileUtils.h>
39 #include <Common/InetAddr.h>
40 #include <Common/InetAddr.h>
41 #include <Common/Properties.h>
42 #include <Common/String.h>
43 #include <Common/StringExt.h>
44 #include <Common/Thread.h>
45 
46 #include <db_cxx.h>
47 
48 #include <chrono>
49 #include <condition_variable>
50 #include <map>
51 #include <memory>
52 #include <mutex>
53 #include <ostream>
54 #include <unordered_map>
55 #include <vector>
56 
57 namespace Hyperspace {
58 
63  typedef std::unordered_map<uint64_t, uint64_t> NotificationMap;
65 
67  class LockRequest {
68  public:
73  LockRequest(uint64_t h=0, int m=0) : handle(h), mode(m) { return; }
75  uint64_t handle;
77  uint32_t mode;
78  };
79 
82  SESSION = 0,
85  };
86 
89  public:
92 
95  std::unique_lock<std::mutex> lock(m_election_mutex);
96  m_election_cond.wait(lock, [this](){ return m_election_done; });
97  }
98 
101  std::lock_guard<std::mutex> lock(m_election_mutex);
102  if (!m_election_done) {
103  m_election_done = true;
104  m_election_cond.notify_all();
105  }
106  }
107 
112  std::lock_guard<std::mutex> lock(m_election_mutex);
113  return m_election_done;
114  }
115 
116  bool do_replication {};
117  bool is_master {};
118  int master_eid {-1};
119  uint32_t num_replicas {};
121  std::unordered_map<int, String> replica_map;
122 
123  private:
124 
127 
129  std::condition_variable m_election_cond;
130 
133  };
134 
136  class BDbHandles {
137  public:
138 
141 
144  close();
145  }
146 
151  void close() {
152  if (open) {
153  try {
154  handle_namespace_db->close(0);
155  handle_state_db->close(0);
156  delete handle_namespace_db;
157  delete handle_state_db;
159  handle_state_db = 0;
160  open = false;
161  }
162  catch(DbException &e) {
163  HT_ERROR_OUT << "Error closing Berkeley DB handles" << HT_END;
164  }
165  }
166  }
167 
169  bool open;
170 
173 
176  };
177 
179  typedef std::shared_ptr<BDbHandles> BDbHandlesPtr;
180 
182  class BDbTxn {
183  public:
186 
190  void commit(int flag=0) {
191  db_txn->commit(flag);
192  db_txn = 0;
193  }
194 
196  void abort() {
197  db_txn->abort();
198  db_txn = 0;
199  }
200 
203 
206 
208  DbTxn *db_txn;
209  };
210 
216  std::ostream &operator<<(std::ostream &out, const BDbTxn &txn);
217 
221  public:
222 
230  const String &basedir,
231  const std::vector<Thread::id> &thread_ids,
232  bool force_recover=false);
233 
238 
246  void do_checkpoint();
247 
253  bool is_master() {
254  // its the master if we're not doing replication or this is the replication master
256  }
257 
264  else {
266  if (it != m_replication_info.replica_map.end())
267  return it->second;
268  else
269  return (String) "";
270  }
271  }
272 
276  void start_transaction(BDbTxn &txn);
277 
278  bool get_xattr_i32(BDbTxn &txn, const String &fname,
279  const String &aname, uint32_t *valuep);
280  void set_xattr_i32(BDbTxn &txn, const String &fname,
281  const String &aname, uint32_t value);
282  bool get_xattr_i64(BDbTxn &txn, const String &fname,
283  const String &aname, uint64_t *valuep);
284  void set_xattr_i64(BDbTxn &txn, const String &fname,
285  const String &aname, uint64_t value);
286  void set_xattr(BDbTxn &txn, const String &fname,
287  const String &aname, const void *value, size_t value_len);
288  bool get_xattr(BDbTxn &txn, const String &fname, const String &aname,
290  bool incr_attr(BDbTxn &txn, const String &fname, const String &aname,
291  uint64_t *valuep);
292 
293  bool exists_xattr(BDbTxn &txn, const String &fname, const String &aname);
294  void del_xattr(BDbTxn &txn, const String &fname, const String &aname);
295  void mkdir(BDbTxn &txn, const String &name);
296  void unlink(BDbTxn &txn, const String &name);
297  bool exists(BDbTxn &txn, String fname, bool *is_dir_p=0);
298  void create(BDbTxn &txn, const String &fname, bool temp);
299  void get_directory_listing(BDbTxn &txn, String fname,
300  std::vector<DirEntry> &listing);
301  void get_directory_attr_listing(BDbTxn &txn, String fname, const String &aname,
302  bool include_sub_entries,
303  std::vector<DirEntryAttr> &listing);
304  void get_directory_attr_listing(BDbTxn &txn, String fname, const String &aname,
305  std::vector<DirEntryAttr> &listing);
306  void get_all_names(BDbTxn &txn, std::vector<String> &names);
307  bool list_xattr(BDbTxn &txn, const String& fname, std::vector<String> &anames);
308  /*
309  * Persists a new event in the StateDB
310  *
311  * @param txn BerkeleyDB txn for this DB update
312  * @param type Event type
313  * @param id Event id
314  * @param mask Event mask
315  */
316  void create_event(BDbTxn &txn, uint32_t type, uint64_t id, uint32_t mask);
317  // for named event
318  void create_event(BDbTxn &txn, uint32_t type, uint64_t id, uint32_t mask,
319  const String &name);
320  void create_event(BDbTxn &txn, uint32_t type, uint64_t id, uint32_t mask, uint32_t mode);
321  void create_event(BDbTxn &txn, uint32_t type, uint64_t id, uint32_t mask,
322  uint32_t mode, uint64_t generation);
323 
324  /*
325  * Remove specified event from the StateDB
326  *
327  * @param txn BerkeleyDB txn for this DB update
328  * @param id Event id
329  */
330  void delete_event(BDbTxn &txn, uint64_t id);
331 
332  /*
333  * Set the handles that are affected by this event
334  *
335  * @param txn BerkeleyDB txn for this DB update
336  * @param id Event id
337  * @param handles array of handles that are affected by this event
338  */
339  void set_event_notification_handles(BDbTxn &txn, uint64_t id,
340  const std::vector<uint64_t> &handles);
341 
342  /*
343  * Check if the specified event is in the StateDB
344  *
345  * @param txn BerkeleyDB txn for this DB update
346  * @param id Event id
347  * @return true if found false ow
348  */
349  bool event_exists(BDbTxn &txn, uint64_t id);
350 
351  /*
352  * Persist a new SessionData object in the StateDB
353  *
354  * @param txn BerkeleyDB txn for this DB update
355  * @param id Session id
356  * @param addr Stringified remote host address
357  */
358  void create_session(BDbTxn &txn, uint64_t id, const String &addr);
359 
360  /*
361  * Delete info for specified session from StateDB
362  *
363  * @param txn BerkeleyDB txn for this DB update
364  * @param id Session id
365  */
366  void delete_session(BDbTxn &txn, uint64_t id);
367 
368  /*
369  * Delete info for specified session from StateDB
370  *
371  * @param txn BerkeleyDB txn for this DB update
372  * @param id Session id
373  */
374  void expire_session(BDbTxn &txn, uint64_t id);
375 
376 
377  /*
378  * Store new handle opened by specified session
379  *
380  * @param txn BerkeleyDB txn for this DB update
381  * @param id Session id
382  * @param handle_id Handle id
383  */
384  void add_session_handle(BDbTxn &txn, uint64_t id, uint64_t handle_id);
385 
386  /*
387  * return all the handles a session has open
388  *
389  * @param txn BerkeleyDB txn for this DB update
390  * @param id Session id
391  * @param handles vector into which open handle ids will be inserted
392  */
393  void get_session_handles(BDbTxn &txn, uint64_t id, std::vector<uint64_t> &handles);
394 
395 
396  /*
397  * Remove a handle from a session
398  *
399  * @param txn BerkeleyDB txn for this DB update
400  * @param id Session id
401  * @param handle_id Handle id
402  * @return true if handle was open and has been deleted
403  */
404  bool delete_session_handle(BDbTxn &txn, uint64_t id, uint64_t handle_id);
405 
406 
407  /*
408  * Check if specified session exists in StateDB
409  *
410  * @param txn BerkeleyDB txn for this DB update
411  * @param id Session id
412  * @return true if session existsn StateDB, false ow
413  */
414  bool session_exists(BDbTxn &txn, uint64_t id);
415 
416  /*
417  * Get name of session executable
418  *
419  * @param txn BerkeleyDB txn for this DB update
420  * @param id Session id
421  * @return remote session executable
422  */
423  String get_session_name(BDbTxn &txn, uint64_t id);
424 
425  /*
426  * Set name of session executable
427  *
428  * @param txn BerkeleyDB txn for this DB update
429  * @param id Session id
430  * @param name of the session executable
431  */
432  void set_session_name(BDbTxn &txn, uint64_t id, const String &name);
433 
434 
435  /*
436  * Persist a new handle in StateDB
437  *
438  * @param txn BerkeleyDB txn for this DB update
439  * @param id Handle id
440  * @param node_name Name of node associated with this handle
441  * @param open_flags Open flags for this handle
442  * @param event_mask Event notification mask
443  * @param session_id Id of session associated with this handle
444  * @param locked true if node is locked
445  * @param del_state state of handle deletion operation
446  */
447  void create_handle(BDbTxn &txn, uint64_t id, String node_name,
448  uint32_t open_flags, uint32_t event_mask, uint64_t session_id,
449  bool locked, uint32_t del_state);
450 
451  /*
452  * Delete all info for this handle from StateDB
453  *
454  * @param txn BerkeleyDB txn for this DB update
455  * @param id Handle id
456  */
457  void delete_handle(BDbTxn &txn, uint64_t id);
458 
459  /*
460  * Get open flags for handle
461  *
462  * @param txn BerkeleyDB txn for this DB update
463  * @param id Handle id
464  * @return open_flags for handle
465  */
466  uint32_t get_handle_open_flags(BDbTxn &txn, uint64_t id);
467 
468  /*
469  * Set deletion state for handle
470  *
471  * @param txn BerkeleyDB txn for this DB update
472  * @param id Handle id
473  * @param del_state new deletion state
474  */
475  void set_handle_del_state(BDbTxn &txn, uint64_t id, uint32_t del_state);
476 
477  /*
478  * Get handle deletion state for handle
479  *
480  * @param txn BerkeleyDB txn for this DB update
481  * @param id Handle id
482  * @return deletion state for handle
483  */
484  uint32_t get_handle_del_state(BDbTxn &txn, uint64_t id);
485 
486  /*
487  * Set open flags for handle
488  *
489  * @param txn BerkeleyDB txn for this DB update
490  * @param id Handle id
491  * @param open_flags new flags
492  */
493  void set_handle_open_flags(BDbTxn &txn, uint64_t id, uint32_t open_flags);
494 
495  /*
496  * Set event mask for handle
497  *
498  * @param txn BerkeleyDB txn for this DB update
499  * @param id Handle id
500  * @param event_mask new event mask
501  */
502  void set_handle_event_mask(BDbTxn &txn, uint64_t id, uint32_t event_mask);
503 
504  /*
505  * Get event mask for handle
506  *
507  * @param txn BerkeleyDB txn for this DB update
508  * @param id Handle id
509  * @return event mask
510  */
511  uint32_t get_handle_event_mask(BDbTxn &txn, uint64_t id);
512 
513  /*
514  * Set the node associated with this handle
515  *
516  * @param txn BerkeleyDB txn for this DB update
517  * @param id Handle id
518  * @param node_name name of node assoc with this handle
519  */
520  void set_handle_node(BDbTxn &txn, uint64_t id, const String &node_name);
521 
522  /*
523  * Get the node associated with this handle
524  *
525  * @param txn BerkeleyDB txn for this DB update
526  * @param id Handle id
527  * @param node_name name of node assoc with this handle, if not found node_name = ""
528  */
529  void get_handle_node(BDbTxn &txn, uint64_t id, String &node_name);
530 
531  /*
532  * Get the session associated with this handle
533  *
534  * @param txn BerkeleyDB txn for this DB update
535  * @param id Handle id
536  * @return session id for this handle
537  */
538  uint64_t get_handle_session(BDbTxn &txn, uint64_t id);
539 
540 
541  /*
542  * Set the locked-ness this handle
543  *
544  * @param txn BerkeleyDB txn for this DB update
545  * @param id Handle id
546  * @param locked
547  */
548  void set_handle_locked(BDbTxn &txn, uint64_t id, bool locked);
549 
550  /*
551  * Get the locked-ness this handle
552  *
553  * @param txn BerkeleyDB txn for this DB update
554  * @param id Handle id
555  * @return true if handle is locked
556  */
557  bool handle_is_locked(BDbTxn &txn, uint64_t id);
558 
559  /*
560  * Check if info for this handle is in the StateDb
561  *
562  * @param txn BerkeleyDB txn for this DB update
563  * @param id Handle id
564  * @return true if handle exists in StateDb
565  */
566  bool handle_exists(BDbTxn &txn, uint64_t id);
567 
568  /*
569  * Persist a new node in StateDB
570  *
571  * @param txn BerkeleyDB txn for this DB update
572  * @param name Node name
573  * @param ephemeral true if node is ephemeral
574  * @param lock_generation node lock generation
575  * @param cur_lock_mode node lock mode
576  * @param exclusive_handle handle id of exclusive lock handle
577  */
578  void create_node(BDbTxn &txn, const String &name, bool ephemeral=false,
579  uint64_t lock_generation=0, uint32_t cur_lock_mode=0, uint64_t exclusive_handle=0);
580 
581  /*
582  * Set the lock generation this node
583  *
584  * @param txn BerkeleyDB txn for this DB update
585  * @param name Node name
586  * @param lock_generation
587  */
588  void set_node_lock_generation(BDbTxn &txn, const String &name, uint64_t lock_generation);
589 
590  /*
591  * Increment the lock generation this node
592  *
593  * @param txn BerkeleyDB txn for this DB update
594  * @param name Node name
595  * @return current lock generation (after increment)
596  */
597  uint64_t incr_node_lock_generation(BDbTxn &txn, const String &name);
598 
599 
600  /*
601  * Set the node ephemeral-ness
602  *
603  * @param txn BerkeleyDB txn for this DB update
604  * @param name Node name
605  * @param ephemeral
606  */
607  void set_node_ephemeral(BDbTxn &txn, const String &name, bool ephemeral);
608 
609  /*
610  * Set the node ephemeral-ness
611  *
612  * @param txn BerkeleyDB txn for this DB update
613  * @param name Node name
614  * @return true if node is ephemeral
615  */
616  bool node_is_ephemeral(BDbTxn &txn, const String &name);
617 
618  /*
619  * Set the node current lock mode
620  *
621  * @param txn BerkeleyDB txn for this DB update
622  * @param name Node name
623  * @param lock_mode
624  */
625  void set_node_cur_lock_mode(BDbTxn &txn, const String &name, uint32_t lock_mode);
626 
627  /*
628  * Get the node current lock mode
629  *
630  * @param txn BerkeleyDB txn for this DB update
631  * @param name Node name
632  * @return lock_mode
633  */
634  uint32_t get_node_cur_lock_mode(BDbTxn &txn, const String &name);
635 
636  /*
637  * Set the node exclusive_lock_handle
638  *
639  * @param txn BerkeleyDB txn for this DB update
640  * @param name Node name
641  * @param exclusive_lock_handle
642  */
643  void set_node_exclusive_lock_handle(BDbTxn &txn, const String &name,
644  uint64_t exclusive_lock_handle);
645 
646  /*
647  * Get the node exclusive_lock_handle
648  *
649  * @param txn BerkeleyDB txn for this DB update
650  * @param name Node name
651  * @return exclusive lock handle
652  */
653  uint64_t get_node_exclusive_lock_handle(BDbTxn &txn, const String &name);
654 
655 
656  /*
657  * Add a handle to the node
658  *
659  * @param txn BerkeleyDB txn for this DB update
660  * @param name Node name
661  * @param handle
662  */
663  void add_node_handle(BDbTxn &txn, const String &name, uint64_t handle);
664 
665  /*
666  * Remove a handle from the node
667  *
668  * @param txn BerkeleyDB txn for this DB update
669  * @param name Node name
670  * @param handle
671  */
672  void delete_node_handle(BDbTxn &txn, const String &name, uint64_t handle);
673 
674  /*
675  * Returns whether any handles have this node open
676  *
677  * @param txn BerkeleyDB txn for this DB update
678  * @param name Node name
679  * @return true if at least one handle has this node open
680  */
681  bool node_has_open_handles(BDbTxn &txn, const String &name);
682 
683  /*
684  * Check if a node has any pending lock requests from non-expired handles
685  *
686  * @param txn BerkeleyDB txn for this DB update
687  * @param name Node name
688  * @return true if node has at least one pending lock request
689  */
690  bool node_has_pending_lock_request(BDbTxn &txn, const String &name);
691 
698  bool get_node_pending_lock_request(BDbTxn &txn, const String &name,
699  LockRequest &front_req);
700 
701 
707  void add_node_pending_lock_request(BDbTxn &txn, const String &name,
708  LockRequest &request);
709  /*
710  * Remove a lock request to the node
711  *
712  * @param txn BerkeleyDB txn for this DB update
713  * @param name Node name
714  * @param handle handle requesting lock
715  */
716  void delete_node_pending_lock_request(BDbTxn &txn, const String &name, uint64_t handle);
717 
718  /*
719  * Add a shared lock handle
720  *
721  * @param txn BerkeleyDB txn for this DB update
722  * @param name Node name
723  * @param handle handle requesting lock
724  */
725  void add_node_shared_lock_handle(BDbTxn &txn, const String &name, uint64_t handle);
726 
727  /*
728  * Get a map of(handle id, session id) for notifications registered for a certain
729  * event occuring to a node
730  *
731  * @param txn BerkeleyDB txn
732  * @param name Node name
733  * @param event_mask indicates the event that is ocurring
734  * @param handles_to_sessions map specifying notifications to be sent
735  * @return true if there are some notifications that need to be sent out
736  */
737  bool get_node_event_notification_map(BDbTxn &txn, const String &name, uint32_t event_mask,
738  NotificationMap &handles_to_sessions);
739 
740  /*
741  * Get all open handles for a node
742  *
743  * @param txn BerkeleyDB txn
744  * @param name Node name
745  * @param handles vector of node handles
746  */
747  void get_node_handles(BDbTxn &txn, const String &name, std::vector<uint64_t> &handles);
748 
749  /*
750  * Remove node shared lock handle
751  *
752  * @param txn BerkeleyDB txn for this DB update
753  * @param name Node name
754  * @param handle_id to be deleted
755  */
756  void delete_node_shared_lock_handle(BDbTxn &txn, const String &name, uint64_t handle_id);
757 
758  /*
759  * Delete all info for this node from StateDB
760  *
761  * @param txn BerkeleyDB txn for this DB update
762  * @param name Node name
763  * @return false if node doesn't exist true if node was deleted
764  */
765  bool delete_node(BDbTxn &txn, const String &name);
766 
767  /*
768  * Check if info for this node is in the StateDb
769  *
770  * @param txn BerkeleyDB txn for this DB update
771  * @param name Node name
772  * @return true if node exists in StateDb
773  */
774  bool node_exists(BDbTxn &txn, const String &name);
775 
776  /*
777  * Check if node has any shared lock handles
778  *
779  * @param txn BerkeleyDB txn for this DB update
780  * @param name Node name
781  * @return true if node has shared lock handles
782  */
783  bool node_has_shared_lock_handles(BDbTxn &txn, const String &name);
784 
785  uint64_t get_next_id_i64(BDbTxn &txn, IdentifierType id_type, bool increment = false);
786 
787  static const char NODE_ATTR_DELIM = 0x01;
788 
789 
790  private:
791  /*
792  * Initialize per worker thread DB handles
793  */
794  void init_db_handles(const std::vector<Thread::id> &thread_ids);
795  BDbHandlesPtr get_db_handles();
796  void build_attr_key(BDbTxn &, String &keystr,
797  const String &aname, Dbt &key);
798  static void db_event_callback(DbEnv *dbenv, uint32_t which, void *info);
799  static void db_err_callback(const DbEnv *dbenv, const char *errpfx, const char *msg);
800  static void db_msg_callback(const DbEnv *dbenv, const char *msg);
801 
804  DbEnv m_env;
805  uint32_t m_db_flags {};
806  static const char *ms_name_namespace_db;
807  static const char *ms_name_state_db;
808  typedef std::map<Thread::id, BDbHandlesPtr> ThreadHandleMap;
809  ThreadHandleMap m_thread_handle_map;
810 
814  std::chrono::steady_clock::duration m_log_gc_interval;
815  std::chrono::steady_clock::time_point m_last_log_gc_time;
816  };
817 
820 } // namespace Hyperspace
821 
822 #endif // Hyperspace_BerkeleyDbFilesystem_h
Session identifier.
uint32_t get_handle_del_state(BDbTxn &txn, uint64_t id)
static std::mutex mutex
Definition: Logger.cc:43
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.
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.
Definition: String.h:44
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.
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.
Definition: DynamicBuffer.h:42
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)
Hyperspace definitions
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
Definition: Properties.h:447
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)
#define HT_END
Definition: Logger.h:220
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
#define HT_ERROR_OUT
Definition: Logger.h:301
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)
Handle identifier.
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.
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)
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)
uint32_t mode
Lock mode.
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)
Event identifier.
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)
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.
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)
void set_node_exclusive_lock_handle(BDbTxn &txn, const String &name, uint64_t exclusive_lock_handle)