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

br: add warmup process to volume snapshot restore #5229

Merged
merged 19 commits into from
Aug 18, 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
60 changes: 60 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,32 @@ For BR image, if it does not contain tag, Pod will use image ‘ToolImage:${
</tr>
<tr>
<td>
<code>warmup</code></br>
<em>
<a href="#restorewarmupmode">
RestoreWarmupMode
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>Warmup represents whether to initialize TiKV volumes after volume snapshot restore</p>
</td>
</tr>
<tr>
<td>
<code>warmupImage</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>WarmupImage represents using what image to initialize TiKV volumes</p>
</td>
</tr>
<tr>
<td>
<code>podSecurityContext</code></br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#podsecuritycontext-v1-core">
Expand Down Expand Up @@ -13959,6 +13985,32 @@ For BR image, if it does not contain tag, Pod will use image &lsquo;ToolImage:${
</tr>
<tr>
<td>
<code>warmup</code></br>
<em>
<a href="#restorewarmupmode">
RestoreWarmupMode
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>Warmup represents whether to initialize TiKV volumes after volume snapshot restore</p>
</td>
</tr>
<tr>
<td>
<code>warmupImage</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>WarmupImage represents using what image to initialize TiKV volumes</p>
</td>
</tr>
<tr>
<td>
<code>podSecurityContext</code></br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#podsecuritycontext-v1-core">
Expand Down Expand Up @@ -14088,6 +14140,14 @@ RestoreConditionType
</tr>
</tbody>
</table>
<h3 id="restorewarmupmode">RestoreWarmupMode</h3>
<p>
(<em>Appears on:</em>
<a href="#restorespec">RestoreSpec</a>)
</p>
<p>
<p>RestoreWarmupMode represents when to initialize TiKV volumes</p>
</p>
<h3 id="s3storageprovider">S3StorageProvider</h3>
<p>
(<em>Appears on:</em>
Expand Down
24 changes: 24 additions & 0 deletions docs/api-references/federation-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,30 @@ string
<p>PriorityClassName of Restore Job Pods</p>
</td>
</tr>
<tr>
<td>
<code>warmup</code></br>
<em>
github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.RestoreWarmupMode
</em>
</td>
<td>
<em>(Optional)</em>
<p>Warmup represents whether to initialize TiKV volumes after volume snapshot restore</p>
</td>
</tr>
<tr>
<td>
<code>warmupImage</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>WarmupImage represents using what image to initialize TiKV volumes</p>
</td>
</tr>
</tbody>
</table>
<h3 id="volumerestorememberstatus">VolumeRestoreMemberStatus</h3>
Expand Down
4 changes: 4 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15259,6 +15259,10 @@ spec:
type: boolean
volumeAZ:
type: string
warmup:
type: string
warmupImage:
type: string
type: object
status:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,10 @@ spec:
type: array
toolImage:
type: string
warmup:
type: string
warmupImage:
type: string
type: object
type: object
status:
Expand Down
4 changes: 4 additions & 0 deletions manifests/crd/v1/pingcap.com_restores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,10 @@ spec:
type: boolean
volumeAZ:
type: string
warmup:
type: string
warmupImage:
type: string
type: object
status:
properties:
Expand Down
4 changes: 4 additions & 0 deletions manifests/federation-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3011,6 +3011,10 @@ spec:
type: array
toolImage:
type: string
warmup:
type: string
warmupImage:
type: string
type: object
type: object
status:
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/federation/pingcap/v1alpha1/openapi_generated.go

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

13 changes: 13 additions & 0 deletions pkg/apis/federation/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ type VolumeRestoreMemberSpec struct {
ServiceAccount string `json:"serviceAccount,omitempty"`
// PriorityClassName of Restore Job Pods
PriorityClassName string `json:"priorityClassName,omitempty"`
// Warmup represents whether to initialize TiKV volumes after volume snapshot restore
// +optional
Warmup pingcapv1alpha1.RestoreWarmupMode `json:"warmup,omitempty"`
// WarmupImage represents using what image to initialize TiKV volumes
// +optional
WarmupImage string `json:"warmupImage,omitempty"`
}

type VolumeRestoreMemberBackupInfo struct {
Expand Down Expand Up @@ -441,6 +447,11 @@ const (
VolumeRestoreRunning VolumeRestoreConditionType = "Running"
// VolumeRestoreVolumeComplete means all the restore members are volume complete
VolumeRestoreVolumeComplete VolumeRestoreConditionType = "VolumeComplete"
// VolumeRestoreWarmUpStarted means the Restore has successfully started warmup pods to
// initialize volumes restored from snapshots
VolumeRestoreWarmUpStarted VolumeRestoreConditionType = "WarmUpStarted"
// VolumeRestoreWarmUpComplete means the Restore has successfully warmed up all TiKV volumes
VolumeRestoreWarmUpComplete VolumeRestoreConditionType = "WarmUpComplete"
// VolumeRestoreTiKVComplete means all the restore members are tikv complete
VolumeRestoreTiKVComplete VolumeRestoreConditionType = "TikvComplete"
// VolumeRestoreDataComplete means all the restore members are data complete
Expand All @@ -460,6 +471,8 @@ const (
VolumeRestoreStepRestoreVolume VolumeRestoreStepType = "RestoreVolume"
// VolumeRestoreStepStartTiKV is start tikv step
VolumeRestoreStepStartTiKV VolumeRestoreStepType = "StartTiKV"
// VolumeRestoreStepWarmUp is warm up tikv volumes step
VolumeRestoreStepWarmUp VolumeRestoreStepType = "WarmUp"
// VolumeRestoreStepRestoreData is restore data step
VolumeRestoreStepRestoreData VolumeRestoreStepType = "RestoreData"
// VolumeRestoreStepRestartTiKV is restart tikv step
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/federation/pingcap/v1alpha1/volume_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ func IsVolumeRestoreVolumeComplete(volumeRestore *VolumeRestore) bool {
return condition != nil && condition.Status == corev1.ConditionTrue
}

func IsVolumeRestoreWarmUpStarted(volumeRestore *VolumeRestore) bool {
_, condition := GetVolumeRestoreCondition(&volumeRestore.Status, VolumeRestoreWarmUpStarted)
return condition != nil && condition.Status == corev1.ConditionTrue
}

func IsVolumeRestoreWarmUpComplete(volumeRestore *VolumeRestore) bool {
_, condition := GetVolumeRestoreCondition(&volumeRestore.Status, VolumeRestoreWarmUpComplete)
return condition != nil && condition.Status == corev1.ConditionTrue
}

func IsVolumeRestoreTiKVComplete(volumeRestore *VolumeRestore) bool {
_, condition := GetVolumeRestoreCondition(&volumeRestore.Status, VolumeRestoreTiKVComplete)
return condition != nil && condition.Status == corev1.ConditionTrue
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const (

// RestoreLabelKey is restore key
RestoreLabelKey string = "tidb.pingcap.com/restore"
// RestoreWarmUpLabelKey defines which pod the restore warms up
RestoreWarmUpLabelKey string = "tidb.pingcap.com/warm-up-pod"

// BackupProtectionFinalizer is the name of finalizer on backups or federation backups
BackupProtectionFinalizer string = "tidb.pingcap.com/backup-protection"
Expand Down Expand Up @@ -168,6 +170,8 @@ const (
CleanJobLabelVal string = "clean"
// RestoreJobLabelVal is restore job label value
RestoreJobLabelVal string = "restore"
// RestoreWarmUpJobLabelVal is restore warmup job label value
RestoreWarmUpJobLabelVal string = "warmup"
// BackupJobLabelVal is backup job label value
BackupJobLabelVal string = "backup"
// BackupScheduleJobLabelVal is backup schedule job label value
Expand Down Expand Up @@ -352,6 +356,10 @@ func (l Label) RestoreJob() Label {
return l.Component(RestoreJobLabelVal)
}

func (l Label) RestoreWarmUpJob() Label {
return l.Component(RestoreWarmUpJobLabelVal)
}

// Backup assigns specific value to backup key in label
func (l Label) Backup(val string) Label {
l[BackupLabelKey] = val
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.

12 changes: 12 additions & 0 deletions pkg/apis/pingcap/v1alpha1/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ func IsRestoreVolumeComplete(restore *Restore) bool {
return condition != nil && condition.Status == corev1.ConditionTrue
}

// IsRestoreWarmUpStarted returns true if all the warmup jobs has successfully started
func IsRestoreWarmUpStarted(restore *Restore) bool {
_, condition := GetRestoreCondition(&restore.Status, RestoreWarmUpStarted)
return condition != nil && condition.Status == corev1.ConditionTrue
}

// IsRestoreWarmUpComplete returns true if all the warmup jobs has successfully finished
func IsRestoreWarmUpComplete(restore *Restore) bool {
_, condition := GetRestoreCondition(&restore.Status, RestoreWarmUpComplete)
return condition != nil && condition.Status == corev1.ConditionTrue
}

// IsRestoreTiKVComplete returns true if all TiKVs run successfully during volume restore
func IsRestoreTiKVComplete(restore *Restore) bool {
_, condition := GetRestoreCondition(&restore.Status, RestoreTiKVComplete)
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,11 @@ const (
// RestoreVolumeComplete means the Restore has successfully executed part-1 and the
// backup volumes have been rebuilded from the corresponding snapshot
RestoreVolumeComplete RestoreConditionType = "VolumeComplete"
// RestoreWarmUpStarted means the Restore has successfully started warm up pods to
// initialize volumes restored from snapshots
RestoreWarmUpStarted RestoreConditionType = "WarmUpStarted"
// RestoreWarmUpComplete means the Restore has successfully warmed up all TiKV volumes
RestoreWarmUpComplete RestoreConditionType = "WarmUpComplete"
// RestoreDataComplete means the Restore has successfully executed part-2 and the
// data in restore volumes has been deal with consistency based on min_resolved_ts
RestoreDataComplete RestoreConditionType = "DataComplete"
Expand Down Expand Up @@ -2448,6 +2453,12 @@ type RestoreSpec struct {
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// TableFilter means Table filter expression for 'db.table' matching. BR supports this from v4.0.3.
TableFilter []string `json:"tableFilter,omitempty"`
// Warmup represents whether to initialize TiKV volumes after volume snapshot restore
// +optional
Warmup RestoreWarmupMode `json:"warmup,omitempty"`
// WarmupImage represents using what image to initialize TiKV volumes
// +optional
WarmupImage string `json:"warmupImage,omitempty"`

// PodSecurityContext of the component
// +optional
Expand All @@ -2469,6 +2480,16 @@ const (
FederalVolumeRestoreFinish FederalVolumeRestorePhase = "restore-finish"
)

// RestoreWarmupMode represents when to initialize TiKV volumes
type RestoreWarmupMode string

const (
// RestoreWarmupModeSync means initialize TiKV volumes before TiKV starts
RestoreWarmupModeSync RestoreWarmupMode = "sync"
// RestoreWarmupModeASync means initialize TiKV volumes after restore complete
RestoreWarmupModeASync RestoreWarmupMode = "async"
)

// RestoreStatus represents the current status of a tidb cluster restore.
type RestoreStatus struct {
// TimeStarted is the time at which the restore was started.
Expand Down
Loading
Loading