-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Draft: Tablet schema initialization refactoring #10533
Changes from 43 commits
cfeb733
235944b
10d736a
0a5fb2b
6d50661
d0b5f28
e6dcba5
6b31101
8dda034
01fe631
c12124b
b7eb505
46cc9a0
761569a
2f2424c
2c095a5
9152b24
d5f4426
2cec8db
d88be5a
2e97acd
7ae5ee4
01f677e
8073fae
e3fcec5
2afb03f
20ea847
c883d05
6e7624a
24fd674
158f439
caacdbb
31747de
a840438
492c765
5a820f4
aa76d9f
46496ef
88704ce
235d596
36acdb6
87c4d94
46267e5
817493d
4ad6160
b189736
005214e
fb5eed4
63f3c7a
0939da5
5bd4c89
d996c8a
fa7c9a8
7861992
ae4d344
48a84d8
c11fe74
5d2617f
2f4d794
e80e365
ff58952
76e13f2
fb938b2
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,104 @@ | ||
# This file is executed immediately after mysql_install_db, | ||
# to initialize a fresh data directory. | ||
|
||
############################################################################### | ||
# WARNING: This sql is *NOT* safe for production use, | ||
# as it contains default well-known users and passwords. | ||
# Care should be taken to change these users and passwords | ||
# for production. | ||
############################################################################### | ||
|
||
############################################################################### | ||
# Equivalent of mysql_secure_installation | ||
############################################################################### | ||
# Changes during the init db should not make it to the binlog. | ||
# They could potentially create errant transactions on replicas. | ||
SET sql_log_bin = 0; | ||
# Remove anonymous users. | ||
DELETE FROM mysql.user WHERE User = ''; | ||
|
||
# Disable remote root access (only allow UNIX socket). | ||
DELETE FROM mysql.user WHERE User = 'root' AND Host != 'localhost'; | ||
|
||
# Remove test database. | ||
DROP DATABASE IF EXISTS test; | ||
|
||
############################################################################### | ||
# Vitess defaults | ||
############################################################################### | ||
|
||
# Vitess-internal database. | ||
CREATE DATABASE IF NOT EXISTS _vt; | ||
# Note that definitions of local_metadata and shard_metadata should be the same | ||
# as in production which is defined in go/vt/mysqlctl/metadata_tables.go. | ||
CREATE TABLE IF NOT EXISTS _vt.local_metadata ( | ||
name VARCHAR(255) NOT NULL, | ||
value VARCHAR(255) NOT NULL, | ||
db_name VARBINARY(255) NOT NULL, | ||
PRIMARY KEY (db_name, name) | ||
) ENGINE=InnoDB; | ||
CREATE TABLE IF NOT EXISTS _vt.shard_metadata ( | ||
name VARCHAR(255) NOT NULL, | ||
value MEDIUMBLOB NOT NULL, | ||
db_name VARBINARY(255) NOT NULL, | ||
PRIMARY KEY (db_name, name) | ||
) ENGINE=InnoDB; | ||
|
||
# Admin user with all privileges. | ||
CREATE USER 'vt_dba'@'localhost'; | ||
GRANT ALL ON *.* TO 'vt_dba'@'localhost'; | ||
GRANT GRANT OPTION ON *.* TO 'vt_dba'@'localhost'; | ||
|
||
# User for app traffic, with global read-write access. | ||
CREATE USER 'vt_app'@'localhost'; | ||
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, FILE, | ||
REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, | ||
LOCK TABLES, EXECUTE, REPLICATION CLIENT, CREATE VIEW, | ||
SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER | ||
ON *.* TO 'vt_app'@'localhost'; | ||
|
||
# User for app debug traffic, with global read access. | ||
CREATE USER 'vt_appdebug'@'localhost'; | ||
GRANT SELECT, SHOW DATABASES, PROCESS ON *.* TO 'vt_appdebug'@'localhost'; | ||
|
||
# User for administrative operations that need to be executed as non-SUPER. | ||
# Same permissions as vt_app here. | ||
CREATE USER 'vt_allprivs'@'localhost'; | ||
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, FILE, | ||
REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, | ||
LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, | ||
SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER | ||
ON *.* TO 'vt_allprivs'@'localhost'; | ||
|
||
# User for slave replication connections. | ||
CREATE USER 'vt_repl'@'%'; | ||
GRANT REPLICATION SLAVE ON *.* TO 'vt_repl'@'%'; | ||
|
||
# User for Vitess VReplication (base vstreamers and vplayer). | ||
CREATE USER 'vt_filtered'@'localhost'; | ||
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, FILE, | ||
REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, | ||
LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, | ||
SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER | ||
ON *.* TO 'vt_filtered'@'localhost'; | ||
|
||
# User for general MySQL monitoring. | ||
CREATE USER 'vt_monitoring'@'localhost'; | ||
GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD | ||
ON *.* TO 'vt_monitoring'@'localhost'; | ||
GRANT SELECT, UPDATE, DELETE, DROP | ||
ON performance_schema.* TO 'vt_monitoring'@'localhost'; | ||
|
||
# User for Orchestrator (https://github.com/openark/orchestrator). | ||
CREATE USER 'orc_client_user'@'%' IDENTIFIED BY 'orc_client_user_password'; | ||
GRANT SUPER, PROCESS, REPLICATION SLAVE, RELOAD | ||
ON *.* TO 'orc_client_user'@'%'; | ||
GRANT SELECT | ||
ON _vt.* TO 'orc_client_user'@'%'; | ||
|
||
FLUSH PRIVILEGES; | ||
|
||
RESET SLAVE ALL; | ||
RESET MASTER; | ||
|
||
# add custom sql here |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,6 +269,12 @@ func takeBackup(ctx context.Context, topoServer *topo.Server, backupStorage back | |
if err := mysqld.ResetReplication(ctx); err != nil { | ||
return fmt.Errorf("can't reset replication: %v", err) | ||
} | ||
// We need to switch off super-read-only before we create database. | ||
_ = mysqld.SetSuperReadOnly(false) | ||
defer func() { | ||
_ = mysqld.SetSuperReadOnly(true) | ||
}() | ||
Comment on lines
+272
to
+276
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. Should we not read the super_readonly value here too before we do a defer to true? What if super read-only was turned off in the beginning, do we want to enable it in the end? |
||
|
||
cmds := mysqlctl.CreateReparentJournal() | ||
cmds = append(cmds, fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", sqlescape.EscapeID(dbName))) | ||
if err := mysqld.ExecuteSuperQueryList(ctx, cmds); err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ Usage of vtctld: | |
--hot_row_protection_concurrent_transactions int Number of concurrent transactions let through to the txpool/MySQL for the same hot row. Should be > 1 to have enough 'ready' transactions in MySQL and benefit from a pipelining effect. (default 5) | ||
--hot_row_protection_max_global_queue_size int Global queue limit across all row (ranges). Useful to prevent that the queue can grow unbounded. (default 1000) | ||
--hot_row_protection_max_queue_size int Maximum number of BeginExecute RPCs which will be queued for the same row (range). (default 20) | ||
--init_populate_metadata (init parameter) populate metadata tables even if restore_from_backup is disabled. If restore_from_backup is enabled, metadata tables are always populated regardless of this flag. | ||
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. This flag shouldn't be in vtctld |
||
--jaeger-agent-host string host and port to send spans to. if empty, no tracing will be done | ||
--keep_logs duration keep logs for this long (using ctime) (zero to keep forever) (default 0s) | ||
--keep_logs_by_mtime duration keep logs for this long (using mtime) (zero to keep forever) (default 0s) | ||
|
@@ -190,11 +191,13 @@ Usage of vtctld: | |
--security_policy string the name of a registered security policy to use for controlling access to URLs - empty means allow all for anyone (built-in policies: deny-all, read-only) | ||
--service_map StringList comma separated list of services to enable (or disable if prefixed with '-') Example: grpc-queryservice | ||
--serving_state_grace_period duration how long to pause after broadcasting health to vtgate, before enforcing a new serving state (default 0s) | ||
--set_super_read_only_after_schema_initializer Set super_read_only in mysql to true after we are done with all schema initialization during vttablet initialization. (default true) | ||
--shutdown_grace_period float how long to wait (in seconds) for queries and transactions to complete during graceful shutdown. | ||
--sql-max-length-errors int truncate queries in error logs to the given length (default unlimited) | ||
--sql-max-length-ui int truncate queries in debug UIs to the given length (default 512) (default 512) | ||
--srv_topo_cache_refresh duration how frequently to refresh the topology for cached entries (default 1s) | ||
--srv_topo_cache_ttl duration how long to use cached entries for topology (default 1s) | ||
--srv_topo_no_cache_for_get Always query topo when getting current value of the key | ||
--srv_topo_timeout duration topo server timeout (default 5s) | ||
--stats_backend string The name of the registered push-based monitoring/stats backend to use | ||
--stats_combine_dimensions string List of dimensions to be combined into a single "all" value in exported stats vars | ||
|
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.
Is this separate file created for the super_read_only changes which are only present in the MySQL file?