-
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
Conversation
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
config/init_maria_db.sql
Outdated
# This file is executed immediately after mysql_install_db, | ||
# to initialize a fresh data directory. |
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?
// We need to switch off super-read-only before we create database. | ||
_ = mysqld.SetSuperReadOnly(false) | ||
defer func() { | ||
_ = mysqld.SetSuperReadOnly(true) | ||
}() |
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.
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?
if err := c.WriteComQuery("SELECT @@global.super_read_only"); err != nil { | ||
return nil, err | ||
} | ||
res, _, _, err := c.ReadQueryResult(1, false) | ||
if err == nil && len(res.Rows) == 1 { | ||
sro := res.Rows[0][0].ToString() | ||
if sro == "1" || sro == "ON" { | ||
if err = c.WriteComQuery("SET GLOBAL super_read_only='OFF'"); err != nil { | ||
return nil, err | ||
} | ||
} | ||
} |
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.
Instead, isn't it easier to turn off super read-only regardless of what its value is before, since we'll only end up running one query then?
func (c *Conn) ExecuteSetSuperReadOnly() (result *sqltypes.Result, err error) { | ||
// Note: MariaDB does not have super_read_only but support for it is EOL in v14.0+ | ||
if !c.IsMariaDB() { | ||
if err := c.WriteComQuery("SELECT @@global.super_read_only"); err != nil { | ||
return nil, err | ||
} | ||
res, _, _, err := c.ReadQueryResult(1, false) | ||
if err == nil && len(res.Rows) == 1 { | ||
sro := res.Rows[0][0].ToString() | ||
if sro == "0" || sro == "OFF" { | ||
if err = c.WriteComQuery("SET GLOBAL super_read_only='ON'"); err != nil { | ||
return nil, err | ||
} | ||
} | ||
} | ||
} | ||
|
||
return result, err | ||
} |
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.
Same as above
if err := c.WriteComQuery("SELECT @@global.read_only"); err != nil { | ||
return nil, err | ||
} | ||
res, _, _, err := c.ReadQueryResult(1, false) | ||
if err == nil && len(res.Rows) == 1 { | ||
sro := res.Rows[0][0].ToString() | ||
if sro == "1" || sro == "ON" { | ||
if err = c.WriteComQuery("SET GLOBAL read_only='OFF'"); err != nil { | ||
return nil, err | ||
} | ||
} | ||
} | ||
|
||
return result, err |
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.
Same as above
@@ -51,7 +51,7 @@ func TestSysNumericPrecisionScale(t *testing.T) { | |||
|
|||
func TestCreateAndDropDatabase(t *testing.T) { | |||
// note that this is testing vttest and not vtgate | |||
conn, err := mysql.Connect(ctx, &vtParams) | |||
conn, err := mysql.Connect(ctx, &mysqlParams) |
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.
This doesn't seem correct. We should be connecting to vtgate and not mysql
var initFile = path.Join(os.Getenv("VTROOT"), "config/init_db.sql") | ||
if !env.IsSQLFlavor() { | ||
initFile = path.Join(os.Getenv("VTROOT"), "config/init_maria_db.sql") | ||
} |
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.
Instead of asking the environment, we could query the MySQL instance directly to know if it is mariadb distribution or not. This would prevent users from running into configuration issues.
{{if (eq .Platform "mariadb103")}} | ||
# mariadb103 | ||
export MYSQL_FLAVOR="MariaDB103" | ||
{{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.
If we decide to go with reading the MySQL version from the instance itself, this won't be required.
go/vt/srvtopo/query.go
Outdated
if *srvTopoNoCacheForGet { | ||
entry := &queryEntry{ | ||
key: wkey, | ||
} | ||
result, err := q.query(ctx, entry) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return result, nil | ||
} |
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 change related to schema initialization?
go/flags/endtoend/vtctld.txt
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
This flag shouldn't be in vtctld
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
Signed-off-by: Rameez Sajwani <rameezwazirali@hotmail.com>
This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:
If no action is taken within 7 days, this PR will be closed. |
This PR was closed because it has been stale for 7 days with no activity. |
Signed-off-by: Rameez Sajwani rameezwazirali@hotmail.com
Description
This is an attempt to consolidated all schema initialization and DB creation at the tablet start-up. The idea is if we can do all schema changes in one place and then seal the db with super-read-only, it will help us avoid errant GTIDs.
Details
We have created Schema_Initialization class which contains list of initialization modules needed to be run during tablet setup. Every module needs to register themselves with schema_Initializer e.g metadata_tables.go, online DDL/executor.go, rpc_replication.go etc.
During tablet initialization at various places in code-base whether we are bootstrapping a completely new tablet or restoring from backup we executes these modules registered as part of their init() routine. Once all the modules are executed we set 'super_read_only' false. This means we won't allow any mutation outside primary tablet. This will help us avoid errand GTIDS.
During tablet promotion we set super-read-only to false and during tablet demotion we set super-read-only to true. This way apart from primary tablet no other replica will be able to produce schema changes from outside.
For Reference
Some related work items done in the past
#10094
#9312
#10448
Unresolved Issued during code changes:
go/test/endtoend/cluster/cluster_process.go
Related Issue(s)
#10363
Checklist
Deployment Notes