@@ -136,7 +136,7 @@ type Config struct {
136136
137137 RemoteClusterName string
138138 RemoteClusterNamespace string
139- //TODO: add it in env
139+ // add it in env
140140 ServerIDStartOffset string
141141}
142142
@@ -225,6 +225,8 @@ func NewInitConfig() *Config {
225225 NeedUpgrade : needUpgrade ,
226226 RemoteClusterName : getEnvValue ("REMOTE_CLUSTER_NAME" ),
227227 RemoteClusterNamespace : getEnvValue ("REMOTE_CLUSTER_NAMESPACE" ),
228+ // SERVER_ID_OFFSET
229+ ServerIDStartOffset : getEnvValue ("SERVER_ID_OFFSET" ),
228230 }
229231}
230232
@@ -308,10 +310,22 @@ func (cfg *Config) XBackupName() (string, string) {
308310func (cfg * Config ) buildExtraConfig (filePath string ) (* ini.File , error ) {
309311 conf := ini .Empty ()
310312 sec := conf .Section ("mysqld" )
311- startIndex := mysqlServerIDOffset
313+ // convert cfg.SERVER_ID_OFFSET to int
314+ var offset int
315+ var err error
316+ if offset , err = strconv .Atoi (cfg .ServerIDStartOffset ); err != nil {
317+ offset = 0
318+ }
319+ startIndex := func () int {
320+ if offset <= 0 {
321+ return mysqlServerIDOffset
322+ }
323+ return offset
324+ }()
325+
312326 ordinal , err := utils .GetOrdinal (cfg .HostName )
313327 arr := strings .Split (cfg .HostName , "-" )
314- if len (cfg .RemoteClusterName ) > 0 {
328+ if len (cfg .RemoteClusterName ) > 0 && offset <= 0 {
315329 log .Info ("It has remote cluster server-id start offset +100" )
316330 startIndex += mysqlServerIDOffsetInc
317331 }
0 commit comments