Skip to content

Commit

Permalink
Add support to customize spare replicas during VolumeReplace (#5666)
Browse files Browse the repository at this point in the history
Co-authored-by: Xuecheng Zhang <[email protected]>
  • Loading branch information
anish-db and csuzhangxc committed Jun 28, 2024
1 parent dfd5ac2 commit 32166b6
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 3 deletions.
30 changes: 30 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12331,6 +12331,21 @@ string
<p>Mode is the mode of PD cluster</p>
</td>
</tr>
<tr>
<td>
<code>spareVolReplaceReplicas</code></br>
<em>
int32
</em>
</td>
<td>
<em>(Optional)</em>
<p>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).
Optional: Defaults to 1</p>
</td>
</tr>
</tbody>
</table>
<h3 id="pdstatus">PDStatus</h3>
Expand Down Expand Up @@ -22653,6 +22668,21 @@ ScalePolicy
<p>ScalePolicy is the scale configuration for TiKV</p>
</td>
</tr>
<tr>
<td>
<code>spareVolReplaceReplicas</code></br>
<em>
int32
</em>
</td>
<td>
<em>(Optional)</em>
<p>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).
Optional: Defaults to 1</p>
</td>
</tr>
</tbody>
</table>
<h3 id="tikvstatus">TiKVStatus</h3>
Expand Down
8 changes: 8 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24779,6 +24779,10 @@ spec:
type: object
serviceAccount:
type: string
spareVolReplaceReplicas:
format: int32
minimum: 0
type: integer
startTimeout:
default: 30
type: integer
Expand Down Expand Up @@ -41162,6 +41166,10 @@ spec:
type: boolean
serviceAccount:
type: string
spareVolReplaceReplicas:
format: int32
minimum: 0
type: integer
statefulSetUpdateStrategy:
type: string
storageClassName:
Expand Down
8 changes: 8 additions & 0 deletions manifests/crd/v1/pingcap.com_tidbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5725,6 +5725,10 @@ spec:
type: object
serviceAccount:
type: string
spareVolReplaceReplicas:
format: int32
minimum: 0
type: integer
startTimeout:
default: 30
type: integer
Expand Down Expand Up @@ -22108,6 +22112,10 @@ spec:
type: boolean
serviceAccount:
type: string
spareVolReplaceReplicas:
format: int32
minimum: 0
type: integer
statefulSetUpdateStrategy:
type: string
storageClassName:
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func setTikvSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.TiKV.MaxFailoverCount == nil {
tc.Spec.TiKV.MaxFailoverCount = pointer.Int32Ptr(3)
}
if tc.Spec.TiKV.SpareVolReplaceReplicas == nil {
tc.Spec.TiKV.SpareVolReplaceReplicas = pointer.Int32Ptr(1)
}
}

func setPdSpecDefault(tc *v1alpha1.TidbCluster) {
Expand All @@ -126,6 +129,9 @@ func setPdSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.PD.MaxFailoverCount == nil {
tc.Spec.PD.MaxFailoverCount = pointer.Int32Ptr(3)
}
if tc.Spec.PD.SpareVolReplaceReplicas == nil {
tc.Spec.PD.SpareVolReplaceReplicas = pointer.Int32Ptr(1)
}
}

func setPDMSSpecDefault(tc *v1alpha1.TidbCluster) {
Expand Down
14 changes: 14 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: 2 additions & 2 deletions pkg/apis/pingcap/v1alpha1/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ func (tc *TidbCluster) PDStsDesiredReplicas() int32 {
}
var spareReplaceReplicas int32 = 0
if tc.Status.PD.VolReplaceInProgress {
spareReplaceReplicas = 1
spareReplaceReplicas = *tc.Spec.PD.SpareVolReplaceReplicas
}
return tc.Spec.PD.Replicas + tc.GetPDDeletedFailureReplicas() + spareReplaceReplicas
}
Expand Down Expand Up @@ -709,7 +709,7 @@ func (tc *TidbCluster) TiKVStsDesiredReplicas() int32 {
}
var spareReplaceReplicas int32 = 0
if tc.Status.TiKV.VolReplaceInProgress {
spareReplaceReplicas = 1
spareReplaceReplicas = *tc.Spec.TiKV.SpareVolReplaceReplicas
}
return tc.Spec.TiKV.Replicas + int32(len(tc.Status.TiKV.FailureStores)) + spareReplaceReplicas
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,14 @@ type PDSpec struct {
// +optional
// +kubebuilder:validation:Enum:="";"ms"
Mode string `json:"mode,omitempty"`

// 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).
// Optional: Defaults to 1
// +kubebuilder:validation:Minimum=0
// +optional
SpareVolReplaceReplicas *int32 `json:"spareVolReplaceReplicas,omitempty"`
}

// +k8s:openapi-gen=true
Expand Down Expand Up @@ -758,6 +766,14 @@ type TiKVSpec struct {
// ScalePolicy is the scale configuration for TiKV
// +optional
ScalePolicy ScalePolicy `json:"scalePolicy,omitempty"`

// 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).
// Optional: Defaults to 1
// +kubebuilder:validation:Minimum=0
// +optional
SpareVolReplaceReplicas *int32 `json:"spareVolReplaceReplicas,omitempty"`
}

// TiFlashSpec contains details of TiFlash members
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 3 additions & 1 deletion pkg/manager/member/tikv_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ func TestTiKVMemberManagerSyncUpdate(t *testing.T) {
modify: func(tc *v1alpha1.TidbCluster) {
// Random test change to affect pod spec template.
tc.Spec.TiKV.ServiceAccount = "test_new_account"
tc.Spec.TiKV.SpareVolReplaceReplicas = pointer.Int32(1)
tc.Status.TiKV.VolReplaceInProgress = true
},
pdStores: &pdapi.StoresInfo{Count: 0, Stores: []*pdapi.StoreInfo{}},
Expand Down Expand Up @@ -2149,7 +2150,8 @@ func TestGetNewTiKVSetForTidbCluster(t *testing.T) {
},
Spec: v1alpha1.TidbClusterSpec{
TiKV: &v1alpha1.TiKVSpec{
Replicas: 3,
Replicas: 3,
SpareVolReplaceReplicas: pointer.Int32(1),
},
PD: &v1alpha1.PDSpec{},
TiDB: &v1alpha1.TiDBSpec{},
Expand Down

0 comments on commit 32166b6

Please sign in to comment.