Skip to content

Commit

Permalink
This is an automated cherry-pick of #5696
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
wxiaomou authored and ti-chi-bot committed Oct 8, 2024
1 parent 0fc3adb commit 57ae26b
Show file tree
Hide file tree
Showing 8 changed files with 833 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -11867,6 +11867,33 @@ int
</tr>
<tr>
<td>
<<<<<<< HEAD
=======
<code>initWaitTime</code></br>
<em>
int
</em>
</td>
<td>
<p>Wait time before pd get started. This wait time is to allow the new DNS record to propagate,
ensuring that the PD DNS resolves to the same IP address as the pod.</p>
</td>
</tr>
<tr>
<td>
<code>mode</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Mode is the mode of PD cluster</p>
</td>
</tr>
<tr>
<td>
>>>>>>> 5d83d8960 ([PD] add option to wait a certain time before start pd (#5696))
<code>spareVolReplaceReplicas</code></br>
<em>
int32
Expand Down
3 changes: 3 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22399,6 +22399,9 @@ spec:
- name
type: object
type: array
initWaitTime:
default: 0
type: integer
labels:
additionalProperties:
type: string
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 @@ -4935,6 +4935,9 @@ spec:
- name
type: object
type: array
initWaitTime:
default: 0
type: integer
labels:
additionalProperties:
type: string
Expand Down
17 changes: 17 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.

8 changes: 8 additions & 0 deletions pkg/apis/pingcap/v1alpha1/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
// shutdown a TiCDC pod.
defaultTiCDCGracefulShutdownTimeout = 10 * time.Minute
defaultPDStartTimeout = 30
defaultPDInitWaitTime = 0

// the latest version
versionLatest = "latest"
Expand Down Expand Up @@ -1282,3 +1283,10 @@ func (tc *TidbCluster) PDStartTimeout() int {
}
return defaultPDStartTimeout
}

func (tc *TidbCluster) PDInitWaitTime() int {
if tc.Spec.PD != nil && tc.Spec.PD.InitWaitTime != 0 {
return tc.Spec.PD.InitWaitTime
}
return defaultPDInitWaitTime
}
13 changes: 13 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,19 @@ type PDSpec struct {
// +kubebuilder:default=30
StartTimeout int `json:"startTimeout,omitempty"`

<<<<<<< HEAD
=======
// Wait time before pd get started. This wait time is to allow the new DNS record to propagate,
// ensuring that the PD DNS resolves to the same IP address as the pod.
// +kubebuilder:default=0
InitWaitTime int `json:"initWaitTime,omitempty"`

// Mode is the mode of PD cluster
// +optional
// +kubebuilder:validation:Enum:="";"ms"
Mode string `json:"mode,omitempty"`

>>>>>>> 5d83d8960 ([PD] add option to wait a certain time before start pd (#5696))
// The default number of spare replicas to scale up when using VolumeReplace feature.
// In multi-az deployments with topology spread constraints you may need to set this to number of zones to avoid
// zone skew after volume replace (total replicas always whole multiples of zones).
Expand Down
88 changes: 88 additions & 0 deletions pkg/manager/member/startscript/v2/pd_start_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,25 @@ type PDStartScriptModel struct {
ExtraArgs string
PDAddresses string
PDStartTimeout int
PDInitWaitTime int
}

<<<<<<< HEAD
=======
// PDMSStartScriptModel contain fields for rendering PD Micro Service start script
type PDMSStartScriptModel struct {
PDStartTimeout int
PDInitWaitTime int
PDAddresses string

PDMSDomain string
ListenAddr string
AdvertiseListenAddr string

AcrossK8s *AcrossK8sScriptModel
}

>>>>>>> 5d83d8960 ([PD] add option to wait a certain time before start pd (#5696))
// RenderPDStartScript renders PD start script from TidbCluster
func RenderPDStartScript(tc *v1alpha1.TidbCluster) (string, error) {
m := &PDStartScriptModel{}
Expand Down Expand Up @@ -78,6 +95,8 @@ func RenderPDStartScript(tc *v1alpha1.TidbCluster) (string, error) {

m.PDStartTimeout = tc.PDStartTimeout()

m.PDInitWaitTime = tc.PDInitWaitTime()

waitForDnsNameIpMatchOnStartup := slices.Contains(
tc.Spec.StartScriptV2FeatureFlags, v1alpha1.StartScriptV2FeatureFlagWaitForDnsNameIpMatch)

Expand All @@ -93,13 +112,82 @@ func RenderPDStartScript(tc *v1alpha1.TidbCluster) (string, error) {
return renderTemplateFunc(pdStartScriptTpl, m)
}

<<<<<<< HEAD
=======
func RenderPDTSOStartScript(tc *v1alpha1.TidbCluster) (string, error) {
return renderPDMSStartScript(tc, "tso")
}

func RenderPDSchedulingStartScript(tc *v1alpha1.TidbCluster) (string, error) {
return renderPDMSStartScript(tc, "scheduling")
}

// RenderPDMCSStartScript renders TSO start script from TidbCluster
func renderPDMSStartScript(tc *v1alpha1.TidbCluster, name string) (string, error) {
m := &PDMSStartScriptModel{}
tcName := tc.Name
tcNS := tc.Namespace

peerServiceName := controller.PDMSPeerMemberName(tcName, name)
m.PDMSDomain = fmt.Sprintf("${PDMS_POD_NAME}.%s.%s.svc", peerServiceName, tcNS)
if tc.Spec.ClusterDomain != "" {
m.PDMSDomain = m.PDMSDomain + "." + tc.Spec.ClusterDomain
}

m.PDStartTimeout = tc.PDStartTimeout()

m.PDInitWaitTime = tc.PDInitWaitTime()

preferPDAddressesOverDiscovery := slices.Contains(
tc.Spec.StartScriptV2FeatureFlags, v1alpha1.StartScriptV2FeatureFlagPreferPDAddressesOverDiscovery)
if preferPDAddressesOverDiscovery {
pdAddressesWithSchemeAndPort := addressesWithSchemeAndPort(tc.Spec.PDAddresses, "", v1alpha1.DefaultPDClientPort)
m.PDAddresses = strings.Join(pdAddressesWithSchemeAndPort, ",")
}
if len(m.PDAddresses) == 0 {
if tc.AcrossK8s() {
m.AcrossK8s = &AcrossK8sScriptModel{
PDAddr: fmt.Sprintf("%s://%s:%d", tc.Scheme(), controller.PDMemberName(tcName), v1alpha1.DefaultPDClientPort),
DiscoveryAddr: fmt.Sprintf("%s-discovery.%s:10261", tcName, tcNS),
}
m.PDAddresses = "${result}" // get pd addr in subscript
} else if tc.Heterogeneous() && tc.WithoutLocalPD() {
m.PDAddresses = fmt.Sprintf("%s://%s:%d", tc.Scheme(), controller.PDMemberName(tc.Spec.Cluster.Name), v1alpha1.DefaultPDClientPort) // use pd of reference cluster
} else {
m.PDAddresses = fmt.Sprintf("%s://%s:%d", tc.Scheme(), controller.PDMemberName(tcName), v1alpha1.DefaultPDClientPort)
}
}

m.ListenAddr = fmt.Sprintf("%s://0.0.0.0:%d", tc.Scheme(), v1alpha1.DefaultPDClientPort)

// Need to use `PD_DOMAIN` to reuse the same logic with PD in function `pdWaitForDnsIpMatchSubScript`.
m.AdvertiseListenAddr = fmt.Sprintf("%s://${PD_DOMAIN}:%d", tc.Scheme(), v1alpha1.DefaultPDClientPort)

waitForDnsNameIpMatchOnStartup := slices.Contains(
tc.Spec.StartScriptV2FeatureFlags, v1alpha1.StartScriptV2FeatureFlagWaitForDnsNameIpMatch)

msStartScriptTpl := template.Must(
template.Must(
template.New("pdms-start-script").Parse(pdmsStartSubScript),
).Parse(
componentCommonScript +
replacePdStartScriptCustomPorts(
replacePdStartScriptDnsAwaitPart(waitForDnsNameIpMatchOnStartup,
enableMicroServiceModeDynamic(name, pdmsStartScriptTplText)))))

return renderTemplateFunc(msStartScriptTpl, m)
}

>>>>>>> 5d83d8960 ([PD] add option to wait a certain time before start pd (#5696))
const (
// pdStartSubScript contains optional subscripts used in start script.
pdStartSubScript = ``

pdWaitForDnsIpMatchSubScript = `
componentDomain=${PD_DOMAIN}
waitThreshold={{ .PDStartTimeout }}
initWaitTime={{ .PDInitWaitTime }}
sleep initWaitTime
nsLookupCmd="dig ${componentDomain} A ${componentDomain} AAAA +search +short"
` + componentCommonWaitForDnsIpMatchScript

Expand Down
Loading

0 comments on commit 57ae26b

Please sign in to comment.