statefile

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func OpenBolt(path string, opts *bbolt.Options, buckets ...string) (*bbolt.DB, error)

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

func Remove(path string) error

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

func Write(path string, data []byte) error

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.

Jump to

Keyboard shortcuts

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