From 4d3125504de5c401272697474ce91aad2e6ac2a7 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Fri, 4 Aug 2023 19:07:15 +0800 Subject: [PATCH] opt: keep ports config for TiFlash 7.1.0+ to avoid restarting (#5223) (#5225) Co-authored-by: csuzhangxc --- pkg/apis/label/label.go | 5 +++++ pkg/apis/pingcap/v1alpha1/tidbcluster.go | 5 +++++ pkg/manager/member/tiflash_util.go | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/apis/label/label.go b/pkg/apis/label/label.go index c70a650c29..3007555fd2 100644 --- a/pkg/apis/label/label.go +++ b/pkg/apis/label/label.go @@ -140,6 +140,11 @@ const ( // when TiDB cluster is restored from volume snapshot based backup. AnnTiKVVolumesReadyKey = "tidb.pingcap.com/tikv-volumes-ready" + // AnnoTiFlash710KeepPortsKey is the annotation key to indicate whether the TiFlash v7.1.0+ keeps ports to avoid restart. + // ports: tcp_port, http_port, tcp_port_secure and https_port. + // NOTE: this annotation should only be used for existing TiFlash v7.1.0+ clusters with ports config items. + AnnoTiFlash710KeepPortsKey = "tidb.pingcap.com/tiflash-710-keep-ports" + // PDLabelVal is PD label value PDLabelVal string = "pd" // TiDBLabelVal is TiDB label value diff --git a/pkg/apis/pingcap/v1alpha1/tidbcluster.go b/pkg/apis/pingcap/v1alpha1/tidbcluster.go index 8f4698f002..0b4abbf54a 100644 --- a/pkg/apis/pingcap/v1alpha1/tidbcluster.go +++ b/pkg/apis/pingcap/v1alpha1/tidbcluster.go @@ -1132,6 +1132,11 @@ func (tc *TidbCluster) SkipTLSWhenConnectTiDB() bool { return ok } +func (tc *TidbCluster) KeepTiFlash710Ports() bool { + _, ok := tc.Annotations[label.AnnoTiFlash710KeepPortsKey] + return ok +} + // TODO: We Should better do not specified the default value ourself if user not specified the item. func (tc *TidbCluster) TiCDCTimezone() string { if tc.Spec.TiCDC != nil && tc.Spec.TiCDC.Config != nil { diff --git a/pkg/manager/member/tiflash_util.go b/pkg/manager/member/tiflash_util.go index f954385289..f10c54c0c0 100644 --- a/pkg/manager/member/tiflash_util.go +++ b/pkg/manager/member/tiflash_util.go @@ -164,7 +164,7 @@ func getTiFlashConfigV2(tc *v1alpha1.TidbCluster) *v1alpha1.TiFlashConfigWraper common.SetIfNil("tmp_path", "/data0/tmp") // port - if ok, err := tiflashEqualOrGreaterThanV710.Check(version); err == nil && !ok { + if ok, err := tiflashEqualOrGreaterThanV710.Check(version); err == nil && !ok || tc.KeepTiFlash710Ports() { common.SetIfNil("tcp_port", int64(v1alpha1.DefaultTiFlashTcpPort)) common.SetIfNil("http_port", int64(v1alpha1.DefaultTiFlashHttpPort)) } @@ -229,7 +229,7 @@ func getTiFlashConfigV2(tc *v1alpha1.TidbCluster) *v1alpha1.TiFlashConfigWraper common.Set("security.ca_path", path.Join(tiflashCertPath, corev1.ServiceAccountRootCAKey)) common.Set("security.cert_path", path.Join(tiflashCertPath, corev1.TLSCertKey)) common.Set("security.key_path", path.Join(tiflashCertPath, corev1.TLSPrivateKeyKey)) - if ok, err := tiflashEqualOrGreaterThanV710.Check(version); err == nil && !ok { + if ok, err := tiflashEqualOrGreaterThanV710.Check(version); err == nil && !ok || tc.KeepTiFlash710Ports() { common.SetIfNil("tcp_port_secure", int64(v1alpha1.DefaultTiFlashTcpPort)) common.SetIfNil("https_port", int64(v1alpha1.DefaultTiFlashHttpPort)) }