From 830bc0946b4caa768636e795978bbb9206d3526b Mon Sep 17 00:00:00 2001 From: ailinkid <314806019@qq.com> Date: Tue, 10 Aug 2021 13:04:08 +0800 Subject: [PATCH 1/3] add physical table placement_policy in mysql schema Signed-off-by: ailinkid <314806019@qq.com> --- session/bootstrap.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index 372badc39932b..d3ce3e6c36e20 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -339,6 +339,22 @@ const ( WITH_GRANT_OPTION enum('N','Y') NOT NULL DEFAULT 'N', PRIMARY KEY (USER,HOST,PRIV) );` + + // CreatePlacementPolicyTable store the placement policys. + CreatePlacementPolicyTable = `CREATE TABLE IF NOT EXISTS mysql.placement_policy ( + NAME varchar(255) NOT NULL, + PRIMARY_REGION varchar(255) DEFAULT NULL, + REGIONS varchar(255) DEFAULT NULL, + LEADERS BIGINT UNSIGNED DEFAULT NULL, + FOLLOWERS BIGINT UNSIGNED DEFAULT NULL, + VOTERS BIGINT UNSIGNED DEFAULT NULL, + SCHEDULE varchar(255) DEFAULT NULL, + CONSTRAINTS varchar(255) DEFAULT NULL, + LEADER_CONSTRAINTS varchar(255) DEFAULT NULL, + FOLLOWER_CONSTRAINTS varchar(255) DEFAULT NULL, + VOTER_CONSTRAINTS varchar(255) DEFAULT NULL, + PRIMARY KEY (NAME) + );` ) // bootstrap initiates system DB for a store. @@ -498,11 +514,13 @@ const ( version71 = 71 // version72 adds snapshot column for mysql.stats_meta version72 = 72 + // version73 adds the placement policy for mysql.placement_meta + version73 = 73 ) // currentBootstrapVersion is defined as a variable, so we can modify its value for testing. // please make sure this is the largest version -var currentBootstrapVersion int64 = version72 +var currentBootstrapVersion int64 = version73 var ( bootstrapVersion = []func(Session, int64){ @@ -578,6 +596,7 @@ var ( upgradeToVer70, upgradeToVer71, upgradeToVer72, + upgradeToVer73, } ) @@ -1527,6 +1546,13 @@ func upgradeToVer72(s Session, ver int64) { doReentrantDDL(s, "ALTER TABLE mysql.stats_meta ADD COLUMN snapshot BIGINT(64) UNSIGNED NOT NULL DEFAULT 0", infoschema.ErrColumnExists) } +func upgradeToVer73(s Session, ver int64) { + if ver >= version73 { + return + } + doReentrantDDL(s, CreatePlacementPolicyTable) +} + func writeOOMAction(s Session) { comment := "oom-action is `log` by default in v3.0.x, `cancel` by default in v4.0.11+" mustExecute(s, `INSERT HIGH_PRIORITY INTO %n.%n VALUES (%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE= %?`, @@ -1605,6 +1631,8 @@ func doDDLWorks(s Session) { mustExecute(s, CreateStatsFMSketchTable) // Create global_grants mustExecute(s, CreateGlobalGrantsTable) + // Create placement_policy + mustExecute(s, CreatePlacementPolicyTable) } // doDMLWorks executes DML statements in bootstrap stage. From db4e7e1f3383030a9dce8c5e28fa9a3c3b0c9b23 Mon Sep 17 00:00:00 2001 From: Arenatlx Date: Tue, 10 Aug 2021 14:13:39 +0800 Subject: [PATCH 2/3] Update session/bootstrap.go Co-authored-by: Morgan Tocker --- session/bootstrap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index d3ce3e6c36e20..a72a90bf85d31 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -342,7 +342,7 @@ const ( // CreatePlacementPolicyTable store the placement policys. CreatePlacementPolicyTable = `CREATE TABLE IF NOT EXISTS mysql.placement_policy ( - NAME varchar(255) NOT NULL, + NAME varchar(64) NOT NULL, PRIMARY_REGION varchar(255) DEFAULT NULL, REGIONS varchar(255) DEFAULT NULL, LEADERS BIGINT UNSIGNED DEFAULT NULL, From 11befc7607d1232b36f7f91564c7b45077222019 Mon Sep 17 00:00:00 2001 From: ailinkid <314806019@qq.com> Date: Tue, 10 Aug 2021 14:27:02 +0800 Subject: [PATCH 3/3] pass test Signed-off-by: ailinkid <314806019@qq.com> --- executor/infoschema_reader_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/executor/infoschema_reader_test.go b/executor/infoschema_reader_test.go index 400ca848a85c3..e5fbc68d3514a 100644 --- a/executor/infoschema_reader_test.go +++ b/executor/infoschema_reader_test.go @@ -914,7 +914,7 @@ func (s *testInfoschemaClusterTableSuite) TestTableStorageStats(c *C) { tk.MustQuery("select TABLE_SCHEMA, sum(TABLE_SIZE) from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'test' group by TABLE_SCHEMA;").Check(testkit.Rows( "test 2", )) - c.Assert(len(tk.MustQuery("select TABLE_NAME from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql';").Rows()), Equals, 24) + c.Assert(len(tk.MustQuery("select TABLE_NAME from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql';").Rows()), Equals, 25) // More tests about the privileges. tk.MustExec("create user 'testuser'@'localhost'") @@ -940,14 +940,14 @@ func (s *testInfoschemaClusterTableSuite) TestTableStorageStats(c *C) { Hostname: "localhost", }, nil, nil), Equals, true) - tk.MustQuery("select count(1) from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql'").Check(testkit.Rows("24")) + tk.MustQuery("select count(1) from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql'").Check(testkit.Rows("25")) c.Assert(tk.Se.Auth(&auth.UserIdentity{ Username: "testuser3", Hostname: "localhost", }, nil, nil), Equals, true) - tk.MustQuery("select count(1) from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql'").Check(testkit.Rows("24")) + tk.MustQuery("select count(1) from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql'").Check(testkit.Rows("25")) } func (s *testInfoschemaTableSuite) TestSequences(c *C) {