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

make pd start timeout configurable #5071

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -11528,6 +11528,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 @@ -19683,6 +19683,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 @@ -19661,6 +19661,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