-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opt out of binlogs #759
Opt out of binlogs #759
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2019 Zach Moazeni. | ||
See https://github.com/github/gh-ost/blob/master/LICENSE | ||
*/ | ||
|
||
package logic | ||
zmoazeni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
type GTIDSet struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh TIL about Perhaps I don't need this logic after all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hrm. I may be missing something, but I couldn't figure out a clean way to use |
||
server_uuid string | ||
gtid_executed string | ||
} | ||
|
||
func NewGTIDSet(server_uuid, gtid_executed string) GTIDSet { | ||
return GTIDSet{server_uuid, gtid_executed} | ||
} | ||
|
||
func (set *GTIDSet) originalServerGTIDs() (string, bool) { | ||
if !strings.Contains(set.gtid_executed, set.server_uuid) { | ||
return "", false | ||
} | ||
gtids := strings.Split(set.gtid_executed, ",") | ||
for _, gtid := range gtids { | ||
if strings.Contains(gtid, set.server_uuid) { | ||
return strings.TrimSpace(gtid), true | ||
} | ||
} | ||
|
||
// Shouldn't run into this. Only necessary for type checker | ||
return "", false | ||
} | ||
|
||
func (set *GTIDSet) Revert(current_gtid_executed string) string { | ||
if !strings.Contains(current_gtid_executed, set.server_uuid) { | ||
return current_gtid_executed | ||
} | ||
gtids := strings.Split(current_gtid_executed, ",") | ||
newGtids := make([]string, 0, len(gtids)) | ||
originalServerGTIDs, found := set.originalServerGTIDs() | ||
if found { | ||
// revert back to original gtid_executed JUST for the server_uuid | ||
for _, gtid := range gtids { | ||
if strings.Contains(gtid, set.server_uuid) { | ||
newGtids = append(newGtids, originalServerGTIDs) | ||
} else { | ||
newGtids = append(newGtids, strings.TrimSpace(gtid)) | ||
} | ||
} | ||
} else { | ||
// trim server_uuid current_gtid_executed out of the set and return | ||
for _, gtid := range gtids { | ||
if !strings.Contains(gtid, set.server_uuid) { | ||
newGtids = append(newGtids, strings.TrimSpace(gtid)) | ||
} | ||
} | ||
} | ||
return strings.Join(newGtids, ",\n") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright 2019 Zach Moazeni. | ||
See https://github.com/github/gh-ost/blob/master/LICENSE | ||
*/ | ||
|
||
package logic | ||
|
||
import ( | ||
"testing" | ||
|
||
test "github.com/outbrain/golib/tests" | ||
) | ||
|
||
func TestRevert(t *testing.T) { | ||
{ | ||
set := NewGTIDSet("00005722-2222-2222-2222-222222222222", "00005721-1111-1111-1111-111111111111:1-52") | ||
newGTIDs := set.Revert("00005721-1111-1111-1111-111111111111:1-54,\n00005722-2222-2222-2222-222222222222:1-7") | ||
test.S(t).ExpectEquals(newGTIDs, "00005721-1111-1111-1111-111111111111:1-54") | ||
} | ||
{ | ||
set := NewGTIDSet("00005722-2222-2222-2222-222222222222", "00005721-1111-1111-1111-111111111111:1-52") | ||
newGTIDs := set.Revert("00005721-1111-1111-1111-111111111111:1-54") | ||
test.S(t).ExpectEquals(newGTIDs, "00005721-1111-1111-1111-111111111111:1-54") | ||
} | ||
{ | ||
set := NewGTIDSet("00005722-2222-2222-2222-222222222222", "00005721-1111-1111-1111-111111111111:1-52,\n00005722-2222-2222-2222-222222222222:1-7") | ||
newGTIDs := set.Revert("00005721-1111-1111-1111-111111111111:1-100,\n00005722-2222-2222-2222-222222222222:1-80") | ||
test.S(t).ExpectEquals(newGTIDs, "00005721-1111-1111-1111-111111111111:1-100,\n00005722-2222-2222-2222-222222222222:1-7") | ||
} | ||
{ | ||
set := NewGTIDSet("00005722-2222-2222-2222-222222222222", "00005721-1111-1111-1111-111111111111:1-52,\n00005722-2222-2222-2222-222222222222:1-7") | ||
newGTIDs := set.Revert("00005721-1111-1111-1111-111111111111:1-100,\n00005722-2222-2222-2222-222222222222:1-80,\n00005722-3333-3333-3333-333333333333:1-5") | ||
test.S(t).ExpectEquals(newGTIDs, "00005721-1111-1111-1111-111111111111:1-100,\n00005722-2222-2222-2222-222222222222:1-7,\n00005722-3333-3333-3333-333333333333:1-5") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
# shellcheck disable=SC2168 | ||
|
||
sleep 1 # let any any replication catch up | ||
|
||
local master_server_uuid replica_server_uuid gtid_executed gtid_purged | ||
|
||
master_server_uuid=$(gh-ost-test-mysql-master test -e "SELECT @@global.server_uuid" -ss) | ||
replica_server_uuid=$(gh-ost-test-mysql-replica test -e "SELECT @@global.server_uuid" -ss) | ||
gtid_executed=$(gh-ost-test-mysql-replica test -e "SELECT @@global.gtid_executed" -ss) | ||
gtid_purged=$(gh-ost-test-mysql-replica test -e "SELECT @@global.gtid_purged" -ss) | ||
|
||
if ! echo "$gtid_executed" | grep -q "$replica_server_uuid" ; then | ||
echo | ||
echo "ERROR gtid_executed is missing original gh-ost gtids" | ||
# shellcheck disable=SC2154 | ||
echo "prior gtid_executed: $gtid_executed_pristine" | ||
echo "current gtid_executed: $gtid_executed" | ||
return 1 | ||
fi | ||
|
||
if [ "$gtid_executed" != "$gtid_purged" ] ; then | ||
echo | ||
echo "ERROR gtid_executed and gtid_purged don't match" | ||
echo "gtid_executed: $gtid_executed" | ||
echo "gtid_purged: $gtid_purged" | ||
return 1 | ||
fi | ||
|
||
local max_pristine_master_tx max_current_master_tx | ||
max_pristine_master_tx=$(echo "$gtid_executed_pristine" | grep -o -P "${master_server_uuid}:\d+-\d+" | cut -d ":" -f 2 | cut -d "-" -f 2) | ||
max_current_master_tx=$(echo "$gtid_executed" | grep -o -P "${master_server_uuid}:\d+-\d+" | cut -d ":" -f 2 | cut -d "-" -f 2) | ||
|
||
if (( max_current_master_tx <= max_pristine_master_tx )) ; then | ||
echo | ||
echo "ERROR gtid_executed trimmed legitimate master gtids." | ||
echo "current gtid_executed should > prior gtid_executed" | ||
echo "prior gtid_executed: $gtid_executed_pristine" | ||
echo "current gtid_executed: $gtid_executed" | ||
return 1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
# shellcheck disable=SC2168 | ||
|
||
local gtid_executed_pristine | ||
|
||
# Write something to the replica-only. Make sure it stays even after GTID surgery | ||
gh-ost-test-mysql-replica test -e "CREATE TABLE replica_only (id INTEGER); INSERT INTO replica_only VALUES (1), (2), (3);" | ||
|
||
# shellcheck disable=SC2034 | ||
gtid_executed_pristine=$(gh-ost-test-mysql-replica test -e "SELECT @@global.gtid_executed" -ss) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
drop table if exists gh_ost_test; | ||
create table gh_ost_test ( | ||
id int auto_increment, | ||
i int not null, | ||
color varchar(32), | ||
primary key(id) | ||
) auto_increment=1; | ||
|
||
drop event if exists gh_ost_test; | ||
|
||
insert into gh_ost_test values (null, 11, 'red'); | ||
insert into gh_ost_test values (null, 13, 'green'); | ||
insert into gh_ost_test values (null, 17, 'blue'); | ||
|
||
delimiter ;; | ||
create event gh_ost_test | ||
on schedule every 1 second | ||
starts current_timestamp | ||
ends current_timestamp + interval 60 second | ||
on completion not preserve | ||
enable | ||
do | ||
begin | ||
insert into gh_ost_test values (null, 11, 'orange'); | ||
insert into gh_ost_test values (null, 13, 'brown'); | ||
end ;; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--throttle-query='select false' --sql-log-bin=false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(5.5) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
drop table if exists gh_ost_test; | ||
create table gh_ost_test ( | ||
id int auto_increment, | ||
i int not null, | ||
color varchar(32), | ||
primary key(id) | ||
) auto_increment=1; | ||
|
||
drop event if exists gh_ost_test; | ||
|
||
insert into gh_ost_test values (null, 11, 'red'); | ||
insert into gh_ost_test values (null, 13, 'green'); | ||
insert into gh_ost_test values (null, 17, 'blue'); | ||
|
||
delimiter ;; | ||
create event gh_ost_test | ||
on schedule every 2 second | ||
starts current_timestamp | ||
ends current_timestamp + interval 60 second | ||
on completion not preserve | ||
enable | ||
do | ||
begin | ||
insert into gh_ost_test values (null, 11, 'orange'); | ||
insert into gh_ost_test values (null, 13, 'brown'); | ||
end ;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should discuss whether we should allow
--allow-on-master
to work considering the scope of the GTID surgery. Feels super dangerous.