CUBRID Engine  latest
lockfree_transaction_table.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 //
20 // lockfree_transaction_table.hpp
21 //
22 // Each lock-free data structure needs a transaction table to safely reclaim retired nodes. The table must be part
23 // of a system (which dictates how many transactions are possible). It maintains two important cursors: the global
24 // transaction ID and the minimum active transaction ID.
25 //
26 // Whenever a transaction starts, it is assigned the global transaction ID. Whenever a node is retired, the global
27 // ID is incremented.
28 //
29 // The minimum active transaction ID is computed by checking all table transaction descriptors. Only when the minimum
30 // active transaction ID exceeds the ID of a deleted hazard pointer, it is safe to remove the pointer.
31 //
32 // See lockfree_transaction_system.hpp description for an overview of the lock-free transaction implementation.
33 //
34 
35 #ifndef _LOCKFREE_TRANSACTION_TABLE_HPP_
36 #define _LOCKFREE_TRANSACTION_TABLE_HPP_
37 
39 
40 #include <atomic>
41 #include <mutex>
42 
43 // forward definitions
44 namespace lockfree
45 {
46  namespace tran
47  {
48  class system;
49  class descriptor;
50  }
51 }
52 
53 namespace lockfree
54 {
55  namespace tran
56  {
57  class table
58  {
59  public:
60  table (system &sys);
61  ~table ();
62 
63  descriptor &get_descriptor (const index &tran_index);
64 
65  void start_tran (const index &tran_index);
66  void end_tran (const index &tran_index);
67 
68  id get_current_global_tranid () const;
69  id get_new_global_tranid ();
70  id get_min_active_tranid () const;
71 
72  size_t get_total_retire_count () const;
73  size_t get_total_reclaim_count () const;
74  size_t get_current_retire_count () const;
75 
76  private:
77  /* number of transactions between computing min_active_transaction_id */
78  static const id MATI_REFRESH_INTERVAL = 100;
79 
80  void compute_min_active_tranid ();
81 
84  std::atomic<id> m_global_tranid; /* global delete ID for all delete operations */
85  std::atomic<id> m_min_active_tranid; /* minimum curr_delete_id of all used LF_DTRAN_ENTRY entries */
86  };
87  } // namespace tran
88 } // namespace lockfree
89 
90 #endif // _LOCKFREE_TRANSACTION_TABLE_HPP_