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

remove temp data in pv for backup #2897

Merged
merged 12 commits into from
Jul 14, 2020

Conversation

lichunzhu
Copy link
Contributor

@lichunzhu lichunzhu commented Jul 10, 2020

What problem does this PR solve?

Fix #2075

What is changed and how does it work?

Delete temp files in PV (even if an error occurs).

Check List

Tests

  • Unit test
  • E2E test
  • Manual test (add detailed scripts or steps below)
    Manual apply import/export job, the data can be deleted.

Related changes

  • Need to cherry-pick to the release branch

Does this PR introduce a user-facing change?:

Clean temporary files in `Backup` export job to save space

@lichunzhu lichunzhu requested review from DanielZhangQD and cofyc July 10, 2020 03:55
@lichunzhu lichunzhu added the status/PTAL PR needs to be reviewed label Jul 10, 2020
@lichunzhu
Copy link
Contributor Author

Current implementation will delete tempary data even if an error occurs. It's not good for debug but can save more space.
WDYT?

cofyc
cofyc previously approved these changes Jul 10, 2020
Copy link
Contributor

@cofyc cofyc left a comment

Choose a reason for hiding this comment

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

oh, maybe it's better to clean data only if the upload succeeds.

This is not only for debugging, it's about data safety. For example, the upload process may fail due to network failures, IMO it's better we don't delete local backup data in this case.

@cofyc
Copy link
Contributor

cofyc commented Jul 10, 2020

After the upload is completed successfully, it's safe to remove local backup data.

@lichunzhu
Copy link
Contributor Author

After the upload is completed successfully, it's safe to remove local backup data.

What about restore?

@lichunzhu
Copy link
Contributor Author

After the upload is completed successfully, it's safe to remove local backup data.

Maybe we can remove the unpacked datadir? Similiarly can we remove the tar package in lightning restore after it's unpacked?

@cofyc
Copy link
Contributor

cofyc commented Jul 10, 2020

I think it's ok to clean temporary files in restoring since the original data is persisted.

@@ -152,7 +153,9 @@ func (rm *RestoreManager) performRestore(restore *v1alpha1.Restore) error {
klog.Infof("download cluster %s backup %s data success", rm, rm.BackupPath)

restoreDataDir := filepath.Dir(restoreDataPath)
defer os.RemoveAll(restoreDataPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest not removing data after restore.

@@ -262,6 +263,8 @@ func (bm *BackupManager) performBackup(backup *v1alpha1.Backup, db *sql.DB) erro
Message: backupErr.Error(),
})
errs = append(errs, uerr)
// just delete backupFullPath since it will never be used except for debug
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's useful for debug, can we keep it just in case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in df73f02

@@ -166,6 +167,8 @@ func (rm *RestoreManager) performRestore(restore *v1alpha1.Restore) error {
return errorutils.NewAggregate(errs)
}
klog.Infof("unarchive cluster %s backup %s data success", rm, restoreDataPath)
// unarchive succeed, origin archive can be deleted now
Copy link
Contributor

Choose a reason for hiding this comment

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

What about keeping the tar, it does not make much difference since we keep the unarchieved files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in df73f02

DanielZhangQD
DanielZhangQD previously approved these changes Jul 11, 2020
Copy link
Contributor

@DanielZhangQD DanielZhangQD left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot
Copy link
Contributor

@DanielZhangQD,Thanks for your review.

@cofyc
Copy link
Contributor

cofyc commented Jul 13, 2020

release notes should be accurate and concise for the end-users as they are part of our documentation. please always update the release notes to reflect the latest change and follow the conventions used in our documentation.

my suggestion:

Clean temporary files in `Backup` export job to save space

@lichunzhu
Copy link
Contributor Author

release notes should be accurate and concise for the end-users as they are part of our documentation. please always update the release notes to reflect the latest change and follow the conventions used in our documentation.

my suggestion:

Clean temporary files in `Backup` export job to save space

revised

@lichunzhu
Copy link
Contributor Author

/run-all-tests

@DanielZhangQD
Copy link
Contributor

/run-all-tests

@lichunzhu
Copy link
Contributor Author

@cofyc PTAL again

cofyc
cofyc previously approved these changes Jul 14, 2020
ti-srebot
ti-srebot previously approved these changes Jul 14, 2020
@@ -282,6 +283,8 @@ func (bm *BackupManager) performBackup(backup *v1alpha1.Backup, db *sql.DB) erro
return errorutils.NewAggregate(errs)
}
klog.Infof("archive cluster %s backup data %s success", bm, archiveBackupPath)
// archive succeed, origin dir can be deleted safely
Copy link
Contributor

Choose a reason for hiding this comment

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

getCommitTsFromMetadata in L305 will fail.

@lichunzhu lichunzhu dismissed stale reviews from ti-srebot, cofyc, and DanielZhangQD via a23fa3b July 14, 2020 03:55
Copy link
Contributor

@DanielZhangQD DanielZhangQD left a comment

Choose a reason for hiding this comment

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

LGTM

@DanielZhangQD DanielZhangQD merged commit 02bc61b into pingcap:master Jul 14, 2020
ti-srebot pushed a commit to ti-srebot/tidb-operator that referenced this pull request Jul 14, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-1.1 in PR #2922

ti-srebot added a commit that referenced this pull request Jul 14, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: Chunzhu Li <lichunzhu@stu.xjtu.edu.cn>
lichunzhu added a commit to lichunzhu/docs-tidb-operator that referenced this pull request Jul 14, 2020
ti-srebot pushed a commit to pingcap/docs-tidb-operator that referenced this pull request Jul 16, 2020
* document how to delete backup

* document gc behavior during backup

* address comments, add description for pingcap/tidb-operator#2888 (comment) and pingcap/tidb-operator#2897

* address comments

* address comments

* address comments

* Apply suggestions from code review

Co-authored-by: Ran <huangran@pingcap.com>
@lichunzhu lichunzhu deleted the removePVTmpData branch September 2, 2020 07:11
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.

Backup data in PV is not cleaned up after backup with CR (Mydumper)
4 participants