Skip to content

🍀 Proposal: Support for rollback in case of error in intermediate steps #1173

Closed

Description

@aFlyBird0

What Would You Like to Add? Why Is This Needed?

// applyUpgrade use os.Rename replace old version dtm with the latest one
// (1) rename current dtm file name to `dtm-bak`.
// (2) rename `dtm-tmp` to current dtm file name.
// (3) grant new dtm file execute permission.
// (4) remove `dtm-bak` binary file.
// TODO(hxcGit): Support for rollback in case of error in intermediate steps
func applyUpgrade(workDir string) error {
dtmFilePath := filepath.Join(workDir, dtmFileName)
dtmBakFilePath := filepath.Join(workDir, dtmBakFileName)
dtmTmpFilePath := filepath.Join(workDir, dtmTmpFileName)
if err := os.Rename(dtmFilePath, dtmBakFilePath); err != nil {
return err
}
log.Debugf("Dtm upgrade: rename %s to dtm-bak successfully.", dtmFileName)
if err := os.Rename(dtmTmpFilePath, dtmFilePath); err != nil {
return err
}
log.Debugf("Dtm upgrade: rename dtm-tmp to %s successfully.", dtmFileName)
if err := os.Chmod(dtmFilePath, 0755); err != nil {
return err
}
log.Debugf("Dtm upgrade: grant %s execute permission successfully.", dtmFileName)
if err := os.Remove(dtmBakFilePath); err != nil {
return err
}
log.Debug("Dtm upgrade: remove dtm-bak successfully.")
return nil
}

Design

Anything else

Activity

  1. 0zyt commented on Oct 16, 2022

    @0zyt

    I want to do it

  2. aFlyBird0 commented on Oct 16, 2022

    @aFlyBird0
    MemberAuthor

    I want to do it

    Do as much as you like!

  3. 0zyt commented on Oct 16, 2022

    @0zyt

    @xavier-hou Hi,Do you think it is necessary to consider being interrupted by a signal such as CTRL+C?

  4. 0zyt commented on Oct 16, 2022

    @0zyt

    This is the commit on my branch:0zyt@3f62a93

    I had a discussion with @aFlyBird0 about writing test for this feature because I couldn't find a better way to test this feature.

    06a239906039e95fe4b78db8e2cdbff

    The codes above from @aFlyBird0 ,

    I think this is a practical and effective way to test, but it doesn't look elegant at first glance.
    The other way is to keep it simple and elegant and not change the function signature and to verify it locally by me or other members, but this is not a transparent way to test an open source project and may not be good enough.
    So I would like to hear your thoughts.

    @xavier-hou @Danielhui @steinliber @IronCore864

    I will PR after getting a better way.

  5. IronCore864 commented on Oct 17, 2022

    @IronCore864
    Member

    nd a better way to test this feature.

    I think this is a way to test it, but as you said, it changes the signature of the func, which might be a bit confusing to read.

    I personally suggest a better way to test it. What do you guys think?

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions