diff --git a/go/cmd/vtcombo/vschema_watcher.go b/go/cmd/vtcombo/vschema_watcher.go index 9194f61e774..948ed67bea7 100644 --- a/go/cmd/vtcombo/vschema_watcher.go +++ b/go/cmd/vtcombo/vschema_watcher.go @@ -26,6 +26,7 @@ import ( vschemapb "vitess.io/vitess/go/vt/proto/vschema" vttestpb "vitess.io/vitess/go/vt/proto/vttest" "vitess.io/vitess/go/vt/topo" + "vitess.io/vitess/go/vt/vtgate/vindexes" ) func startVschemaWatcher(vschemaPersistenceDir string, keyspaces []*vttestpb.Keyspace, ts *topo.Server) { @@ -61,6 +62,10 @@ func loadKeyspacesFromDir(dir string, keyspaces []*vttestpb.Keyspace, ts *topo.S log.Fatalf("Unable to parse keyspace file %v: %v", ksFile, err) } + _, err = vindexes.BuildKeyspace(keyspace) + if err != nil { + log.Fatalf("Invalid keyspace definition: %v", err) + } ts.SaveVSchema(context.Background(), ks.Name, keyspace) log.Infof("Loaded keyspace %v from %v\n", ks.Name, ksFile) } diff --git a/go/cmd/vtctldclient/command/keyspaces.go b/go/cmd/vtctldclient/command/keyspaces.go index 393b4795d8f..c224e3eb26b 100644 --- a/go/cmd/vtctldclient/command/keyspaces.go +++ b/go/cmd/vtctldclient/command/keyspaces.go @@ -25,9 +25,9 @@ import ( "github.com/spf13/cobra" "vitess.io/vitess/go/cmd/vtctldclient/cli" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/logutil" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/topo" topodatapb "vitess.io/vitess/go/vt/proto/topodata" @@ -425,7 +425,7 @@ func init() { CreateKeyspace.Flags().StringVar(&createKeyspaceOptions.BaseKeyspace, "base-keyspace", "", "The base keyspace for a snapshot keyspace.") CreateKeyspace.Flags().StringVar(&createKeyspaceOptions.SnapshotTimestamp, "snapshot-timestamp", "", "The snapshot time for a snapshot keyspace, as a timestamp in RFC3339 format.") CreateKeyspace.Flags().StringVar(&createKeyspaceOptions.DurabilityPolicy, "durability-policy", "none", "Type of durability to enforce for this keyspace. Default is none. Possible values include 'semi_sync' and others as dictated by registered plugins.") - CreateKeyspace.Flags().StringVar(&createKeyspaceOptions.SidecarDBName, "sidecar-db-name", sidecardb.DefaultName, "(Experimental) Name of the Vitess sidecar database that tablets in this keyspace will use for internal metadata.") + CreateKeyspace.Flags().StringVar(&createKeyspaceOptions.SidecarDBName, "sidecar-db-name", sidecar.DefaultName, "(Experimental) Name of the Vitess sidecar database that tablets in this keyspace will use for internal metadata.") Root.AddCommand(CreateKeyspace) DeleteKeyspace.Flags().BoolVarP(&deleteKeyspaceOptions.Recursive, "recursive", "r", false, "Recursively delete all shards in the keyspace, and all tablets in those shards.") diff --git a/go/constants/sidecar/name.go b/go/constants/sidecar/name.go new file mode 100644 index 00000000000..063452782b7 --- /dev/null +++ b/go/constants/sidecar/name.go @@ -0,0 +1,42 @@ +/* +Copyright 2023 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package sidecar + +import ( + "sync/atomic" +) + +const ( + DefaultName = "_vt" +) + +var ( + // This should be accessed via GetName() + sidecarDBName atomic.Value +) + +func init() { + sidecarDBName.Store(DefaultName) +} + +func SetName(name string) { + sidecarDBName.Store(name) +} + +func GetName() string { + return sidecarDBName.Load().(string) +} diff --git a/go/test/endtoend/cluster/cluster_process.go b/go/test/endtoend/cluster/cluster_process.go index 9c1f879a832..5db2078d666 100644 --- a/go/test/endtoend/cluster/cluster_process.go +++ b/go/test/endtoend/cluster/cluster_process.go @@ -36,13 +36,13 @@ import ( "testing" "time" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/json2" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/test/endtoend/filelock" "vitess.io/vitess/go/vt/grpcclient" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext" "vitess.io/vitess/go/vt/vtgate/vtgateconn" @@ -329,7 +329,7 @@ func (cluster *LocalProcessCluster) startKeyspace(keyspace Keyspace, shardNames log.Infof("Starting keyspace: %v", keyspace.Name) if keyspace.SidecarDBName == "" { - keyspace.SidecarDBName = sidecardb.DefaultName + keyspace.SidecarDBName = sidecar.DefaultName } // Create the keyspace if it doesn't already exist. _ = cluster.VtctlProcess.CreateKeyspace(keyspace.Name, keyspace.SidecarDBName) @@ -482,7 +482,7 @@ func (cluster *LocalProcessCluster) StartKeyspaceLegacy(keyspace Keyspace, shard log.Infof("Starting keyspace: %v", keyspace.Name) if keyspace.SidecarDBName == "" { - keyspace.SidecarDBName = sidecardb.DefaultName + keyspace.SidecarDBName = sidecar.DefaultName } // Create the keyspace if it doesn't already exist. _ = cluster.VtctlProcess.CreateKeyspace(keyspace.Name, keyspace.SidecarDBName) @@ -623,7 +623,7 @@ func (cluster *LocalProcessCluster) SetupCluster(keyspace *Keyspace, shards []Sh log.Infof("Starting keyspace: %v", keyspace.Name) if keyspace.SidecarDBName == "" { - keyspace.SidecarDBName = sidecardb.DefaultName + keyspace.SidecarDBName = sidecar.DefaultName } if !cluster.ReusingVTDATAROOT { diff --git a/go/test/endtoend/cluster/vttablet_process.go b/go/test/endtoend/cluster/vttablet_process.go index 522c205114a..eb44a96f346 100644 --- a/go/test/endtoend/cluster/vttablet_process.go +++ b/go/test/endtoend/cluster/vttablet_process.go @@ -35,10 +35,10 @@ import ( "testing" "time" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/sqlparser" ) @@ -519,7 +519,7 @@ func (vttablet *VttabletProcess) ToggleProfiling() error { // WaitForVReplicationToCatchup waits for "workflow" to finish copying func (vttablet *VttabletProcess) WaitForVReplicationToCatchup(t testing.TB, workflow, database string, sidecarDBName string, duration time.Duration) { if sidecarDBName == "" { - sidecarDBName = sidecardb.DefaultName + sidecarDBName = sidecar.DefaultName } // Escape it if/as needed ics := sqlparser.NewIdentifierCS(sidecarDBName) diff --git a/go/test/endtoend/encryption/encryptedreplication/encrypted_replication_test.go b/go/test/endtoend/encryption/encryptedreplication/encrypted_replication_test.go index 4fb53d8f6fb..725659a5ee1 100644 --- a/go/test/endtoend/encryption/encryptedreplication/encrypted_replication_test.go +++ b/go/test/endtoend/encryption/encryptedreplication/encrypted_replication_test.go @@ -25,10 +25,10 @@ import ( "github.com/stretchr/testify/require" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/test/endtoend/encryption" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/sidecardb" ) var ( @@ -131,7 +131,7 @@ func initializeCluster(t *testing.T) (int, error) { for _, keyspaceStr := range []string{keyspace} { KeyspacePtr := &cluster.Keyspace{Name: keyspaceStr} keyspace := *KeyspacePtr - if err := clusterInstance.VtctlProcess.CreateKeyspace(keyspace.Name, sidecardb.DefaultName); err != nil { + if err := clusterInstance.VtctlProcess.CreateKeyspace(keyspace.Name, sidecar.DefaultName); err != nil { return 1, err } shard := &cluster.Shard{ diff --git a/go/test/endtoend/encryption/encryptedtransport/encrypted_transport_test.go b/go/test/endtoend/encryption/encryptedtransport/encrypted_transport_test.go index ec4a553849b..b076006ec2c 100644 --- a/go/test/endtoend/encryption/encryptedtransport/encrypted_transport_test.go +++ b/go/test/endtoend/encryption/encryptedtransport/encrypted_transport_test.go @@ -65,10 +65,10 @@ import ( "github.com/pkg/errors" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/test/endtoend/encryption" "vitess.io/vitess/go/vt/proto/vtrpc" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/vterrors" "github.com/stretchr/testify/assert" @@ -350,7 +350,7 @@ func clusterSetUp(t *testing.T) (int, error) { for _, keyspaceStr := range []string{keyspace} { KeyspacePtr := &cluster.Keyspace{Name: keyspaceStr} keyspace := *KeyspacePtr - if err := clusterInstance.VtctlProcess.CreateKeyspace(keyspace.Name, sidecardb.DefaultName); err != nil { + if err := clusterInstance.VtctlProcess.CreateKeyspace(keyspace.Name, sidecar.DefaultName); err != nil { return 1, err } shard := &cluster.Shard{ diff --git a/go/test/endtoend/mysqlctl/mysqlctl_test.go b/go/test/endtoend/mysqlctl/mysqlctl_test.go index 121449866cf..3b28c5bcf30 100644 --- a/go/test/endtoend/mysqlctl/mysqlctl_test.go +++ b/go/test/endtoend/mysqlctl/mysqlctl_test.go @@ -25,8 +25,8 @@ import ( "github.com/stretchr/testify/require" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/test/endtoend/cluster" - "vitess.io/vitess/go/vt/sidecardb" ) var ( @@ -53,7 +53,7 @@ func TestMain(m *testing.M) { return 1 } - if err := clusterInstance.VtctlProcess.CreateKeyspace(keyspaceName, sidecardb.DefaultName); err != nil { + if err := clusterInstance.VtctlProcess.CreateKeyspace(keyspaceName, sidecar.DefaultName); err != nil { return 1 } diff --git a/go/test/endtoend/mysqlctld/mysqlctld_test.go b/go/test/endtoend/mysqlctld/mysqlctld_test.go index a8da1ccb948..908a870d6f0 100644 --- a/go/test/endtoend/mysqlctld/mysqlctld_test.go +++ b/go/test/endtoend/mysqlctld/mysqlctld_test.go @@ -26,10 +26,10 @@ import ( "github.com/stretchr/testify/require" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/vt/mysqlctl/mysqlctlclient" "vitess.io/vitess/go/test/endtoend/cluster" - "vitess.io/vitess/go/vt/sidecardb" ) var ( @@ -56,7 +56,7 @@ func TestMain(m *testing.M) { return 1 } - if err := clusterInstance.VtctlProcess.CreateKeyspace(keyspaceName, sidecardb.DefaultName); err != nil { + if err := clusterInstance.VtctlProcess.CreateKeyspace(keyspaceName, sidecar.DefaultName); err != nil { return 1 } diff --git a/go/test/endtoend/recovery/pitr/shardedpitr_test.go b/go/test/endtoend/recovery/pitr/shardedpitr_test.go index a532b1ce919..d04b5600362 100644 --- a/go/test/endtoend/recovery/pitr/shardedpitr_test.go +++ b/go/test/endtoend/recovery/pitr/shardedpitr_test.go @@ -29,11 +29,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/sidecardb" ) var ( @@ -304,8 +304,8 @@ func performResharding(t *testing.T) { require.NoError(t, err) waitTimeout := 30 * time.Second - shard0Primary.VttabletProcess.WaitForVReplicationToCatchup(t, "ks.reshardWorkflow", dbName, sidecardb.DefaultName, waitTimeout) - shard1Primary.VttabletProcess.WaitForVReplicationToCatchup(t, "ks.reshardWorkflow", dbName, sidecardb.DefaultName, waitTimeout) + shard0Primary.VttabletProcess.WaitForVReplicationToCatchup(t, "ks.reshardWorkflow", dbName, sidecar.DefaultName, waitTimeout) + shard1Primary.VttabletProcess.WaitForVReplicationToCatchup(t, "ks.reshardWorkflow", dbName, sidecar.DefaultName, waitTimeout) waitForNoWorkflowLag(t, clusterInstance, "ks.reshardWorkflow") diff --git a/go/test/endtoend/sharded/sharded_keyspace_test.go b/go/test/endtoend/sharded/sharded_keyspace_test.go index 1560d531a28..857dc455206 100644 --- a/go/test/endtoend/sharded/sharded_keyspace_test.go +++ b/go/test/endtoend/sharded/sharded_keyspace_test.go @@ -26,9 +26,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/sidecardb" ) var ( @@ -84,7 +84,7 @@ func TestMain(m *testing.M) { if err := clusterInstance.StartTopo(); err != nil { return 1, err } - if err := clusterInstance.VtctlProcess.CreateKeyspace(keyspaceName, sidecardb.DefaultName); err != nil { + if err := clusterInstance.VtctlProcess.CreateKeyspace(keyspaceName, sidecar.DefaultName); err != nil { return 1, err } diff --git a/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go b/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go index 82a92f8cc87..1c9f4b0b6e2 100644 --- a/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go +++ b/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go @@ -28,10 +28,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/test/endtoend/utils" - "vitess.io/vitess/go/vt/sidecardb" ) var ( @@ -67,7 +67,7 @@ func TestMain(m *testing.M) { // For upgrade/downgrade tests. if vtgateVer < 17 || vttabletVer < 17 { // Then only the default sidecarDBName is supported. - sidecarDBName = sidecardb.DefaultName + sidecarDBName = sidecar.DefaultName } // Start topo server diff --git a/go/test/endtoend/vtgate/schematracker/sharded_prs/st_sharded_test.go b/go/test/endtoend/vtgate/schematracker/sharded_prs/st_sharded_test.go index 9b58ff80ff5..3ff0b61b482 100644 --- a/go/test/endtoend/vtgate/schematracker/sharded_prs/st_sharded_test.go +++ b/go/test/endtoend/vtgate/schematracker/sharded_prs/st_sharded_test.go @@ -24,8 +24,7 @@ import ( "testing" "time" - "vitess.io/vitess/go/vt/sidecardb" - + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -142,7 +141,7 @@ func TestMain(m *testing.M) { // For upgrade/downgrade tests. if vtgateVer < 17 || vttabletVer < 17 { // Then only the default sidecarDBName is supported. - sidecarDBName = sidecardb.DefaultName + sidecarDBName = sidecar.DefaultName } clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--schema_change_signal") diff --git a/go/test/endtoend/vtgate/schematracker/unsharded/st_unsharded_test.go b/go/test/endtoend/vtgate/schematracker/unsharded/st_unsharded_test.go index 245d6bed84c..1a37dfb5cf7 100644 --- a/go/test/endtoend/vtgate/schematracker/unsharded/st_unsharded_test.go +++ b/go/test/endtoend/vtgate/schematracker/unsharded/st_unsharded_test.go @@ -24,11 +24,11 @@ import ( "testing" "time" - "vitess.io/vitess/go/test/endtoend/utils" - "vitess.io/vitess/go/vt/sidecardb" - "github.com/stretchr/testify/require" + "vitess.io/vitess/go/constants/sidecar" + "vitess.io/vitess/go/test/endtoend/utils" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -68,7 +68,7 @@ func TestMain(m *testing.M) { // For upgrade/downgrade tests. if vtgateVer < 17 || vttabletVer < 17 { // Then only the default sidecarDBName is supported. - sidecarDBName = sidecardb.DefaultName + sidecarDBName = sidecar.DefaultName } // Start topo server diff --git a/go/vt/binlog/binlogplayer/dbclient.go b/go/vt/binlog/binlogplayer/dbclient.go index 251da23e929..594a0639473 100644 --- a/go/vt/binlog/binlogplayer/dbclient.go +++ b/go/vt/binlog/binlogplayer/dbclient.go @@ -20,11 +20,11 @@ import ( "context" "fmt" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/dbconfigs" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/sqlparser" ) @@ -55,7 +55,7 @@ type dbClientImplWithSidecarDBReplacement struct { // NewDBClient creates a DBClient instance func NewDBClient(params dbconfigs.Connector) DBClient { - if sidecardb.GetName() != sidecardb.DefaultName { + if sidecar.GetName() != sidecar.DefaultName { return &dbClientImplWithSidecarDBReplacement{ dbClientImpl{dbConfig: params}, } @@ -141,7 +141,7 @@ func (dc *dbClientImpl) ExecuteFetch(query string, maxrows int) (*sqltypes.Resul func (dcr *dbClientImplWithSidecarDBReplacement) ExecuteFetch(query string, maxrows int) (*sqltypes.Result, error) { // Replace any provided sidecar database qualifiers with the correct one. - uq, err := sqlparser.ReplaceTableQualifiers(query, sidecardb.DefaultName, sidecardb.GetName()) + uq, err := sqlparser.ReplaceTableQualifiers(query, sidecar.DefaultName, sidecar.GetName()) if err != nil { return nil, err } diff --git a/go/vt/mysqlctl/reparent.go b/go/vt/mysqlctl/reparent.go index a258b530f9f..c75db53ace9 100644 --- a/go/vt/mysqlctl/reparent.go +++ b/go/vt/mysqlctl/reparent.go @@ -21,6 +21,7 @@ This file contains the reparenting methods for mysqlctl. */ import ( + "context" "time" "vitess.io/vitess/go/vt/sidecardb" @@ -28,8 +29,6 @@ import ( "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/log" - - "context" ) // GenerateInitialBinlogEntry is used to create a binlog entry when diff --git a/go/vt/sidecardb/identifier_cache.go b/go/vt/sidecardb/identifier_cache.go index a010923081d..002d8750ba1 100644 --- a/go/vt/sidecardb/identifier_cache.go +++ b/go/vt/sidecardb/identifier_cache.go @@ -22,6 +22,7 @@ import ( "sync/atomic" "time" + "vitess.io/vitess/go/constants/sidecar" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vterrors" @@ -88,7 +89,7 @@ func (ic *IdentifierCache) Get(keyspace string) (string, error) { return "", err } if sdbname == "" { - sdbname = DefaultName + sdbname = sidecar.DefaultName } sdbid = sqlparser.String(sqlparser.NewIdentifierCS(sdbname)) diff --git a/go/vt/sidecardb/sidecardb.go b/go/vt/sidecardb/sidecardb.go index df87dab2288..19bed3e5340 100644 --- a/go/vt/sidecardb/sidecardb.go +++ b/go/vt/sidecardb/sidecardb.go @@ -26,8 +26,8 @@ import ( "runtime" "strings" "sync" - "sync/atomic" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/history" "vitess.io/vitess/go/mysql" @@ -45,7 +45,6 @@ import ( ) const ( - DefaultName = "_vt" createSidecarDBQuery = "create database if not exists %s" sidecarDBExistsQuery = "select 'true' as 'dbexists' from information_schema.SCHEMATA where SCHEMA_NAME = %a" showCreateTableQuery = "show create table %s.%s" @@ -70,8 +69,6 @@ const ( ) var ( - // This should be accessed via GetName() - sidecarDBName atomic.Value sidecarTables []*sidecarTable // All tables needed in the sidecar database have @@ -100,7 +97,6 @@ type ddlError struct { } func init() { - sidecarDBName.Store(DefaultName) ddlCount = stats.NewCounter(StatsKeyQueryCount, "Number of queries executed") ddlErrorCount = stats.NewCounter(StatsKeyErrorCount, "Number of errors during sidecar schema upgrade") ddlErrorHistory = history.New(maxDDLErrorHistoryLength) @@ -134,7 +130,7 @@ func validateSchemaDefinition(name, schema string) (string, error) { if qualifier != "" { return "", vterrors.Errorf(vtrpcpb.Code_INTERNAL, "database qualifier of %s specified for the %s table when there should not be one", qualifier, name) } - createTable.Table.Qualifier = sqlparser.NewIdentifierCS(GetName()) + createTable.Table.Qualifier = sqlparser.NewIdentifierCS(sidecar.GetName()) if !strings.EqualFold(tableName, name) { return "", vterrors.Errorf(vtrpcpb.Code_INTERNAL, "table name of %s does not match the table name specified within the file: %s", name, tableName) } @@ -193,7 +189,7 @@ func printCallerDetails() { pc, _, line, ok := runtime.Caller(2) details := runtime.FuncForPC(pc) if ok && details != nil { - log.Infof("%s schema init called from %s:%d\n", GetName(), details.Name(), line) + log.Infof("%s schema init called from %s:%d\n", sidecar.GetName(), details.Name(), line) } } @@ -207,19 +203,11 @@ type schemaInit struct { // execute the specified query within the database. type Exec func(ctx context.Context, query string, maxRows int, useDB bool) (*sqltypes.Result, error) -func SetName(name string) { - sidecarDBName.Store(name) -} - -func GetName() string { - return sidecarDBName.Load().(string) -} - // GetIdentifier returns the sidecar database name as an SQL // identifier string, most importantly this means that it will // be properly escaped if/as needed. func GetIdentifier() string { - ident := sqlparser.NewIdentifierCS(GetName()) + ident := sqlparser.NewIdentifierCS(sidecar.GetName()) return sqlparser.String(ident) } @@ -325,7 +313,7 @@ func (si *schemaInit) setPermissiveSQLMode() (func(), error) { } func (si *schemaInit) doesSidecarDBExist() (bool, error) { - query, err := sqlparser.ParseAndBind(sidecarDBExistsQuery, sqltypes.StringBindVariable(GetName())) + query, err := sqlparser.ParseAndBind(sidecarDBExistsQuery, sqltypes.StringBindVariable(sidecar.GetName())) if err != nil { return false, err } @@ -337,10 +325,10 @@ func (si *schemaInit) doesSidecarDBExist() (bool, error) { switch len(rs.Rows) { case 0: - log.Infof("doesSidecarDBExist: %s not found", GetName()) + log.Infof("doesSidecarDBExist: %s not found", sidecar.GetName()) return false, nil case 1: - log.Infof("doesSidecarDBExist: found %s", GetName()) + log.Infof("doesSidecarDBExist: found %s", sidecar.GetName()) return true, nil default: // This should never happen. @@ -354,7 +342,7 @@ func (si *schemaInit) createSidecarDB() error { log.Error(err) return err } - log.Infof("createSidecarDB: %s", GetName()) + log.Infof("createSidecarDB: %s", sidecar.GetName()) return nil } @@ -460,7 +448,7 @@ func (si *schemaInit) ensureSchema(table *sidecarTable) error { ddlCount.Add(1) return nil } - log.Infof("Table schema was already up to date for the %s table in the %s sidecar database", table.name, GetName()) + log.Infof("Table schema was already up to date for the %s table in the %s sidecar database", table.name, sidecar.GetName()) return nil } @@ -510,7 +498,7 @@ func AddSchemaInitQueries(db *fakesqldb.DB, populateTables bool) { for _, q := range sidecarDBInitQueries { db.AddQuery(sqlparser.BuildParsedQuery(q, GetIdentifier()).Query, result) } - sdbe, _ := sqlparser.ParseAndBind(sidecarDBExistsQuery, sqltypes.StringBindVariable(GetName())) + sdbe, _ := sqlparser.ParseAndBind(sidecarDBExistsQuery, sqltypes.StringBindVariable(sidecar.GetName())) db.AddQuery(sdbe, result) for _, table := range sidecarTables { result = &sqltypes.Result{} @@ -545,7 +533,7 @@ func MatchesInitQuery(query string) bool { return true } } - sdbe, _ := sqlparser.ParseAndBind(sidecarDBExistsQuery, sqltypes.StringBindVariable(GetName())) + sdbe, _ := sqlparser.ParseAndBind(sidecarDBExistsQuery, sqltypes.StringBindVariable(sidecar.GetName())) if strings.EqualFold(sdbe, query) { return true } diff --git a/go/vt/sidecardb/sidecardb_test.go b/go/vt/sidecardb/sidecardb_test.go index 49b91ae5bdc..d65115c2c20 100644 --- a/go/vt/sidecardb/sidecardb_test.go +++ b/go/vt/sidecardb/sidecardb_test.go @@ -24,6 +24,7 @@ import ( "strings" "testing" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/vt/sqlparser" "github.com/stretchr/testify/require" @@ -142,9 +143,9 @@ func TestMiscSidecarDB(t *testing.T) { result := sqltypes.MakeTestResult(sqltypes.MakeTestFields( "dbexists", "int64"), - GetName(), + sidecar.GetName(), ) - dbeq, err := sqlparser.ParseAndBind(sidecarDBExistsQuery, sqltypes.StringBindVariable(GetName())) + dbeq, err := sqlparser.ParseAndBind(sidecarDBExistsQuery, sqltypes.StringBindVariable(sidecar.GetName())) require.NoError(t, err) db.AddQuery(dbeq, result) db.AddQuery(sqlparser.BuildParsedQuery(createSidecarDBQuery, GetIdentifier()).Query, &sqltypes.Result{}) diff --git a/go/vt/topo/helpers/copy.go b/go/vt/topo/helpers/copy.go index f0ae912243b..5a1a5cd3465 100644 --- a/go/vt/topo/helpers/copy.go +++ b/go/vt/topo/helpers/copy.go @@ -26,6 +26,7 @@ import ( "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/topoproto" + "vitess.io/vitess/go/vt/vtgate/vindexes" topodatapb "vitess.io/vitess/go/vt/proto/topodata" ) @@ -55,6 +56,11 @@ func CopyKeyspaces(ctx context.Context, fromTS, toTS *topo.Server) { vs, err := fromTS.GetVSchema(ctx, keyspace) switch { case err == nil: + _, err = vindexes.BuildKeyspace(vs) + if err != nil { + log.Errorf("BuildKeyspace(%v): %v", keyspace, err) + break + } if err := toTS.SaveVSchema(ctx, keyspace, vs); err != nil { log.Errorf("SaveVSchema(%v): %v", keyspace, err) } diff --git a/go/vt/topo/keyspace.go b/go/vt/topo/keyspace.go index ddec9f4e0a8..feb80c374e5 100755 --- a/go/vt/topo/keyspace.go +++ b/go/vt/topo/keyspace.go @@ -20,7 +20,7 @@ import ( "context" "path" - "vitess.io/vitess/go/vt/sidecardb" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/event" @@ -233,7 +233,7 @@ func (ts *Server) GetSidecarDBName(ctx context.Context, keyspace string) (string if keyspaceInfo.SidecarDbName != "" { return keyspaceInfo.SidecarDbName, nil } - return sidecardb.DefaultName, nil + return sidecar.DefaultName, nil } func (ts *Server) GetThrottlerConfig(ctx context.Context, keyspace string) (*topodatapb.ThrottlerConfig, error) { diff --git a/go/vt/topo/shard.go b/go/vt/topo/shard.go index cd98325cd3c..3f7be3cc676 100644 --- a/go/vt/topo/shard.go +++ b/go/vt/topo/shard.go @@ -29,9 +29,9 @@ import ( "google.golang.org/protobuf/proto" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/proto/vtrpc" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/event" @@ -365,7 +365,7 @@ func (ts *Server) GetOrCreateShard(ctx context.Context, keyspace, shard string) // fully initialize and perform certain operations (e.g. // OnlineDDL or VReplication workflows) if they are using a // different sidecar database name. - ksi := topodatapb.Keyspace{SidecarDbName: sidecardb.GetName()} + ksi := topodatapb.Keyspace{SidecarDbName: sidecar.GetName()} if err = ts.CreateKeyspace(ctx, keyspace, &ksi); err != nil && !IsErrType(err, NodeExists) { return nil, vterrors.Wrapf(err, "CreateKeyspace(%v) failed", keyspace) } diff --git a/go/vt/topo/vschema.go b/go/vt/topo/vschema.go index c167475a462..0f63a26c2ae 100644 --- a/go/vt/topo/vschema.go +++ b/go/vt/topo/vschema.go @@ -17,27 +17,20 @@ limitations under the License. package topo import ( + "context" "path" "google.golang.org/protobuf/proto" - "context" - "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/vterrors" vschemapb "vitess.io/vitess/go/vt/proto/vschema" - "vitess.io/vitess/go/vt/vtgate/vindexes" ) -// SaveVSchema first validates the VSchema, then saves it. +// SaveVSchema saves a Vschema. A valid Vschema should be passed in. It does not verify its correctness. // If the VSchema is empty, just remove it. func (ts *Server) SaveVSchema(ctx context.Context, keyspace string, vschema *vschemapb.Keyspace) error { - _, err := vindexes.BuildKeyspace(vschema) - if err != nil { - return err - } - nodePath := path.Join(KeyspacesPath, keyspace, VSchemaFile) data, err := vschema.MarshalVT() if err != nil { diff --git a/go/vt/vtcombo/tablet_map.go b/go/vt/vtcombo/tablet_map.go index 18923177def..712b0f40633 100644 --- a/go/vt/vtcombo/tablet_map.go +++ b/go/vt/vtcombo/tablet_map.go @@ -394,6 +394,10 @@ func CreateKs( return 0, fmt.Errorf("cannot load vschema file %v for keyspace %v: %v", f, keyspace, err) } + _, err = vindexes.BuildKeyspace(formal) + if err != nil { + return 0, fmt.Errorf("BuildKeyspace(%v) failed: %v", keyspace, err) + } if err := ts.SaveVSchema(ctx, keyspace, formal); err != nil { return 0, fmt.Errorf("SaveVSchema(%v) failed: %v", keyspace, err) } diff --git a/go/vt/vtctl/grpcvtctldserver/server.go b/go/vt/vtctl/grpcvtctldserver/server.go index 68cff9702a8..9ad16b8b98e 100644 --- a/go/vt/vtctl/grpcvtctldserver/server.go +++ b/go/vt/vtctl/grpcvtctldserver/server.go @@ -60,6 +60,7 @@ import ( "vitess.io/vitess/go/vt/vtctl/schematools" "vitess.io/vitess/go/vt/vtctl/workflow" "vitess.io/vitess/go/vt/vterrors" + "vitess.io/vitess/go/vt/vtgate/vindexes" "vitess.io/vitess/go/vt/vttablet/tmclient" logutilpb "vitess.io/vitess/go/vt/proto/logutil" @@ -356,6 +357,12 @@ func (s *VtctldServer) ApplyVSchema(ctx context.Context, req *vtctldatapb.ApplyV return &vtctldatapb.ApplyVSchemaResponse{VSchema: vs}, nil } + _, err = vindexes.BuildKeyspace(vs) + if err != nil { + err = vterrors.Wrapf(err, "BuildKeyspace(%s)", req.Keyspace) + return nil, err + } + if err = s.ts.SaveVSchema(ctx, req.Keyspace, vs); err != nil { err = vterrors.Wrapf(err, "SaveVSchema(%s, %v)", req.Keyspace, req.VSchema) return nil, err diff --git a/go/vt/vtctl/vtctl.go b/go/vt/vtctl/vtctl.go index fa9d8a1e1d0..6611043f368 100644 --- a/go/vt/vtctl/vtctl.go +++ b/go/vt/vtctl/vtctl.go @@ -97,6 +97,7 @@ import ( "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/cmd/vtctldclient/cli" @@ -119,7 +120,6 @@ import ( vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/proto/vttime" "vitess.io/vitess/go/vt/schema" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/topoproto" @@ -1819,7 +1819,7 @@ func commandCreateKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags baseKeyspace := subFlags.String("base_keyspace", "", "Specifies the base keyspace for a snapshot keyspace") timestampStr := subFlags.String("snapshot_time", "", "Specifies the snapshot time for this keyspace") durabilityPolicy := subFlags.String("durability-policy", "none", "Type of durability to enforce for this keyspace. Default is none. Possible values include 'semi_sync' and others as dictated by registered plugins.") - sidecarDBName := subFlags.String("sidecar-db-name", sidecardb.DefaultName, "(Experimental) Name of the Vitess sidecar database that tablets in this keyspace will use for internal metadata.") + sidecarDBName := subFlags.String("sidecar-db-name", sidecar.DefaultName, "(Experimental) Name of the Vitess sidecar database that tablets in this keyspace will use for internal metadata.") if err := subFlags.Parse(args); err != nil { return err } @@ -3418,6 +3418,10 @@ func commandApplyVSchema(ctx context.Context, wr *wrangler.Wrangler, subFlags *p return err } + if _, err := vindexes.BuildKeyspace(vs); err != nil { + return err + } + if err := wr.TopoServer().SaveVSchema(ctx, keyspace, vs); err != nil { return err } diff --git a/go/vt/vtgate/executor_framework_test.go b/go/vt/vtgate/executor_framework_test.go index 25b5e4e4183..01e3854a21d 100644 --- a/go/vt/vtgate/executor_framework_test.go +++ b/go/vt/vtgate/executor_framework_test.go @@ -29,6 +29,7 @@ import ( "github.com/stretchr/testify/require" "vitess.io/vitess/go/cache" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/streamlog" "vitess.io/vitess/go/vt/discovery" @@ -130,7 +131,7 @@ func createExecutorEnv() (executor *Executor, sbc1, sbc2, sbclookup *sandboxconn s := createSandbox(KsTestSharded) s.VSchema = executorVSchema serv := newSandboxForCells([]string{cell}) - serv.topoServer.CreateKeyspace(context.Background(), "TestExecutor", &topodatapb.Keyspace{SidecarDbName: sidecardb.DefaultName}) + serv.topoServer.CreateKeyspace(context.Background(), "TestExecutor", &topodatapb.Keyspace{SidecarDbName: sidecar.DefaultName}) // Force a new cache to use for lookups of the sidecar database identifier // in use by each keyspace -- as we want to use a different load function // than the one already created by the vtgate as it uses a different topo. diff --git a/go/vt/vtgate/vschema_manager.go b/go/vt/vtgate/vschema_manager.go index baa232a87d8..cd482c8ba84 100644 --- a/go/vt/vtgate/vschema_manager.go +++ b/go/vt/vtgate/vschema_manager.go @@ -70,6 +70,12 @@ func (vm *VSchemaManager) UpdateVSchema(ctx context.Context, ksName string, vsch } ks := vschema.Keyspaces[ksName] + + _, err = vindexes.BuildKeyspace(ks) + if err != nil { + return err + } + err = topoServer.SaveVSchema(ctx, ksName, ks) if err != nil { return err diff --git a/go/vt/vttablet/onlineddl/executor.go b/go/vt/vttablet/onlineddl/executor.go index cbf287ac090..eef05a5aa58 100644 --- a/go/vt/vttablet/onlineddl/executor.go +++ b/go/vt/vttablet/onlineddl/executor.go @@ -40,6 +40,7 @@ import ( "google.golang.org/protobuf/encoding/prototext" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqlescape" "vitess.io/vitess/go/sqltypes" @@ -55,7 +56,6 @@ import ( "vitess.io/vitess/go/vt/schema" "vitess.io/vitess/go/vt/schemadiff" "vitess.io/vitess/go/vt/servenv" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/topoproto" @@ -292,7 +292,7 @@ func (e *Executor) executeQueryWithSidecarDBReplacement(ctx context.Context, que defer conn.Recycle() // Replace any provided sidecar DB qualifiers with the correct one. - uq, err := sqlparser.ReplaceTableQualifiers(query, sidecardb.DefaultName, sidecardb.GetName()) + uq, err := sqlparser.ReplaceTableQualifiers(query, sidecar.DefaultName, sidecar.GetName()) if err != nil { return nil, err } @@ -327,7 +327,7 @@ func (e *Executor) Open() error { }) e.vreplicationLastError = make(map[string]*vterrors.LastError) - if sidecardb.GetName() != sidecardb.DefaultName { + if sidecar.GetName() != sidecar.DefaultName { e.execQuery = e.executeQueryWithSidecarDBReplacement } else { e.execQuery = e.executeQuery diff --git a/go/vt/vttablet/tabletmanager/rpc_query.go b/go/vt/vttablet/tabletmanager/rpc_query.go index 37ab3367009..0d21cee7677 100644 --- a/go/vt/vttablet/tabletmanager/rpc_query.go +++ b/go/vt/vttablet/tabletmanager/rpc_query.go @@ -19,10 +19,10 @@ package tabletmanager import ( "context" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/sqlescape" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/sqlparser" querypb "vitess.io/vitess/go/vt/proto/query" @@ -66,7 +66,7 @@ func (tm *TabletManager) ExecuteFetchAsDba(ctx context.Context, req *tabletmanag } // Replace any provided sidecar database qualifiers with the correct one. - uq, err := sqlparser.ReplaceTableQualifiers(string(req.Query), sidecardb.DefaultName, sidecardb.GetName()) + uq, err := sqlparser.ReplaceTableQualifiers(string(req.Query), sidecar.DefaultName, sidecar.GetName()) if err != nil { return nil, err } @@ -107,7 +107,7 @@ func (tm *TabletManager) ExecuteFetchAsAllPrivs(ctx context.Context, req *tablet } // Replace any provided sidecar database qualifiers with the correct one. - uq, err := sqlparser.ReplaceTableQualifiers(string(req.Query), sidecardb.DefaultName, sidecardb.GetName()) + uq, err := sqlparser.ReplaceTableQualifiers(string(req.Query), sidecar.DefaultName, sidecar.GetName()) if err != nil { return nil, err } @@ -131,7 +131,7 @@ func (tm *TabletManager) ExecuteFetchAsApp(ctx context.Context, req *tabletmanag } defer conn.Recycle() // Replace any provided sidecar database qualifiers with the correct one. - uq, err := sqlparser.ReplaceTableQualifiers(string(req.Query), sidecardb.DefaultName, sidecardb.GetName()) + uq, err := sqlparser.ReplaceTableQualifiers(string(req.Query), sidecar.DefaultName, sidecar.GetName()) if err != nil { return nil, err } @@ -145,7 +145,7 @@ func (tm *TabletManager) ExecuteQuery(ctx context.Context, req *tabletmanagerdat tablet := tm.Tablet() target := &querypb.Target{Keyspace: tablet.Keyspace, Shard: tablet.Shard, TabletType: tablet.Type} // Replace any provided sidecar database qualifiers with the correct one. - uq, err := sqlparser.ReplaceTableQualifiers(string(req.Query), sidecardb.DefaultName, sidecardb.GetName()) + uq, err := sqlparser.ReplaceTableQualifiers(string(req.Query), sidecar.DefaultName, sidecar.GetName()) if err != nil { return nil, err } diff --git a/go/vt/vttablet/tabletmanager/rpc_vreplication.go b/go/vt/vttablet/tabletmanager/rpc_vreplication.go index 771cbf33f32..969433a7568 100644 --- a/go/vt/vttablet/tabletmanager/rpc_vreplication.go +++ b/go/vt/vttablet/tabletmanager/rpc_vreplication.go @@ -22,6 +22,7 @@ import ( "google.golang.org/protobuf/encoding/prototext" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/textutil" "vitess.io/vitess/go/vt/discovery" @@ -325,7 +326,7 @@ func (tm *TabletManager) UpdateVReplicationWorkflow(ctx context.Context, req *ta // VReplicationExec executes a vreplication command. func (tm *TabletManager) VReplicationExec(ctx context.Context, query string) (*querypb.QueryResult, error) { // Replace any provided sidecar databsae qualifiers with the correct one. - uq, err := sqlparser.ReplaceTableQualifiers(query, sidecardb.DefaultName, sidecardb.GetName()) + uq, err := sqlparser.ReplaceTableQualifiers(query, sidecar.DefaultName, sidecar.GetName()) if err != nil { return nil, err } diff --git a/go/vt/vttablet/tabletmanager/rpc_vreplication_test.go b/go/vt/vttablet/tabletmanager/rpc_vreplication_test.go index 05708f924f0..a1e64550224 100644 --- a/go/vt/vttablet/tabletmanager/rpc_vreplication_test.go +++ b/go/vt/vttablet/tabletmanager/rpc_vreplication_test.go @@ -24,9 +24,9 @@ import ( "github.com/stretchr/testify/require" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/textutil" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vtctl/workflow" @@ -355,7 +355,7 @@ func TestMoveTables(t *testing.T) { _, err := ws.MoveTablesCreate(ctx, req) require.NoError(t, err) - tenv.vrdbClient.ExpectRequest(fmt.Sprintf("use %s", sidecardb.DefaultName), &sqltypes.Result{}, nil) + tenv.vrdbClient.ExpectRequest(fmt.Sprintf("use %s", sidecar.DefaultName), &sqltypes.Result{}, nil) _, err = ws.WorkflowSwitchTraffic(ctx, &vtctldatapb.WorkflowSwitchTrafficRequest{ Keyspace: req.TargetKeyspace, Workflow: req.Workflow, @@ -391,7 +391,7 @@ func TestUpdateVReplicationWorkflow(t *testing.T) { tablet := tenv.addTablet(tabletUID, keyspace, shard) defer tenv.deleteTablet(tablet.tablet) - parsed := sqlparser.BuildParsedQuery(sqlSelectVReplicationWorkflowConfig, sidecardb.DefaultName, ":wf") + parsed := sqlparser.BuildParsedQuery(sqlSelectVReplicationWorkflowConfig, sidecar.DefaultName, ":wf") bindVars := map[string]*querypb.BindVariable{ "wf": sqltypes.StringBindVariable(workflow), } @@ -500,9 +500,9 @@ func TestUpdateVReplicationWorkflow(t *testing.T) { tt.request.State = binlogdatapb.VReplicationWorkflowState_Stopped // These are the same for each RPC call. - tenv.vrdbClient.ExpectRequest(fmt.Sprintf("use %s", sidecardb.DefaultName), &sqltypes.Result{}, nil) + tenv.vrdbClient.ExpectRequest(fmt.Sprintf("use %s", sidecar.DefaultName), &sqltypes.Result{}, nil) tenv.vrdbClient.ExpectRequest(selectQuery, selectRes, nil) - tenv.vrdbClient.ExpectRequest(fmt.Sprintf("use %s", sidecardb.DefaultName), &sqltypes.Result{}, nil) + tenv.vrdbClient.ExpectRequest(fmt.Sprintf("use %s", sidecar.DefaultName), &sqltypes.Result{}, nil) tenv.vrdbClient.ExpectRequest(idQuery, idRes, nil) // This is our expected query, which will also short circuit diff --git a/go/vt/vttablet/tabletmanager/tm_init.go b/go/vt/vttablet/tabletmanager/tm_init.go index 67d50c71e78..da4e142c0a5 100644 --- a/go/vt/vttablet/tabletmanager/tm_init.go +++ b/go/vt/vttablet/tabletmanager/tm_init.go @@ -46,6 +46,7 @@ import ( "github.com/spf13/pflag" "golang.org/x/sync/semaphore" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/flagutil" "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/netutil" @@ -61,7 +62,6 @@ import ( querypb "vitess.io/vitess/go/vt/proto/query" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/servenv" - "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/topoproto" "vitess.io/vitess/go/vt/topotools" @@ -496,7 +496,7 @@ func (tm *TabletManager) createKeyspaceShard(ctx context.Context) (*topo.ShardIn // If the keyspace exists but this is the first tablet added, then // update the keyspace record to the default. if ks.SidecarDbName == "" { - ks.SidecarDbName = sidecardb.DefaultName + ks.SidecarDbName = sidecar.DefaultName getlockctx, cancel := context.WithTimeout(context.Background(), topo.RemoteOperationTimeout) defer cancel() lockctx, unlock, lockErr := tm.TopoServer.LockKeyspace(getlockctx, tablet.Keyspace, "Setting sidecar database name") @@ -513,7 +513,7 @@ func (tm *TabletManager) createKeyspaceShard(ctx context.Context) (*topo.ShardIn } } // Have the tablet use the sidecar database that's set for the keyspace. - sidecardb.SetName(ks.SidecarDbName) + sidecar.SetName(ks.SidecarDbName) return nil } if err := tm.withRetry(ctx, "setting sidecar database name", setSidecarDBName); err != nil { diff --git a/go/vt/vttablet/tabletmanager/vreplication/controller_plan.go b/go/vt/vttablet/tabletmanager/vreplication/controller_plan.go index 5d2091d335d..463b5b53a9f 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/controller_plan.go +++ b/go/vt/vttablet/tabletmanager/vreplication/controller_plan.go @@ -19,6 +19,7 @@ package vreplication import ( "fmt" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/sqlparser" ) @@ -85,7 +86,7 @@ func buildInsertPlan(ins *sqlparser.Insert) (*controllerPlan, error) { if err != nil { return nil, err } - if tableName.Qualifier.String() != sidecardb.GetName() && tableName.Qualifier.String() != sidecardb.DefaultName { + if tableName.Qualifier.String() != sidecar.GetName() && tableName.Qualifier.String() != sidecar.DefaultName { return nil, fmt.Errorf("invalid database name: %s", tableName.Qualifier.String()) } switch tableName.Name.String() { @@ -154,7 +155,7 @@ func buildUpdatePlan(upd *sqlparser.Update) (*controllerPlan, error) { if err != nil { return nil, err } - if tableName.Qualifier.String() != sidecardb.GetName() && tableName.Qualifier.String() != sidecardb.DefaultName { + if tableName.Qualifier.String() != sidecar.GetName() && tableName.Qualifier.String() != sidecar.DefaultName { return nil, fmt.Errorf("invalid database name: %s", tableName.Qualifier.String()) } switch tableName.Name.String() { @@ -211,7 +212,7 @@ func buildDeletePlan(del *sqlparser.Delete) (*controllerPlan, error) { if err != nil { return nil, err } - if tableName.Qualifier.String() != sidecardb.GetName() && tableName.Qualifier.String() != sidecardb.DefaultName { + if tableName.Qualifier.String() != sidecar.GetName() && tableName.Qualifier.String() != sidecar.DefaultName { return nil, fmt.Errorf("invalid database name: %s", tableName.Qualifier.String()) } switch tableName.Name.String() { @@ -285,7 +286,7 @@ func buildSelectPlan(sel *sqlparser.Select) (*controllerPlan, error) { if err != nil { return nil, err } - if tableName.Qualifier.String() != sidecardb.GetName() && tableName.Qualifier.String() != sidecardb.DefaultName { + if tableName.Qualifier.String() != sidecar.GetName() && tableName.Qualifier.String() != sidecar.DefaultName { return nil, fmt.Errorf("invalid database name: %s", tableName.Qualifier.String()) } switch tableName.Name.String() { diff --git a/go/vt/vttablet/tabletserver/health_streamer.go b/go/vt/vttablet/tabletserver/health_streamer.go index ad9acf495d8..50a31262f00 100644 --- a/go/vt/vttablet/tabletserver/health_streamer.go +++ b/go/vt/vttablet/tabletserver/health_streamer.go @@ -27,11 +27,10 @@ import ( "github.com/spf13/pflag" + "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/vttablet/tabletserver/schema" "vitess.io/vitess/go/vt/servenv" - "vitess.io/vitess/go/vt/sidecardb" - "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/dbconfigs" diff --git a/go/vt/vttablet/tabletserver/repltracker/reader.go b/go/vt/vttablet/tabletserver/repltracker/reader.go index 5bbe62eb1bf..ebe4938dd12 100644 --- a/go/vt/vttablet/tabletserver/repltracker/reader.go +++ b/go/vt/vttablet/tabletserver/repltracker/reader.go @@ -17,6 +17,7 @@ limitations under the License. package repltracker import ( + "context" "fmt" "sync" "time" @@ -26,8 +27,6 @@ import ( "vitess.io/vitess/go/vt/vterrors" - "context" - "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/timer" "vitess.io/vitess/go/vt/log" diff --git a/go/vt/vttablet/tabletserver/repltracker/writer.go b/go/vt/vttablet/tabletserver/repltracker/writer.go index bbd28aa557e..c742cbb29fd 100644 --- a/go/vt/vttablet/tabletserver/repltracker/writer.go +++ b/go/vt/vttablet/tabletserver/repltracker/writer.go @@ -17,6 +17,7 @@ limitations under the License. package repltracker import ( + "context" "fmt" "sync" "sync/atomic" @@ -24,8 +25,6 @@ import ( "google.golang.org/protobuf/proto" - "context" - "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/timer" "vitess.io/vitess/go/vt/dbconnpool" diff --git a/go/vt/vttablet/tabletserver/schema/engine.go b/go/vt/vttablet/tabletserver/schema/engine.go index 5d5cd2e6ca3..5026e14b1ed 100644 --- a/go/vt/vttablet/tabletserver/schema/engine.go +++ b/go/vt/vttablet/tabletserver/schema/engine.go @@ -28,20 +28,19 @@ import ( "golang.org/x/exp/maps" - "vitess.io/vitess/go/sqltypes" - "vitess.io/vitess/go/vt/concurrency" - "vitess.io/vitess/go/vt/mysqlctl/tmutils" - "vitess.io/vitess/go/vt/sidecardb" - "vitess.io/vitess/go/acl" "vitess.io/vitess/go/mysql" + "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/stats" "vitess.io/vitess/go/timer" + "vitess.io/vitess/go/vt/concurrency" "vitess.io/vitess/go/vt/dbconfigs" "vitess.io/vitess/go/vt/dbconnpool" "vitess.io/vitess/go/vt/log" + "vitess.io/vitess/go/vt/mysqlctl/tmutils" "vitess.io/vitess/go/vt/schema" "vitess.io/vitess/go/vt/servenv" + "vitess.io/vitess/go/vt/sidecardb" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/vtgate/evalengine" diff --git a/go/vt/vttablet/tabletserver/schema/tracker.go b/go/vt/vttablet/tabletserver/schema/tracker.go index e864fd4191b..415b4fcedda 100644 --- a/go/vt/vttablet/tabletserver/schema/tracker.go +++ b/go/vt/vttablet/tabletserver/schema/tracker.go @@ -23,11 +23,9 @@ import ( "sync" "time" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/schema" "vitess.io/vitess/go/vt/sidecardb" - - "vitess.io/vitess/go/mysql" - "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/sqltypes" diff --git a/go/vt/vttablet/tabletserver/twopc.go b/go/vt/vttablet/tabletserver/twopc.go index bc6c3816121..11dea639d25 100644 --- a/go/vt/vttablet/tabletserver/twopc.go +++ b/go/vt/vttablet/tabletserver/twopc.go @@ -17,6 +17,7 @@ limitations under the License. package tabletserver import ( + "context" "fmt" "time" @@ -25,8 +26,6 @@ import ( "vitess.io/vitess/go/vt/vtgate/evalengine" - "context" - "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/dbconfigs" "vitess.io/vitess/go/vt/dbconnpool" diff --git a/go/vt/vttablet/tabletserver/vstreamer/vstreamer.go b/go/vt/vttablet/tabletserver/vstreamer/vstreamer.go index 9c821bdc506..e8a3055dae8 100644 --- a/go/vt/vttablet/tabletserver/vstreamer/vstreamer.go +++ b/go/vt/vttablet/tabletserver/vstreamer/vstreamer.go @@ -26,6 +26,7 @@ import ( "google.golang.org/protobuf/encoding/prototext" "google.golang.org/protobuf/proto" + "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/mysql" mysqlbinlog "vitess.io/vitess/go/mysql/binlog" "vitess.io/vitess/go/mysql/collations" @@ -575,10 +576,10 @@ func (vs *vstreamer) parseEvent(ev mysql.BinlogEvent) ([]*binlogdatapb.VEvent, e log.Infof("table map changed: id %d for %s has changed to %s", id, plan.Table.Name, tm.Name) } - if tm.Database == sidecardb.GetName() && tm.Name == "resharding_journal" { + if tm.Database == sidecar.GetName() && tm.Name == "resharding_journal" { // A journal is a special case that generates a JOURNAL event. return nil, vs.buildJournalPlan(id, tm) - } else if tm.Database == sidecardb.GetName() && tm.Name == "schema_version" && !vs.se.SkipMetaCheck { + } else if tm.Database == sidecar.GetName() && tm.Name == "schema_version" && !vs.se.SkipMetaCheck { // Generates a Version event when it detects that a schema is stored in the schema_version table. return nil, vs.buildVersionPlan(id, tm) } diff --git a/go/vt/vttest/local_cluster.go b/go/vt/vttest/local_cluster.go index a577657748d..9a4466bce29 100644 --- a/go/vt/vttest/local_cluster.go +++ b/go/vt/vttest/local_cluster.go @@ -32,12 +32,12 @@ import ( "time" "unicode" - "vitess.io/vitess/go/vt/sidecardb" - "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/prototext" "google.golang.org/protobuf/proto" + "vitess.io/vitess/go/vt/sidecardb" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/log"