-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Migrate registry from previous incorrect path #10486
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1e70cfd
migrate registries from incorrect path
kvch 0e0a490
add changelog entry
kvch fe8ab2b
add more fixes
kvch b0ef85b
fix error msg
kvch a132de4
close files before running `SafeRotate`
kvch 47cbc40
address review notes
kvch 5c73b8e
best effort syncing
kvch 4453f55
fix error checking :facepalm:
kvch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ package checkpoint | |
|
||
import ( | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
@@ -88,7 +89,10 @@ func NewCheckpoint(file string, maxUpdates int, interval time.Duration) (*Checkp | |
save: make(chan JournalState, 1), | ||
} | ||
|
||
c.file = paths.Resolve(paths.Data, c.file) | ||
err := c.findRegistryFile() | ||
if err != nil { | ||
return nil, fmt.Errorf("error locating the proper registry file: %+v", err) | ||
} | ||
|
||
// Minimum batch size. | ||
if c.maxUpdates < 1 { | ||
|
@@ -123,6 +127,53 @@ func NewCheckpoint(file string, maxUpdates int, interval time.Duration) (*Checkp | |
return c, nil | ||
} | ||
|
||
// Previously the registry file was written to the root folder. It was fixed on | ||
// 7.x but not on 6.x. Thus, migration is needed, so users avoid losing state info. | ||
func (c *Checkpoint) findRegistryFile() error { | ||
migratedPath := paths.Resolve(paths.Data, c.file) | ||
|
||
fs, err := os.Stat(c.file) | ||
if os.IsNotExist(err) { | ||
c.file = migratedPath | ||
return nil | ||
} else if err != nil { | ||
return fmt.Errorf("error accessing previous registry file: %+v", err) | ||
} | ||
|
||
f, err := os.Open(c.file) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
target, err := os.OpenFile(migratedPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fs.Mode()) | ||
if err != nil { | ||
return err | ||
} | ||
defer target.Close() | ||
|
||
if _, err := io.Copy(target, f); err != nil { | ||
return err | ||
} | ||
|
||
err = target.Sync() | ||
if err != nil { | ||
return fmt.Errorf("error while syncing new registry file to disk: %+v", err) | ||
} | ||
|
||
c.file = migratedPath | ||
|
||
p := filepath.Dir(migratedPath) | ||
pf, err := os.Open(p) | ||
if err != nil { | ||
return nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit; |
||
defer pf.Close() | ||
pf.Sync() | ||
|
||
return nil | ||
} | ||
|
||
// run is worker loop that reads incoming state information from the save | ||
// channel and persists it when the number of changes reaches maxEvents or | ||
// the amount of time since the last disk write reaches flushInterval. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the copy is not 'safe' without extra call to
target.Sync()
. Some filesystems (without journaling) also require a sync operation on the parent directory in order to sync file + directory meta data.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Donz.