Documentation
¶
Overview ¶
Package statefile writes and opens the files a node keeps in its state directory: the small files written whole, and the bbolt databases opened with their buckets in place. A shared library: no loops of its own, no policy.
A reader of a file written whole sees the old content or the new one, and a crash leaves one of the two. Every such file has a single writer — a loop, the boot, or the holder of a mutex — for the writes to one path share one temporary name; bbolt serializes a database's writers itself.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadOrCreate ¶
func LoadOrCreate[T any]( path string, decode func([]byte) (T, error), create func() (T, []byte, error), ) (T, error)
LoadOrCreate returns the value the file at path holds, as decode reads it; a decode error names the path. When the file is missing, create returns a fresh value and its bytes, and Write persists the bytes before the value returns.
func OpenBolt ¶
OpenBolt opens the bbolt database at path with opts, creating the file with mode 0600 when missing (its directory must exist), and creates the named buckets it lacks. A failed bucket setup closes the database again, releasing its file lock.
func Remove ¶
Remove removes the file at path and syncs its directory, so the removal survives a crash. A missing file is not an error.
func Write ¶
Write replaces the file at path with data, mode 0600: it writes the data to <path>.tmp, syncs it, renames it over the path, and syncs the directory. A missing parent directory is created with mode 0700 and synced into its own parent. A failed write removes the temporary file, and the path keeps its old content unless the rename has already replaced it. Writes to one path must not overlap.
Types ¶
This section is empty.