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

binlog: support binlog.pump.config configurations for pump and drainer #693

Merged
merged 30 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ee2e0ee
change tidb-binlog configration
weekface Jul 25, 2019
bdb857c
tiny fix
weekface Jul 25, 2019
731855a
adjust stability test to support new binlog config way
xiaojingchen Jul 25, 2019
3d141fa
Merge branch 'binlog-config' of https://github.com/weekface/tidb-oper…
xiaojingchen Jul 25, 2019
616797c
add http scheme for pd url
xiaojingchen Jul 25, 2019
c78c631
Merge branch 'master' into binlog-config
xiaojingchen Jul 25, 2019
71bb0a4
fix template
xiaojingchen Jul 29, 2019
bc58375
Merge branch 'binlog-config' of https://github.com/weekface/tidb-oper…
xiaojingchen Jul 29, 2019
f2fcbf8
Merge branch 'master' into binlog-config
xiaojingchen Jul 29, 2019
dc82f1d
Merge branch 'master' into binlog-config
xiaojingchen Jul 29, 2019
d7a34e3
Merge branch 'master' into binlog-config
xiaojingchen Jul 31, 2019
f2b99c0
refine log
xiaojingchen Jul 31, 2019
7b4ae79
Merge branch 'binlog-config' of https://github.com/weekface/tidb-oper…
xiaojingchen Jul 31, 2019
3d89c37
Merge branch 'master' into binlog-config
xiaojingchen Jul 31, 2019
8fe32a6
fix log
xiaojingchen Jul 31, 2019
7756fed
Merge branch 'binlog-config' of https://github.com/weekface/tidb-oper…
xiaojingchen Jul 31, 2019
e8dc9a2
Merge branch 'master' into binlog-config
xiaojingchen Aug 1, 2019
363d36d
fix
xiaojingchen Aug 1, 2019
43e95af
Merge branch 'binlog-config' of https://github.com/weekface/tidb-oper…
xiaojingchen Aug 1, 2019
4e9965c
Merge branch 'master' into binlog-config
xiaojingchen Aug 1, 2019
e8c3dde
Merge branch 'master' into binlog-config
weekface Aug 12, 2019
bb29346
fix typo
weekface Aug 12, 2019
b02de98
Merge branch 'binlog-config' of https://github.com/weekface/tidb-oper…
weekface Aug 12, 2019
b55c392
fix e2e
weekface Aug 12, 2019
4f300a4
fix e2e
weekface Aug 12, 2019
fd8208c
Merge branch 'master' into binlog-config
xiaojingchen Aug 12, 2019
051876c
Merge branch 'master' into binlog-config
xiaojingchen Aug 13, 2019
9531a77
address comment
weekface Aug 13, 2019
1c33136
Merge branch 'binlog-config' of https://github.com/weekface/tidb-oper…
weekface Aug 13, 2019
419a902
Update charts/tidb-cluster/values.yaml
weekface Aug 13, 2019
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
31 changes: 31 additions & 0 deletions charts/tidb-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,34 @@ config-file: |-
{{ include "tidb-configmap.data" . | sha256sum | trunc 8 }}
{{- end -}}

{{/*
Encapsulate pump configmap data for consistent digest calculation
*/}}
{{- define "pump-configmap.data" -}}
pump-config: |-
{{- if .Values.binlog.pump.config }}
{{ .Values.binlog.pump.config | indent 2 }}
{{- else -}}
{{ tuple "config/_pump-config.tpl" . | include "helm-toolkit.utils.template" | indent 2 }}
{{- end -}}
{{- end -}}

{{- define "pump-configmap.data-digest" -}}
{{ include "pump-configmap.data" . | sha256sum | trunc 8 }}
{{- end -}}

{{/*
Encapsulate drainer configmap data for consistent digest calculation
*/}}
{{- define "drainer-configmap.data" -}}
drainer-config: |-
{{- if .Values.binlog.drainer.config }}
{{ .Values.binlog.drainer.config | indent 2 }}
{{- else -}}
{{ tuple "config/_drainer-config.tpl" . | include "helm-toolkit.utils.template" | indent 2 }}
{{- end -}}
{{- end -}}

{{- define "drainer-configmap.data-digest" -}}
{{ include "drainer-configmap.data" . | sha256sum | trunc 8 }}
{{- end -}}
16 changes: 16 additions & 0 deletions charts/tidb-cluster/templates/drainer-configmap-rollout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.enableConfigMapRollout }}
{{- if .Values.binlog.drainer.create }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "cluster.name" . }}-drainer-{{ template "drainer-configmap.data-digest" . }}
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: drainer
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
data:
{{ include "drainer-configmap.data" . | indent 2 }}
{{- end -}}
{{- end -}}
3 changes: 1 addition & 2 deletions charts/tidb-cluster/templates/drainer-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ metadata:
app.kubernetes.io/component: drainer
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
data:
drainer-config: |-
{{ tuple "config/_drainer-config.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
{{ include "drainer-configmap.data" . | indent 2 }}
{{- end -}}
4 changes: 4 additions & 0 deletions charts/tidb-cluster/templates/drainer-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ spec:
volumes:
- name: config
configMap:
{{- if .Values.enableConfigMapRollout }}
name: {{ template "cluster.name" . }}-drainer-{{ template "drainer-configmap.data-digest" . }}
aylei marked this conversation as resolved.
Show resolved Hide resolved
{{- else }}
name: {{ template "cluster.name" . }}-drainer
{{- end }}
items:
- key: drainer-config
path: drainer.toml
Expand Down
16 changes: 16 additions & 0 deletions charts/tidb-cluster/templates/pump-configmap-rollout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.enableConfigMapRollout }}
{{- if .Values.binlog.pump.create }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "cluster.name" . }}-pump-{{ template "pump-configmap.data-digest" . }}
labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: pump
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
data:
{{ include "pump-configmap.data" . | indent 2 }}
{{- end }}
{{- end }}
5 changes: 2 additions & 3 deletions charts/tidb-cluster/templates/pump-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ metadata:
app.kubernetes.io/component: pump
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
data:
pump-config: |-
{{ tuple "config/_pump-config.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
{{- end -}}
{{ include "pump-configmap.data" . | indent 2 }}
{{ end }}
4 changes: 4 additions & 0 deletions charts/tidb-cluster/templates/pump-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ spec:
volumes:
- name: config
configMap:
{{- if .Values.enableConfigMapRollout }}
name: {{ template "cluster.name" . }}-pump-{{ template "pump-configmap.data-digest" . }}
aylei marked this conversation as resolved.
Show resolved Hide resolved
{{- else }}
name: {{ template "cluster.name" . }}-pump
{{- end }}
items:
- key: pump-config
path: pump.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ done

/drainer \
-L={{ .Values.binlog.drainer.logLevel | default "info" }} \
-pd-urls=http://{{ template "cluster.name" . }}-pd:2379 \
-addr=`echo ${HOSTNAME}`.{{ template "cluster.name" . }}-drainer:8249 \
-config=/etc/drainer/drainer.toml \
-disable-detect={{ .Values.binlog.drainer.disableDetect | default false }} \
Expand Down
1 change: 1 addition & 0 deletions charts/tidb-cluster/templates/scripts/_start_pump.sh.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set -euo pipefail
/pump \
-pd-urls=http://{{ template "cluster.name" . }}-pd:2379 \
-L={{ .Values.binlog.pump.logLevel | default "info" }} \
-advertise-addr=`echo ${HOSTNAME}`.{{ template "cluster.name" . }}-pump:8250 \
-config=/etc/pump/pump.toml \
Expand Down
29 changes: 29 additions & 0 deletions charts/tidb-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ binlog:
# number of seconds between heartbeat ticks (in 2 seconds)
heartbeatInterval: 2

# Please refer to https://github.com/pingcap/tidb-binlog/blob/master/cmd/pump/pump.toml for the default
# pump configurations (change to the tags of your pump version),
# just follow the format in the file and configure in the 'config' section
# as below if you want to customize any configuration.
# config: |
# gc = 7
# heartbeat-interval = 2
# [storage]
# sync-log = true
# stop-write-at-available-space = "10Gi"

drainer:
create: false
image: pingcap/tidb-binlog:v3.0.1
Expand Down Expand Up @@ -474,6 +485,24 @@ binlog:
# kafkaAddrs: "127.0.0.1:9092"
# kafkaVersion: "0.8.2.0"

# Please refer to https://github.com/pingcap/tidb-binlog/blob/master/cmd/drainer/drainer.toml for the default
# drainer configurations (change to the tags of your drainer version),
# just follow the format in the file and configure in the 'config' section
# as below if you want to customize any configuration.
# config: |
# worker-count = 16
# detect-interval = 10
# disable-dispatch = false
# ignore-schemas = "INFORMATION_SCHEMA,PERFORMANCE_SCHEMA,mysql"
# safe-mode = false
# txn-batch = 20
# db-type = "mysql"
# [syncer.to]
# # host = "127.0.0.1"
# # user = "root"
# # password = ""
# # port = 3306

scheduledBackup:
create: false
# https://github.com/pingcap/tidb-cloud-backup
Expand Down
30 changes: 21 additions & 9 deletions tests/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ type TidbClusterConfig struct {
BlockWriteConfig blockwriter.Config
GrafanaClient *metrics.Client
TopologyKey string

pumpConfig []string
drainerConfig []string
}

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

sets := map[string]string{
"binlog.pump.create": "true",
"binlog.drainer.destDBType": "mysql",
"binlog.drainer.mysql.host": fmt.Sprintf("%s-tidb.%s", to.ClusterName, to.Namespace),
"binlog.drainer.mysql.user": "root",
"binlog.drainer.mysql.password": to.Password,
"binlog.drainer.mysql.port": "4000",
"binlog.drainer.ignoreSchemas": "",
"binlog.pump.create": "true",
}
if withDrainer {
sets["binlog.drainer.create"] = "true"
Expand All @@ -2304,14 +2301,29 @@ func (oa *operatorActions) DeployIncrementalBackup(from *TidbClusterConfig, to *
sets["binlog.drainer.initialCommitTs"] = ts
}

from.drainerConfig = []string{
"worker-count = 16",
"detect-interval = 10",
"disable-dispatch = false",
`ignore-schemas = ""`,
`safe-mode = false`,
`txn-batch = 20`,
`db-type = "mysql"`,
`[syncer.to]`,
fmt.Sprintf(`host = "%s-tidb.%s"`, to.ClusterName, to.Namespace),
fmt.Sprintf(`user = "%s"`, "root"),
fmt.Sprintf(`password = "%s"`, to.Password),
fmt.Sprintf(`port = %d`, 4000),
}

cmd, err := oa.getHelmUpgradeClusterCmd(from, sets)
if err != nil {
return err
}
glog.Infof(cmd)
res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to launch scheduler backup job: %v, %s", err, string(res))
return fmt.Errorf("failed to launch incremental backup job: %v, %s", err, string(res))
}
return nil
}
Expand Down Expand Up @@ -2439,7 +2451,7 @@ func (oa *operatorActions) CheckIncrementalBackup(info *TidbClusterConfig, withD

err := wait.Poll(oa.pollInterval, DefaultPollTimeout, fn)
if err != nil {
return fmt.Errorf("failed to launch scheduler backup job: %v", err)
return fmt.Errorf("failed to check incremental backup job: %v", err)
}
return nil

Expand Down
5 changes: 4 additions & 1 deletion tests/cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"
"strconv"

"github.com/golang/glog"
)

func (tc *TidbClusterConfig) set(name string, value string) (string, bool) {
Expand Down Expand Up @@ -113,7 +115,7 @@ func (tc *TidbClusterConfig) BuildSubValues(path string) (string, error) {
"[log]",
`level = "info"`,
}
subValues := GetSubValuesOrDie(tc.ClusterName, tc.Namespace, tc.TopologyKey, pdConfig, tikvConfig, tidbConfig)
subValues := GetSubValuesOrDie(tc.ClusterName, tc.Namespace, tc.TopologyKey, pdConfig, tikvConfig, tidbConfig, tc.pumpConfig, tc.drainerConfig)
subVaulesPath := fmt.Sprintf("%s/%s.yaml", path, tc.ClusterName)
_, err := os.Stat(subVaulesPath)
if err != nil {
Expand All @@ -134,5 +136,6 @@ func (tc *TidbClusterConfig) BuildSubValues(path string) (string, error) {
if err != nil {
return "", err
}
glog.Infof("subValues:\n %s", subValues)
return subVaulesPath, nil
}
39 changes: 36 additions & 3 deletions tests/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ var affinityTemp string = `{{.Kind}}:
topologyKey: {{.TopologyKey}}
namespaces:
- {{.Namespace}}
binlog:
`

var binlogTemp string = `binlog:
pump:
tolerations:
- key: node-role
Expand All @@ -119,6 +121,10 @@ binlog:
topologyKey: {{.TopologyKey}}
namespaces:
- {{.Namespace}}
{{if .PumpConfig}}
config: |
{{range .PumpConfig}} {{.}}
{{end}}{{end}}
drainer:
tolerations:
- key: node-role
Expand All @@ -133,6 +139,10 @@ binlog:
topologyKey: {{.TopologyKey}}
namespaces:
- {{.Namespace}}
{{if .DrainerConfig}}
config: |
{{range .DrainerConfig}} {{.}}
{{end}}{{end}}
`

type AffinityInfo struct {
Expand All @@ -144,7 +154,14 @@ type AffinityInfo struct {
Config []string
}

func GetSubValuesOrDie(clusterName, namespace, topologyKey string, pdConfig []string, tikvConfig []string, tidbConfig []string) string {
type BinLogInfo struct {
PumpConfig []string
DrainerConfig []string
Namespace string
TopologyKey string
}

func GetSubValuesOrDie(clusterName, namespace, topologyKey string, pdConfig []string, tikvConfig []string, tidbConfig []string, pumpConfig []string, drainerConfig []string) string {
temp, err := template.New("dt-affinity").Parse(affinityTemp)
if err != nil {
slack.NotifyAndPanic(err)
Expand All @@ -165,7 +182,23 @@ func GetSubValuesOrDie(clusterName, namespace, topologyKey string, pdConfig []st
if err != nil {
slack.NotifyAndPanic(err)
}
return fmt.Sprintf("%s%s%s", pdbuff.String(), tikvbuff.String(), tidbbuff.String())
subValues := fmt.Sprintf("%s%s%s", pdbuff.String(), tikvbuff.String(), tidbbuff.String())

if pumpConfig == nil && drainerConfig == nil {
return subValues
}

btemp, err := template.New("binlog").Parse(binlogTemp)
if err != nil {
slack.NotifyAndPanic(err)
}
binlogbuff := new(bytes.Buffer)
err = btemp.Execute(binlogbuff, &BinLogInfo{PumpConfig: pumpConfig, DrainerConfig: drainerConfig, Namespace: namespace, TopologyKey: topologyKey})
if err != nil {
slack.NotifyAndPanic(err)
}
subValues = fmt.Sprintf("%s%s", subValues, binlogbuff.String())
return subValues
}

const (
Expand Down