Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

relay: fix GTID recover after relay log recovered #335

Merged
merged 9 commits into from
Oct 28, 2019

Conversation

csuzhangxc
Copy link
Member

What problem does this PR solve?

MySQL may not save all previous GTID sets in its binlog file as Previous_gtids event in some special scenarios (not confirmed yet, but maybe a bug, ref https://bugs.mysql.com/bug.php?id=93809).

example:

  • the real previous GTID sets: 00c04543-f584-11e9-a765-0242ac120002:1-60
  • GTID sets in Previous_gtids event: 00c04543-f584-11e9-a765-0242ac120002:45-60
  • then the recovered GTID sets will become 00c04543-f584-11e9-a765-0242ac120002:45-60, but this should still be 00c04543-f584-11e9-a765-0242ac120002:1-60.
  • use 00c04543-f584-11e9-a765-0242ac120002:45-60 to request the master is wrong, because this will cause the master to send binlog events in 00c04543-f584-11e9-a765-0242ac120002:1-44. if this events are purged, an error (ERROR 1236 (HY000): The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.) will reported; if this events are not purged, they will be sent again.

What is changed and how it works?

only truncate the Stop of the GTID set intervals, like truncating 00c04543-f584-11e9-a765-0242ac120002:1-60 with 00c04543-f584-11e9-a765-0242ac120002:40-50 will get 00c04543-f584-11e9-a765-0242ac120002:1-50.

Check List

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch
  • Need to be included in the release note

@csuzhangxc csuzhangxc added priority/normal Minor change, requires approval from ≥1 primary reviewer status/PTAL This PR is ready for review. Add this label back after committing new changes type/bug-fix Bug fix priority/release-blocker This PR blocks a release. Please review it ASAP. needs-cherry-pick-release-1.0 This PR should be cherry-picked to release-1.0. Remove this label after cherry-picked to release-1.0 needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated labels Oct 25, 2019
@csuzhangxc
Copy link
Member Author

/run-all-tests

1 similar comment
@csuzhangxc
Copy link
Member Author

/run-all-tests

@codecov
Copy link

codecov bot commented Oct 25, 2019

Codecov Report

Merging #335 into master will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##            master      #335   +/-   ##
=========================================
  Coverage   60.147%   60.147%           
=========================================
  Files          135       135           
  Lines        15236     15236           
=========================================
  Hits          9164      9164           
  Misses        5173      5173           
  Partials       899       899

@csuzhangxc
Copy link
Member Author

@amyangfei @WangXiangUSTC PTAL

Copy link
Contributor

@WangXiangUSTC WangXiangUSTC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest LGTM

pkg/gtid/gtid.go Show resolved Hide resolved
},
{
before: "00c04543-f584-11e9-a765-0242ac120002:40-60:70:80-100",
end: "00c04543-f584-11e9-a765-0242ac120002:45-55:70:85-95",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about also add a case before's interval's num is different with end, for example:
before: "00c04543-f584-11e9-a765-0242ac120002:40-60:70:80-100",
end: "00c04543-f584-11e9-a765-0242ac120002:45-55:85-95"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 added in feeed29.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about also add for mariadb

Copy link
Contributor

@WangXiangUSTC WangXiangUSTC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@WangXiangUSTC WangXiangUSTC added status/LGT1 One reviewer already commented LGTM and removed status/PTAL This PR is ready for review. Add this label back after committing new changes labels Oct 28, 2019
relay/relay.go Outdated Show resolved Hide resolved
relay/relay.go Outdated Show resolved Hide resolved
@csuzhangxc
Copy link
Member Author

/run-all-tests

Copy link
Contributor

@amyangfei amyangfei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@amyangfei amyangfei removed the status/LGT1 One reviewer already commented LGTM label Oct 28, 2019
@amyangfei amyangfei added the status/LGT2 Two reviewers already commented LGTM, ready for merge label Oct 28, 2019
@csuzhangxc csuzhangxc merged commit c6344f3 into pingcap:master Oct 28, 2019
@csuzhangxc csuzhangxc deleted the fix-recover-gtid branch October 28, 2019 11:13
@sre-bot
Copy link

sre-bot commented Oct 28, 2019

cherry pick to release-1.0 in PR #339

@sre-bot sre-bot added already-cherry-pick-1.0 The related PR is already cherry-picked to release-1.0. Add this label once the PR is cherry-picked and removed needs-cherry-pick-release-1.0 This PR should be cherry-picked to release-1.0. Remove this label after cherry-picked to release-1.0 labels Oct 28, 2019
@csuzhangxc csuzhangxc added already-update-release-note The release note is updated. Add this label once the release note is updated and removed needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated labels Nov 1, 2019
lichunzhu pushed a commit to lichunzhu/dm that referenced this pull request Apr 6, 2020
@lance6716
Copy link
Collaborator

The problem in PR description is caused by MySQL slave forget to set log_slave_updates=ON. The GTIDs when log_slave_updates is OFF will not be saved in Previous_gtids events.

MySQL [(none)]> select @@global.gtid_purged;
+------------------------------------------+
| @@global.gtid_purged                     |
+------------------------------------------+
| 250e86b4-ba95-11ea-9e12-b15aac539905:1-3 |
+------------------------------------------+
1 row in set (0.000 sec)

MySQL [(none)]> select @@global.gtid_executed;
+------------------------------------------+
| @@global.gtid_executed                   |
+------------------------------------------+
| 250e86b4-ba95-11ea-9e12-b15aac539905:1-4 |
+------------------------------------------+

MySQL [(none)]> show binlog events in 'binlog.000003';
+---------------+-----+----------------+-----------+-------------+-------------------------------------------------------------------+
| Log_name      | Pos | Event_type     | Server_id | End_log_pos | Info                                                              |
+---------------+-----+----------------+-----------+-------------+-------------------------------------------------------------------+
| binlog.000003 |   4 | Format_desc    |         1 |         123 | Server ver: 5.7.23-log, Binlog ver: 4                             |
| binlog.000003 | 123 | Previous_gtids |         1 |         154 |                                                                   |
| binlog.000003 | 154 | Gtid           |         2 |         219 | SET @@SESSION.GTID_NEXT= '250e86b4-ba95-11ea-9e12-b15aac539905:4' |
| binlog.000003 | 219 | Query          |         2 |         282 | BEGIN                                                             |
| binlog.000003 | 282 | Table_map      |         2 |         327 | table_id: 108 (gset.t1)                                           |
| binlog.000003 | 327 | Write_rows     |         2 |         367 | table_id: 108 flags: STMT_END_F                                   |
| binlog.000003 | 367 | Xid            |         2 |         398 | COMMIT /* xid=6 */                                                |
+---------------+-----+----------------+-----------+-------------+-------------------------------------------------------------------+
7 rows in set (0.001 sec)

since now we introduced #1430 , the Truncate interface is no longer needed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
already-cherry-pick-1.0 The related PR is already cherry-picked to release-1.0. Add this label once the PR is cherry-picked already-update-release-note The release note is updated. Add this label once the release note is updated priority/normal Minor change, requires approval from ≥1 primary reviewer priority/release-blocker This PR blocks a release. Please review it ASAP. status/LGT2 Two reviewers already commented LGTM, ready for merge type/bug-fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants