atomicfs

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: BSD-3-Clause Imports: 6 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadMarker

func ReadMarker(fs vfs.FS, dir, markerName string) (string, error)

ReadMarker looks up the current state of a marker returning just the current value of the marker. Callers that may need to move the marker to a new value should use LocateMarker.

Types

type Marker

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

A Marker provides an interface for maintaining a single string value on the filesystem. The marker may be atomically moved from value to value.

The implementation creates a new marker file for each new value, embedding the value in the marker filename.

Marker is not safe for concurrent use. Multiple processes may not read or move the same marker simultaneously. A Marker may only be constructed through LocateMarker.

Marker names must be unique within the directory.

func LocateMarker

func LocateMarker(fs vfs.FS, dir, markerName string) (*Marker, string, error)

LocateMarker loads the current state of a marker. It returns a handle to the Marker that may be used to move the marker and the current value of the marker.

func (*Marker) Close

func (a *Marker) Close() error

Close releases all resources in use by the marker.

func (*Marker) Move

func (a *Marker) Move(newValue string) error

Move atomically moves the marker to a new value.

If Move returns a nil error, the new marker value is guaranteed to be persisted to stable storage. If Move returns an error, the current value of the marker may be the old value or the new value. Callers may retry a Move error.

If an error occurs while syncing the directory, Move panics.

func (*Marker) NextIter

func (a *Marker) NextIter() uint64

NextIter returns the next iteration number that the marker will use. Clients may use this number for formulating new values that are unused.

func (*Marker) RemoveObsolete

func (a *Marker) RemoveObsolete() error

RemoveObsolete removes any obsolete files discovered while locating the marker or files unable to be removed during Move.

Jump to

Keyboard shortcuts

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