MySQL 8.0.29
Source Code Documentation
rpl_mta_submode.h
Go to the documentation of this file.
1/* Copyright (c) 2013, 2021, 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 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#ifndef MTA_SUBMODE_H
23#define MTA_SUBMODE_H
24
25#include <stddef.h>
26#include <sys/types.h>
27#include <atomic>
28#include <set>
29#include <utility>
30
31#include "libbinlogevents/include/binlog_event.h" // SEQ_UNINIT
32#include "log_event.h"
33#include "my_inttypes.h"
34#include "my_thread_local.h" // my_thread_id
35#include "prealloced_array.h" // Prealloced_array
36
37class Log_event;
38class Query_log_event;
39class Relay_log_info;
40class Slave_worker;
41class THD;
42struct TABLE;
43
45
47 /* Parallel slave based on Database name */
49 /* Parallel slave based on group information from Binlog group commit */
51};
52
53// Extend the following class as per requirement for each sub mode
55 private:
56 protected:
57 /* Parallel type */
59
60 public:
61 Mts_submode() = default;
63 // pure virtual methods. Should be extended in the derieved class
64
65 /* Logic to schedule the next event. called at the B event for each
66 transaction */
67 virtual int schedule_next_event(Relay_log_info *rli, Log_event *ev) = 0;
68
69 /* logic to attach temp tables Should be extended in the derieved class */
70 virtual void attach_temp_tables(THD *thd, const Relay_log_info *rli,
71 Query_log_event *ev) = 0;
72
73 /* logic to detach temp tables. Should be extended in the derieved class */
74 virtual void detach_temp_tables(THD *thd, const Relay_log_info *rli,
75 Query_log_event *ev) = 0;
76
77 /* returns the least occupied worker. Should be extended in the derieved class
78 */
81 Log_event *ev) = 0;
82 /* wait for slave workers to finish */
84 Slave_worker *ignore = nullptr) = 0;
85
86 /**
87 Sets additional context before the event is set to execute.
88 */
90 Log_event &) {
91 return false;
92 }
93
94 virtual ~Mts_submode() = default;
95};
96
97/**
98 DB partitioned submode
99 For significance of each method check definition of Mts_submode
100*/
102 public:
104 int schedule_next_event(Relay_log_info *rli, Log_event *ev) override;
105 void attach_temp_tables(THD *thd, const Relay_log_info *rli,
106 Query_log_event *ev) override;
107 void detach_temp_tables(THD *thd, const Relay_log_info *rli,
108 Query_log_event *ev) override;
111 Log_event *) override;
112 ~Mts_submode_database() override = default;
114 Slave_worker *ignore = nullptr) override;
116 Log_event &ev) override;
117
118 private:
121 std::vector<Log_event *> &events);
122};
123
124/**
125 Parallelization using Master parallelization information
126 For significance of each method check definition of Mts_submode
127 */
129 private:
133 /* "instant" value of committed transactions low-water-mark */
134 std::atomic<longlong> last_lwm_timestamp;
135 /* GAQ index corresponding to the min commit point */
139
140 public:
143 /*
144 the logical timestamp of the olderst transaction that is being waited by
145 before to resume scheduling.
146 */
147 std::atomic<longlong> min_waited_timestamp;
148 /*
149 Committed transactions and those that are waiting for their commit parents
150 comprise sequences whose items are identified as GAQ index.
151 An empty sequence is described by the following magic value which can't
152 be in the GAQ legitimate range.
153 todo: an alternative could be to pass a magic value to the constructor.
154 E.g GAQ.size as a good candidate being outside of the valid range.
155 That requires further wl6314 refactoring in activation/deactivation
156 of the scheduler.
157 */
158 static const ulong INDEX_UNDEF = (ulong)-1;
159
160 protected:
161 std::pair<uint, my_thread_id> get_server_and_thread_id(TABLE *table);
163
164 public:
166 int schedule_next_event(Relay_log_info *rli, Log_event *ev) override;
167 void attach_temp_tables(THD *thd, const Relay_log_info *rli,
168 Query_log_event *ev) override;
169 void detach_temp_tables(THD *thd, const Relay_log_info *rli,
170 Query_log_event *) override;
173 Log_event *ev) override;
174 /* Sets the force new group variable */
175 inline void start_new_group() {
176 force_new_group = true;
177 first_event = true;
178 }
179 /**
180 Withdraw the delegated_job increased by the group.
181 */
184 Slave_worker *ignore = nullptr) override;
186 longlong last_committed_arg);
187 /*
188 LEQ comparison of two logical timestamps follows regular rules for
189 integers. SEQ_UNINIT is regarded as the least value in the clock domain.
190
191 @param a the lhs logical timestamp value
192 @param b the rhs logical timestamp value
193
194 @return true when a "<=" b,
195 false otherwise
196 */
197 static bool clock_leq(longlong a, longlong b) {
198 if (a == SEQ_UNINIT)
199 return true;
200 else if (b == SEQ_UNINIT)
201 return false;
202 else
203 return a <= b;
204 }
205
206 longlong get_lwm_timestamp(Relay_log_info *rli, bool need_lock);
208 ~Mts_submode_logical_clock() override = default;
209};
210
211#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:659
DB partitioned submode For significance of each method check definition of Mts_submode.
Definition: rpl_mta_submode.h:101
bool unfold_transaction_payload_event(Format_description_event &fde, Transaction_payload_log_event &tple, std::vector< Log_event * > &events)
Definition: rpl_mta_submode.cc:186
Mts_submode_database()
Definition: rpl_mta_submode.h:103
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:318
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:74
~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:116
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:392
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:229
int schedule_next_event(Relay_log_info *rli, Log_event *ev) override
Does necessary arrangement before scheduling next event.
Definition: rpl_mta_submode.cc:66
Parallelization using Master parallelization information For significance of each method check defini...
Definition: rpl_mta_submode.h:128
Slave_worker * get_free_worker(Relay_log_info *rli)
Protected method to fetch a worker having no events assigned.
Definition: rpl_mta_submode.cc:1001
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:897
ulong last_lwm_index
Definition: rpl_mta_submode.h:136
bool first_event
Definition: rpl_mta_submode.h:130
longlong sequence_number
Definition: rpl_mta_submode.h:138
std::atomic< longlong > last_lwm_timestamp
Definition: rpl_mta_submode.h:134
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:561
bool is_error
Definition: rpl_mta_submode.h:142
~Mts_submode_logical_clock() override=default
uint jobs_done
Definition: rpl_mta_submode.h:141
longlong last_committed
Definition: rpl_mta_submode.h:137
static const ulong INDEX_UNDEF
Definition: rpl_mta_submode.h:158
int schedule_next_event(Relay_log_info *rli, Log_event *ev) override
Does necessary arrangement before scheduling next event.
Definition: rpl_mta_submode.cc:620
static bool clock_leq(longlong a, longlong b)
Definition: rpl_mta_submode.h:197
longlong estimate_lwm_timestamp()
Definition: rpl_mta_submode.h:207
std::atomic< longlong > min_waited_timestamp
Definition: rpl_mta_submode.h:147
bool force_new_group
Definition: rpl_mta_submode.h:130
uint delegated_jobs
Definition: rpl_mta_submode.h:132
void withdraw_delegated_job()
Withdraw the delegated_job increased by the group.
Definition: rpl_mta_submode.h:182
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:818
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:871
Mts_submode_logical_clock()
Definition: rpl_mta_submode.cc:422
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:1066
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:479
bool is_new_group
Definition: rpl_mta_submode.h:131
void start_new_group()
Definition: rpl_mta_submode.h:175
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:1019
Definition: rpl_mta_submode.h:54
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:89
enum_mts_parallel_type type
Definition: rpl_mta_submode.h:58
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:62
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:1385
Definition: rpl_rli.h:201
Definition: rpl_rli_pdb.h:497
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:945
Definition: log_event.h:3740
For binlog version 4.
Definition: control_events.h:230
const int64_t SEQ_UNINIT
Uninitialized timestamp value (for either last committed or sequence number).
Definition: binlog_event.h:138
Binary log event definitions.
Some integer typedefs for easier portability.
long long int longlong
Definition: my_inttypes.h:54
static bool ignore
Definition: mysqlimport.cc:65
Prealloced_array< Slave_worker *, 4 > Slave_worker_array
Definition: rpl_mta_submode.h:42
enum_mts_parallel_type
Definition: rpl_mta_submode.h:46
@ MTS_PARALLEL_TYPE_LOGICAL_CLOCK
Definition: rpl_mta_submode.h:50
@ MTS_PARALLEL_TYPE_DB_NAME
Definition: rpl_mta_submode.h:48
Definition: table.h:1394
unsigned int uint
Definition: uca-dump.cc:29