Skip to content
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

Refactor code to remove evalengine as a dependency of VTOrc #13642

Merged
merged 4 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 5 additions & 0 deletions go/cmd/vtcombo/vschema_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move vindexes outside of vtgate as well here since we use it in many others? Is it worth moving it to go/vt/vindexes for example then?

Copy link
Member

Choose a reason for hiding this comment

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

Yes we should move it out, but that can also be a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I don't want to do that in this PR.

)

func startVschemaWatcher(vschemaPersistenceDir string, keyspaces []*vttestpb.Keyspace, ts *topo.Server) {
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions go/cmd/vtctldclient/command/keyspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"vitess.io/vitess/go/cmd/vtctldclient/cli"
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/sidecardb"
"vitess.io/vitess/go/vt/sidecardb/dbname"
GuptaManan100 marked this conversation as resolved.
Show resolved Hide resolved
"vitess.io/vitess/go/vt/topo"

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
Expand Down Expand Up @@ -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", dbname.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.")
Expand Down
8 changes: 4 additions & 4 deletions go/mysql/endtoend/schema_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"
"testing"

"vitess.io/vitess/go/vt/sidecardb"
"vitess.io/vitess/go/vt/sidecardb/dbname"
"vitess.io/vitess/go/vt/sqlparser"

"github.com/stretchr/testify/require"
Expand All @@ -42,9 +42,9 @@ func TestChangeSchemaIsNoticed(t *testing.T) {
require.NoError(t, err)
defer conn.Close()

clearQuery := sqlparser.BuildParsedQuery(mysql.ClearSchemaCopy, sidecardb.GetIdentifier()).Query
insertQuery := sqlparser.BuildParsedQuery(mysql.InsertIntoSchemaCopy, sidecardb.GetIdentifier()).Query
detectQuery := sqlparser.BuildParsedQuery(mysql.DetectSchemaChange, sidecardb.GetIdentifier()).Query
clearQuery := sqlparser.BuildParsedQuery(mysql.ClearSchemaCopy, dbname.GetIdentifier()).Query
insertQuery := sqlparser.BuildParsedQuery(mysql.InsertIntoSchemaCopy, dbname.GetIdentifier()).Query
detectQuery := sqlparser.BuildParsedQuery(mysql.DetectSchemaChange, dbname.GetIdentifier()).Query

tests := []struct {
name string
Expand Down
8 changes: 4 additions & 4 deletions go/test/endtoend/cluster/cluster_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
"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/sidecardb/dbname"
"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"
"vitess.io/vitess/go/vt/vtgate/vtgateconn"
Expand Down Expand Up @@ -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 = dbname.DefaultName
}
// Create the keyspace if it doesn't already exist.
_ = cluster.VtctlProcess.CreateKeyspace(keyspace.Name, keyspace.SidecarDBName)
Expand Down Expand Up @@ -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 = dbname.DefaultName
}
// Create the keyspace if it doesn't already exist.
_ = cluster.VtctlProcess.CreateKeyspace(keyspace.Name, keyspace.SidecarDBName)
Expand Down Expand Up @@ -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 = dbname.DefaultName
}

if !cluster.ReusingVTDATAROOT {
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/cluster/vttablet_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"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/sidecardb/dbname"
"vitess.io/vitess/go/vt/sqlparser"
)

Expand Down Expand Up @@ -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 = dbname.DefaultName
}
// Escape it if/as needed
ics := sqlparser.NewIdentifierCS(sidecarDBName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"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"
"vitess.io/vitess/go/vt/sidecardb/dbname"
)

var (
Expand Down Expand Up @@ -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, dbname.DefaultName); err != nil {
return 1, err
}
shard := &cluster.Shard{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ import (
"github.com/pkg/errors"

"vitess.io/vitess/go/test/endtoend/encryption"
"vitess.io/vitess/go/vt/sidecardb/dbname"

"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/sidecardb"
"vitess.io/vitess/go/vt/vterrors"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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, dbname.DefaultName); err != nil {
return 1, err
}
shard := &cluster.Shard{
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/mysqlctl/mysqlctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/vt/sidecardb"
"vitess.io/vitess/go/vt/sidecardb/dbname"
)

var (
Expand All @@ -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, dbname.DefaultName); err != nil {
return 1
}

Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/mysqlctld/mysqlctld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/vt/mysqlctl/mysqlctlclient"
"vitess.io/vitess/go/vt/sidecardb/dbname"

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/vt/sidecardb"
)

var (
Expand All @@ -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, dbname.DefaultName); err != nil {
return 1
}

Expand Down
6 changes: 3 additions & 3 deletions go/test/endtoend/recovery/pitr/shardedpitr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"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"
"vitess.io/vitess/go/vt/sidecardb/dbname"
)

var (
Expand Down Expand Up @@ -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, dbname.DefaultName, waitTimeout)
shard1Primary.VttabletProcess.WaitForVReplicationToCatchup(t, "ks.reshardWorkflow", dbName, dbname.DefaultName, waitTimeout)

waitForNoWorkflowLag(t, clusterInstance, "ks.reshardWorkflow")

Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/sharded/sharded_keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/sidecardb"
"vitess.io/vitess/go/vt/sidecardb/dbname"
)

var (
Expand Down Expand Up @@ -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, dbname.DefaultName); err != nil {
return 1, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"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"
"vitess.io/vitess/go/vt/sidecardb/dbname"
)

var (
Expand Down Expand Up @@ -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 = dbname.DefaultName
}

// Start topo server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import (
"testing"
"time"

"vitess.io/vitess/go/vt/sidecardb"

"vitess.io/vitess/go/test/endtoend/utils"
"vitess.io/vitess/go/vt/sidecardb/dbname"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -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 = dbname.DefaultName
}

clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--schema_change_signal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/test/endtoend/utils"
"vitess.io/vitess/go/vt/sidecardb/dbname"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/cluster"
)
Expand Down Expand Up @@ -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 = dbname.DefaultName
}

// Start topo server
Expand Down
6 changes: 3 additions & 3 deletions go/vt/binlog/binlogplayer/dbclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"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/sidecardb/dbname"
"vitess.io/vitess/go/vt/sqlparser"
)

Expand Down Expand Up @@ -55,7 +55,7 @@ type dbClientImplWithSidecarDBReplacement struct {

// NewDBClient creates a DBClient instance
func NewDBClient(params dbconfigs.Connector) DBClient {
if sidecardb.GetName() != sidecardb.DefaultName {
if dbname.GetName() != dbname.DefaultName {
return &dbClientImplWithSidecarDBReplacement{
dbClientImpl{dbConfig: params},
}
Expand Down Expand Up @@ -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, dbname.DefaultName, dbname.GetName())
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions go/vt/mysqlctl/reparent.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ This file contains the reparenting methods for mysqlctl.
*/

import (
"context"
"time"

"vitess.io/vitess/go/vt/sidecardb"
"vitess.io/vitess/go/vt/sidecardb/dbname"
"vitess.io/vitess/go/vt/sqlparser"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/vt/log"

"context"
)

// GenerateInitialBinlogEntry is used to create a binlog entry when
Expand All @@ -50,15 +50,15 @@ func PopulateReparentJournal(timeCreatedNS int64, actionName, primaryAlias strin
}
return sqlparser.BuildParsedQuery("INSERT INTO %s.reparent_journal "+
"(time_created_ns, action_name, primary_alias, replication_position) "+
"VALUES (%d, '%s', '%s', '%s')", sidecardb.GetIdentifier(),
"VALUES (%d, '%s', '%s', '%s')", dbname.GetIdentifier(),
timeCreatedNS, actionName, primaryAlias, posStr).Query
}

// queryReparentJournal returns the SQL query to use to query the database
// for a reparent_journal row.
func queryReparentJournal(timeCreatedNS int64) string {
return sqlparser.BuildParsedQuery("SELECT action_name, primary_alias, replication_position FROM %s.reparent_journal WHERE time_created_ns=%d",
sidecardb.GetIdentifier(), timeCreatedNS).Query
dbname.GetIdentifier(), timeCreatedNS).Query
}

// WaitForReparentJournal will wait until the context is done for
Expand Down
36 changes: 36 additions & 0 deletions go/vt/sidecardb/dbname/name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dbname

import (
"sync/atomic"

"vitess.io/vitess/go/vt/sqlparser"
GuptaManan100 marked this conversation as resolved.
Show resolved Hide resolved
)

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)
}

// 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())
return sqlparser.String(ident)
}
Loading