util

package
v0.20.0-alpha8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2016 License: Apache-2.0, Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Contains utility code for use by volume plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FsInfo

func FsInfo(path string) (int64, int64, error)

FSInfo linux returns (available bytes, byte capacity, error) for the filesystem that path resides upon.

func IsReady

func IsReady(dir string) bool

IsReady checks for the existence of a regular file called 'ready' in the given directory and returns true if that file exists.

func SetReady

func SetReady(dir string)

SetReady creates a file called 'ready' in the given directory. It logs an error if the file cannot be created.

Types

type AtomicWriter

type AtomicWriter struct {
	// contains filtered or unexported fields
}

AtomicWriter handles atomically projecting content for a set of files into a target directory. AtomicWriter maintains a sentinel file named "..sentinel" in the target directory which is updated after new data is projected into the target directory, allowing consumers of the data to listen for updates by monitoring the sentinel file with inotify or fanotify.

Note:

  1. AtomicWriter reserves the set of pathnames starting with `..`.
  2. AtomicWriter offers no concurrency guarantees and must be synchronized by the caller.

The visible files in this volume are symlinks to files in the writer's data directory. Actual files are stored in a hidden timestamped directory which is symlinked to by the data directory. The timestamped directory and data directory symlink are created in the writer's target dir.  This scheme allows the files to be atomically updated by changing the target of the data directory symlink.

func NewAtomicWriter

func NewAtomicWriter(targetDir, logContext string) (*AtomicWriter, error)

NewAtomicWriter creates a new AtomicWriter configured to write to the given target directory, or returns an error if the target directory does not exist.

func (*AtomicWriter) Write

func (w *AtomicWriter) Write(payload map[string][]byte) error

Write does an atomic projection of the given payload into the writer's target directory. Input paths must not begin with '..'.

The Write algorithm is:

  1. The payload is validated; if the payload is invalid, the function returns

  2. The user-visible portion of the volume is walked to determine whether any portion of the payload was deleted and is still present on disk. If the payload is already present on disk and there are no deleted files, the function returns

  3. A check is made to determine whether data present in the payload has changed 4.  A new timestamped dir is created

  4. The payload is written to the new timestamped directory 6.  Symlinks and directory for new user-visible files are created (if needed).

    For example consider the files: <target-dir>/podName <target-dir>/user/labels <target-dir>/k8s/annotations

    The user visible files are symbolic links into the internal data directory: <target-dir>/podName -> ..data/podName <target-dir>/usr/labels -> ../..data/usr/labels <target-dir>/k8s/annotations -> ../..data/k8s/annotations

    Relative links are created into the data directory for files in subdirectories.

    The data directory itself is a link to a timestamped directory with the real data: <target-dir>/..data -> ..2016_02_01_15_04_05.12345678/ 7.  The current timestamped directory is detected by reading the data directory symlink 8.  A symlink to the new timestamped directory ..data_tmp is created that will become the new data directory 9.  The new data directory symlink is renamed to the data directory; rename is atomic

  1. The sentinel file modification and access times are updated (file is created if it does not already exist)
  2. Old paths are removed from the user-visible portion of the target directory

12.  The previous timestamped directory is removed, if it exists

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL