1 /* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 #include <algorithm> // std::find
24 #include "binlog.h" // mysql_bin_log
25 #include "mysqld.h" // key_rwlock_gtid_mode_lock
26 #include "sql/rpl_gtid.h"
27 #include "sql/rpl_msr.h" // channel_map
28
29 Gtid_mode global_gtid_mode;
30
31 ulong Gtid_mode::sysvar_mode;
32
33 const char *Gtid_mode::names[] = {"OFF", "OFF_PERMISSIVE", "ON_PERMISSIVE",
34 "ON", NullS};
35
36 Checkable_rwlock Gtid_mode::lock{
37 #ifdef HAVE_PSI_INTERFACE
38 key_rwlock_gtid_mode_lock
39 #endif
40 };
41
set(value_type value)42 void Gtid_mode::set(value_type value) {
43 m_atomic_mode.store(value, std::memory_order_release);
44 }
45
get() const46 Gtid_mode::value_type Gtid_mode::get() const {
47 return (value_type)m_atomic_mode.load(std::memory_order_acquire);
48 }
49
50 #ifndef DBUG_OFF
get_string() const51 const char *Gtid_mode::get_string() const { return to_string(get()); }
52 #endif // ifndef DBUG_OFF
53
from_string(const std::string s)54 std::pair<bool, Gtid_mode::value_type> Gtid_mode::from_string(
55 const std::string s) {
56 // Subtract 1 to exclude the null
57 auto end = names + sizeof(names) / sizeof(names[0]) - 1;
58 auto ret = std::find(names, end, s);
59 if (ret == end)
60 return std::pair<bool, Gtid_mode::value_type>(true, OFF);
61 else
62 return std::pair<bool, Gtid_mode::value_type>(
63 false, static_cast<value_type>(ret - names));
64 }
65
to_string(Gtid_mode::value_type value)66 const char *Gtid_mode::to_string(Gtid_mode::value_type value) {
67 return names[value];
68 }
69
operator <<(std::ostream & oss,Gtid_mode::value_type const & mode)70 std::ostream &operator<<(std::ostream &oss, Gtid_mode::value_type const &mode) {
71 oss << Gtid_mode::to_string(mode);
72 return oss;
73 }
74
75 #ifndef DBUG_OFF
operator <<(std::ostream & oss,Gtid_mode const & mode)76 std::ostream &operator<<(std::ostream &oss, Gtid_mode const &mode) {
77 oss << mode.get_string();
78 return oss;
79 }
80 #endif
81