writer

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 17 Imported by: ? 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 writer provides a durable raw-chunk cache. Namespace references are the recovery log: referenced raw chunks are pinned until their backend replacement is committed and the metadata log has been synced.

Index

Constants

This section is empty.

Variables

View Source
var ErrJournalFull = errors.New("history journal checkpoint required")

Functions

This section is empty.

Types

type Journal added in v1.0.2

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

Journal is an append-only, bounded local write-ahead file owned by a Store. Append copies bytes into the OS; Sync establishes power-loss durability. Callers reserve capacity before changing memory, then append or release it. A successful Reset atomically installs a new epoch, after its consumer has durably committed both data and its epoch marker elsewhere.

func (*Journal) Append added in v1.0.2

func (j *Journal) Append(parts ...[]byte) error

Append consumes one reservation of exactly the combined payload size. Slices need only stay valid until Append returns, avoiding a Go heap copy of the request's data. A write failure poisons this journal until reopen.

func (*Journal) AppendReserved added in v1.0.2

func (j *Journal) AppendReserved(reserved int64, parts ...[]byte) error

AppendReserved consumes a prior reservation even if encoding reduced the payload. Actual bytes must not exceed the original reserved payload size.

func (*Journal) Bytes added in v1.0.2

func (j *Journal) Bytes() int64

func (*Journal) Close added in v1.0.2

func (j *Journal) Close() error

func (*Journal) Empty added in v1.0.2

func (j *Journal) Empty() bool

func (*Journal) ID added in v1.0.2

func (j *Journal) ID() [16]byte

func (*Journal) Release added in v1.0.2

func (j *Journal) Release(payload int64)

func (*Journal) Reserve added in v1.0.2

func (j *Journal) Reserve(payload int64) error

Reserve includes frame overhead. A failed reservation has no side effects.

func (*Journal) Reset added in v1.0.2

func (j *Journal) Reset() error

func (*Journal) Scan added in v1.0.2

func (j *Journal) Scan(ctx context.Context, visit func([]byte) error) error

Scan holds the journal lock; visit must not reenter Journal or retain data.

func (*Journal) Sync added in v1.0.2

func (j *Journal) Sync() error

type Stats

type Stats struct {
	CapacityBytes      int64 `json:"capacity_bytes"`
	UsedBytes          int64 `json:"used_bytes"`
	DirtyBytes         int64 `json:"dirty_bytes"`
	DirtyChunks        int64 `json:"dirty_chunks"`
	CleanBytes         int64 `json:"clean_bytes"`
	ReservedBytes      int64 `json:"reserved_bytes"`
	CleanPutBytes      int64 `json:"clean_put_bytes"`
	PutBytes           int64 `json:"put_bytes"`
	PutNanos           int64 `json:"put_nanos"`
	WaitNanos          int64 `json:"wait_nanos"`
	Evictions          int64 `json:"evictions"`
	ReadHits           int64 `json:"read_hits"`
	ReadMisses         int64 `json:"read_misses"`
	Waiters            int64 `json:"waiters"`
	DirectorySyncs     int64 `json:"directory_syncs"`
	DirectorySyncNanos int64 `json:"directory_sync_nanos"`
	DirectoryCoalesced int64 `json:"directory_coalesced"`
}

type Store

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

func Open

func Open(root string, capacity int64, owner string) (_ *Store, resultErr error)

Open takes an exclusive process lock. owner identifies the metadata store; using another namespace's cache is rejected rather than evicting its data. Call Recover before serving requests or adding chunks.

func (*Store) Close

func (s *Store) Close() error

func (*Store) OpenChunk

func (s *Store) OpenChunk(key string) (*os.File, bool, error)

OpenChunk opens under the eviction lock. An unlinked clean object remains readable through the returned fd until the caller closes it.

func (*Store) OpenJournal added in v1.0.2

func (s *Store) OpenJournal(capacity int64) (*Journal, error)

OpenJournal shares the raw store's exclusive owner lock. The caller must close the journal before closing Store. A partial final frame is discarded; corruption in a complete frame is an error, never silently skipped.

func (*Store) Pin added in v1.0.1

func (s *Store) Pin(key string) error

Pin protects an already published object while an independent metadata snapshot is prepared. The caller must Unpin after copying/uploading it.

func (*Store) PutClean

func (s *Store) PutClean(ctx context.Context, key string, data []byte) (bool, error)

PutClean opportunistically publishes verified decoded data without a pin. It never waits for capacity, another publisher, or dirty writers, and never evicts existing cache data. Five percent (at least one incoming chunk) stays free for dirty admission. False means an existing object or pressure skipped the fill. A successful fill uses the same crash-safe publication as PutPin.

func (*Store) PutPin

func (s *Store) PutPin(ctx context.Context, key string, data []byte) error

PutPin writes one immutable chunk and makes it durable BEFORE it can be referenced by the metadata log. Full dirty caches apply cancellable pressure to writers; background workers can continue reading and unpinning chunks.

func (*Store) Recover

func (s *Store) Recover(pins map[string]int) error

Recover pins all raw references before any clean-cache eviction. Missing dirty data prevents mounting; it must never turn into a sparse zero chunk.

func (*Store) Stats

func (s *Store) Stats() Stats

func (*Store) UnderPressure

func (s *Store) UnderPressure() bool

UnderPressure reports blocked disk admission so the uploader can expedite metadata retirement instead of waiting for the periodic group commit.

func (*Store) Unpin

func (s *Store) Unpin(key string)

Unpin must follow durable metadata retirement. Clean raw data is retained for range reads and is evicted only when space is needed by new writes.

Jump to

Keyboard shortcuts

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