MySQL 8.0.37
Source Code Documentation
rpl_mta_submode.h
Go to the documentation of this file.
1/* Copyright (c) 2013, 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#ifndef MTA_SUBMODE_H
24#define MTA_SUBMODE_H
25
26#include <stddef.h>
27#include <sys/types.h>
28#include <atomic>
29#include <set>
30#include <utility>
31
32#include "libbinlogevents/include/binlog_event.h" // SEQ_UNINIT
33#include "log_event.h"
34#include "my_inttypes.h"
35#include "my_thread_local.h" // my_thread_id
36#include "prealloced_array.h" // Prealloced_array
37
38class Log_event;
39class Query_log_event;
40class Relay_log_info;
41class Slave_worker;
42class THD;
43struct TABLE;
44
46
48 /* Parallel slave based on Database name */
50 /* Parallel slave based on group information from Binlog group commit */
52};
53
54// Extend the following class as per requirement for each sub mode
56 private:
57 protected:
58 /* Parallel type */
60
61 public:
62 Mts_submode() = default;
64 // pure virtual methods. Should be extended in the derieved class
65
66 /* Logic to schedule the next event. called at the B event for each
67 transaction */
68 virtual int schedule_next_event(Relay_log_info *rli, Log_event *ev) = 0;
69
70 /* logic to attach temp tables Should be extended in the derieved class */
71 virtual void attach_temp_tables(THD *thd, const Relay_log_info *rli,
72 Query_log_event *ev) = 0;
73
74 /* logic to detach temp tables. Should be extended in the derieved class */
75 virtual void detach_temp_tables(THD *thd, const Relay_log_info *rli,
76 Query_log_event *ev) = 0;
77
78 /* returns the least occupied worker. Should be extended in the derieved class
79 */
82 Log_event *ev) = 0;
83 /* wait for slave workers to finish */
85 Slave_worker *ignore = nullptr) = 0;
86
87 /**
88 Sets additional context before the event is set to execute.
89 */
91 Log_event &) {
92 return false;
93 }
94
95 virtual ~Mts_submode() = default;
96};
97
98/**
99 DB partitioned submode
100 For significance of each method check definition of Mts_submode
101*/
103 public:
105 int schedule_next_event(Relay_log_info *rli, Log_event *ev) override;
106 void attach_temp_tables(THD *thd, const Relay_log_info *rli,
107 Query_log_event *ev) override;
108 void detach_temp_tables(THD *thd, const Relay_log_info *rli,
109 Query_log_event *ev) override;
112 Log_event *) override;
113 ~Mts_submode_database() override = default;
115 Slave_worker *ignore = nullptr) override;
117 Log_event &ev) override;
118
119 private:
122 std::vector<Log_event *> &events);
123};
124
125/**
126 Parallelization using Master parallelization information
127 For significance of each method check definition of Mts_submode
128 */
130 private:
134 /* "instant" value of committed transactions low-water-mark */
135 std::atomic<longlong> last_lwm_timestamp;
136 /* GAQ index corresponding to the min commit point */
140
141 public:
144 /*
145 the logical timestamp of the olderst transaction that is being waited by
146 before to resume scheduling.
147 */
148 std::atomic<longlong> min_waited_timestamp;
149 /*
150 Committed transactions and those that are waiting for their commit parents
151 comprise sequences whose items are identified as GAQ index.
152 An empty sequence is described by the following magic value which can't
153 be in the GAQ legitimate range.
154 todo: an alternative could be to pass a magic value to the constructor.
155 E.g GAQ.size as a good candidate being outside of the valid range.
156 That requires further wl6314 refactoring in activation/deactivation
157 of the scheduler.
158 */
159 static const ulong INDEX_UNDEF = (ulong)-1;
160
161 protected:
162 std::pair<uint, my_thread_id> get_server_and_thread_id(TABLE *table);
164
165 public:
167 int schedule_next_event(Relay_log_info *rli, Log_event *ev) override;
168 void attach_temp_tables(THD *thd, const Relay_log_info *rli,
169 Query_log_event *ev) override;
170 void detach_temp_tables(THD *thd, const Relay_log_info *rli,
171 Query_log_event *) override;
174 Log_event *ev) override;
175 /* Sets the force new group variable */
176 inline void start_new_group() {
177 force_new_group = true;
178 first_event = true;
179 }
180 /**
181 Withdraw the delegated_job increased by the group.
182 */
185 Slave_worker *ignore = nullptr) override;
187 longlong last_committed_arg);
188 /*
189 LEQ comparison of two logical timestamps follows regular rules for
190 integers. SEQ_UNINIT is regarded as the least value in the clock domain.
191
192 @param a the lhs logical timestamp value
193 @param b the rhs logical timestamp value
194
195 @return true when a "<=" b,
196 false otherwise
197 */
198 static bool clock_leq(longlong a, longlong b) {
199 if (a == SEQ_UNINIT)
200 return true;
201 else if (b == SEQ_UNINIT)
202 return false;
203 else
204 return a <= b;
205 }
206
207 longlong get_lwm_timestamp(Relay_log_info *rli, bool need_lock);
209 ~Mts_submode_logical_clock() override = default;
210};
211
212#endif /*MTA_SUBMODE_H*/
Contains the classes representing events occurring in the replication stream.
This is the abstract base class for binary log events.
Definition: log_event.h:541
DB partitioned submode For significance of each method check definition of Mts_submode.
Definition: rpl_mta_submode.h:102
bool unfold_transaction_payload_event(Format_description_event &fde, Transaction_payload_log_event &tple, std::vector< Log_event * > &events)
Mts_submode_database()
Definition: rpl_mta_submode.h:104
void detach_temp_tables(THD *thd, const Relay_log_info *rli, Query_log_event *ev) override
Logic to detach the temporary tables from the worker threads upon event execution.
Definition: rpl_mta_submode.cc:272
void attach_temp_tables(THD *thd, const Relay_log_info *rli, Query_log_event *ev) override
Logic to attach temporary tables.
Definition: rpl_mta_submode.cc:75
~Mts_submode_database() override=default
int wait_for_workers_to_finish(Relay_log_info *rli, Slave_worker *ignore=nullptr) override
Function is called by Coordinator when it identified an event requiring sequential execution.
Definition: rpl_mta_submode.cc:117
Slave_worker * get_least_occupied_worker(Relay_log_info *, Slave_worker_array *ws, Log_event *) override
Logic to get least occupied worker when the sql mts_submode= database.
Definition: rpl_mta_submode.cc:346
bool set_multi_threaded_applier_context(const Relay_log_info &rli, Log_event &ev) override
Sets additional context before the event is set to execute.
Definition: rpl_mta_submode.cc:187
int schedule_next_event(Relay_log_info *rli, Log_event *ev) override
Does necessary arrangement before scheduling next event.
Definition: rpl_mta_submode.cc:67
Parallelization using Master parallelization information For significance of each method check defini...
Definition: rpl_mta_submode.h:129
Slave_worker * get_free_worker(Relay_log_info *rli)
Protected method to fetch a worker having no events assigned.
Definition: rpl_mta_submode.cc:955
Slave_worker * get_least_occupied_worker(Relay_log_info *rli, Slave_worker_array *ws, Log_event *ev) override
Logic to get least occupied worker when the sql mts_submode= master_parallel.
Definition: rpl_mta_submode.cc:851
ulong last_lwm_index
Definition: rpl_mta_submode.h:137
bool first_event
Definition: rpl_mta_submode.h:131
longlong sequence_number
Definition: rpl_mta_submode.h:139
std::atomic< longlong > last_lwm_timestamp
Definition: rpl_mta_submode.h:135
bool wait_for_last_committed_trx(Relay_log_info *rli, longlong last_committed_arg)
The method implements logical timestamp conflict detection and resolution through waiting by the call...
Definition: rpl_mta_submode.cc:515
bool is_error
Definition: rpl_mta_submode.h:143
~Mts_submode_logical_clock() override=default
uint jobs_done
Definition: rpl_mta_submode.h:142
longlong last_committed
Definition: rpl_mta_submode.h:138
static const ulong INDEX_UNDEF
Definition: rpl_mta_submode.h:159
int schedule_next_event(Relay_log_info *rli, Log_event *ev) override
Does necessary arrangement before scheduling next event.
Definition: rpl_mta_submode.cc:574
static bool clock_leq(longlong a, longlong b)
Definition: rpl_mta_submode.h:198
longlong estimate_lwm_timestamp()
Definition: rpl_mta_submode.h:208
std::atomic< longlong > min_waited_timestamp
Definition: rpl_mta_submode.h:148
bool force_new_group
Definition: rpl_mta_submode.h:131
uint delegated_jobs
Definition: rpl_mta_submode.h:133
void withdraw_delegated_job()
Withdraw the delegated_job increased by the group.
Definition: rpl_mta_submode.h:183
void attach_temp_tables(THD *thd, const Relay_log_info *rli, Query_log_event *ev) override
Logic to attach the temporary tables from the worker threads upon event execution.
Definition: rpl_mta_submode.cc:772
void detach_temp_tables(THD *thd, const Relay_log_info *rli, Query_log_event *) override
Logic to detach the temporary tables from the worker threads upon event execution.
Definition: rpl_mta_submode.cc:825
Mts_submode_logical_clock()
Definition: rpl_mta_submode.cc:376
std::pair< uint, my_thread_id > get_server_and_thread_id(TABLE *table)
Protected method to fetch the server_id and pseudo_thread_id from a temporary table.
Definition: rpl_mta_submode.cc:1020
longlong get_lwm_timestamp(Relay_log_info *rli, bool need_lock)
The method finds the minimum logical timestamp (low-water-mark) of committed transactions.
Definition: rpl_mta_submode.cc:433
bool is_new_group
Definition: rpl_mta_submode.h:132
void start_new_group()
Definition: rpl_mta_submode.h:176
int wait_for_workers_to_finish(Relay_log_info *rli, Slave_worker *ignore=nullptr) override
Waits for slave workers to finish off the pending tasks before returning.
Definition: rpl_mta_submode.cc:973
Definition: rpl_mta_submode.h:55
virtual ~Mts_submode()=default
virtual bool set_multi_threaded_applier_context(const Relay_log_info &, Log_event &)
Sets additional context before the event is set to execute.
Definition: rpl_mta_submode.h:90
enum_mts_parallel_type type
Definition: rpl_mta_submode.h:59
virtual void attach_temp_tables(THD *thd, const Relay_log_info *rli, Query_log_event *ev)=0
enum_mts_parallel_type get_type()
Definition: rpl_mta_submode.h:63
virtual int schedule_next_event(Relay_log_info *rli, Log_event *ev)=0
virtual void detach_temp_tables(THD *thd, const Relay_log_info *rli, Query_log_event *ev)=0
virtual int wait_for_workers_to_finish(Relay_log_info *rli, Slave_worker *ignore=nullptr)=0
Mts_submode()=default
virtual Slave_worker * get_least_occupied_worker(Relay_log_info *rli, Slave_worker_array *ws, Log_event *ev)=0
A Query event is written to the binary log whenever the database is modified on the master,...
Definition: log_event.h:1284
Definition: rpl_rli.h:203
Definition: rpl_rli_pdb.h:498
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: log_event.h:3711
For binlog version 4.
Definition: control_events.h:231
const int64_t SEQ_UNINIT
Uninitialized timestamp value (for either last committed or sequence number).
Definition: binlog_event.h:147
Binary log event definitions.
Some integer typedefs for easier portability.
long long int longlong
Definition: my_inttypes.h:55
static bool ignore
Definition: mysqlimport.cc:66
Prealloced_array< Slave_worker *, 4 > Slave_worker_array
Definition: rpl_mta_submode.h:43
enum_mts_parallel_type
Definition: rpl_mta_submode.h:47
@ MTS_PARALLEL_TYPE_LOGICAL_CLOCK
Definition: rpl_mta_submode.h:51
@ MTS_PARALLEL_TYPE_DB_NAME
Definition: rpl_mta_submode.h:49
Definition: table.h:1398
unsigned int uint
Definition: uca9-dump.cc:75