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
- Variables
- type Client
- func (c *Client) DeleteAll(context.Context) error
- func (c *Client) DeleteLTXFiles(ctx context.Context, a []*ltx.FileInfo) error
- func (c *Client) Fenced() error
- func (c *Client) Head() ltx.TXID
- func (c *Client) Init(context.Context) error
- func (c *Client) LTXFiles(ctx context.Context, level int, seek ltx.TXID, _ bool) (ltx.FileIterator, error)
- func (c *Client) OpenLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, offset, size int64) (io.ReadCloser, error)
- func (c *Client) SetLogger(logger *slog.Logger)
- func (c *Client) Type() string
- func (c *Client) WriteLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, r io.Reader) (*ltx.FileInfo, error)
- type Leader
- type Lease
Constants ¶
const DBPrefix = "db"
DBPrefix is the blob prefix the spike keeps the LTX history under.
const LeaseKey = "lease.json"
LeaseKey is the blob holding the leadership lease.
Variables ¶
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 (*Client) DeleteAll ¶
DeleteAll implements litestream.ReplicaClient. Litestream only calls it from tests and tooling, and the spike never needs it.
func (*Client) DeleteLTXFiles ¶
DeleteLTXFiles implements litestream.ReplicaClient. Retention and compaction cleanup delete files, so a stale leader must not reach this.
func (*Client) Fenced ¶
Fenced returns a wrapped ErrFenced once the client is fenced, otherwise nil.
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.
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) Exec ¶
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.
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 ¶
AcquireLease takes the lease for owner with the next epoch, creating it with If-None-Match: * or replacing the current one with If-Match.