Skip to content

Commit ffaec94

Browse files
DISTMYSQL-421: Remove master-slave terminologies in Orchestrator
1. Orchestrator calls intercepted by QueryStringProvider 2. Test framework adjusted to be able to use 8.4 Temporary solution: Hacked dbdeployer added (out of the box it doesn't work with 8.4)
1 parent 1754ca9 commit ffaec94

File tree

20 files changed

+544
-106
lines changed

20 files changed

+544
-106
lines changed

docker/Dockerfile.system

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ RUN git clone -b $ci_env_branch $ci_env_repo # cache
1919

2020
# Setup dbdeployer
2121
RUN mkdir /dbdeployer
22-
RUN (cd /dbdeployer && wget https://github.com/datacharmer/dbdeployer/releases/download/v1.64.0/dbdeployer-1.64.0.linux.tar.gz)
23-
RUN (cd /dbdeployer && tar -xf dbdeployer-1.64.0.linux.tar.gz)
24-
RUN (cd /dbdeployer && ln -s dbdeployer-1.64.0.linux dbdeployer)
22+
RUN (cd /dbdeployer && wget https://github.com/datacharmer/dbdeployer/releases/download/v1.73.0/dbdeployer-1.73.0.linux.tar.gz)
23+
RUN (cd /dbdeployer && tar -xf dbdeployer-1.73.0.linux.tar.gz)
24+
RUN (cd /dbdeployer && ln -s dbdeployer-1.73.0.linux dbdeployer)
2525
RUN (cd /dbdeployer && ./dbdeployer defaults update reserved-ports '0')
2626
RUN (cd /orchestrator/orchestrator-ci-env/bin/linux && ln -s /dbdeployer/dbdeployer)
2727

28+
# Temporary solution:
29+
# dbdeployer patched to work with PS 8.4
30+
COPY docker/resources/dbdeployer /dbdeployer/dbdeployer84
31+
RUN (cd /dbdeployer && ./dbdeployer84 defaults update reserved-ports '0')
32+
RUN (cd /orchestrator/orchestrator-ci-env/bin/linux && ln -s /dbdeployer/dbdeployer84)
33+
2834
# For dev purposes only, just to avoid downloading over and over via download-mysql script
2935
# RUN (mkdir /orchestrator/orchestrator-ci-env/mysql-tarballs-downloaded)
30-
# COPY docker/Percona-Server-8.0.30-22-Linux.x86_64.glibc2.17-minimal.tar.gz /orchestrator/orchestrator-ci-env/mysql-tarballs-downloaded/
36+
# COPY docker/mysql-8.4.0-linux-glibc2.17-x86_64-minimal.tar.xz /orchestrator/orchestrator-ci-env/mysql-tarballs-downloaded/
3137

3238
RUN (cd /orchestrator/orchestrator-ci-env && cp bin/linux/systemctl.py /usr/bin/systemctl)
3339
RUN (cd /orchestrator/orchestrator-ci-env && script/deploy-haproxy)

docker/Dockerfile.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM golang:1.20.3-bullseye
22
LABEL maintainer="[email protected]"
33

44
RUN apt-get update
5-
RUN apt-get install -y lsb-release rsync libaio1 numactl sqlite3
5+
RUN apt-get install -y lsb-release rsync libaio1 numactl sqlite3 libncurses5 libtinfo5
66
RUN rm -rf /var/lib/apt/lists/*
77

88
ENV WORKPATH /go/src/github.com/openark/orchestrator

docker/resources/dbdeployer

13.1 MB
Binary file not shown.

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab h1:xveKWz2iauee
2323
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
2424
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
2525
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
26+
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
2627
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
2728
github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
2829
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=

go/cmd/orchestrator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func main() {
136136

137137
if len(flag.Args()) == 0 && *command == "" {
138138
// No command, no argument: just prompt
139-
fmt.Println(app.AppPrompt)
139+
fmt.Print(app.AppPrompt)
140140
return
141141
}
142142

go/db/db.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func openTopology(host string, port int, readTimeout int) (db *sql.DB, err error
107107
return nil, err
108108
}
109109
}
110-
sqlUtilsLogger := SqlUtilsLogger{client_context: host + ":" + strconv.Itoa(port)}
110+
sqlUtilsLogger := SqlUtilsLogger{client_context: host + ":" + strconv.Itoa(port), backend_connection: false}
111111
if db, _, err = sqlutils.GetDB(mysql_uri, sqlUtilsLogger); err != nil {
112112
return nil, err
113113
}
@@ -131,7 +131,7 @@ func openOrchestratorMySQLGeneric() (db *sql.DB, fromCache bool, err error) {
131131
if config.Config.MySQLOrchestratorUseMutualTLS {
132132
uri, _ = SetupMySQLOrchestratorTLS(uri)
133133
}
134-
sqlUtilsLogger := SqlUtilsLogger{client_context: config.Config.MySQLOrchestratorHost + ":" + strconv.FormatUint(uint64(config.Config.MySQLOrchestratorPort), 10)}
134+
sqlUtilsLogger := SqlUtilsLogger{client_context: config.Config.MySQLOrchestratorHost + ":" + strconv.FormatUint(uint64(config.Config.MySQLOrchestratorPort), 10), backend_connection: true}
135135
return sqlutils.GetDB(uri, sqlUtilsLogger)
136136
}
137137

@@ -200,7 +200,7 @@ func OpenOrchestrator() (db *sql.DB, err error) {
200200
}
201201
}
202202
dsn := getMySQLURI()
203-
sqlUtilsLogger := SqlUtilsLogger{client_context: config.Config.MySQLOrchestratorHost + ":" + strconv.FormatUint(uint64(config.Config.MySQLOrchestratorPort), 10)}
203+
sqlUtilsLogger := SqlUtilsLogger{client_context: config.Config.MySQLOrchestratorHost + ":" + strconv.FormatUint(uint64(config.Config.MySQLOrchestratorPort), 10), backend_connection: true}
204204
db, fromCache, err = sqlutils.GetDB(dsn, sqlUtilsLogger)
205205
if err == nil && !fromCache {
206206
log.Debugf("Connected to orchestrator backend: %v", safeMySQLURI(dsn))

go/db/tls.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,46 @@ func init() {
5757
}
5858

5959
type SqlUtilsLogger struct {
60-
client_context string
60+
client_context string
61+
backend_connection bool
6162
}
6263

6364
func (logger SqlUtilsLogger) OnError(caller_context string, query string, err error) error {
64-
query = strings.Join(strings.Fields(query), " ") // trim whitespaces
65-
query = strings.Replace(query, "%", "%%", -1) // escape %
65+
query = strings.Join(strings.Fields(query), " ") // trim whitespaces
66+
query = strings.Replace(query, "%", "%%", -1) // escape %
6667

6768
msg := fmt.Sprintf("%+v(%+v) %+v: %+v",
68-
caller_context,
69-
logger.client_context,
70-
query,
71-
err)
69+
caller_context,
70+
logger.client_context,
71+
query,
72+
err)
7273

7374
return log.Errorf(msg)
7475
}
7576

77+
// This validator is for dev purposes only. Call of this validator is
78+
// disabled in sqlutils.go
79+
var query_whitelist = []string{
80+
"substring_index(host, ':', 1) as slave_hostname",
81+
}
82+
83+
func (logger SqlUtilsLogger) ValidateQuery(query string) {
84+
if !logger.backend_connection {
85+
// check if whitelisted
86+
for i := 0; i < len(query_whitelist); i++ {
87+
if strings.Contains(query, query_whitelist[i]) {
88+
return
89+
}
90+
}
91+
92+
lquery := strings.ToLower(query)
93+
if strings.Contains(lquery, "master") || strings.Contains(lquery, "slave") {
94+
log.Error("QUERY CONTAINS MASTER / SLAVE: ")
95+
// panic("Query contains master/slave: " + query)
96+
}
97+
}
98+
}
99+
76100
func requiresTLS(host string, port int, mysql_uri string) bool {
77101
cacheKey := fmt.Sprintf("%s:%d", host, port)
78102

@@ -82,7 +106,7 @@ func requiresTLS(host string, port int, mysql_uri string) bool {
82106
}
83107

84108
required := false
85-
sqlUtilsLogger := SqlUtilsLogger{client_context: host + ":" + strconv.Itoa(port)}
109+
sqlUtilsLogger := SqlUtilsLogger{client_context: host + ":" + strconv.Itoa(port), backend_connection: false}
86110
db, _, _ := sqlutils.GetDB(mysql_uri, sqlUtilsLogger)
87111
if err := db.Ping(); err != nil && (strings.Contains(err.Error(), Error3159) || strings.Contains(err.Error(), Error1045)) {
88112
required = true

go/golib/sqlutils/sqlutils.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,35 @@ func (this *RowMap) GetTime(key string) time.Time {
170170
return time.Time{}
171171
}
172172

173+
func validateQuery(query string, db *sql.DB) {
174+
// dev purposes only. Remove this return to call query validator function.
175+
return
176+
177+
knownDBsMutex.RLock()
178+
defer func() {
179+
knownDBsMutex.RUnlock()
180+
}()
181+
if logger, exists := DB2logger[db]; exists && logger != nil {
182+
logger.ValidateQuery((query))
183+
}
184+
}
185+
173186
// knownDBs is a DB cache by uri
174187
var knownDBs map[string]*sql.DB = make(map[string]*sql.DB)
175188
var knownDBsMutex = &sync.RWMutex{}
176189

177190
type Logger interface {
178191
OnError(context string, query string, err error) error
192+
ValidateQuery(query string)
179193
}
194+
180195
// it is also protected by knownDBsMutex
181196
var DB2logger map[*sql.DB]Logger = make(map[*sql.DB]Logger)
182197

183198
// GetDB returns a DB instance based on uri.
184199
// logger parameter is optional. If nil, internal logging will be used.
185200
// bool result indicates whether the DB was returned from cache; err
186-
func GetGenericDB(driverName, dataSourceName string ,logger Logger) (*sql.DB, bool, error) {
201+
func GetGenericDB(driverName, dataSourceName string, logger Logger) (*sql.DB, bool, error) {
187202
knownDBsMutex.Lock()
188203
defer func() {
189204
knownDBsMutex.Unlock()
@@ -221,7 +236,7 @@ func GetSQLiteDB(dbFile string, logger Logger) (*sql.DB, bool, error) {
221236
func RowToArray(rows *sql.Rows, columns []string) []CellData {
222237
buff := make([]interface{}, len(columns))
223238
data := make([]CellData, len(columns))
224-
for i, _ := range buff {
239+
for i := range buff {
225240
buff[i] = data[i].NullString()
226241
}
227242
rows.Scan(buff...)
@@ -265,7 +280,7 @@ func ScanRowsToMaps(rows *sql.Rows, on_row func(RowMap) error) error {
265280
return err
266281
}
267282

268-
func logErrorInternal(context string, db *sql.DB, query string, err error) error{
283+
func logErrorInternal(context string, db *sql.DB, query string, err error) error {
269284
// find logger registered by the client
270285
knownDBsMutex.RLock()
271286
defer func() {
@@ -282,6 +297,7 @@ func logErrorInternal(context string, db *sql.DB, query string, err error) error
282297
// QueryRowsMap is a convenience function allowing querying a result set while poviding a callback
283298
// function activated per read row.
284299
func QueryRowsMap(db *sql.DB, query string, on_row func(RowMap) error, args ...interface{}) (err error) {
300+
validateQuery(query, db)
285301
defer func() {
286302
if derr := recover(); derr != nil {
287303
err = fmt.Errorf("QueryRowsMap unexpected error: %+v", derr)
@@ -302,6 +318,7 @@ func QueryRowsMap(db *sql.DB, query string, on_row func(RowMap) error, args ...i
302318

303319
// queryResultData returns a raw array of rows for a given query, optionally reading and returning column names
304320
func queryResultData(db *sql.DB, query string, retrieveColumns bool, args ...interface{}) (resultData ResultData, columns []string, err error) {
321+
validateQuery(query, db)
305322
defer func() {
306323
if derr := recover(); derr != nil {
307324
err = errors.New(fmt.Sprintf("QueryRowsMap unexpected error: %+v", derr))
@@ -358,6 +375,7 @@ func QueryRowsMapBuffered(db *sql.DB, query string, on_row func(RowMap) error, a
358375

359376
// ExecNoPrepare executes given query using given args on given DB, without using prepared statements.
360377
func ExecNoPrepare(db *sql.DB, query string, args ...interface{}) (res sql.Result, err error) {
378+
validateQuery(query, db)
361379
defer func() {
362380
if derr := recover(); derr != nil {
363381
err = errors.New(fmt.Sprintf("ExecNoPrepare unexpected error: %+v", derr))
@@ -374,6 +392,7 @@ func ExecNoPrepare(db *sql.DB, query string, args ...interface{}) (res sql.Resul
374392
// ExecQuery executes given query using given args on given DB. It will safele prepare, execute and close
375393
// the statement.
376394
func execInternal(silent bool, db *sql.DB, query string, args ...interface{}) (res sql.Result, err error) {
395+
validateQuery(query, db)
377396
defer func() {
378397
if derr := recover(); derr != nil {
379398
err = errors.New(fmt.Sprintf("execInternal unexpected error: %+v", derr))

go/inst/analysis_dao.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/openark/orchestrator/go/config"
2525
"github.com/openark/orchestrator/go/db"
2626
"github.com/openark/orchestrator/go/process"
27-
"github.com/openark/orchestrator/go/raft"
27+
orcraft "github.com/openark/orchestrator/go/raft"
2828
"github.com/openark/orchestrator/go/util"
2929

3030
"github.com/openark/golib/log"

go/inst/cluster_alias_dao.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func UpdateClusterAliases() error {
206206
// MySQL backend (Orchestrator supports only SQLite and MySQL backends)
207207
// INSERT ON DUPLICATE KEY UPDATE is more performant than REPLACE in MySQL
208208
err = updateClusterAliasesUsingInsert()
209-
if (err != nil) {
209+
if err != nil {
210210
// Fallback to the original, safe implementation
211211
err = updateClusterAliasesUsingReplace()
212212
}

0 commit comments

Comments
 (0)