Skip to content

Commit 97f4cfe

Browse files
committed
*: add serveroffset
1 parent 084b158 commit 97f4cfe

File tree

8 files changed

+71
-9
lines changed

8 files changed

+71
-9
lines changed

api/v1alpha1/mysqlcluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ type MysqlClusterSpec struct {
123123
// +optional
124124
// +kubebuilder:default:=false
125125
LeaderAsFollower bool `json:"leaderAsfollower,omitempty"`
126+
127+
// Specification offset of mysql serverid start at
128+
// +optional
129+
// +kubebuilder:default:0
130+
ServerIDOffset int `json:"serverIDOffset,omitempty"`
126131
}
127132

128133
// ReadOnly define the ReadOnly pods

api/v1beta1/mysqlcluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ type MysqlClusterSpec struct {
154154
// +optional
155155
// +kubebuilder:default:=false
156156
LeaderAsFollower bool `json:"leaderAsfollower,omitempty"`
157+
158+
// Specification offset of mysql serverid start at
159+
// +optional
160+
// +kubebuilder:default:0
161+
ServerIDOffset int `json:"serverIDOffset,omitempty"`
157162
}
158163

159164
// ReadOnly define the ReadOnly pods

api/v1beta1/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/mysql-operator/templates/mysql.radondb.com_mysqlclusters.yaml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,17 @@ spec:
22642264
required:
22652265
- num
22662266
type: object
2267+
remoteCluster:
2268+
description: remote replica source
2269+
properties:
2270+
name:
2271+
type: string
2272+
namespace:
2273+
type: string
2274+
required:
2275+
- name
2276+
- namespace
2277+
type: object
22672278
replicas:
22682279
default: 3
22692280
description: Replicas is the number of pods.
@@ -2283,6 +2294,9 @@ spec:
22832294
description: RestorePoint is the target date and time to restore data.
22842295
The format is "2006-01-02 15:04:05"
22852296
type: string
2297+
serverIDOffset:
2298+
description: Specification offset of mysql serverid start at
2299+
type: integer
22862300
sourceConfig:
22872301
description: Bootstraping from remote data source
22882302
properties:
@@ -3521,12 +3535,19 @@ spec:
35213535
remote:
35223536
description: Bootstraping from remote data source
35233537
properties:
3538+
remoteCluster:
3539+
description: remote replica source
3540+
properties:
3541+
name:
3542+
type: string
3543+
namespace:
3544+
type: string
3545+
required:
3546+
- name
3547+
- namespace
3548+
type: object
35243549
sourceConfig:
3525-
description: "Adapts a secret into a projected volume. \n
3526-
The contents of the target Secret's Data field will be presented
3527-
in a projected volume as files using the keys in the Data
3528-
field as the file names. Note that this is identical to
3529-
a secret volume source without the default mode."
3550+
description: xtrabackup remote source
35303551
properties:
35313552
items:
35323553
description: If unspecified, each key-value pair in the
@@ -4774,6 +4795,9 @@ spec:
47744795
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
47754796
type: object
47764797
type: object
4798+
serverIDOffset:
4799+
description: Specification offset of mysql serverid start at
4800+
type: integer
47774801
service:
47784802
description: Specification of the service that exposes the MySQL leader
47794803
instance.

config/crd/bases/mysql.radondb.com_mysqlclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,9 @@ spec:
22762276
description: RestorePoint is the target date and time to restore data.
22772277
The format is "2006-01-02 15:04:05"
22782278
type: string
2279+
serverIDOffset:
2280+
description: Specification offset of mysql serverid start at
2281+
type: integer
22792282
sourceConfig:
22802283
description: Bootstraping from remote data source
22812284
properties:
@@ -4774,6 +4777,9 @@ spec:
47744777
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
47754778
type: object
47764779
type: object
4780+
serverIDOffset:
4781+
description: Specification offset of mysql serverid start at
4782+
type: integer
47774783
service:
47784784
description: Specification of the service that exposes the MySQL leader
47794785
instance.

mysqlcluster/container/init_sidecar.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ func (c *initSidecar) getEnvVars() []corev1.EnvVar {
164164
})
165165

166166
}
167+
if c.Spec.ServerIDOffset > 0 {
168+
envs = append(envs, corev1.EnvVar{
169+
Name: "SERVER_ID_OFFSET",
170+
Value: strconv.Itoa(int(c.Spec.ServerIDOffset)),
171+
})
172+
}
167173

168174
return envs
169175
}

mysqlcluster/syncer/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343
)
4444

4545
// The max quantity of the statuses.
46-
const maxStatusesQuantity = 10
46+
// const maxStatusesQuantity = 10
4747

4848
// The retry time for check node status.
4949
const checkNodeStatusRetry = 3

sidecar/config.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
308310
func (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

Comments
 (0)