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

Control backup gc by completed and failed bakcups number #4480

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

just1900
Copy link
Contributor

@just1900 just1900 commented Mar 17, 2022

Signed-off-by: just1900 [email protected]

What problem does this PR solve?

fix #3660

What is changed and how does it work?

adding MaxCompletedBackups and MaxFailedBackups fields to control backup gc.

Code changes

  • Has Go code change
  • Has CI related scripts change

Tests

  • Unit test
  • E2E test
  • Manual test
  • No code

Side effects

  • Breaking backward compatibility
  • Other side effects:

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation

Release Notes

Please refer to Release Notes Language Style Guide before writing the release note.

control backup gc by completed and failed bakcups number

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Mar 17, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • KanShiori
  • csuzhangxc

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

klog.Infof("backup schedule %s/%s gc backup %s success", ns, bsName, backup.GetName())
}

if deleteCount == len(backupsList) && deleteCount > 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this condition, because only if .spec.maxBackups is 0 will this condition be true, which is impossible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this impossible?

@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2022

Codecov Report

Merging #4480 (8a025a8) into master (0d13639) will increase coverage by 9.56%.
The diff coverage is 69.69%.

@@            Coverage Diff             @@
##           master    #4480      +/-   ##
==========================================
+ Coverage   62.79%   72.35%   +9.56%     
==========================================
  Files         184      188       +4     
  Lines       19875    22310    +2435     
==========================================
+ Hits        12480    16142    +3662     
+ Misses       6262     5043    -1219     
+ Partials     1133     1125       -8     
Flag Coverage Δ
e2e 60.09% <0.00%> (?)
unittest 62.80% <71.87%> (+0.01%) ⬆️

@just1900 just1900 changed the title WIP: control backup gc by completed and failed bakcups number Control backup gc by completed and failed bakcups number Mar 17, 2022
@just1900 just1900 changed the title Control backup gc by completed and failed bakcups number WIP: Control backup gc by completed and failed bakcups number Mar 17, 2022
Signed-off-by: just1900 <[email protected]>
@just1900 just1900 changed the title WIP: Control backup gc by completed and failed bakcups number Control backup gc by completed and failed bakcups number Mar 23, 2022
@just1900
Copy link
Contributor Author

seems like a issue exists when backupGCByPolicy and backupGCByMaxBackups concurrently delete backups.

Signed-off-by: just1900 <[email protected]>
@just1900
Copy link
Contributor Author

/test pull-e2e-kind-serial

@KanShiori
Copy link
Collaborator

/test pull-e2e-kind pull-e2e-kind-br pull-e2e-kind-tngm

@ti-chi-bot
Copy link
Member

@just1900: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

// if both MaxCompletedBackups and MaxBackups are set, operator will keep no more than MaxCompletedBackups completed backups,
// and no more than MaxBackups backups in total.
// +kubebuilder:default:=3
// +kubebuilder:validation:Minimum:=1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the old backupSchedule, if the user does not configure MaxBackups, which means no clean-up for the backups, with this change, after upgrading the TiDB Operator, only 3 completed backups will be retained, and the others will be cleaned, right? If yes, this is unexpected behavior.

// and no more than MaxBackups backups in total.
// +kubebuilder:default:=1
// +optional
MaxFailedBackups *int32 `json:"maxFailedBackups,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

// if MaxBackups and MaxReservedTime are set at the same time, MaxReservedTime is preferred.
if bs.Spec.MaxReservedTime != nil {
bm.backupGCByMaxReservedTime(bs)
return
}

if bs.Spec.MaxBackups != nil && *bs.Spec.MaxBackups > 0 {
if (bs.Spec.MaxBackups != nil && *bs.Spec.MaxBackups > 0) || bs.Spec.MaxCompletedBackups != nil || bs.Spec.MaxFailedBackups != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the *bs.Spec.MaxCompletedBackups > 0 and *bs.Spec.MaxFailedBackups > 0

// All backups have been deleted, so the last backup information in the backupSchedule should be reset
bm.resetLastBackup(bs)
if bs.Spec.MaxBackups != nil && int(*bs.Spec.MaxBackups) > 0 && totalCnt > int(*bs.Spec.MaxBackups) {
totalCnt--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also adjust the value of complete count and failed count here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MaxBackups behavior on BackupSchedule
6 participants