File: primary_election_invocation_handler.h

package info (click to toggle)
mysql-8.0 8.0.45-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,048 kB
  • sloc: cpp: 4,685,434; ansic: 412,712; pascal: 108,396; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; python: 21,816; sh: 17,285; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,083; makefile: 1,793; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (196 lines) | stat: -rw-r--r-- 6,874 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* Copyright (c) 2018, 2025, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is designed to work with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have either included with
   the program or referenced in the documentation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#ifndef PRIMARY_ELECTION_INVOCATION_HANDLER_INCLUDED
#define PRIMARY_ELECTION_INVOCATION_HANDLER_INCLUDED

#include <string>
#include <vector>

#include "plugin/group_replication/include/member_info.h"
#include "plugin/group_replication/include/plugin_handlers/primary_election_include.h"
#include "plugin/group_replication/include/plugin_handlers/primary_election_primary_process.h"
#include "plugin/group_replication/include/plugin_handlers/primary_election_secondary_process.h"
#include "plugin/group_replication/include/plugin_messages/single_primary_message.h"
#include "plugin/group_replication/include/plugin_observers/group_transaction_observation_manager.h"

/**
  @class Primary_election_handler
  The base class to request and execute an election
*/
class Primary_election_handler {
 public:
  /**
    Instantiate a new election handler
    @param[in] components_stop_timeout  the timeout when waiting on shutdown
  */
  Primary_election_handler(ulong components_stop_timeout);

  /** Class destructor */
  ~Primary_election_handler();

  /**
    Send a message to all members requesting an election

    @param primary_uuid  the primary member to elect
    @param mode          the election mode to use
  */
  int request_group_primary_election(std::string primary_uuid,
                                     enum_primary_election_mode mode);

  /**
    Handle new received primary message of type SINGLE_PRIMARY_PRIMARY_ELECTION
    @param message The received primary message
    @param notification_ctx the notification object to report changes
    @return !=0 in case of error
  */
  int handle_primary_election_message(Single_primary_message *message,
                                      Notification_context *notification_ctx);

  /**
    Execute the primary member selection if needed and the election algorithm
    invocation.

    @param primary_uuid  the primary member to elect
    @param mode          the election mode to use
    @param notification_ctx the notification object to report changes

    @return !=0 in case of error
  */
  int execute_primary_election(std::string &primary_uuid,
                               enum_primary_election_mode mode,
                               Notification_context *notification_ctx);

  /**
    Print server executed GTID and applier retrieved GTID in logs.
  */
  void print_gtid_info_in_log();

  /**
    Is an election process running?
    @return true if yes, false if no
  */
  bool is_an_election_running();

  /**
   Sets if the election process is running or not
   @param election_running is the election running or not
  */
  void set_election_running(bool election_running);

  /**
    End any running election process.
    @return !=0 in case of error
  */
  int terminate_election_process();

  // Consistency transaction manager notifiers
  /**
    Notify transaction consistency manager that election is running
  */
  void notify_election_running();

  /**
    Notify transaction consistency manager that election ended
  */
  void notify_election_end();

  /**
    Sets the component stop timeout.

    @param[in]  timeout      the timeout
  */
  void set_stop_wait_timeout(ulong timeout);

 private:
  /**
    Get the member to elect from all group members.
    This method returns the current primary if one exists
    If no primary exists this method returns one of the lowest version present
    in the group according to a weight or uuid criteria.

    @param[out] primary_uuid  the primary member to elect
    @param[in]  all_members_info The members currently in the group

    @return true if a primary is found, false otherwise
  */
  bool pick_primary_member(std::string &primary_uuid,
                           Group_member_info_list *all_members_info);

  /**
  Execute the standard primary election algorithm (that supports primary
  appointments)

    @param primary_uuid  the primary member to elect
    @param mode          the election mode to use
  */
  int internal_primary_election(std::string &primary_uuid,
                                enum_primary_election_mode mode);

  /**
    Execute the legacy (<8.0.12) primary election algorithm

    @param primary_uuid  the primary member to elect
  */
  int legacy_primary_election(std::string &primary_uuid);

  /** The handler to handle the election on the primary member */
  Primary_election_primary_process primary_election_handler;

  /** The handler to handle the election in the secondary members */
  Primary_election_secondary_process secondary_election_handler;

  /** Is an election running? */
  bool election_process_running;

  /** The lock for the running flag*/
  mysql_mutex_t flag_lock;
};

/**
  Sort lower version members based on member weight if member version
  is greater than equal to PRIMARY_ELECTION_MEMBER_WEIGHT_VERSION or uuid.

  @param all_members_info    the vector with members info
  @param lowest_version_end  first iterator position where members version
                             increases.
*/
void sort_members_for_election(
    Group_member_info_list *all_members_info,
    Group_member_info_list_iterator lowest_version_end);

/**
  Sort members based on member_version and get first iterator position
  where member version differs.

  @param all_members_info    the vector with members info

  @return  the first iterator position where members version increase.

  @note from the start of the list to the returned iterator, all members have
        the lowest version in the group.
 */
Group_member_info_list_iterator sort_and_get_lowest_version_member_position(
    Group_member_info_list *all_members_info);

#endif /* PRIMARY_ELECTION_INVOCATION_HANDLER_INCLUDED */