Skip to content

Commit

Permalink
make pd start timeout configurable (#5071) (#5095)
Browse files Browse the repository at this point in the history
Co-authored-by: olivia_chen <[email protected]>
  • Loading branch information
ti-chi-bot and olivia_chen committed Jun 26, 2023
1 parent 3dc9543 commit fc03647
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 6 deletions.
11 changes: 11 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -11457,6 +11457,17 @@ string
<p>Start up script version</p>
</td>
</tr>
<tr>
<td>
<code>startTimeout</code></br>
<em>
int
</em>
</td>
<td>
<p>Timeout threshold when pd get started</p>
</td>
</tr>
</tbody>
</table>
<h3 id="pdstatus">PDStatus</h3>
Expand Down
3 changes: 3 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19673,6 +19673,9 @@ spec:
type: object
serviceAccount:
type: string
startTimeout:
default: 30
type: integer
startUpScriptVersion:
enum:
- ""
Expand Down
3 changes: 3 additions & 0 deletions manifests/crd/v1/pingcap.com_tidbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5065,6 +5065,9 @@ spec:
type: object
serviceAccount:
type: string
startTimeout:
default: 30
type: integer
startUpScriptVersion:
enum:
- ""
Expand Down
2 changes: 2 additions & 0 deletions manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5059,6 +5059,8 @@ spec:
type: object
serviceAccount:
type: string
startTimeout:
type: integer
startUpScriptVersion:
enum:
- ""
Expand Down
2 changes: 2 additions & 0 deletions manifests/crd_v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19651,6 +19651,8 @@ spec:
type: object
serviceAccount:
type: string
startTimeout:
type: integer
startUpScriptVersion:
enum:
- ""
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ type PDSpec struct {
// +optional
// +kubebuilder:validation:Enum:="";"v1"
StartUpScriptVersion string `json:"startUpScriptVersion,omitempty"`

// Timeout threshold when pd get started
// +kubebuilder:default=30
StartTimeout int `json:"startTimeout,omitempty"`
}

// TiKVSpec contains details of TiKV members
Expand Down
5 changes: 3 additions & 2 deletions pkg/manager/member/startscript/v1/render_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ func RenderPDStartScript(tc *v1alpha1.TidbCluster) (string, error) {
AcrossK8s: tc.AcrossK8s(),
ClusterDomain: tc.Spec.ClusterDomain,
},
Scheme: tc.Scheme(),
DataDir: filepath.Join(constants.PDDataVolumeMountPath, tc.Spec.PD.DataSubDir),
Scheme: tc.Scheme(),
DataDir: filepath.Join(constants.PDDataVolumeMountPath, tc.Spec.PD.DataSubDir),
PDStartTimeout: tc.Spec.PD.StartTimeout,
}
if tc.Spec.PD.StartUpScriptVersion == "v1" {
model.CheckDomainScript = checkDNSV1
Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/member/startscript/v1/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ encoded_domain_url=` + "`" + `echo ${domain}:2380 | base64 | tr "\n" " " | sed "
`
elapseTime=0
period=1
threshold=30
threshold={{ .PDStartTimeout }}
while true; do
sleep ${period}
elapseTime=$(( elapseTime+period ))
Expand Down Expand Up @@ -245,6 +245,7 @@ type PDStartScriptModel struct {
Scheme string
DataDir string
CheckDomainScript string
PDStartTimeout int
}

var tikvStartScriptTplText = `#!/bin/sh
Expand Down
4 changes: 3 additions & 1 deletion pkg/manager/member/startscript/v1/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,9 @@ exec /pd-server ${ARGS}

tc := &v1alpha1.TidbCluster{
Spec: v1alpha1.TidbClusterSpec{
PD: &v1alpha1.PDSpec{},
PD: &v1alpha1.PDSpec{
StartTimeout: 30,
},
},
}
tc.Name = "test-pd"
Expand Down
5 changes: 4 additions & 1 deletion pkg/manager/member/startscript/v2/pd_start_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type PDStartScriptModel struct {
AdvertiseClientURL string
DiscoveryAddr string
ExtraArgs string
PDStartTimeout int
}

// RenderPDStartScript renders PD start script from TidbCluster
Expand Down Expand Up @@ -66,6 +67,8 @@ func RenderPDStartScript(tc *v1alpha1.TidbCluster) (string, error) {

m.DiscoveryAddr = fmt.Sprintf("%s-discovery.%s:10261", tcName, tcNS)

m.PDStartTimeout = tc.Spec.PD.StartTimeout

return renderTemplateFunc(pdStartScriptTpl, m)
}

Expand All @@ -80,7 +83,7 @@ PD_DOMAIN={{ .PDDomain }}

elapseTime=0
period=1
threshold=30
threshold={{ .PDStartTimeout }}
while true; do
sleep ${period}
elapseTime=$(( elapseTime+period ))
Expand Down
4 changes: 3 additions & 1 deletion pkg/manager/member/startscript/v2/pd_start_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,9 @@ exec /pd-server ${ARGS}

tc := &v1alpha1.TidbCluster{
Spec: v1alpha1.TidbClusterSpec{
PD: &v1alpha1.PDSpec{},
PD: &v1alpha1.PDSpec{
StartTimeout: 30,
},
},
}
tc.Name = "start-script-test"
Expand Down

0 comments on commit fc03647

Please sign in to comment.