Skip to content

Commit 8382f84

Browse files
authored
binlog: support binlog.pump.config configurations for pump and drainer (#693) (#767)
(cherry picked from commit a320e52)
1 parent aaac224 commit 8382f84

13 files changed

+166
-18
lines changed

charts/tidb-cluster/templates/_helpers.tpl

+31
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,34 @@ config-file: |-
7979
{{ include "tidb-configmap.data" . | sha256sum | trunc 8 }}
8080
{{- end -}}
8181

82+
{{/*
83+
Encapsulate pump configmap data for consistent digest calculation
84+
*/}}
85+
{{- define "pump-configmap.data" -}}
86+
pump-config: |-
87+
{{- if .Values.binlog.pump.config }}
88+
{{ .Values.binlog.pump.config | indent 2 }}
89+
{{- else -}}
90+
{{ tuple "config/_pump-config.tpl" . | include "helm-toolkit.utils.template" | indent 2 }}
91+
{{- end -}}
92+
{{- end -}}
93+
94+
{{- define "pump-configmap.data-digest" -}}
95+
{{ include "pump-configmap.data" . | sha256sum | trunc 8 }}
96+
{{- end -}}
97+
98+
{{/*
99+
Encapsulate drainer configmap data for consistent digest calculation
100+
*/}}
101+
{{- define "drainer-configmap.data" -}}
102+
drainer-config: |-
103+
{{- if .Values.binlog.drainer.config }}
104+
{{ .Values.binlog.drainer.config | indent 2 }}
105+
{{- else -}}
106+
{{ tuple "config/_drainer-config.tpl" . | include "helm-toolkit.utils.template" | indent 2 }}
107+
{{- end -}}
108+
{{- end -}}
109+
110+
{{- define "drainer-configmap.data-digest" -}}
111+
{{ include "drainer-configmap.data" . | sha256sum | trunc 8 }}
112+
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{- if .Values.enableConfigMapRollout }}
2+
{{- if .Values.binlog.drainer.create }}
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: {{ template "cluster.name" . }}-drainer-{{ template "drainer-configmap.data-digest" . }}
7+
labels:
8+
app.kubernetes.io/name: {{ template "chart.name" . }}
9+
app.kubernetes.io/managed-by: {{ .Release.Service }}
10+
app.kubernetes.io/instance: {{ .Release.Name }}
11+
app.kubernetes.io/component: drainer
12+
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
13+
data:
14+
{{ include "drainer-configmap.data" . | indent 2 }}
15+
{{- end -}}
16+
{{- end -}}

charts/tidb-cluster/templates/drainer-configmap.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ metadata:
1010
app.kubernetes.io/component: drainer
1111
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
1212
data:
13-
drainer-config: |-
14-
{{ tuple "config/_drainer-config.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
13+
{{ include "drainer-configmap.data" . | indent 2 }}
1514
{{- end -}}

charts/tidb-cluster/templates/drainer-statefulset.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ spec:
5858
volumes:
5959
- name: config
6060
configMap:
61+
{{- if .Values.enableConfigMapRollout }}
62+
name: {{ template "cluster.name" . }}-drainer-{{ template "drainer-configmap.data-digest" . }}
63+
{{- else }}
6164
name: {{ template "cluster.name" . }}-drainer
65+
{{- end }}
6266
items:
6367
- key: drainer-config
6468
path: drainer.toml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{- if .Values.enableConfigMapRollout }}
2+
{{- if .Values.binlog.pump.create }}
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: {{ template "cluster.name" . }}-pump-{{ template "pump-configmap.data-digest" . }}
7+
labels:
8+
app.kubernetes.io/name: {{ template "chart.name" . }}
9+
app.kubernetes.io/managed-by: {{ .Release.Service }}
10+
app.kubernetes.io/instance: {{ .Release.Name }}
11+
app.kubernetes.io/component: pump
12+
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
13+
data:
14+
{{ include "pump-configmap.data" . | indent 2 }}
15+
{{- end }}
16+
{{- end }}

charts/tidb-cluster/templates/pump-configmap.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ metadata:
1010
app.kubernetes.io/component: pump
1111
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
1212
data:
13-
pump-config: |-
14-
{{ tuple "config/_pump-config.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
15-
{{- end -}}
13+
{{ include "pump-configmap.data" . | indent 2 }}
14+
{{ end }}

charts/tidb-cluster/templates/pump-statefulset.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ spec:
5858
volumes:
5959
- name: config
6060
configMap:
61+
{{- if .Values.enableConfigMapRollout }}
62+
name: {{ template "cluster.name" . }}-pump-{{ template "pump-configmap.data-digest" . }}
63+
{{- else }}
6164
name: {{ template "cluster.name" . }}-pump
65+
{{- end }}
6266
items:
6367
- key: pump-config
6468
path: pump.toml

charts/tidb-cluster/templates/scripts/_start_drainer.sh.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ done
2626

2727
/drainer \
2828
-L={{ .Values.binlog.drainer.logLevel | default "info" }} \
29+
-pd-urls=http://{{ template "cluster.name" . }}-pd:2379 \
2930
-addr=`echo ${HOSTNAME}`.{{ template "cluster.name" . }}-drainer:8249 \
3031
-config=/etc/drainer/drainer.toml \
3132
-disable-detect={{ .Values.binlog.drainer.disableDetect | default false }} \

charts/tidb-cluster/templates/scripts/_start_pump.sh.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set -euo pipefail
22
/pump \
3+
-pd-urls=http://{{ template "cluster.name" . }}-pd:2379 \
34
-L={{ .Values.binlog.pump.logLevel | default "info" }} \
45
-advertise-addr=`echo ${HOSTNAME}`.{{ template "cluster.name" . }}-pump:8250 \
56
-config=/etc/pump/pump.toml \

charts/tidb-cluster/values.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,17 @@ binlog:
423423
# number of seconds between heartbeat ticks (in 2 seconds)
424424
heartbeatInterval: 2
425425

426+
# Please refer to https://github.com/pingcap/tidb-binlog/blob/master/cmd/pump/pump.toml for the default
427+
# pump configurations (change to the tags of your pump version),
428+
# just follow the format in the file and configure in the 'config' section
429+
# as below if you want to customize any configuration.
430+
# config: |
431+
# gc = 7
432+
# heartbeat-interval = 2
433+
# [storage]
434+
# sync-log = true
435+
# stop-write-at-available-space = "10Gi"
436+
426437
drainer:
427438
create: false
428439
image: pingcap/tidb-binlog:v3.0.1
@@ -474,6 +485,24 @@ binlog:
474485
# kafkaAddrs: "127.0.0.1:9092"
475486
# kafkaVersion: "0.8.2.0"
476487

488+
# Please refer to https://github.com/pingcap/tidb-binlog/blob/master/cmd/drainer/drainer.toml for the default
489+
# drainer configurations (change to the tags of your drainer version),
490+
# just follow the format in the file and configure in the 'config' section
491+
# as below if you want to customize any configuration.
492+
# config: |
493+
# worker-count = 16
494+
# detect-interval = 10
495+
# disable-dispatch = false
496+
# ignore-schemas = "INFORMATION_SCHEMA,PERFORMANCE_SCHEMA,mysql"
497+
# safe-mode = false
498+
# txn-batch = 20
499+
# db-type = "mysql"
500+
# [syncer.to]
501+
# # host = "127.0.0.1"
502+
# # user = "root"
503+
# # password = ""
504+
# # port = 3306
505+
477506
scheduledBackup:
478507
create: false
479508
# https://github.com/pingcap/tidb-cloud-backup

tests/actions.go

+21-9
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ type TidbClusterConfig struct {
263263
BlockWriteConfig blockwriter.Config
264264
GrafanaClient *metrics.Client
265265
TopologyKey string
266+
267+
pumpConfig []string
268+
drainerConfig []string
266269
}
267270

268271
func (tc *TidbClusterConfig) String() string {
@@ -2289,13 +2292,7 @@ func (oa *operatorActions) DeployIncrementalBackup(from *TidbClusterConfig, to *
22892292
glog.Infof("begin to deploy incremental backup cluster[%s] namespace[%s]", from.ClusterName, from.Namespace)
22902293

22912294
sets := map[string]string{
2292-
"binlog.pump.create": "true",
2293-
"binlog.drainer.destDBType": "mysql",
2294-
"binlog.drainer.mysql.host": fmt.Sprintf("%s-tidb.%s", to.ClusterName, to.Namespace),
2295-
"binlog.drainer.mysql.user": "root",
2296-
"binlog.drainer.mysql.password": to.Password,
2297-
"binlog.drainer.mysql.port": "4000",
2298-
"binlog.drainer.ignoreSchemas": "",
2295+
"binlog.pump.create": "true",
22992296
}
23002297
if withDrainer {
23012298
sets["binlog.drainer.create"] = "true"
@@ -2304,14 +2301,29 @@ func (oa *operatorActions) DeployIncrementalBackup(from *TidbClusterConfig, to *
23042301
sets["binlog.drainer.initialCommitTs"] = ts
23052302
}
23062303

2304+
from.drainerConfig = []string{
2305+
"worker-count = 16",
2306+
"detect-interval = 10",
2307+
"disable-dispatch = false",
2308+
`ignore-schemas = ""`,
2309+
`safe-mode = false`,
2310+
`txn-batch = 20`,
2311+
`db-type = "mysql"`,
2312+
`[syncer.to]`,
2313+
fmt.Sprintf(`host = "%s-tidb.%s"`, to.ClusterName, to.Namespace),
2314+
fmt.Sprintf(`user = "%s"`, "root"),
2315+
fmt.Sprintf(`password = "%s"`, to.Password),
2316+
fmt.Sprintf(`port = %d`, 4000),
2317+
}
2318+
23072319
cmd, err := oa.getHelmUpgradeClusterCmd(from, sets)
23082320
if err != nil {
23092321
return err
23102322
}
23112323
glog.Infof(cmd)
23122324
res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
23132325
if err != nil {
2314-
return fmt.Errorf("failed to launch scheduler backup job: %v, %s", err, string(res))
2326+
return fmt.Errorf("failed to launch incremental backup job: %v, %s", err, string(res))
23152327
}
23162328
return nil
23172329
}
@@ -2439,7 +2451,7 @@ func (oa *operatorActions) CheckIncrementalBackup(info *TidbClusterConfig, withD
24392451

24402452
err := wait.Poll(oa.pollInterval, DefaultPollTimeout, fn)
24412453
if err != nil {
2442-
return fmt.Errorf("failed to launch scheduler backup job: %v", err)
2454+
return fmt.Errorf("failed to check incremental backup job: %v", err)
24432455
}
24442456
return nil
24452457

tests/cluster_info.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"os"
66
"strconv"
7+
8+
"github.com/golang/glog"
79
)
810

911
func (tc *TidbClusterConfig) set(name string, value string) (string, bool) {
@@ -113,7 +115,7 @@ func (tc *TidbClusterConfig) BuildSubValues(path string) (string, error) {
113115
"[log]",
114116
`level = "info"`,
115117
}
116-
subValues := GetSubValuesOrDie(tc.ClusterName, tc.Namespace, tc.TopologyKey, pdConfig, tikvConfig, tidbConfig)
118+
subValues := GetSubValuesOrDie(tc.ClusterName, tc.Namespace, tc.TopologyKey, pdConfig, tikvConfig, tidbConfig, tc.pumpConfig, tc.drainerConfig)
117119
subVaulesPath := fmt.Sprintf("%s/%s.yaml", path, tc.ClusterName)
118120
_, err := os.Stat(subVaulesPath)
119121
if err != nil {
@@ -134,5 +136,6 @@ func (tc *TidbClusterConfig) BuildSubValues(path string) (string, error) {
134136
if err != nil {
135137
return "", err
136138
}
139+
glog.Infof("subValues:\n %s", subValues)
137140
return subVaulesPath, nil
138141
}

tests/util.go

+36-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ var affinityTemp string = `{{.Kind}}:
104104
topologyKey: {{.TopologyKey}}
105105
namespaces:
106106
- {{.Namespace}}
107-
binlog:
107+
`
108+
109+
var binlogTemp string = `binlog:
108110
pump:
109111
tolerations:
110112
- key: node-role
@@ -119,6 +121,10 @@ binlog:
119121
topologyKey: {{.TopologyKey}}
120122
namespaces:
121123
- {{.Namespace}}
124+
{{if .PumpConfig}}
125+
config: |
126+
{{range .PumpConfig}} {{.}}
127+
{{end}}{{end}}
122128
drainer:
123129
tolerations:
124130
- key: node-role
@@ -133,6 +139,10 @@ binlog:
133139
topologyKey: {{.TopologyKey}}
134140
namespaces:
135141
- {{.Namespace}}
142+
{{if .DrainerConfig}}
143+
config: |
144+
{{range .DrainerConfig}} {{.}}
145+
{{end}}{{end}}
136146
`
137147

138148
type AffinityInfo struct {
@@ -144,7 +154,14 @@ type AffinityInfo struct {
144154
Config []string
145155
}
146156

147-
func GetSubValuesOrDie(clusterName, namespace, topologyKey string, pdConfig []string, tikvConfig []string, tidbConfig []string) string {
157+
type BinLogInfo struct {
158+
PumpConfig []string
159+
DrainerConfig []string
160+
Namespace string
161+
TopologyKey string
162+
}
163+
164+
func GetSubValuesOrDie(clusterName, namespace, topologyKey string, pdConfig []string, tikvConfig []string, tidbConfig []string, pumpConfig []string, drainerConfig []string) string {
148165
temp, err := template.New("dt-affinity").Parse(affinityTemp)
149166
if err != nil {
150167
slack.NotifyAndPanic(err)
@@ -165,7 +182,23 @@ func GetSubValuesOrDie(clusterName, namespace, topologyKey string, pdConfig []st
165182
if err != nil {
166183
slack.NotifyAndPanic(err)
167184
}
168-
return fmt.Sprintf("%s%s%s", pdbuff.String(), tikvbuff.String(), tidbbuff.String())
185+
subValues := fmt.Sprintf("%s%s%s", pdbuff.String(), tikvbuff.String(), tidbbuff.String())
186+
187+
if pumpConfig == nil && drainerConfig == nil {
188+
return subValues
189+
}
190+
191+
btemp, err := template.New("binlog").Parse(binlogTemp)
192+
if err != nil {
193+
slack.NotifyAndPanic(err)
194+
}
195+
binlogbuff := new(bytes.Buffer)
196+
err = btemp.Execute(binlogbuff, &BinLogInfo{PumpConfig: pumpConfig, DrainerConfig: drainerConfig, Namespace: namespace, TopologyKey: topologyKey})
197+
if err != nil {
198+
slack.NotifyAndPanic(err)
199+
}
200+
subValues = fmt.Sprintf("%s%s", subValues, binlogbuff.String())
201+
return subValues
169202
}
170203

171204
const (

0 commit comments

Comments
 (0)