forked from kunpengcompute/mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpl_rli.h
2372 lines (1998 loc) · 84.5 KB
/
rpl_rli.h
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
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 also distributed 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 included with MySQL.
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 RPL_RLI_H
#define RPL_RLI_H
#if defined(__SUNPRO_CC)
/*
Solaris Studio 12.5 has a bug where, if you use dynamic_cast
and then later #include this file (which Boost does), you will
get a compile error. Work around it by just including it right now.
*/
#include <cxxabi.h>
#endif
#include <sys/types.h>
#include <time.h>
#include <atomic>
#include <memory>
#include <string>
#include <vector>
#include "lex_string.h"
#include "libbinlogevents/include/binlog_event.h"
#include "m_string.h"
#include "map_helpers.h"
#include "my_bitmap.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_loglevel.h"
#include "my_psi_config.h"
#include "my_sys.h"
#include "mysql/components/services/mysql_cond_bits.h"
#include "mysql/components/services/mysql_mutex_bits.h"
#include "mysql/components/services/psi_mutex_bits.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/thread_type.h"
#include "prealloced_array.h" // Prealloced_array
#include "sql/binlog.h" // MYSQL_BIN_LOG
#include "sql/log_event.h" //Gtid_log_event
#include "sql/psi_memory_key.h"
#include "sql/query_options.h"
#include "sql/rpl_gtid.h" // Gtid_set
#include "sql/rpl_info.h" // Rpl_info
#include "sql/rpl_mts_submode.h" // enum_mts_parallel_type
#include "sql/rpl_slave_until_options.h"
#include "sql/rpl_tblmap.h" // table_mapping
#include "sql/rpl_trx_boundary_parser.h"
#include "sql/rpl_utility.h" // Deferred_log_events
#include "sql/sql_class.h" // THD
#include "sql/system_variables.h"
#include "sql/table.h"
class Commit_order_manager;
class Master_info;
class Rpl_filter;
class Rpl_info_handler;
class Slave_committed_queue;
class Slave_worker;
class String;
struct LEX_MASTER_INFO;
struct db_worker_hash_entry;
extern uint sql_slave_skip_counter;
typedef Prealloced_array<Slave_worker *, 4> Slave_worker_array;
typedef struct slave_job_item {
Log_event *data;
uint relay_number;
my_off_t relay_pos;
} Slave_job_item;
/*******************************************************************************
Replication SQL Thread
Relay_log_info contains:
- the current relay log
- the current relay log offset
- master log name
- master log sequence corresponding to the last update
- misc information specific to the SQL thread
Relay_log_info is initialized from a repository, i.e. table or file, if there is
one. Otherwise, data members are intialized with defaults by calling
init_relay_log_info().
The relay.info table/file shall be updated whenever: (i) the relay log file
is rotated, (ii) SQL Thread is stopped, (iii) while processing a Xid_log_event,
(iv) after a Query_log_event (i.e. commit or rollback) and (v) after processing
any statement written to the binary log without a transaction context.
The Xid_log_event is a commit for transactional engines and must be handled
differently to provide reliability/data integrity. In this case, positions
are updated within the context of the current transaction. So
. If the relay.info is stored in a transactional repository and the server
crashes before successfully committing the transaction the changes to the
position table will be rolled back along with the data.
. If the relay.info is stored in a non-transactional repository, for instance,
a file or a system table created using MyIsam, and the server crashes before
successfully committing the transaction the changes to the position table
will not be rolled back but data will.
In particular, when there are mixed transactions, i.e a transaction that updates
both transaction and non-transactional engines, the Xid_log_event is still used
but reliability/data integrity cannot be achieved as we shall explain in what
follows.
Changes to non-transactional engines, such as MyIsam, cannot be rolled back if a
failure happens. For that reason, there is no point in updating the positions
within the boundaries of any on-going transaction. This is true for both commit
and rollback. If a failure happens after processing the pseudo-transaction but
before updating the positions, the transaction will be re-executed when the
slave is up most likely causing an error that needs to be manually circumvented.
This is a well-known issue when non-transactional statements are executed.
Specifically, if rolling back any transaction, positions are updated outside the
transaction boundaries. However, there may be a problem in this scenario even
when only transactional engines are updated. This happens because if there is a
rollback and such transaction is written to the binary log, a non-transactional
engine was updated or a temporary table was created or dropped within its
boundaries.
In particular, in both STATEMENT and MIXED logging formats, this happens because
any temporary table is automatically dropped after a shutdown/startup.
See BUG#26945 for further details.
Statements written to the binary log outside the boundaries of a transaction are
DDLs or maintenance commands which are not transactional. These means that they
cannot be rolled back if a failure happens. In such cases, the positions are
updated after processing the events. If a failure happens after processing the
statement but before updating the positions, the statement will be
re-executed when the slave is up most likely causing an error that needs to be
manually circumvented. This is a well-known issue when non-transactional
statements are executed.
The --sync-relay-log-info does not have effect when a system table, either
transactional or non-transactional is used.
To correctly recovery from failures, one should combine transactional system
tables along with the --relay-log-recovery.
*******************************************************************************/
class Relay_log_info : public Rpl_info {
friend class Rpl_info_factory;
public:
/**
Set of possible return values for the member methods related to
`PRIVILEGE_CHECKS_USER` management.
*/
enum class enum_priv_checks_status : int {
/** Function ended successfully */
SUCCESS = 0,
/** Value for user is anonymous (''@'...') */
USER_ANONYMOUS,
/** Value for the username part of the user is larger than 32 characters */
USERNAME_TOO_LONG,
/** Value for the hostname part of the user is larger than 255 characters */
HOSTNAME_TOO_LONG,
/** Value for the hostname part of the user has illegal characters */
HOSTNAME_SYNTAX_ERROR,
/**
Value for the username part of the user is NULL but the value for the
hostname is not NULL.
*/
USERNAME_NULL_HOSTNAME_NOT_NULL,
/**
Provided user doesn't exists.
*/
USER_DOES_NOT_EXIST,
/**
Provided user doesn't have the necesary privileges to execute the needed
operations.
*/
USER_DOES_NOT_HAVE_PRIVILEGES,
/** Values provided for the internal variables are corrupted. */
USER_DATA_CORRUPTED,
/**
Provided user doesn't have `FILE` privileges during the execution of a
`LOAD DATA`event.
*/
LOAD_DATA_EVENT_NOT_ALLOWED
};
enum class enum_require_row_status : int {
/** Function ended successfully */
SUCCESS = 0,
/** Value for `privilege_checks_user` is not empty */
PRIV_CHECKS_USER_NOT_NULL
};
/*
The per-channel filter associated with this RLI
*/
Rpl_filter *rpl_filter;
/**
Flags for the state of the replication.
*/
enum enum_state_flag {
/** The replication thread is inside a statement */
IN_STMT,
/** Flag counter. Should always be last */
STATE_FLAGS_COUNT
};
/**
Identifies what is the slave policy on primary keys in tables.
*/
enum enum_require_table_primary_key {
/**No policy, used on PFS*/
PK_CHECK_NONE = 0,
/**
The slave sets the value of sql_require_primary_key according to
the source replicated value.
*/
PK_CHECK_STREAM = 1,
/** The slave enforces tables to have primary keys for a given channel*/
PK_CHECK_ON = 2,
/** The slave does not enforce any policy around primary keys*/
PK_CHECK_OFF = 3
};
/*
The SQL thread owns one Relay_log_info, and each client that has
executed a BINLOG statement owns one Relay_log_info. This function
returns zero for the Relay_log_info object that belongs to the SQL
thread and nonzero for Relay_log_info objects that belong to
clients.
*/
inline bool belongs_to_client() {
DBUG_ASSERT(info_thd);
return !info_thd->slave_thread;
}
/* Instrumentation key for performance schema for mts_temp_table_LOCK */
#ifdef HAVE_PSI_INTERFACE
PSI_mutex_key m_key_mts_temp_table_LOCK;
#endif
/*
Lock to protect race condition while transferring temporary table from
worker thread to coordinator thread and vice-versa
*/
mysql_mutex_t mts_temp_table_LOCK;
/*
Lock to acquire by methods that concurrently update lwm of committed
transactions and the min waited timestamp and its index.
*/
mysql_mutex_t mts_gaq_LOCK;
mysql_cond_t logical_clock_cond;
/*
If true, events with the same server id should be replicated. This
field is set on creation of a relay log info structure by copying
the value of ::replicate_same_server_id and can be overridden if
necessary. For example of when this is done, check sql_binlog.cc,
where the BINLOG statement can be used to execute "raw" events.
*/
bool replicate_same_server_id;
/*
Protected with internal locks.
Must get data_lock when resetting the logs.
*/
MYSQL_BIN_LOG relay_log;
/*
Identifies when the recovery process is going on.
See sql/rpl_slave.h:init_recovery for further details.
*/
bool is_relay_log_recovery;
/* The following variables are safe to read any time */
/*
When we restart slave thread we need to have access to the previously
created temporary tables. Modified only on init/end and by the SQL
thread, read only by SQL thread.
*/
TABLE *save_temporary_tables;
/* parent Master_info structure */
Master_info *mi;
/* number of temporary tables open in this channel */
std::atomic<int32> atomic_channel_open_temp_tables{0};
/** the status of the commit timestamps for the relay log */
enum {
/*
no GTID log event has been processed, so it is not known if this log
has commit timestamps
*/
COMMIT_TS_UNKNOWN,
// the immediate master does not support commit timestamps
COMMIT_TS_NOT_FOUND,
// the immediate master supports commit timestamps
COMMIT_TS_FOUND
} commit_timestamps_status;
/**
@return the pointer to the Gtid_monitoring_info.
*/
Gtid_monitoring_info *get_gtid_monitoring_info() {
return gtid_monitoring_info;
}
/**
Stores the details of the transaction which has just started processing.
This function is called by the STS applier or MTS worker when applying a
Gtid.
@param gtid_arg the gtid of the trx
@param original_ts_arg the original commit timestamp of the transaction
@param immediate_ts_arg the immediate commit timestamp of the transaction
@param skipped true if the transaction was gtid skipped
*/
void started_processing(Gtid gtid_arg, ulonglong original_ts_arg,
ulonglong immediate_ts_arg, bool skipped = false) {
gtid_monitoring_info->start(gtid_arg, original_ts_arg, immediate_ts_arg,
skipped);
}
/**
Stores the details of the transaction which has just started processing.
This function is called by the MTS coordinator when queuing a Gtid to
a worker.
@param gtid_log_ev_arg the gtid log event of the trx
*/
void started_processing(Gtid_log_event *gtid_log_ev_arg) {
Gtid gtid = {0, 0};
if (gtid_log_ev_arg->get_type() == ASSIGNED_GTID) {
gtid = {gtid_log_ev_arg->get_sidno(true), gtid_log_ev_arg->get_gno()};
}
started_processing(gtid, gtid_log_ev_arg->original_commit_timestamp,
gtid_log_ev_arg->immediate_commit_timestamp);
}
/**
When the processing of a transaction is completed, that timestamp is
recorded, the information is copied to last_processed_trx and the
information in processing_trx is cleared.
If the transaction was "applied" but GTID-skipped, the copy will not
happen and the last_processed_trx will keep its current value.
*/
void finished_processing() { gtid_monitoring_info->finish(); }
/**
@return True if there is a transaction being currently processed
*/
bool is_processing_trx() {
return gtid_monitoring_info->is_processing_trx_set();
}
/**
Clears the processing_trx structure fields. Normally called when there is an
error while processing the transaction.
*/
void clear_processing_trx() { gtid_monitoring_info->clear_processing_trx(); }
/**
Clears the Gtid_monitoring_info fields.
*/
void clear_gtid_monitoring_info() { gtid_monitoring_info->clear(); }
/**
When a transaction is retried, the error number and message, and total number
of retries are stored. The timestamp for this error is also set here.
@param transient_errno_arg Transient error number.
@param transient_err_message_arg Transient error message.
@param trans_retries_arg Number of times this transaction has been
retried so far.
*/
void retried_processing(uint transient_errno_arg,
const char *transient_err_message_arg,
ulong trans_retries_arg) {
gtid_monitoring_info->store_transient_error(
transient_errno_arg, transient_err_message_arg, trans_retries_arg);
}
/*
If on init_info() call error_on_rli_init_info is true that means
that previous call to init_info() terminated with an error, RESET
SLAVE must be executed and the problem fixed manually.
*/
bool error_on_rli_init_info;
/**
Variable is set to true as long as
original_commit_timestamp > immediate_commit_timestamp so that the
corresponding warning is only logged once.
*/
bool gtid_timestamps_warning_logged;
/**
Retrieves the username part of the `PRIVILEGE_CHECKS_USER` option of `CHANGE
MASTER TO` statement.
@return a string holding the username part of the user or an empty string.
*/
std::string get_privilege_checks_username() const;
/**
Retrieves the host part of the `PRIVILEGE_CHECKS_USER` option of `CHANGE
MASTER TO` statement.
@return a string holding the host part of the user or an empty string.
*/
std::string get_privilege_checks_hostname() const;
/**
Returns whether or not there is no user configured for
`PRIVILEGE_CHECKS_USER`.
@return true if there is no user configured for `PRIVILEGE_CHECKS_USER` and
false otherwise.
*/
bool is_privilege_checks_user_null() const;
/**
Returns whether or not the internal data regarding `PRIVILEGE_CHECKS_USER`
is corrupted. This may happen, for instance, if the user tries to change the
Relay_log_info repository manually or after a server crash.
@return true if the data is corrupted, false otherwise.
*/
bool is_privilege_checks_user_corrupted() const;
/**
Clears the info related to the data initialized from
`PRIVILEGE_CHECKS_USER`.
*/
void clear_privilege_checks_user();
/**
Sets the flag that tells whether or not the data regarding the
`PRIVILEGE_CHECKS_USER` is corrupted.
@param is_corrupted the flag value.
*/
void set_privilege_checks_user_corrupted(bool is_corrupted);
/**
Initializes data related to `PRIVILEGE_CHECKS_USER`, specifically the user
name and the user hostname.
@param param_privilege_checks_username the username part of the user.
@param param_privilege_checks_hostname the hostname part of the user.
@return a status code describing the state of the data initialization.
*/
enum_priv_checks_status set_privilege_checks_user(
char const *param_privilege_checks_username,
char const *param_privilege_checks_hostname);
/**
Checks the validity and integrity of the data related to
`PRIVILEGE_CHECKS_USER`, specifically the user name and the user
hostname. Also checks if the user exists.
This method takes no parameters as it checks the values stored in the
internal member variables.
@return a status code describing the state of the data initialization.
*/
enum_priv_checks_status check_privilege_checks_user();
/**
Checks the validity and integrity of the data related to
`PRIVILEGE_CHECKS_USER`, specifically the user name and the user
hostname. Also checks if the user exists.
@param param_privilege_checks_username the username part of the user.
@param param_privilege_checks_hostname the hostname part of the user.
@return a status code describing the state of the data initialization.
*/
enum_priv_checks_status check_privilege_checks_user(
char const *param_privilege_checks_username,
char const *param_privilege_checks_hostname);
/**
Checks the existence of user provided as part of the `PRIVILEGE_CHECKS_USER`
option.
@param param_privilege_checks_username the username part of the user.
@param param_privilege_checks_hostname the host part of the user.
@return a status code describing the state of the data initialization.
*/
enum_priv_checks_status check_applier_acl_user(
char const *param_privilege_checks_username,
char const *param_privilege_checks_hostname);
/**
Returns a printable representation of the username and hostname currently
being used in the applier security context or empty strings other wise.
@return an `std::pair` containing the username and the hostname printable
representations.
*/
std::pair<const char *, const char *>
print_applier_security_context_user_host() const;
/**
Outputs the error message associated with applier thread user privilege
checks error `error_code`.
The output stream to which is outputted is decided based on `to_client`
which, if set to `true` will output the message to the client session and if
`false` will output to the server log.
@param level the message urgency level, e.g., `ERROR_LEVEL`,
`WARNING_LEVEL`, etc.
@param status_code the status code to output the associated error message
for.
@param to_client a flag indicating if the message should be sent to the
client session or to the server log.
@param channel_name name of the channel for which the error is being
reported.
@param user_name username for which the error is being reported.
@param host_name hostname for which the error is being reported.
*/
void report_privilege_check_error(enum loglevel level,
enum_priv_checks_status status_code,
bool to_client,
char const *channel_name = nullptr,
char const *user_name = nullptr,
char const *host_name = nullptr) const;
/**
Initializes the security context associated with the `PRIVILEGE_CHECKS_USER`
user that is to be used by the provided THD object.
@return a status code describing the state of the data initialization.
*/
enum_priv_checks_status initialize_security_context(THD *thd);
/**
Initializes the security context associated with the `PRIVILEGE_CHECKS_USER`
user that is to be used by the applier thread.
@return a status code describing the state of the data initialization.
*/
enum_priv_checks_status initialize_applier_security_context();
/**
Returns whether the slave is running in row mode only.
@return true if row_format_required is active, false otherwise.
*/
bool is_row_format_required() const;
/**
Sets the flag that tells whether or not the slave is running in row mode
only.
@param require_row the flag value.
*/
void set_require_row_format(bool require_row);
/**
Returns what is the slave policy concerning primary keys on
replicated tables.
@return STREAM if it replicates the source values, ON if it enforces the
need on primary keys, OFF if it does no enforce any restrictions.
*/
enum_require_table_primary_key get_require_table_primary_key_check() const;
/**
Sets the field that tells what is the slave policy concerning primary keys
on replicated tables.
@param require_pk the policy value.
*/
void set_require_table_primary_key_check(
enum_require_table_primary_key require_pk);
/*
This will be used to verify transactions boundaries of events being applied
Its output is used to detect when events were not logged using row based
logging.
*/
Replication_transaction_boundary_parser transaction_parser;
/*
Let's call a group (of events) :
- a transaction
or
- an autocommiting query + its associated events (INSERT_ID,
TIMESTAMP...)
We need these rli coordinates :
- relay log name and position of the beginning of the group we currently are
executing. Needed to know where we have to restart when replication has
stopped in the middle of a group (which has been rolled back by the slave).
- relay log name and position just after the event we have just
executed. This event is part of the current group.
Formerly we only had the immediately above coordinates, plus a 'pending'
variable, but this dealt wrong with the case of a transaction starting on a
relay log and finishing (commiting) on another relay log. Case which can
happen when, for example, the relay log gets rotated because of
max_binlog_size.
*/
protected:
/**
Event group means a group of events of a transaction. group_relay_log_name
and group_relay_log_pos record the place before where all event groups
are applied. When slave starts, it resume to apply events from
group_relay_log_pos. They will be initialized to the begin of the first
relay log file if it is a new slave(including SLAVE RESET). Then,
group_relay_log_pos is advanced after each transaction is applied
successfully in single thread slave. For MTS, group_relay_log_pos
is updated by mts checkpoint mechanism. group_relay_log_pos and
group_relay_log_name are stored into relay_log_info file/table
periodically. When server startup, they are loaded from relay log info
file/table.
*/
char group_relay_log_name[FN_REFLEN];
ulonglong group_relay_log_pos;
char event_relay_log_name[FN_REFLEN];
/* The suffix number of relay log name */
uint event_relay_log_number;
ulonglong event_relay_log_pos;
ulonglong future_event_relay_log_pos;
/* current event's start position in relay log */
my_off_t event_start_pos;
/*
Original log name and position of the group we're currently executing
(whose coordinates are group_relay_log_name/pos in the relay log)
in the master's binlog. These concern the *group*, because in the master's
binlog the log_pos that comes with each event is the position of the
beginning of the group.
Note: group_master_log_name, group_master_log_pos must only be
written from the thread owning the Relay_log_info (SQL thread if
!belongs_to_client(); client thread executing BINLOG statement if
belongs_to_client()).
*/
char group_master_log_name[FN_REFLEN];
volatile my_off_t group_master_log_pos;
private:
Gtid_set *gtid_set;
/*
Identifies when this object belongs to the SQL thread and was not
created for a client thread or some other purpose including
Slave_worker instance initializations. Ends up serving the same
purpose as the belongs_to_client method, but its value is set
earlier on in the class constructor.
*/
bool rli_fake;
/* Flag that ensures the retrieved GTID set is initialized only once. */
bool gtid_retrieved_initialized;
/**
Stores information on the last processed transaction or the transaction
that is currently being processed.
STS:
- timestamps of the currently applying/last applied transaction
MTS:
- coordinator thread: timestamps of the currently scheduling/last scheduled
transaction in a worker's queue
- worker thread: timestamps of the currently applying/last applied
transaction
*/
Gtid_monitoring_info *gtid_monitoring_info;
/**
It will be set to true when receiver truncated relay log for some reason.
The truncated data may already be read by applier. So applier need to check
it each time the binlog_end_pos is updated.
*/
bool m_relay_log_truncated = false;
/**
The user name part of the user passed on to `PRIVILEGE_CHECKS_USER`.
*/
std::string m_privilege_checks_username;
/**
The host name part of the user passed on to `PRIVILEGE_CHECKS_USER`.
*/
std::string m_privilege_checks_hostname;
/**
Tells whether or not the internal data regarding `PRIVILEGE_CHECKS_USER` is
corrupted. This may happen if the user tries to change the Relay_log_info
repository by hand.
*/
bool m_privilege_checks_user_corrupted;
/**
Tells if the slave is only accepting events logged with row based logging.
It also blocks
Operations with temporary table creation/deletion
Operations with LOAD DATA
Events: INTVAR_EVENT, RAND_EVENT, USER_VAR_EVENT
*/
bool m_require_row_format;
/**
Identifies what is the slave policy on primary keys in tables.
If set to STREAM it just replicates the value of sql_require_primary_key.
If set to ON it fails when the source tries to replicate a table creation
or alter operation that does not have a primary key.
If set to OFF it does not enforce any policies on the channel for primary
keys.
*/
enum_require_table_primary_key m_require_table_primary_key_check;
public:
bool is_relay_log_truncated() { return m_relay_log_truncated; }
Sid_map *get_sid_map() { return gtid_set->get_sid_map(); }
Checkable_rwlock *get_sid_lock() { return get_sid_map()->get_sid_lock(); }
void add_logged_gtid(rpl_sidno sidno, rpl_gno gno) {
get_sid_lock()->assert_some_lock();
DBUG_ASSERT(sidno <= get_sid_map()->get_max_sidno());
gtid_set->ensure_sidno(sidno);
gtid_set->_add_gtid(sidno, gno);
}
/**
Adds a GTID set to received GTID set.
@param gtid_set the gtid_set to add
@return RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.
*/
enum_return_status add_gtid_set(const Gtid_set *gtid_set);
const Gtid_set *get_gtid_set() const { return gtid_set; }
bool reinit_sql_thread_io_cache(const char *log, bool need_data_lock);
/**
Check if group_relay_log_name is in index file.
@param [out] errmsg An error message is returned if error happens.
@retval false It is valid.
@retval true It is invalid. In this case, *errmsg is set to point to
the error message.
*/
bool is_group_relay_log_name_invalid(const char **errmsg);
/**
Reset group_relay_log_name and group_relay_log_pos to the start of the
first relay log file. The caller must hold data_lock.
@param[out] errmsg An error message is set into it if error happens.
@retval false Success
@retval true Error
*/
bool reset_group_relay_log_pos(const char **errmsg);
/*
Update the error number, message and timestamp fields. This function is
different from va_report() as va_report() also logs the error message in the
log apart from updating the error fields.
*/
void fill_coord_err_buf(loglevel level, int err_code,
const char *buff_coord) const;
/*
Flag that the group_master_log_pos is invalid. This may occur
(for example) after CHANGE MASTER TO RELAY_LOG_POS. This will
be unset after the first event has been executed and the
group_master_log_pos is valid again.
*/
bool is_group_master_log_pos_invalid;
/*
Handling of the relay_log_space_limit optional constraint.
ignore_log_space_limit is used to resolve a deadlock between I/O and SQL
threads, the SQL thread sets it to unblock the I/O thread and make it
temporarily forget about the constraint.
*/
ulonglong log_space_limit, log_space_total;
std::atomic<bool> ignore_log_space_limit;
/*
Used by the SQL thread to instructs the IO thread to rotate
the logs when the SQL thread needs to purge to release some
disk space.
*/
std::atomic<bool> sql_force_rotate_relay;
time_t last_master_timestamp;
/**
Reset the delay.
This is used by RESET SLAVE to clear the delay.
*/
void clear_sql_delay() { sql_delay = 0; }
/*
Needed for problems when slave stops and we want to restart it
skipping one or more events in the master log that have caused
errors, and have been manually applied by DBA already.
*/
volatile uint32 slave_skip_counter;
volatile ulong abort_pos_wait; /* Incremented on change master */
mysql_mutex_t log_space_lock;
mysql_cond_t log_space_cond;
/*
Condition and its parameters from START SLAVE UNTIL clause.
UNTIL condition is tested with is_until_satisfied() method that is
called by exec_relay_log_event(). is_until_satisfied() caches the result
of the comparison of log names because log names don't change very often;
this cache is invalidated by parts of code which change log names with
notify_*_log_name_updated() methods. (They need to be called only if SQL
thread is running).
*/
enum {
UNTIL_NONE = 0,
UNTIL_MASTER_POS,
UNTIL_RELAY_POS,
UNTIL_SQL_BEFORE_GTIDS,
UNTIL_SQL_AFTER_GTIDS,
UNTIL_SQL_AFTER_MTS_GAPS,
UNTIL_SQL_VIEW_ID,
UNTIL_DONE
} until_condition;
char cached_charset[6];
/*
trans_retries varies between 0 to slave_transaction_retries and counts how
many times the slave has retried the present transaction; gets reset to 0
when the transaction finally succeeds. retried_trans is a cumulative
counter: how many times the slave has retried a transaction (any) since
slave started.
*/
ulong trans_retries, retried_trans;
/*
If the end of the hot relay log is made of master's events ignored by the
slave I/O thread, these two keep track of the coords (in the master's
binlog) of the last of these events seen by the slave I/O thread. If not,
ign_master_log_name_end[0] == 0.
As they are like a Rotate event read/written from/to the relay log, they
are both protected by rli->relay_log.LOCK_binlog_end_pos.
*/
char ign_master_log_name_end[FN_REFLEN];
ulonglong ign_master_log_pos_end;
/*
Indentifies where the SQL Thread should create temporary files for the
LOAD DATA INFILE. This is used for security reasons.
*/
char slave_patternload_file[FN_REFLEN];
size_t slave_patternload_file_size;
/**
Identifies the last time a checkpoint routine has been executed.
*/
struct timespec last_clock;
/**
Invalidates cached until_log_name and event_relay_log_name comparison
result. Should be called after switch to next relay log if
there chances that sql_thread is running.
*/
inline void notify_relay_log_change() {
if (until_condition == UNTIL_RELAY_POS)
dynamic_cast<Until_position *>(until_option)->notify_log_name_change();
}
/**
Receiver thread notifies that it truncated some data from relay log.
data_lock will be acquired, so the caller should not hold data_lock.
*/
void notify_relay_log_truncated();
/**
Applier clears the flag after it handled the situation. The caller must
hold data_lock.
*/
void clear_relay_log_truncated();
/**
The same as @c notify_group_relay_log_name_update but for
@c group_master_log_name.
*/
inline void notify_group_master_log_name_update() {
if (until_condition == UNTIL_MASTER_POS)
dynamic_cast<Until_position *>(until_option)->notify_log_name_change();
}
inline void inc_event_relay_log_pos() {
event_relay_log_pos = future_event_relay_log_pos;
}
/**
Last executed event group coordinates are updated and optionally
forcibly flushed to a repository.
@param log_pos a value of the executed position to update to
@param need_data_lock whether data_lock should be acquired
@param force the value is passed to eventual flush_info()
*/
int inc_group_relay_log_pos(ulonglong log_pos, bool need_data_lock,
bool force = false);
int wait_for_pos(THD *thd, String *log_name, longlong log_pos,
double timeout);
/**
Wait for a GTID set to be executed.
@param thd The thread for status changes and kill status
@param gtid A char array with a GTID set
@param timeout Number of seconds to wait before timing out
@param update_THD_status Shall the method update the THD stage
@retval 0 The set is already executed
@retval -1 There was a timeout waiting for the set
@retval -2 There was an issue while waiting.
*/
int wait_for_gtid_set(THD *thd, const char *gtid, double timeout,
bool update_THD_status = true);
/**
Wait for a GTID set to be executed.
@param thd The thread for status changes and kill status
@param gtid A String with a GTID set
@param timeout Number of seconds to wait before timing out
@param update_THD_status Shall the method update the THD stage
@retval 0 The set is already executed
@retval -1 There was a timeout waiting for the set
@retval -2 There was an issue while waiting.
*/
int wait_for_gtid_set(THD *thd, String *gtid, double timeout,
bool update_THD_status = true);
/**
Wait for a GTID set to be executed.
@param thd The thread for status changes and kill status
@param wait_gtid_set A GTID_set object
@param timeout Number of seconds to wait before timing out
@param update_THD_status Shall the method update the THD stage
@retval 0 The set is already executed
@retval -1 There was a timeout waiting for the set
@retval -2 There was an issue while waiting.
*/
int wait_for_gtid_set(THD *thd, const Gtid_set *wait_gtid_set, double timeout,
bool update_THD_status = true);
void close_temporary_tables();
RPL_TABLE_LIST *tables_to_lock; /* RBR: Tables to lock */
uint tables_to_lock_count; /* RBR: Count of tables to lock */
table_mapping m_table_map; /* RBR: Mapping table-id to table */
/* RBR: Record Rows_query log event */
Rows_query_log_event *rows_query_ev;
bool get_table_data(TABLE *table_arg, table_def **tabledef_var,
TABLE **conv_table_var) const {
DBUG_ASSERT(tabledef_var && conv_table_var);
for (TABLE_LIST *ptr = tables_to_lock; ptr != nullptr;
ptr = ptr->next_global)
if (ptr->table == table_arg) {
*tabledef_var = &static_cast<RPL_TABLE_LIST *>(ptr)->m_tabledef;
*conv_table_var = static_cast<RPL_TABLE_LIST *>(ptr)->m_conv_table;
DBUG_PRINT("debug", ("Fetching table data for table %s.%s:"
" tabledef: %p, conv_table: %p",
table_arg->s->db.str, table_arg->s->table_name.str,
*tabledef_var, *conv_table_var));
return true;