mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #97642 from claudiubelu/subatomic-symlinks
subatomic: Creates the symlinks to user-visible files later
This commit is contained in:
commit
95d3360467
@ -98,7 +98,10 @@ const (
|
|||||||
// data to determine if an update is required.
|
// data to determine if an update is required.
|
||||||
// 5. A new timestamped dir is created
|
// 5. A new timestamped dir is created
|
||||||
// 6. The payload is written to the new timestamped directory
|
// 6. The payload is written to the new timestamped directory
|
||||||
// 7. Symlinks and directory for new user-visible files are created (if needed).
|
// 7. A symlink to the new timestamped directory ..data_tmp is created that will
|
||||||
|
// become the new data directory
|
||||||
|
// 8. The new data directory symlink is renamed to the data directory; rename is atomic
|
||||||
|
// 9. Symlinks and directory for new user-visible files are created (if needed).
|
||||||
//
|
//
|
||||||
// For example, consider the files:
|
// For example, consider the files:
|
||||||
// <target-dir>/podName
|
// <target-dir>/podName
|
||||||
@ -113,9 +116,9 @@ const (
|
|||||||
// The data directory itself is a link to a timestamped directory with
|
// The data directory itself is a link to a timestamped directory with
|
||||||
// the real data:
|
// the real data:
|
||||||
// <target-dir>/..data -> ..2016_02_01_15_04_05.12345678/
|
// <target-dir>/..data -> ..2016_02_01_15_04_05.12345678/
|
||||||
// 8. A symlink to the new timestamped directory ..data_tmp is created that will
|
// NOTE(claudiub): We need to create these symlinks AFTER we've finished creating and
|
||||||
// become the new data directory
|
// linking everything else. On Windows, if a target does not exist, the created symlink
|
||||||
// 9. The new data directory symlink is renamed to the data directory; rename is atomic
|
// will not work properly if the target ends up being a directory.
|
||||||
// 10. Old paths are removed from the user-visible portion of the target directory
|
// 10. Old paths are removed from the user-visible portion of the target directory
|
||||||
// 11. The previous timestamped directory is removed, if it exists
|
// 11. The previous timestamped directory is removed, if it exists
|
||||||
func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
|
func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
|
||||||
@ -178,12 +181,6 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
|
|||||||
klog.V(4).Infof("%s: performed write of new data to ts data directory: %s", w.logContext, tsDir)
|
klog.V(4).Infof("%s: performed write of new data to ts data directory: %s", w.logContext, tsDir)
|
||||||
|
|
||||||
// (7)
|
// (7)
|
||||||
if err = w.createUserVisibleFiles(cleanPayload); err != nil {
|
|
||||||
klog.Errorf("%s: error creating visible symlinks in %s: %v", w.logContext, w.targetDir, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// (8)
|
|
||||||
newDataDirPath := filepath.Join(w.targetDir, newDataDirName)
|
newDataDirPath := filepath.Join(w.targetDir, newDataDirName)
|
||||||
if err = os.Symlink(tsDirName, newDataDirPath); err != nil {
|
if err = os.Symlink(tsDirName, newDataDirPath); err != nil {
|
||||||
os.RemoveAll(tsDir)
|
os.RemoveAll(tsDir)
|
||||||
@ -191,7 +188,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// (9)
|
// (8)
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
os.Remove(dataDirPath)
|
os.Remove(dataDirPath)
|
||||||
err = os.Symlink(tsDirName, dataDirPath)
|
err = os.Symlink(tsDirName, dataDirPath)
|
||||||
@ -206,6 +203,12 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// (9)
|
||||||
|
if err = w.createUserVisibleFiles(cleanPayload); err != nil {
|
||||||
|
klog.Errorf("%s: error creating visible symlinks in %s: %v", w.logContext, w.targetDir, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// (10)
|
// (10)
|
||||||
if err = w.removeUserVisiblePaths(pathsToRemove); err != nil {
|
if err = w.removeUserVisiblePaths(pathsToRemove); err != nil {
|
||||||
klog.Errorf("%s: error removing old visible symlinks: %v", w.logContext, err)
|
klog.Errorf("%s: error removing old visible symlinks: %v", w.logContext, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user