CUBRID Engine  latest
lockfree_transaction_table.cpp
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 
20 
21 #include "lockfree_bitmap.hpp"
24 
25 #include <cassert>
26 
27 namespace lockfree
28 {
29  namespace tran
30  {
31  //
32  // table
33  //
35  : m_sys (sys)
36  , m_all (new descriptor[m_sys.get_max_transaction_count ()] ())
37  , m_global_tranid { 0 }
38  , m_min_active_tranid { 0 }
39  {
40  for (size_t i = 0; i < m_sys.get_max_transaction_count (); i++)
41  {
42  m_all[i].set_table (*this);
43  }
44  }
45 
47  {
48  delete [] m_all;
49  }
50 
51  descriptor &
52  table::get_descriptor (const index &tran_index)
53  {
54  assert (tran_index <= m_sys.get_max_transaction_count ());
55  return m_all[tran_index];
56  }
57 
58  void
59  table::start_tran (const index &tran_index)
60  {
61  get_descriptor (tran_index).start_tran ();
62  }
63 
64  void
65  table::end_tran (const index &tran_index)
66  {
67  get_descriptor (tran_index).end_tran ();
68  }
69 
70  id
72  {
73  id ret = ++m_global_tranid;
74  if (ret % MATI_REFRESH_INTERVAL == 0)
75  {
77  }
78  return ret;
79  }
80 
81  id
83  {
84  return m_global_tranid;
85  }
86 
87  void
89  {
90  // note: all transactions are actually claimed from boot. this code is optimized for this case. if we ever
91  // change how transactions are requested, this must be updated too
92  id minvalue = INVALID_TRANID; // nothing is bigger than INVALID_TRANID
93  for (size_t it = 0; it < m_sys.get_max_transaction_count (); it++)
94  {
95  id tranid = m_all[it].get_transaction_id ();
96  if (minvalue > tranid)
97  {
98  minvalue = tranid;
99  }
100  }
101  m_min_active_tranid.store (minvalue);
102  }
103 
104  id
106  {
107  return m_min_active_tranid;
108  }
109 
110  size_t
112  {
113  size_t total = 0;
114  for (size_t idx = 0; idx < m_sys.get_max_transaction_count (); idx++)
115  {
116  total += m_all[idx].get_total_retire_count ();
117  }
118  return total;
119  }
120 
121  size_t
123  {
124  size_t total = 0;
125  for (size_t idx = 0; idx < m_sys.get_max_transaction_count (); idx++)
126  {
127  total += m_all[idx].get_total_reclaim_count ();
128  }
129  return total;
130  }
131 
132  size_t
134  {
135  size_t total = 0;
136  for (size_t idx = 0; idx < m_sys.get_max_transaction_count (); idx++)
137  {
138  total += m_all[idx].get_current_retire_count ();
139  }
140  return total;
141  }
142  } // namespace tran
143 } // namespace lockfree
#define assert(x)
void end_tran(const index &tran_index)
void start_tran(const index &tran_index)
descriptor & get_descriptor(const index &tran_index)
int i
Definition: dynamic_load.c:954