CUBRID Engine  latest
mvcc_active_tran.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 // MVCC active transactions map
21 //
22 
23 #ifndef _MVCC_ACTIVE_TRAN_HPP_
24 #define _MVCC_ACTIVE_TRAN_HPP_
25 
26 #include "storage_common.h"
27 
28 #include <cassert>
29 #include <cstdint>
30 
32 {
33  public:
36 
37  enum class copy_safety
38  {
41  };
42 
43  void initialize ();
44  void finalize ();
45  void reset ();
46 
48 
49  bool is_active (MVCCID mvccid) const;
50  void copy_to (mvcc_active_tran &dest, copy_safety safety) const;
51  mvcc_active_tran &operator= (const mvcc_active_tran &other) = delete;
52 
55 
56  void set_inactive_mvccid (MVCCID mvccid);
57  void reset_start_mvccid (MVCCID mvccid);
58 
60  void check_valid () const;
61 
62  private:
63  using unit_type = std::uint64_t;
64 
65  static const size_t BITAREA_MAX_SIZE = 500;
66 
67  static const size_t BYTE_BIT_COUNT = 8;
68  static const size_t UNIT_BYTE_COUNT = sizeof (unit_type);
69  static const size_t UNIT_BIT_COUNT = UNIT_BYTE_COUNT * BYTE_BIT_COUNT;
70 
71  static const size_t BITAREA_MAX_MEMSIZE = BITAREA_MAX_SIZE * UNIT_BYTE_COUNT;
72  static const size_t BITAREA_MAX_BITS = BITAREA_MAX_SIZE * UNIT_BIT_COUNT;
73 
74  static const unit_type ALL_ACTIVE = 0;
75  static const unit_type ALL_COMMITTED = (unit_type) -1;
76 
77  /* bit area to store MVCCIDS status - size BITAREA_MAX_SIZE */
79  /* first MVCCID whose status is stored in bit area */
81  /* the area length expressed in bits */
82  volatile size_t m_bit_area_length;
83 
84  /* long time transaction mvccid array */
86  /* long time transactions mvccid array length */
87  volatile size_t m_long_tran_mvccids_length;
88 
90 
91  inline static size_t long_tran_max_size ();
92 
93  inline static size_t bit_size_to_unit_size (size_t bit_count);
94 
95  inline static size_t units_to_bits (size_t unit_count);
96  inline static size_t units_to_bytes (size_t unit_count);
97 
98  inline static unit_type get_mask_of (size_t bit_offset);
99 
100  inline size_t get_bit_offset (MVCCID mvccid) const;
101  inline MVCCID get_mvccid (size_t bit_offset) const;
102  inline unit_type *get_unit_of (size_t bit_offset) const;
103  inline bool is_set (size_t bit_offset) const;
104 
105  size_t get_area_size () const;
106  size_t get_bit_area_memsize () const;
107  size_t get_long_tran_memsize () const;
108 
109  void remove_long_transaction (MVCCID mvccid);
110  void add_long_transaction (MVCCID mvccid);
111  void ltrim_area (size_t trim_size);
112  void set_bitarea_mvccid (MVCCID mvccid);
114 };
115 
116 #endif // !_MVCC_ACTIVE_TRAN_HPP_
size_t get_area_size() const
static const size_t UNIT_BIT_COUNT
std::uint64_t unit_type
MVCCID get_mvccid(size_t bit_offset) const
void reset_start_mvccid(MVCCID mvccid)
static const size_t BITAREA_MAX_BITS
static const unit_type ALL_ACTIVE
unit_type * m_bit_area
void cleanup_migrate_to_long_transations()
static const size_t BYTE_BIT_COUNT
bool is_set(size_t bit_offset) const
MVCCID * m_long_tran_mvccids
static size_t long_tran_max_size()
unit_type * get_unit_of(size_t bit_offset) const
static const size_t UNIT_BYTE_COUNT
static const size_t BITAREA_MAX_SIZE
void set_inactive_mvccid(MVCCID mvccid)
volatile size_t m_long_tran_mvccids_length
MVCCID compute_highest_completed_mvccid() const
void remove_long_transaction(MVCCID mvccid)
static size_t bit_size_to_unit_size(size_t bit_count)
volatile MVCCID m_bit_area_start_mvccid
mvcc_active_tran & operator=(const mvcc_active_tran &other)=delete
UINT64 MVCCID
void check_valid() const
static const unit_type ALL_COMMITTED
size_t get_bit_area_memsize() const
static size_t units_to_bytes(size_t unit_count)
void set_bitarea_mvccid(MVCCID mvccid)
size_t get_long_tran_memsize() const
static const size_t BITAREA_MAX_MEMSIZE
MVCCID get_bit_area_start_mvccid()
MVCCID compute_lowest_active_mvccid() const
bool is_active(MVCCID mvccid) const
void copy_to(mvcc_active_tran &dest, copy_safety safety) const
size_t get_bit_offset(MVCCID mvccid) const
static unit_type get_mask_of(size_t bit_offset)
static size_t units_to_bits(size_t unit_count)
void ltrim_area(size_t trim_size)
volatile size_t m_bit_area_length
void add_long_transaction(MVCCID mvccid)