@@ -21,17 +21,18 @@ spec:
21
21
- " -c"
22
22
- |
23
23
set -ex
24
- # Generate mysql server-id from pod ordinal index.
24
+ # 基于 Pod 序号生成 MySQL 服务器的 ID。
25
25
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
26
26
ordinal=${BASH_REMATCH[1]}
27
27
echo [mysqld] > /mnt/conf.d/server-id.cnf
28
- # Add an offset to avoid reserved server-id=0 value.
28
+ # 添加偏移量以避免使用 server-id=0 这一保留值。
29
29
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
30
30
# Copy appropriate conf.d files from config-map to emptyDir.
31
+ # 将合适的 conf.d 文件从 config-map 复制到 emptyDir。
31
32
if [[ $ordinal -eq 0 ]]; then
32
- cp /mnt/config-map/master .cnf /mnt/conf.d/
33
+ cp /mnt/config-map/primary .cnf /mnt/conf.d/
33
34
else
34
- cp /mnt/config-map/slave .cnf /mnt/conf.d/
35
+ cp /mnt/config-map/replica .cnf /mnt/conf.d/
35
36
fi
36
37
volumeMounts :
37
38
- name : conf
@@ -45,15 +46,15 @@ spec:
45
46
- " -c"
46
47
- |
47
48
set -ex
48
- # Skip the clone if data already exists.
49
+ # 如果已有数据,则跳过克隆。
49
50
[[ -d /var/lib/mysql/mysql ]] && exit 0
50
- # Skip the clone on master (ordinal index 0).
51
+ # 跳过主实例(序号索引 0)的克隆。
51
52
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
52
53
ordinal=${BASH_REMATCH[1]}
53
54
[[ $ordinal -eq 0 ]] && exit 0
54
- # Clone data from previous peer.
55
+ # 从原来的对等节点克隆数据。
55
56
ncat --recv-only mysql-$(($ordinal-1)).mysql 3307 | xbstream -x -C /var/lib/mysql
56
- # Prepare the backup.
57
+ # 准备备份。
57
58
xtrabackup --prepare --target-dir=/var/lib/mysql
58
59
volumeMounts :
59
60
- name : data
88
89
timeoutSeconds : 5
89
90
readinessProbe :
90
91
exec :
91
- # Check we can execute queries over TCP ( skip-networking is off).
92
+ # 检查我们是否可以通过 TCP 执行查询( skip-networking 是关闭的)。
92
93
command : ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"]
93
94
initialDelaySeconds : 5
94
95
periodSeconds : 2
@@ -105,22 +106,22 @@ spec:
105
106
set -ex
106
107
cd /var/lib/mysql
107
108
108
- # Determine binlog position of cloned data, if any.
109
+ # 确定克隆数据的 binlog 位置(如果有的话)。
109
110
if [[ -f xtrabackup_slave_info && "x$(<xtrabackup_slave_info)" != "x" ]]; then
110
- # XtraBackup already generated a partial " CHANGE MASTER TO" query
111
- # because we're cloning from an existing slave. (Need to remove the tailing semicolon !)
111
+ # XtraBackup 已经生成了部分的 “ CHANGE MASTER TO” 查询
112
+ # 因为我们从一个现有副本进行克隆。(需要删除末尾的分号 !)
112
113
cat xtrabackup_slave_info | sed -E 's/;$//g' > change_master_to.sql.in
113
- # Ignore xtrabackup_binlog_info in this case (it's useless).
114
+ # 在这里要忽略 xtrabackup_binlog_info (它是没用的)。
114
115
rm -f xtrabackup_slave_info xtrabackup_binlog_info
115
116
elif [[ -f xtrabackup_binlog_info ]]; then
116
- # We're cloning directly from master. Parse binlog position.
117
+ # 我们直接从主实例进行克隆。解析 binlog 位置。
117
118
[[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
118
119
rm -f xtrabackup_binlog_info xtrabackup_slave_info
119
120
echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
120
121
MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
121
122
fi
122
123
123
- # Check if we need to complete a clone by starting replication.
124
+ # 检查我们是否需要通过启动复制来完成克隆。
124
125
if [[ -f change_master_to.sql.in ]]; then
125
126
echo "Waiting for mysqld to be ready (accepting connections)"
126
127
until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done
@@ -133,11 +134,11 @@ spec:
133
134
MASTER_PASSWORD='', \
134
135
MASTER_CONNECT_RETRY=10; \
135
136
START SLAVE;" || exit 1
136
- # In case of container restart, attempt this at-most-once.
137
+ # 如果容器重新启动,最多尝试一次。
137
138
mv change_master_to.sql.in change_master_to.sql.orig
138
139
fi
139
140
140
- # Start a server to send backups when requested by peers.
141
+ # 当对等点请求时,启动服务器发送备份。
141
142
exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
142
143
"xtrabackup --backup --slave-info --stream=xbstream --host=127.0.0.1 --user=root"
143
144
volumeMounts :
0 commit comments