Skip to content

Commit

Permalink
Merge pull request #7367 from dolthub/db/user
Browse files Browse the repository at this point in the history
[no-release-notes] update sysbench runner to create and init data dir for mysql
  • Loading branch information
coffeegoddd authored Jan 24, 2024
2 parents 7713cc4 + f88bec4 commit b88c416
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ echo '
"--useDoltHubLuaScriptsRepo",
"--output='$format'",
"--mysql-exec=/usr/sbin/mysqld",
"--mysql-socket=/home/tester/.mysql/mysqld.sock",
"--mysql-protocol=unix",
"--from-server='$fromServer'",
"--from-version='$fromVersion'",
Expand Down
4 changes: 3 additions & 1 deletion go/performance/continuous_integration/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"Version": "8.0.22",
"ResultsFormat": "csv",
"ServerExec": "/usr/sbin/mysqld",
"ConnectionProtocol": "unix"
"ConnectionProtocol": "unix",
"ServerUser": "root",
"SkipLogBin": true
}
],
"ScriptDir":"/sysbench-lua-scripts",
Expand Down
4 changes: 3 additions & 1 deletion go/performance/continuous_integration/tpcc-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"Version": "8.0.22",
"ResultsFormat": "csv",
"ServerExec": "/usr/sbin/mysqld",
"ConnectionProtocol": "unix"
"ConnectionProtocol": "unix",
"ServerUser": "root",
"SkipLogBin": true
}
],
"ScriptDir":"/sysbench-tpcc",
Expand Down
15 changes: 14 additions & 1 deletion go/performance/utils/sysbench_runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var defaultSysbenchParams = []string{
}

var defaultDoltServerParams = []string{"sql-server"}
var defaultMysqlServerParams = []string{"--user=mysql"}
var defaultMysqlServerParams = []string{}
var defaultDoltgresServerParams = []string{}
var defaultPostgresServerParams = []string{}

Expand Down Expand Up @@ -269,6 +269,12 @@ type ServerConfig struct {
// InitExec is the path to the server init db executable
InitExec string

// ServerUser is the user account that should start the server
ServerUser string

// SkipLogBin will skip bin logging
SkipLogBin bool

// ServerArgs are the args used to start a server
ServerArgs []string

Expand All @@ -295,6 +301,12 @@ func (sc *ServerConfig) GetServerArgs() []string {
defaultParams = defaultDoltServerParams
} else if sc.Server == MySql {
defaultParams = defaultMysqlServerParams
if sc.ServerUser != "" {
params = append(params, fmt.Sprintf("--user=%s", sc.ServerUser))
}
if sc.SkipLogBin {
params = append(params, "--skip-log-bin")
}
} else if sc.Server == Doltgres {
defaultParams = defaultDoltgresServerParams
} else if sc.Server == Postgres {
Expand All @@ -308,6 +320,7 @@ func (sc *ServerConfig) GetServerArgs() []string {
if sc.Port != 0 {
params = append(params, fmt.Sprintf("--port=%d", sc.Port))
}

params = append(params, sc.ServerArgs...)
return params
}
Expand Down
34 changes: 34 additions & 0 deletions go/performance/utils/sysbench_runner/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,32 @@ type MysqlConfig struct {
func BenchmarkMysql(ctx context.Context, config *Config, serverConfig *ServerConfig) (Results, error) {
withKeyCtx, cancel := context.WithCancel(ctx)

var serverDir string
defer func() {
if serverDir != "" {
os.RemoveAll(serverDir)
}
}()

var localServer bool
var gServer *errgroup.Group
var serverCtx context.Context
var server *exec.Cmd
var err error
if serverConfig.Host == defaultHost {
log.Println("Launching the default server")
localServer = true

serverDir, err = initMysqlDataDir(ctx, serverConfig)
if err != nil {
cancel()
return nil, err
}

gServer, serverCtx = errgroup.WithContext(withKeyCtx)
serverParams := serverConfig.GetServerArgs()
serverParams = append(serverParams, fmt.Sprintf("--datadir=%s", serverDir))

server = getMysqlServer(serverCtx, serverConfig, serverParams)

// launch the mysql server
Expand Down Expand Up @@ -129,6 +146,22 @@ func getMysqlServer(ctx context.Context, config *ServerConfig, params []string)
return ExecCommand(ctx, config.ServerExec, params...)
}

// initMysqlDataDir initializes a mysql data dir and returns the path
func initMysqlDataDir(ctx context.Context, config *ServerConfig) (string, error) {
serverDir, err := createServerDir(dbName)
if err != nil {
return "", err
}

msInit := ExecCommand(ctx, config.ServerExec, "--initialize-insecure", fmt.Sprintf("--datadir=%s", serverDir))
err = msInit.Run()
if err != nil {
return "", err
}

return serverDir, nil
}

func SetupDB(ctx context.Context, mConfig MysqlConfig, databaseName string) (err error) {
dsn, err := FormatDsn(mConfig)
if err != nil {
Expand Down Expand Up @@ -190,6 +223,7 @@ func FormatDsn(mConfig MysqlConfig) (string, error) {
} else {
socketPath = defaultMysqlSocket
}

if mConfig.ConnectionProtocol == tcpProtocol {
return fmt.Sprintf("root@tcp(%s:%d)/", mConfig.Host, mConfig.Port), nil
} else if mConfig.ConnectionProtocol == unixProtocol {
Expand Down
6 changes: 3 additions & 3 deletions go/performance/utils/sysbench_runner/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func BenchmarkPostgres(ctx context.Context, config *Config, serverConfig *Server
log.Println("Launching the default server")
localServer = true

serverDir, err = initPostgresDb(ctx, serverConfig)
serverDir, err = initPostgresDataDir(ctx, serverConfig)
if err != nil {
cancel()
return nil, err
Expand Down Expand Up @@ -142,8 +142,8 @@ func BenchmarkPostgres(ctx context.Context, config *Config, serverConfig *Server
return results, nil
}

// initPostgresDb initializes a dolt repo and returns the repo path
func initPostgresDb(ctx context.Context, config *ServerConfig) (string, error) {
// initPostgresDataDir initializes a postgres data dir and returns the path
func initPostgresDataDir(ctx context.Context, config *ServerConfig) (string, error) {
serverDir, err := createServerDir(dbName)
if err != nil {
return "", err
Expand Down

0 comments on commit b88c416

Please sign in to comment.