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

Add commit ts to restore status #2899

Merged
merged 20 commits into from
Jul 14, 2020

Conversation

lichunzhu
Copy link
Contributor

@lichunzhu lichunzhu commented Jul 10, 2020

What problem does this PR solve?

Fix #2774.

What is changed and how does it work?

Reuse the getCommitTs function for BR and lightning. Save commitTS in restoreStatus.

Check List

Tests

  • Unit test
  • E2E test
  • Manual test (add detailed scripts or steps below)
    The manual checks for lightning and br restore are both okay.
  ...
    secretName: restore-demo-basic-secret
    user: root
status:
  commitTs: "417953765864243201"
  conditions:
  ...

Related changes

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

Does this PR introduce a user-facing change?:

Support show commitTS in restore status.

@lichunzhu lichunzhu added the status/PTAL PR needs to be reviewed label Jul 10, 2020
@@ -58,18 +58,18 @@ type gcsQuery struct {
}

// NewRemoteStorage creates new remote storage
func NewRemoteStorage(backup *v1alpha1.Backup) (*blob.Bucket, error) {
st := util.GetStorageType(backup.Spec.StorageProvider)
func NewRemoteStorage(provider v1alpha1.StorageProvider, fakeRegion bool) (*blob.Bucket, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why add fakeRegion to this function?

@lichunzhu lichunzhu requested a review from DanielZhangQD July 13, 2020 06:22
@lichunzhu
Copy link
Contributor Author

@DanielZhangQD @cofyc PTAL again

cmd/backup-manager/app/import/manager.go Show resolved Hide resolved
Message: err.Error(),
})
errs = append(errs, uerr)
return errorutils.NewAggregate(errs)
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 to return here.

Copy link
Contributor

@cofyc cofyc Jul 14, 2020

Choose a reason for hiding this comment

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

I think it's ok. I don't think it's necessary to continue the restore operation with the backup from which we can't even get the commitTs information.

btw, should we move this before the restore operation like we do in import/manager.go file?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, then i think we can move this block before the GC time setting code block.

@@ -186,6 +201,7 @@ func (rm *RestoreManager) performRestore(restore *v1alpha1.Restore) error {

restore.Status.TimeStarted = metav1.Time{Time: started}
restore.Status.TimeCompleted = metav1.Time{Time: finish}
restore.Status.CommitTs = commitTs
Copy link
Contributor

@cofyc cofyc Jul 14, 2020

Choose a reason for hiding this comment

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

always update commitTs when we get it successfully (edit: ignore)

Copy link
Contributor

@cofyc cofyc Jul 14, 2020

Choose a reason for hiding this comment

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

sorry, maybe it's better not to update it when the restore fails as the commitTs indicates the commit timestamp or position of the restored backup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

which means current implementation is correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

changes in this file LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see

finish := time.Now()
restore.Status.TimeStarted = metav1.Time{Time: started}
restore.Status.TimeCompleted = metav1.Time{Time: finish}
restore.Status.CommitTs = fmt.Sprintf("%d", commitTs)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use strconv.FormatInt(commitTs, 10)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

revised.


Finished dump at: 2019-06-13 10:00:04
*/
func GetCommitTsFromMetadata(backupPath string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a unit test function for this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added in b6e3120

}

// GetCommitTsFromBRMetaData get backup position from `EndVersion` in BR backup meta
func GetCommitTsFromBRMetaData(provider v1alpha1.StorageProvider) (uint64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, better to have a unit test for this function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function get TS from S3 and ts is decoded by proto.Unmarshal. Maybe later we can mock it in another PR. This PR won't add this.

@@ -299,7 +299,7 @@ func (bm *BackupManager) performBackup(backup *v1alpha1.Backup, db *sql.DB) erro
}
klog.Infof("get cluster %s archived backup file %s size %d success", bm, archiveBackupPath, size)

commitTs, err := getCommitTsFromMetadata(backupFullPath)
commitTs, err := util.GetCommitTsFromMetadata(backupFullPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please wait for #2897 which removes the temp data after the compression.

@@ -182,10 +182,26 @@ func (rm *RestoreManager) performRestore(restore *v1alpha1.Restore) error {
}
klog.Infof("restore cluster %s from backup %s success", rm, rm.BackupPath)

commitTs, err := util.GetCommitTsFromMetadata(unarchiveDataPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

As per discussion, please move this block after the uncompression code block.

@lichunzhu
Copy link
Contributor Author

After manual test, br & export & import can record commitTs correctly. PTAL again @cofyc @DanielZhangQD

@lichunzhu
Copy link
Contributor Author

/test pull-e2e-kind-serial

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 48eb1cd into pingcap:master Jul 14, 2020
@lichunzhu lichunzhu deleted the addCommitTsToRestoreStatus branch July 14, 2020 10:05
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 #2925

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>
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.

Add commitTs to RestoreStatus
4 participants