durability

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 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 durability is a spike to validate the durability design: Litestream embedded as a library, replicating to Azure Blob Storage through a ReplicaClient that fences stale leaders with conditional writes. It is not the product, has no stable API, and may be deleted or replaced.

The tests run against Azurite and are behind the "integration" build tag. See docs/content/docs/decisions/0002-durability-spike.md.

Index

Constants

View Source
const DBPrefix = "db"

DBPrefix is the blob prefix the spike keeps the LTX history under.

View Source
const LeaseKey = "lease.json"

LeaseKey is the blob holding the leadership lease.

Variables

View Source
var ErrFenced = errors.New("fenced: another leader owns the history")

ErrFenced is returned, wrapped, by every write and delete once a client has seen evidence that another leader owns the history.

Functions

This section is empty.

Types

type Client

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

Client is a litestream.ReplicaClient for Azure Blob Storage that creates every LTX file with If-None-Match: * and latches into a fenced state on the first sign that it is not the writer of the history.

Head is the highest L0 TXID this client has itself confirmed in storage. A leader may only append L0 head+1, may only write higher-level files that end at or below head, and may only write those or delete anything while the remote L0 head is still its own.

func NewClient

func NewClient(az *azblob.Client, container, prefix string) *Client

NewClient returns a client for LTX files under prefix in container.

func (*Client) DeleteAll

func (c *Client) DeleteAll(context.Context) error

DeleteAll implements litestream.ReplicaClient. Litestream only calls it from tests and tooling, and the spike never needs it.

func (*Client) DeleteLTXFiles

func (c *Client) DeleteLTXFiles(ctx context.Context, a []*ltx.FileInfo) error

DeleteLTXFiles implements litestream.ReplicaClient. Retention and compaction cleanup delete files, so a stale leader must not reach this.

func (*Client) Fenced

func (c *Client) Fenced() error

Fenced returns a wrapped ErrFenced once the client is fenced, otherwise nil.

func (*Client) Head

func (c *Client) Head() ltx.TXID

Head returns the highest L0 TXID this client has confirmed in storage.

func (*Client) Init

func (c *Client) Init(context.Context) error

Init implements litestream.ReplicaClient.

func (*Client) LTXFiles

func (c *Client) LTXFiles(ctx context.Context, level int, seek ltx.TXID, _ bool) (ltx.FileIterator, error)

LTXFiles implements litestream.ReplicaClient.

func (*Client) OpenLTXFile

func (c *Client) OpenLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, offset, size int64) (io.ReadCloser, error)

OpenLTXFile implements litestream.ReplicaClient.

func (*Client) SetLogger

func (c *Client) SetLogger(logger *slog.Logger)

SetLogger implements litestream.ReplicaClient.

func (*Client) Type

func (c *Client) Type() string

Type implements litestream.ReplicaClient.

func (*Client) WriteLTXFile

func (c *Client) WriteLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, r io.Reader) (*ltx.FileInfo, error)

WriteLTXFile implements litestream.ReplicaClient.

type Leader

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

Leader is the single writer of one database. Its working copy lives in a directory that must start empty; object storage holds the only durable copy.

func TakeOffice

func TakeOffice(ctx context.Context, az *azblob.Client, container, dir string) (*Leader, int, error)

TakeOffice restores the latest history into the empty directory dir and commits an epoch bump with put-if-absent. Once that upload succeeds, any older leader's next upload collides and fences it. If another writer wins the slot first, the candidate discards dir and starts again. It returns the number of attempts it needed.

func (*Leader) Close

func (l *Leader) Close(ctx context.Context) error

Close releases the working copy. It does not remove the directory.

func (*Leader) Epoch

func (l *Leader) Epoch() int64

Epoch returns the epoch this leader committed when it took office.

func (*Leader) Exec

func (l *Leader) Exec(ctx context.Context, fn func(*sql.Tx) error) error

Exec runs fn in one write transaction and returns nil only after the resulting change file is confirmed in object storage. A nil return is the acknowledgement.

func (*Leader) Fenced

func (l *Leader) Fenced() error

Fenced returns a wrapped ErrFenced once this leader can no longer write.

func (*Leader) SQL

func (l *Leader) SQL() *sql.DB

SQL returns the leader's connection to its working copy, for reads.

type Lease

type Lease struct {
	Epoch int64  `json:"epoch"`
	Owner string `json:"owner"`
	// contains filtered or unexported fields
}

Lease is the advisory leadership record. It tells pods who should try to take office; it does not make writes safe. That comes from the conditional writes on the log.

shortcut: no expiry or renewal schedule; the tests drive takeover explicitly. A product needs a TTL judged against the storage clock.

func AcquireLease

func AcquireLease(ctx context.Context, az *azblob.Client, container, owner string) (*Lease, error)

AcquireLease takes the lease for owner with the next epoch, creating it with If-None-Match: * or replacing the current one with If-Match.

func (*Lease) Renew

func (l *Lease) Renew(ctx context.Context, az *azblob.Client, container string) error

Renew rewrites the lease only if nobody has replaced it since this holder last wrote it.

Jump to

Keyboard shortcuts

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