Zero  0.1.0
lock.h
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2011-2014, Hewlett-Packard Development Company, LP
3  */
4 
5 #ifndef __LOCK_H
6 #define __LOCK_H
7 
8 #include "w_defines.h"
9 
10 #include "sm_base.h"
11 #include "w_okvl.h"
12 #include "w_okvl_inl.h"
13 #include "lock_s.h"
14 
15 class xct_lock_info_t;
16 class lock_core_m;
17 class lil_global_table;
18 struct RawXct;
19 struct RawLock;
20 class sm_options;
21 
27 class lock_m : public smlevel_0 {
28 public:
29  // initialize/takedown functions for thread-local state
30  static void on_thread_init();
31 
32  static void on_thread_destroy();
33 
34  lock_m(const sm_options& options);
35 
36  ~lock_m();
37 
42  void assert_empty() const;
43 
49  void dump(ostream& o);
50 
51  void stats(
52  u_long& buckets_used,
53  u_long& max_bucket_len,
54  u_long& min_bucket_len,
55  u_long& mode_bucket_len,
56  float& avg_bucket_len,
57  float& var_bucket_len,
58  float& std_bucket_len
59  ) const;
60 
62 
70  okvl_mode get_granted_mode(uint32_t hash, xct_t* xd = nullptr);
71 
105  rc_t lock(uint32_t hash, const okvl_mode& m,
106  bool check, bool wait, bool acquire,
107  xct_t* = nullptr,
108  int timeout = timeout_t::WAIT_SPECIFIED_BY_XCT,
109  RawLock** out = nullptr);
110 
112  rc_t retry_lock(RawLock** lock, bool check_only,
113  int timeout = timeout_t::WAIT_SPECIFIED_BY_XCT);
114 
119 
120  void unlock(RawLock* lock, lsn_t commit_lsn = lsn_t::null);
121 
122  rc_t unlock_duration(bool read_lock_only = false, lsn_t commit_lsn = lsn_t::null);
123 
124  void give_permission_to_violate(lsn_t commit_lsn = lsn_t::null);
125 
126  static void lock_stats(
127  u_long& locks,
128  u_long& acquires,
129  u_long& cache_hits,
130  u_long& unlocks,
131  bool reset);
132 
133  RawXct* allocate_xct();
134 
135  void deallocate_xct(RawXct* xct);
136 
137 private:
138  int _convert_timeout(int timeout);
139 
140  int _convert_timeout(int timeout, xct_t* xd);
141 
142  lock_core_m* core() const {
143  return _core;
144  }
145 
147 };
148 
149 #endif // __LOCK_H
static void on_thread_destroy()
Lock Manager API.See Orthogonal Key Value Locking and Light-weight Intent Lock.
Definition: lock.h:27
rc_t retry_lock(RawLock **lock, bool check_only, int timeout=timeout_t::WAIT_SPECIFIED_BY_XCT)
Definition: lock.cpp:128
lil_global_table * get_lil_global_table()
Definition: lock.cpp:45
Lock table implementation class.
Definition: lock_core.h:31
int _convert_timeout(int timeout)
Definition: lock.cpp:61
void dump(ostream &o)
Unsafely dump the lock hash table (for debugging).
Definition: lock.cpp:39
Definition: lock_lil.h:147
A shadow transaction object for RAW-style lock manager.
Definition: lock_raw.h:469
A transaction. Internal to the storage manager.This class may be used in a limited way for the handli...
Definition: xct.h:185
uint32_t StoreID
Definition: basics.h:47
RawXct * allocate_xct()
Definition: lock.cpp:212
~lock_m()
Definition: lock.cpp:27
Start-up parameters for the storage engine. See OPTIONS.
Definition: sm_options.h:24
static const lsn_t null
Definition: lsn.h:371
Locking-related status of one transaction.
Definition: lock_x.h:127
element_lock_mode
Lock mode for one OKVL component (key, partition, or gap).
Definition: w_okvl.h:107
void unlock(RawLock *lock, lsn_t commit_lsn=lsn_t::null)
Definition: lock.cpp:144
void deallocate_xct(RawXct *xct)
Definition: lock.cpp:216
void assert_empty() const
Unsafely check that the lock table is empty for debugging and assertions at shutdown, when MT-safety shouldn't be an issue.
Definition: lock.cpp:23
void stats(u_long &buckets_used, u_long &max_bucket_len, u_long &min_bucket_len, u_long &mode_bucket_len, float &avg_bucket_len, float &var_bucket_len, float &std_bucket_len) const
Log Sequence Number. See Log Sequence Numbers (LSN).
Definition: lsn.h:243
An RAW-style lock entry in the queue.
Definition: lock_raw.h:133
static constexpr int WAIT_SPECIFIED_BY_XCT
Definition: timeout.h:30
Return code for most functions and methods.
Definition: w_rc.h:87
static void on_thread_init()
Operating system error Malloc Mmap could not map aligned memory Internal error Timed out waiting for resource Bad file descriptor for I O or close Short I O Internal error Feature is not implemented User initiated abort Out of disk space Item not found Invalid volume ID Device is too large for OS file interface Device is not mounted Volume already exists Too many volumes Duplicate entries found Maximum number of stores already created Out of log space Record will not fit Bad save point Bad argument or combination of arguments to function Multiple update threads not allowed for this operation In active Logging is turned off cannot roll back Transaction is not participating in external phase commit Lock timeout Attempt to acquire maintain latch in Q mode failed Need parent and child page fixed in SH or EX modes Deadlock detected Retry the but had some Retry related to locks(used internally)") X(eTOOMANYRETRY
Represents a lock mode of one key entry in the OKVL lock manager.
Definition: w_okvl.h:95
lock_core_m * core() const
Definition: lock.h:142
okvl_mode get_granted_mode(uint32_t hash, xct_t *xd=nullptr)
Returns the lock granted to the given transaction for this lock.
Definition: lock.cpp:49
xct_t * xct()
Definition: smthread.h:575
rc_t lock(uint32_t hash, const okvl_mode &m, bool check, bool wait, bool acquire, xct_t *=nullptr, int timeout=timeout_t::WAIT_SPECIFIED_BY_XCT, RawLock **out=nullptr)
Acquires a lock of the given mode (or stronger)
Definition: lock.cpp:89
lock_core_m * _core
Definition: lock.h:146
rc_t unlock_duration(bool read_lock_only=false, lsn_t commit_lsn=lsn_t::null)
Definition: lock.cpp:185
lock_m(const sm_options &options)
Definition: lock.cpp:17
rc_t intent_store_lock(StoreID stid, okvl_mode::element_lock_mode m)
Definition: lock.cpp:164
static void lock_stats(u_long &locks, u_long &acquires, u_long &cache_hits, u_long &unlocks, bool reset)
void give_permission_to_violate(lsn_t commit_lsn=lsn_t::null)
Definition: lock.cpp:202