Skip to content
Closed
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
f287663
vttablet: stateManager tests WIP
sougou Jun 28, 2020
5b99487
tabletserver: create new ReplTracker skeleton
sougou Jul 3, 2020
2a97a0e
vttablet: move hc flags to tabletenv.TabletConfig
sougou Jul 3, 2020
4b08c81
vttablet: type safe Seconds instead of float64
sougou Jul 3, 2020
3af6df5
vttablet: enable_replication_reporter -> tabletenv
sougou Jul 3, 2020
6d65f9f
vttablet: saving work. need mysqld in tabletserver
sougou Jul 3, 2020
4776c74
vttablet: add mysqld to tabletserver
sougou Jul 4, 2020
7098531
vttablet: ReplTracker functional
sougou Jul 4, 2020
cddd0de
vttablet: switch to use replTracker
sougou Jul 4, 2020
52d6b06
vttablet: tests for ReplTracker
sougou Jul 4, 2020
fff8340
vttablet: new healthStreamer
sougou Jul 4, 2020
e1a1170
vttablet: wire-up most of healthStreamer
sougou Jul 4, 2020
addfd0e
vttablet: streamHealth wired up
sougou Jul 5, 2020
020b2e7
vttablet: status page uses healthStreamer
sougou Jul 5, 2020
9dee129
vttablet: VREngine retries if Open fails
sougou Jul 5, 2020
5f968fc
tm: preparing to delete healthcheck
sougou Jul 5, 2020
b4f2207
vttablet: trying a different heathcheck
sougou Jul 6, 2020
efcf8b3
vttablet: delete old broken health tests
sougou Jul 6, 2020
290ea36
vttablet: make BACKUP StateNotConnected
sougou Jul 6, 2020
2f22ad3
vttablet: fix tabletserver repl health & tests
sougou Jul 6, 2020
ea790b5
vttablet: relpManager initial code
sougou Jul 7, 2020
109aab6
vttablet: fix tabletmanager tests
sougou Jul 7, 2020
6dd319d
vttablet: fix more tests
sougou Jul 7, 2020
ff9dd14
vttablet: replManager unit tests
sougou Jul 8, 2020
30f98a8
vttablet: delete deprecated code
sougou Jul 11, 2020
e8dba28
vttablet: fix after rebase
sougou Jul 11, 2020
42fa9ad
vttablet: move gracePeriod to TabletConfig
sougou Jul 12, 2020
c3bb83e
vttablet: SetServingType handles alsoAllow
sougou Jul 12, 2020
8e23766
vttablet: tmState initial cut
sougou Jul 13, 2020
453497f
vttablet: use tmState
sougou Jul 13, 2020
991dde7
vttablet: create a separate displayState
sougou Jul 16, 2020
124b245
vttablet: check replication on open
sougou Jul 16, 2020
017f2a9
vttablet: remove spurious sleep in binlog_watcher
sougou Jul 16, 2020
6af2b16
vttablet: fix after rebase
sougou Jul 18, 2020
9f2ea0a
vttablet: stateManager details on status page
sougou Jul 18, 2020
0babfd4
vttablet: healthStreamer details on status page
sougou Jul 18, 2020
b1adbdc
vttablet: remove tm's status export
sougou Jul 18, 2020
1ba7b63
vttablet: export reason to status
sougou Jul 18, 2020
e88b4f5
endtoend: start removing InitTablet calls
sougou Jul 18, 2020
635bb2f
vttablet: log repl health changes
sougou Jul 19, 2020
9632050
end2end: fix vertical_split_test
sougou Jul 19, 2020
7189cb8
end2end: sharding test fixes
sougou Jul 19, 2020
a2ec700
end2end: fix shardedrecovery test
sougou Jul 19, 2020
a50662a
end2end: speed up tests
sougou Jul 20, 2020
8ae485d
end2end: remove most InitTablet and CreateDB calls
sougou Jul 20, 2020
09228c6
vttablet: tracker closed on non-serving
sougou Jul 20, 2020
d386dc4
end2end: InitTablet removed: reparent & cellalias
sougou Jul 20, 2020
4029435
vttablet: VREngine retry tests
sougou Jul 20, 2020
1c3de85
vttablet: test for alsoAllow
sougou Jul 20, 2020
d3f4fef
vttablet: tm_state tests
sougou Jul 21, 2020
b716b97
vttablet: add polish
sougou Jul 22, 2020
95deb90
gh-ost credentials
shlomi-noach Jul 19, 2020
77955f7
gh-ost credentials
shlomi-noach Jul 19, 2020
1e89dd8
setting up ghost and handler
shlomi-noach Jul 19, 2020
a429c7b
executor for gh-ost
shlomi-noach Jul 20, 2020
a622661
support OnlineSchemaChange on schema/apply
shlomi-noach Jul 20, 2020
f7c1323
support crearin tempdir and file
shlomi-noach Jul 23, 2020
a4584e6
generate gh-ost wrapper script on the fly. Use temp dir
shlomi-noach Jul 23, 2020
a83e4c6
ApplyOnlineSchemaChange refactored into Controller
shlomi-noach Jul 23, 2020
483fc51
cleanup
shlomi-noach Jul 23, 2020
bebfb01
cleanup and comments
shlomi-noach Jul 23, 2020
6e7fc2f
typo
shlomi-noach Jul 23, 2020
1cd2d47
TODO
shlomi-noach Jul 23, 2020
4496d54
introducing query hint: VitessOnlineDDLHint
shlomi-noach Jul 23, 2020
78aad71
IsOnlineSchemaDDL analysis
shlomi-noach Jul 23, 2020
73ad39b
more explicit hint, also comment suggesting it's a hack for now
shlomi-noach Jul 23, 2020
4d3fbf3
building an OnlineDDL plan
shlomi-noach Jul 23, 2020
1d27705
merged master
shlomi-noach Jul 26, 2020
39f642f
remove online-schema-change code from vtgate and analyzer
shlomi-noach Jul 29, 2020
6df82bd
Revert "remove online-schema-change code from vtgate and analyzer"
shlomi-noach Aug 2, 2020
1346284
online_schema_change manages UUID and writes OSC request to global topo
shlomi-noach Aug 2, 2020
3d623eb
vtctl/tablet_executor write online schema change request to global topo
shlomi-noach Aug 2, 2020
015d974
vtgate intercepts ALTER TABLE statements and writes an online schema …
shlomi-noach Aug 2, 2020
7299301
refactored TopoPath() function
shlomi-noach Aug 2, 2020
5a89653
refactor: applying _vt.schema_migrations schema
shlomi-noach Aug 3, 2020
58b9a3a
refactor: naming
shlomi-noach Aug 3, 2020
e329bda
vtctld review migration requests, explodes per shard
shlomi-noach Aug 4, 2020
fa0e551
adding uuid gomod
shlomi-noach Aug 4, 2020
c551a03
fixed merge conflict
shlomi-noach Aug 4, 2020
2741151
vtctld runs schema checks
shlomi-noach Aug 4, 2020
225bc3b
reporting back UUID in response to ALTER TABLE statement
shlomi-noach Aug 4, 2020
d13b41b
/schema-migration/report-status API endpoint
shlomi-noach Aug 4, 2020
cafb9c1
Using latest gh-ost release from openark org
shlomi-noach Aug 5, 2020
079a987
sqltypes.Result supports NamedResults, via Named() function
shlomi-noach Aug 5, 2020
3393fa5
GetInt64(), GetUint64() convenience methods
shlomi-noach Aug 5, 2020
2336eac
Row() convenience method
shlomi-noach Aug 5, 2020
115de10
convenience methods in RowNamedValues
shlomi-noach Aug 6, 2020
759e76d
ToBool() conveniene method
shlomi-noach Aug 6, 2020
718e890
cleanup, undo adding fields to proto.SchemaChange
shlomi-noach Aug 6, 2020
fbd2457
cleanup, undo adding fields to proto.SchemaChange
shlomi-noach Aug 6, 2020
c78021c
Cleanup, undo and remove logic from tablet manager path
shlomi-noach Aug 6, 2020
142f06f
Cleanup, undo and remove logic from tablet manager path
shlomi-noach Aug 6, 2020
e87faa5
while still WIP, further logic into online ddl executor
shlomi-noach Aug 6, 2020
5029bd7
updating migration status and timestamp in response to API call
shlomi-noach Aug 6, 2020
bb4b328
minor cleanup and rename
shlomi-noach Aug 6, 2020
8481c3c
cleanup: remove unused code
shlomi-noach Aug 6, 2020
2b075df
Autogenerate gh-ost account and privileges
shlomi-noach Aug 6, 2020
de9b561
no need for gh-ost account in config/rice
shlomi-noach Aug 6, 2020
a8ae617
remove debug info
shlomi-noach Aug 6, 2020
6a37b43
remove debug info
shlomi-noach Aug 6, 2020
23b60b5
gh-ost password stored in environment variable, no longer visible as …
shlomi-noach Aug 6, 2020
0822dd0
provide gh-ost with DBName
shlomi-noach Aug 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/init_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ GRANT SUPER, PROCESS, REPLICATION SLAVE, RELOAD
GRANT SELECT
ON _vt.* TO 'orc_client_user'@'%';

# User for gh-ost (https://github.com/github/gh-ost).
CREATE USER 'gh-ost'@'127.0.0.1' IDENTIFIED BY 'gh-ost';
GRANT SUPER, REPLICATION SLAVE
ON *.* TO 'gh-ost'@'127.0.0.1';
GRANT ALTER, CREATE, DELETE, DROP, INDEX, INSERT, LOCK TABLES, SELECT, TRIGGER, UPDATE
ON *.* TO 'gh-ost'@'127.0.0.1';

FLUSH PRIVILEGES;

RESET SLAVE ALL;
Expand Down
5 changes: 5 additions & 0 deletions docker/local/install_local_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz

mkdir -p /var/run/etcd && chown -R vitess:vitess /var/run/etcd

# Install gh-ost
curl -k -L https://github.com/github/gh-ost/releases/download/v1.0.49/gh-ost-binary-linux-20200209110835.tar.gz -o /tmp/gh-ost.tar.gz
(cd /tmp/ && tar xzf gh-ost.tar.gz)
cp /tmp/gh-ost /usr/bin

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just out of curiosity. I can see from security perspective, installing the binary on each tablet is preferred, what are the other tradeoffs to install the binary on each tablet vs remotely on a dedicated server/pod?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Right; the above is just the local docker setup, and so does not represent a production environment. The above is also likely temporary. At any case, an important observation is that gh-ost reads data from MySQL and then mostly writes it back. It reads the data both by connecting into the replication stream as well as normal queries. What we've observed at GitHub is that latency between he machine where gh-ost runs, to the MySQL servers, is important. e.g. we would only run gh-ost in same DC as affected servers. But, I think taking it to the next level and running gh-ost on the very same tablet+MySQL master servers can be beneficial.
Another thing about running gh-ost from dedicated servers is the amount of migrations you'd be able to run concurrently. I don't have the numbers, but I guess if you'd want to run 100 concurrent migrations (say you have 100 shards), then I suspect running 100 gh-ost instances on same dedicated server is unlikely to perform well. Actual testing needed but that's my suspicion.
When you run gh-ost right on the master server, that problem implicitly doesn't exist.

# Clean up files we won't need in the final image.
rm -rf /var/lib/apt/lists/*
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ require (
github.com/hashicorp/serf v0.9.2 // indirect
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
github.com/imdario/mergo v0.3.6 // indirect
github.com/julienschmidt/httprouter v1.3.0
github.com/klauspost/compress v1.4.1 // indirect
github.com/klauspost/cpuid v1.2.0 // indirect
github.com/klauspost/pgzip v1.2.4
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/krishicks/yaml-patch v0.0.10
github.com/krishicks/yaml-patch v0.0.10 // indirect
github.com/magiconair/properties v1.8.1
github.com/mattn/go-runewidth v0.0.3 // indirect
github.com/minio/minio-go v0.0.0-20190131015406-c8a261de75c1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVY
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/tabletmanager/tablet_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestHealthCheck(t *testing.T) {

// stop replication, make sure we don't go unhealthy.
// TODO: replace with StopReplication once StopSlave has been removed
err = clusterInstance.VtctlclientProcess.ExecuteCommand("StopSlave", rTablet.Alias)
err = clusterInstance.VtctlclientProcess.ExecuteCommand("StopReplication", rTablet.Alias)
require.NoError(t, err)
err = clusterInstance.VtctlclientProcess.ExecuteCommand("RunHealthCheck", rTablet.Alias)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/mysqlctl/rice-box.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
Filename: "init_db.sql",
FileModTime: time.Unix(1593186461, 0),

Content: string("# This file is executed immediately after mysql_install_db,\n# to initialize a fresh data directory.\n\n###############################################################################\n# WARNING: This sql is *NOT* safe for production use,\n# as it contains default well-known users and passwords.\n# Care should be taken to change these users and passwords\n# for production.\n###############################################################################\n\n###############################################################################\n# Equivalent of mysql_secure_installation\n###############################################################################\n\n# Changes during the init db should not make it to the binlog.\n# They could potentially create errant transactions on replicas.\nSET sql_log_bin = 0;\n# Remove anonymous users.\nDELETE FROM mysql.user WHERE User = '';\n\n# Disable remote root access (only allow UNIX socket).\nDELETE FROM mysql.user WHERE User = 'root' AND Host != 'localhost';\n\n# Remove test database.\nDROP DATABASE IF EXISTS test;\n\n###############################################################################\n# Vitess defaults\n###############################################################################\n\n# Vitess-internal database.\nCREATE DATABASE IF NOT EXISTS _vt;\n# Note that definitions of local_metadata and shard_metadata should be the same\n# as in production which is defined in go/vt/mysqlctl/metadata_tables.go.\nCREATE TABLE IF NOT EXISTS _vt.local_metadata (\n name VARCHAR(255) NOT NULL,\n value VARCHAR(255) NOT NULL,\n db_name VARBINARY(255) NOT NULL,\n PRIMARY KEY (db_name, name)\n ) ENGINE=InnoDB;\nCREATE TABLE IF NOT EXISTS _vt.shard_metadata (\n name VARCHAR(255) NOT NULL,\n value MEDIUMBLOB NOT NULL,\n db_name VARBINARY(255) NOT NULL,\n PRIMARY KEY (db_name, name)\n ) ENGINE=InnoDB;\n\n# Admin user with all privileges.\nCREATE USER 'vt_dba'@'localhost';\nGRANT ALL ON *.* TO 'vt_dba'@'localhost';\nGRANT GRANT OPTION ON *.* TO 'vt_dba'@'localhost';\n\n# User for app traffic, with global read-write access.\nCREATE USER 'vt_app'@'localhost';\nGRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, FILE,\n REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES,\n LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW,\n SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER\n ON *.* TO 'vt_app'@'localhost';\n\n# User for app debug traffic, with global read access.\nCREATE USER 'vt_appdebug'@'localhost';\nGRANT SELECT, SHOW DATABASES, PROCESS ON *.* TO 'vt_appdebug'@'localhost';\n\n# User for administrative operations that need to be executed as non-SUPER.\n# Same permissions as vt_app here.\nCREATE USER 'vt_allprivs'@'localhost';\nGRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, FILE,\n REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES,\n LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW,\n SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER\n ON *.* TO 'vt_allprivs'@'localhost';\n\n# User for slave replication connections.\nCREATE USER 'vt_repl'@'%';\nGRANT REPLICATION SLAVE ON *.* TO 'vt_repl'@'%';\n\n# User for Vitess filtered replication (binlog player).\n# Same permissions as vt_app.\nCREATE USER 'vt_filtered'@'localhost';\nGRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, FILE,\n REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES,\n LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW,\n SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER\n ON *.* TO 'vt_filtered'@'localhost';\n\n# User for general MySQL monitoring.\nCREATE USER 'vt_monitoring'@'localhost';\nGRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD\n ON *.* TO 'vt_monitoring'@'localhost';\nGRANT SELECT, UPDATE, DELETE, DROP\n ON performance_schema.* TO 'vt_monitoring'@'localhost';\n\n# User for Orchestrator (https://github.com/openark/orchestrator).\nCREATE USER 'orc_client_user'@'%' IDENTIFIED BY 'orc_client_user_password';\nGRANT SUPER, PROCESS, REPLICATION SLAVE, RELOAD\n ON *.* TO 'orc_client_user'@'%';\nGRANT SELECT\n ON _vt.* TO 'orc_client_user'@'%';\n\nFLUSH PRIVILEGES;\n\nRESET SLAVE ALL;\nRESET MASTER;\n"),
Content: string("# This file is executed immediately after mysql_install_db,\n# to initialize a fresh data directory.\n\n###############################################################################\n# WARNING: This sql is *NOT* safe for production use,\n# as it contains default well-known users and passwords.\n# Care should be taken to change these users and passwords\n# for production.\n###############################################################################\n\n###############################################################################\n# Equivalent of mysql_secure_installation\n###############################################################################\n\n# Changes during the init db should not make it to the binlog.\n# They could potentially create errant transactions on replicas.\nSET sql_log_bin = 0;\n# Remove anonymous users.\nDELETE FROM mysql.user WHERE User = '';\n\n# Disable remote root access (only allow UNIX socket).\nDELETE FROM mysql.user WHERE User = 'root' AND Host != 'localhost';\n\n# Remove test database.\nDROP DATABASE IF EXISTS test;\n\n###############################################################################\n# Vitess defaults\n###############################################################################\n\n# Vitess-internal database.\nCREATE DATABASE IF NOT EXISTS _vt;\n# Note that definitions of local_metadata and shard_metadata should be the same\n# as in production which is defined in go/vt/mysqlctl/metadata_tables.go.\nCREATE TABLE IF NOT EXISTS _vt.local_metadata (\n name VARCHAR(255) NOT NULL,\n value VARCHAR(255) NOT NULL,\n db_name VARBINARY(255) NOT NULL,\n PRIMARY KEY (db_name, name)\n ) ENGINE=InnoDB;\nCREATE TABLE IF NOT EXISTS _vt.shard_metadata (\n name VARCHAR(255) NOT NULL,\n value MEDIUMBLOB NOT NULL,\n db_name VARBINARY(255) NOT NULL,\n PRIMARY KEY (db_name, name)\n ) ENGINE=InnoDB;\n\n# Admin user with all privileges.\nCREATE USER 'vt_dba'@'localhost';\nGRANT ALL ON *.* TO 'vt_dba'@'localhost';\nGRANT GRANT OPTION ON *.* TO 'vt_dba'@'localhost';\n\n# User for app traffic, with global read-write access.\nCREATE USER 'vt_app'@'localhost';\nGRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, FILE,\n REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES,\n LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW,\n SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER\n ON *.* TO 'vt_app'@'localhost';\n\n# User for app debug traffic, with global read access.\nCREATE USER 'vt_appdebug'@'localhost';\nGRANT SELECT, SHOW DATABASES, PROCESS ON *.* TO 'vt_appdebug'@'localhost';\n\n# User for administrative operations that need to be executed as non-SUPER.\n# Same permissions as vt_app here.\nCREATE USER 'vt_allprivs'@'localhost';\nGRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, FILE,\n REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES,\n LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW,\n SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER\n ON *.* TO 'vt_allprivs'@'localhost';\n\n# User for slave replication connections.\nCREATE USER 'vt_repl'@'%';\nGRANT REPLICATION SLAVE ON *.* TO 'vt_repl'@'%';\n\n# User for Vitess filtered replication (binlog player).\n# Same permissions as vt_app.\nCREATE USER 'vt_filtered'@'localhost';\nGRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, FILE,\n REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES,\n LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW,\n SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER\n ON *.* TO 'vt_filtered'@'localhost';\n\n# User for general MySQL monitoring.\nCREATE USER 'vt_monitoring'@'localhost';\nGRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD\n ON *.* TO 'vt_monitoring'@'localhost';\nGRANT SELECT, UPDATE, DELETE, DROP\n ON performance_schema.* TO 'vt_monitoring'@'localhost';\n\n# User for Orchestrator (https://github.com/openark/orchestrator).\nCREATE USER 'orc_client_user'@'%' IDENTIFIED BY 'orc_client_user_password';\nGRANT SUPER, PROCESS, REPLICATION SLAVE, RELOAD\n ON *.* TO 'orc_client_user'@'%';\nGRANT SELECT\n ON _vt.* TO 'orc_client_user'@'%';\n# User for gh-ost (https://github.com/github/gh-ost).\nCREATE USER 'gh-ost'@'127.0.0.1' IDENTIFIED BY 'gh-ost';\nGRANT SUPER, REPLICATION SLAVE ON *.* TO 'gh-ost'@'127.0.0.1';\nGRANT ALTER, CREATE, DELETE, DROP, INDEX, INSERT, LOCK TABLES, SELECT, TRIGGER, UPDATE ON *.* TO 'gh-ost'@'127.0.0.1';\n\nFLUSH PRIVILEGES;\n\nRESET SLAVE ALL;\nRESET MASTER;\n"),
}
file5 := &embedded.EmbeddedFile{
Filename: "mycnf/default-fast.cnf",
Expand Down
4 changes: 4 additions & 0 deletions go/vt/mysqlctl/tmutils/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,16 @@ type SchemaChange struct {
AllowReplication bool
BeforeSchema *tabletmanagerdatapb.SchemaDefinition
AfterSchema *tabletmanagerdatapb.SchemaDefinition
Online bool
Hint string
}

// Equal compares two SchemaChange objects.
func (s *SchemaChange) Equal(s2 *SchemaChange) bool {
return s.SQL == s2.SQL &&
s.Force == s2.Force &&
s.Online == s2.Online &&
s.Hint == s2.Hint &&
s.AllowReplication == s2.AllowReplication &&
proto.Equal(s.BeforeSchema, s2.BeforeSchema) &&
proto.Equal(s.AfterSchema, s2.AfterSchema)
Expand Down
16 changes: 16 additions & 0 deletions go/vt/proto/tabletmanagerdata/tabletmanagerdata.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 60 additions & 3 deletions go/vt/schemamanager/tablet_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"golang.org/x/net/context"

"vitess.io/vitess/go/sync2"
"vitess.io/vitess/go/vt/mysqlctl/tmutils"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/wrangler"

Expand All @@ -36,6 +37,7 @@ type TabletExecutor struct {
tablets []*topodatapb.Tablet
isClosed bool
allowBigSchemaChange bool
onlineSchemaChange bool
keyspace string
waitReplicasTimeout time.Duration
}
Expand All @@ -46,6 +48,7 @@ func NewTabletExecutor(wr *wrangler.Wrangler, waitReplicasTimeout time.Duration)
wr: wr,
isClosed: true,
allowBigSchemaChange: false,
onlineSchemaChange: false,
waitReplicasTimeout: waitReplicasTimeout,
}
}
Expand All @@ -62,6 +65,11 @@ func (exec *TabletExecutor) DisallowBigSchemaChange() {
exec.allowBigSchemaChange = false
}

// SetOnlineSchemaChange sets TabletExecutor such that it initiates online schema change migrations
func (exec *TabletExecutor) SetOnlineSchemaChange() {
exec.onlineSchemaChange = true
}

// Open opens a connection to the master for every shard.
func (exec *TabletExecutor) Open(ctx context.Context, keyspace string) error {
if !exec.isClosed {
Expand Down Expand Up @@ -160,6 +168,11 @@ func (exec *TabletExecutor) detectBigSchemaChanges(ctx context.Context, parsedDD
switch ddl.Action {
case sqlparser.DropStr, sqlparser.CreateStr, sqlparser.TruncateStr, sqlparser.RenameStr:
continue
case sqlparser.AlterStr:
if exec.onlineSchemaChange {
// Seeing that we intend to run an online-schema-change, we can skip the "big change" check.
continue
}
}
tableName := ddl.Table.Name.String()
if rowCount, ok := tableWithCount[tableName]; ok {
Expand Down Expand Up @@ -217,15 +230,32 @@ func (exec *TabletExecutor) Execute(ctx context.Context, sqls []string) *Execute

for index, sql := range sqls {
execResult.CurSQLIndex = index
exec.executeOnAllTablets(ctx, &execResult, sql)

stat, err := sqlparser.Parse(sql)
if err != nil {
execResult.ExecutorErr = err.Error()
return &execResult
}
executeOnlineSchemaChange := false
switch ddl := stat.(type) {
case *sqlparser.DDL:
if ddl.Action == sqlparser.AlterStr && exec.onlineSchemaChange {
executeOnlineSchemaChange = true
}
}
exec.wr.Logger().Infof("Received DDL request. online schema change = %t", executeOnlineSchemaChange)
exec.executeOnAllTablets(ctx, &execResult, sql, executeOnlineSchemaChange)
if len(execResult.FailedShards) > 0 {
break
}
}
return &execResult
}

func (exec *TabletExecutor) executeOnAllTablets(ctx context.Context, execResult *ExecuteResult, sql string) {
func (exec *TabletExecutor) executeOnAllTablets(
ctx context.Context, execResult *ExecuteResult, sql string,
executeOnlineSchemaChange bool,
) {
var wg sync.WaitGroup
numOfMasterTablets := len(exec.tablets)
wg.Add(numOfMasterTablets)
Expand All @@ -234,7 +264,11 @@ func (exec *TabletExecutor) executeOnAllTablets(ctx context.Context, execResult
for _, tablet := range exec.tablets {
go func(tablet *topodatapb.Tablet) {
defer wg.Done()
exec.executeOneTablet(ctx, tablet, sql, errChan, successChan)
if executeOnlineSchemaChange {
exec.executeOnlineSchemaChangeOneTablet(ctx, tablet, sql, errChan, successChan)
} else {
exec.executeOneTablet(ctx, tablet, sql, errChan, successChan)
}
}(tablet)
}
wg.Wait()
Expand Down Expand Up @@ -297,6 +331,29 @@ func (exec *TabletExecutor) executeOneTablet(
}
}

// executeOnlineSchemaChangeOneTablet will request the tablet to run an online schema change
func (exec *TabletExecutor) executeOnlineSchemaChangeOneTablet(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This function can be changed to invoke VExec to insert a row in the ghost table (as mentioned in the issue). We can do a pairing session for doing the vttablet part that picks up this change and launches ghost. This approach will allow the schema migration to survive failovers.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

👍 I need to learn more about that

ctx context.Context,
tablet *topodatapb.Tablet,
sql string,
errChan chan ShardWithError,
successChan chan ShardResult,
) {
change := &tmutils.SchemaChange{
SQL: sql,
Online: true,
Hint: "", // TODO(shlomi) generate and populate hint
}
_, err := exec.wr.TabletManagerClient().ApplySchema(ctx, tablet, change)
if err != nil {
errChan <- ShardWithError{Shard: tablet.Shard, Err: err.Error()}
return
}
successChan <- ShardResult{
Shard: tablet.Shard,
}
}

// Close clears tablet executor states
func (exec *TabletExecutor) Close() {
if !exec.isClosed {
Expand Down
Loading