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

VTOrc Code Cleanup - generate_base, replace cluster_name with keyspace and shard. #12012

Merged
merged 25 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
de9662f
feat: refactor generate commands of VTOrc to be in a single file
GuptaManan100 Dec 23, 2022
b52cb1b
refactor: cleanup create table formatting
GuptaManan100 Dec 23, 2022
1f8cc35
feat: cleanup the usage of IsSQLite and IsMySQL
GuptaManan100 Dec 23, 2022
6a6f767
feat: remove unused minimal instance
GuptaManan100 Dec 23, 2022
19dd8ea
feat: remove unused table cluster_domain_name
GuptaManan100 Dec 23, 2022
1d9d8b0
feat: fix vtorc database to store keyspace and shard instead of cluster
GuptaManan100 Dec 27, 2022
6997250
feat: remove unused attributes
GuptaManan100 Dec 27, 2022
3bd217d
feat: remove unused cluster domain
GuptaManan100 Dec 27, 2022
36ae49a
feat: change GetClusterName to GetKeyspaceAndShardName
GuptaManan100 Dec 27, 2022
e8eb8b0
feat: fix insertion into database_instance
GuptaManan100 Dec 27, 2022
27d18b0
feat: fix SnapshotTopologies
GuptaManan100 Dec 27, 2022
c187f46
feat: remove inject unseen primary and inject seed
GuptaManan100 Dec 27, 2022
396a2c4
feat: remove ClusterName from Instance
GuptaManan100 Dec 27, 2022
ec8a64f
feat: fix Audit operations
GuptaManan100 Dec 27, 2022
c2d20bb
feat: add Keyspace and Shard to cluster information to replace Cluste…
GuptaManan100 Dec 27, 2022
ec18e0d
feat: fix attempt failure detection registeration
GuptaManan100 Dec 27, 2022
e7084eb
feat: fix blocked topology recoveries
GuptaManan100 Dec 27, 2022
c4f3807
feat: fix topology recovery
GuptaManan100 Dec 27, 2022
7b7e46b
feat: reading recovery instances
GuptaManan100 Dec 27, 2022
cc22ca5
feat: fix get replication and analysis
GuptaManan100 Dec 27, 2022
e46e853
feat: fix bug in query
GuptaManan100 Dec 27, 2022
3ffc36f
test: add tests to check that filtering by keyspace works for APIs
GuptaManan100 Dec 27, 2022
6bce6fd
feat: remove remaining usages of ClusterName
GuptaManan100 Dec 27, 2022
6b0e477
refactor: fix comment explaining sleep in the test
GuptaManan100 Dec 29, 2022
0de78f9
feat: add code to prevent filtering just by shard and add tests for it
GuptaManan100 Jan 5, 2023
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
2 changes: 1 addition & 1 deletion go/cmd/vtorc/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// addStatusParts adds UI parts to the /debug/status page of VTOrc
func addStatusParts() {
servenv.AddStatusPart("Recent Recoveries", logic.TopologyRecoveriesTemplate, func() any {
recoveries, _ := logic.ReadRecentRecoveries("", false, 0)
recoveries, _ := logic.ReadRecentRecoveries(false, 0)
return recoveries
})
}
10 changes: 10 additions & 0 deletions go/test/endtoend/vtorc/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func TestProblemsAPI(t *testing.T) {
assert.Equal(t, 200, status, resp)
assert.Contains(t, resp, fmt.Sprintf(`"Port": %d`, replica.MySQLPort))

// Verify that filtering by keyspace also works in the API as intended
status, resp = utils.MakeAPICall(t, vtorc, "/api/replication-analysis?keyspace=ks")
assert.Equal(t, 200, status, resp)
assert.Contains(t, resp, fmt.Sprintf(`"Port": %d`, replica.MySQLPort))

// Check that filtering using keyspace and shard works
GuptaManan100 marked this conversation as resolved.
Show resolved Hide resolved
status, resp = utils.MakeAPICall(t, vtorc, "/api/replication-analysis?keyspace=ks&shard=80-")
assert.Equal(t, 200, status, resp)
Expand Down Expand Up @@ -150,6 +155,11 @@ func TestProblemsAPI(t *testing.T) {
assert.Equal(t, 200, status, resp)
assert.Contains(t, resp, fmt.Sprintf(`"InstanceAlias": "%v"`, replica.Alias))

// Check that filtering using keyspace works
status, resp = utils.MakeAPICall(t, vtorc, "/api/problems?keyspace=ks")
assert.Equal(t, 200, status, resp)
assert.Contains(t, resp, fmt.Sprintf(`"InstanceAlias": "%v"`, replica.Alias))

// Check that filtering using keyspace and shard works
status, resp = utils.MakeAPICall(t, vtorc, "/api/problems?keyspace=ks&shard=80-")
assert.Equal(t, 200, status, resp)
Expand Down
2 changes: 0 additions & 2 deletions go/test/endtoend/vtorc/readtopologyinstance/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func TestReadTopologyInstanceBufferable(t *testing.T) {
assert.False(t, primaryInstance.HasReplicationCredentials)
assert.Equal(t, primaryInstance.ReplicationIOThreadState, inst.ReplicationThreadStateNoThread)
assert.Equal(t, primaryInstance.ReplicationSQLThreadState, inst.ReplicationThreadStateNoThread)
assert.Equal(t, fmt.Sprintf("%v:%v", keyspace.Name, shard0.Name), primaryInstance.ClusterName)

// insert an errant GTID in the replica
_, err = utils.RunSQL(t, "insert into vt_insert_test(id, msg) values (10173, 'test 178342')", replica, "vt_ks")
Expand Down Expand Up @@ -159,5 +158,4 @@ func TestReadTopologyInstanceBufferable(t *testing.T) {
assert.False(t, replicaInstance.HasReplicationFilters)
assert.LessOrEqual(t, int(replicaInstance.SecondsBehindPrimary.Int64), 1)
assert.False(t, replicaInstance.AllowTLS)
assert.Equal(t, fmt.Sprintf("%v:%v", keyspace.Name, shard0.Name), replicaInstance.ClusterName)
}
26 changes: 0 additions & 26 deletions go/vt/vtorc/attributes/attributes.go

This file was deleted.

111 changes: 0 additions & 111 deletions go/vt/vtorc/attributes/attributes_dao.go

This file was deleted.

12 changes: 1 addition & 11 deletions go/vt/vtorc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,13 @@ func newConfiguration() *Configuration {
}

func (config *Configuration) postReadAdjustments() error {
if config.IsSQLite() && config.SQLite3DataFile == "" {
if config.SQLite3DataFile == "" {
return fmt.Errorf("SQLite3DataFile must be set")
}

return nil
}

// TODO: Simplify the callers and delete this function
func (config *Configuration) IsSQLite() bool {
return true
}

// TODO: Simplify the callers and delete this function
func (config *Configuration) IsMySQL() bool {
return false
}

// read reads configuration from given file, or silently skips if the file does not exist.
// If the file does exist, then it is expected to be in valid JSON format or the function bails out.
func read(fileName string) (*Configuration, error) {
Expand Down
71 changes: 10 additions & 61 deletions go/vt/vtorc/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ func (dummyRes DummySQLResult) RowsAffected() (int64, error) {
return 1, nil
}

func IsSQLite() bool {
return config.Config.IsSQLite()
}

// OpenTopology returns the DB instance for the vtorc backed database
func OpenVTOrc() (db *sql.DB, err error) {
var fromCache bool
Expand All @@ -73,11 +69,8 @@ func OpenVTOrc() (db *sql.DB, err error) {
return db, err
}

func translateStatement(statement string) (string, error) {
if IsSQLite() {
statement = sqlutils.ToSqlite3Dialect(statement)
}
return statement, nil
func translateStatement(statement string) string {
return sqlutils.ToSqlite3Dialect(statement)
}

// registerVTOrcDeployment updates the vtorc_metadata table upon successful deployment
Expand All @@ -102,30 +95,8 @@ func deployStatements(db *sql.DB, queries []string) error {
if err != nil {
log.Fatal(err.Error())
}
// Ugly workaround ahead.
// Origin of this workaround is the existence of some "timestamp NOT NULL," column definitions,
// where in NO_ZERO_IN_DATE,NO_ZERO_DATE sql_mode are invalid (since default is implicitly "0")
// This means installation of vtorc fails on such configured servers, and in particular on 5.7
// where this setting is the dfault.
// For purpose of backwards compatability, what we do is force sql_mode to be more relaxed, create the schemas
// along with the "invalid" definition, and then go ahead and fix those definitions via following ALTER statements.
// My bad.
originalSQLMode := ""
if config.Config.IsMySQL() {
_ = tx.QueryRow(`select @@session.sql_mode`).Scan(&originalSQLMode)
if _, err := tx.Exec(`set @@session.sql_mode=REPLACE(@@session.sql_mode, 'NO_ZERO_DATE', '')`); err != nil {
log.Fatal(err.Error())
}
if _, err := tx.Exec(`set @@session.sql_mode=REPLACE(@@session.sql_mode, 'NO_ZERO_IN_DATE', '')`); err != nil {
log.Fatal(err.Error())
}
}
for _, query := range queries {
query, err := translateStatement(query)
if err != nil {
log.Fatalf("Cannot initiate vtorc: %+v; query=%+v", err, query)
return err
}
query = translateStatement(query)
if _, err := tx.Exec(query); err != nil {
if strings.Contains(err.Error(), "syntax error") {
log.Fatalf("Cannot initiate vtorc: %+v; query=%+v", err, query)
Expand All @@ -144,11 +115,6 @@ func deployStatements(db *sql.DB, queries []string) error {
}
}
}
if config.Config.IsMySQL() {
if _, err := tx.Exec(`set session sql_mode=?`, originalSQLMode); err != nil {
log.Fatal(err.Error())
}
}
if err := tx.Commit(); err != nil {
log.Fatal(err.Error())
}
Expand All @@ -160,36 +126,27 @@ func deployStatements(db *sql.DB, queries []string) error {
func initVTOrcDB(db *sql.DB) error {
log.Info("Initializing vtorc")
log.Info("Migrating database schema")
_ = deployStatements(db, generateSQLBase)
_ = deployStatements(db, generateSQLPatches)
_ = deployStatements(db, vtorcBackend)
_ = registerVTOrcDeployment(db)

if IsSQLite() {
_, _ = ExecVTOrc(`PRAGMA journal_mode = WAL`)
_, _ = ExecVTOrc(`PRAGMA synchronous = NORMAL`)
}
_, _ = ExecVTOrc(`PRAGMA journal_mode = WAL`)
rsajwani marked this conversation as resolved.
Show resolved Hide resolved
_, _ = ExecVTOrc(`PRAGMA synchronous = NORMAL`)

return nil
}

// execInternal
func execInternal(db *sql.DB, query string, args ...any) (sql.Result, error) {
var err error
query, err = translateStatement(query)
if err != nil {
return nil, err
}
query = translateStatement(query)
res, err := sqlutils.ExecNoPrepare(db, query, args...)
return res, err
}

// ExecVTOrc will execute given query on the vtorc backend database.
func ExecVTOrc(query string, args ...any) (sql.Result, error) {
var err error
query, err = translateStatement(query)
if err != nil {
return nil, err
}
query = translateStatement(query)
db, err := OpenVTOrc()
if err != nil {
return nil, err
Expand All @@ -200,11 +157,7 @@ func ExecVTOrc(query string, args ...any) (sql.Result, error) {

// QueryVTOrcRowsMap
func QueryVTOrcRowsMap(query string, onRow func(sqlutils.RowMap) error) error {
query, err := translateStatement(query)
if err != nil {
log.Fatalf("Cannot query vtorc: %+v; query=%+v", err, query)
return err
}
query = translateStatement(query)
db, err := OpenVTOrc()
if err != nil {
return err
Expand All @@ -215,11 +168,7 @@ func QueryVTOrcRowsMap(query string, onRow func(sqlutils.RowMap) error) error {

// QueryVTOrc
func QueryVTOrc(query string, argsArray []any, onRow func(sqlutils.RowMap) error) error {
query, err := translateStatement(query)
if err != nil {
log.Fatalf("Cannot query vtorc: %+v; query=%+v", err, query)
return err
}
query = translateStatement(query)
db, err := OpenVTOrc()
if err != nil {
return err
Expand Down
Loading