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

sidecar: fix the bug of start index of serverid #854

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all 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
105 changes: 77 additions & 28 deletions sidecar/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (cfg *Config) buildExtraConfig(filePath string) (*ini.File, error) {
log.Info("It has remote cluster server-id start offset +100")
startIndex += mysqlServerIDOffsetInc
}
if len(arr) == 3 && arr[1] == "ro" {
if len(arr) >= 3 && arr[len(arr)-2] == "ro" {
log.Info("It is readonly pod, server-id start offset +100")
startIndex += mysqlServerIDOffsetInc
}
Expand Down Expand Up @@ -426,7 +426,10 @@ func (cfg *Config) buildInitSql(hasInit bool) []byte {
if err != nil {
log.Info("failed to read /mnt/mysql-cm/init.sql")
}
sql := fmt.Sprintf(`SET @@SESSION.SQL_LOG_BIN=0;
var sql string
if cfg.MySQLVersion.Major == 5 {
log.Info("version is 5.7, need not donor userq")
sql = fmt.Sprintf(`SET @@SESSION.SQL_LOG_BIN=0;
CREATE DATABASE IF NOT EXISTS %s;
DROP user IF EXISTS 'root'@'127.0.0.1';
CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY '%s';
Expand All @@ -446,36 +449,82 @@ GRANT SUPER, PROCESS, RELOAD, CREATE, SELECT ON *.* TO '%s'@'%%';
DROP user IF EXISTS '%s'@'%%';
CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
GRANT ALL ON %s.* TO '%s'@'%%' ;
DROP user IF EXISTS '%s'@'%%';
CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
GRANT BACKUP_ADMIN ON *.* TO '%s'@'%%' ;
FLUSH PRIVILEGES;

%s
`,
cfg.Database, //database
cfg.RootPassword,
cfg.InternalRootPassword,
cfg.ReplicationUser, //drop user
cfg.ReplicationUser, cfg.ReplicationPassword, //create user
cfg.ReplicationUser, //grant REPLICATION

cfg.MetricsUser, //drop user MetricsUser
cfg.MetricsUser, cfg.MetricsPassword, //create user
cfg.MetricsUser, //grant

cfg.OperatorUser, //drop user
cfg.OperatorUser, cfg.OperatorPassword, //create
cfg.OperatorUser, //grant

cfg.User, //drop user
cfg.User, cfg.Password, //create user
cfg.Database, cfg.User, //grant
cfg.DonorClone,
cfg.DonorClone, cfg.DonorClonePassword,
cfg.DonorClone, // grant
initSQL,
)
cfg.Database, //database
cfg.RootPassword,
cfg.InternalRootPassword,
cfg.ReplicationUser, //drop user
cfg.ReplicationUser, cfg.ReplicationPassword, //create user
cfg.ReplicationUser, //grant REPLICATION

cfg.MetricsUser, //drop user MetricsUser
cfg.MetricsUser, cfg.MetricsPassword, //create user
cfg.MetricsUser, //grant

cfg.OperatorUser, //drop user
cfg.OperatorUser, cfg.OperatorPassword, //create
cfg.OperatorUser, //grant

cfg.User, //drop user
cfg.User, cfg.Password, //create user
cfg.Database, cfg.User, //grant
initSQL,
)
} else {
sql = fmt.Sprintf(`SET @@SESSION.SQL_LOG_BIN=0;
CREATE DATABASE IF NOT EXISTS %s;
DROP user IF EXISTS 'root'@'127.0.0.1';
CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY '%s';
GRANT ALL ON *.* TO 'root'@'127.0.0.1' with grant option;
DROP user IF EXISTS 'root'@'%%';
CREATE USER 'root'@'%%' IDENTIFIED BY '%s';
GRANT ALL ON *.* TO 'root'@'%%' with grant option;
DROP user IF EXISTS '%s'@'%%';
CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO '%s'@'%%';
DROP user IF EXISTS '%s'@'%%';
CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
GRANT SELECT, PROCESS, REPLICATION CLIENT ON *.* TO '%s'@'%%';
DROP user IF EXISTS '%s'@'%%';
CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
GRANT SUPER, PROCESS, RELOAD, CREATE, SELECT ON *.* TO '%s'@'%%';
DROP user IF EXISTS '%s'@'%%';
CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
GRANT ALL ON %s.* TO '%s'@'%%' ;
DROP user IF EXISTS '%s'@'%%';
CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
GRANT BACKUP_ADMIN ON *.* TO '%s'@'%%' ;
FLUSH PRIVILEGES;

%s
`,
cfg.Database, //database
cfg.RootPassword,
cfg.InternalRootPassword,
cfg.ReplicationUser, //drop user
cfg.ReplicationUser, cfg.ReplicationPassword, //create user
cfg.ReplicationUser, //grant REPLICATION

cfg.MetricsUser, //drop user MetricsUser
cfg.MetricsUser, cfg.MetricsPassword, //create user
cfg.MetricsUser, //grant

cfg.OperatorUser, //drop user
cfg.OperatorUser, cfg.OperatorPassword, //create
cfg.OperatorUser, //grant

cfg.User, //drop user
cfg.User, cfg.Password, //create user
cfg.Database, cfg.User, //grant
cfg.DonorClone,
cfg.DonorClone, cfg.DonorClonePassword,
cfg.DonorClone, // grant
initSQL,
)
}

if hasInit {
sql += "\nRESET SLAVE ALL;\n"
Expand Down
Loading