MySQL 8.4.2
Source Code Documentation
locked_sidno_set.h
Go to the documentation of this file.
1// Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24#ifndef CHANGESTREAMS_INDEX_LOCKED_SIDNO_SET_H_INCLUDED
25#define CHANGESTREAMS_INDEX_LOCKED_SIDNO_SET_H_INCLUDED
26
27#include <functional>
28#include <set>
30#include "sql/rpl_gtid.h"
31
32class Gtid_state;
33
34namespace cs::index {
35
36/// @brief Set that keeps track of TSID locks taken in the current scope.
37/// Provides dead-lock free mechanism for added sidnos, as sidnos are ordered
38/// in the set insuring a deterministic lock order
39/// Locks are added to the set by execution of the add_lock_for_sidno.
40/// Later, the user may call lock(), which will lock all recorded sidno locks.
41/// Locks will be released in destructor.
42/// @details Used to optimize TSID locking/unlocking scheme (e.g. in
43/// assign_automatic_gtids_to_flush_group) to avoid constant locking/unlocking
44/// of TSID locks during the commit flush stage
46 public:
49
50 /// @brief Adds a given sidno to the internal set, does not acquire ownership
51 /// @param sidno TSID being considered
52 /// @details may be called several times for one sidno
53 void add_lock_for_sidno(rpl_sidno sidno);
54
55 /// @brief Locks recorded sidno locks, in order. In case set is already
56 /// locked, function does not take any action
57 void lock();
58
59 /// @brief Destructor, releases all locks kept in the set
61
62 protected:
63 using Set_type = std::set<rpl_sidno>; ///< Type of the set used
64 Set_type m_sidno_set; ///< SIDs for which lock will be acquired
65 std::reference_wrapper<Gtid_state>
66 m_gtid_state; ///< Reference to the current Gtid_state object (avoids
67 ///< using the global gtid_state variable in the class)
68 bool m_locked = false; ///< Is set currently locked?
69};
70
71} // namespace cs::index
72
73#endif // CHANGESTREAMS_INDEX_LOCKED_SIDNO_SET_H_INCLUDED
Represents the server's GTID state: the set of committed GTIDs, the set of lost gtids,...
Definition: rpl_gtid.h:2853
Set that keeps track of TSID locks taken in the current scope.
Definition: locked_sidno_set.h:45
void add_lock_for_sidno(rpl_sidno sidno)
Adds a given sidno to the internal set, does not acquire ownership.
Definition: locked_sidno_set.cc:31
Set_type m_sidno_set
SIDs for which lock will be acquired.
Definition: locked_sidno_set.h:64
bool m_locked
Is set currently locked?
Definition: locked_sidno_set.h:68
Locked_sidno_set(Locked_sidno_set &src)=delete
void lock()
Locks recorded sidno locks, in order.
Definition: locked_sidno_set.cc:36
std::set< rpl_sidno > Set_type
Type of the set used.
Definition: locked_sidno_set.h:63
std::reference_wrapper< Gtid_state > m_gtid_state
Reference to the current Gtid_state object (avoids using the global gtid_state variable in the class)
Definition: locked_sidno_set.h:66
Locked_sidno_set(Gtid_state &gtid_state)
Definition: locked_sidno_set.cc:28
~Locked_sidno_set()
Destructor, releases all locks kept in the set.
Definition: locked_sidno_set.cc:45
Gtid_state * gtid_state
Global state of GTIDs.
Definition: mysqld.cc:1826
Definition: locked_sidno_set.cc:26
int rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: sidno.h:27