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 ¶
- Variables
- type Journal
- func (j *Journal) Append(parts ...[]byte) error
- func (j *Journal) AppendReserved(reserved int64, parts ...[]byte) error
- func (j *Journal) Bytes() int64
- func (j *Journal) Close() error
- func (j *Journal) Empty() bool
- func (j *Journal) ID() [16]byte
- func (j *Journal) Release(payload int64)
- func (j *Journal) Reserve(payload int64) error
- func (j *Journal) Reset() error
- func (j *Journal) Scan(ctx context.Context, visit func([]byte) error) error
- func (j *Journal) Sync() error
- type Stats
- type Store
- func (s *Store) Close() error
- func (s *Store) OpenChunk(key string) (*os.File, bool, error)
- func (s *Store) OpenJournal(capacity int64) (*Journal, error)
- func (s *Store) Pin(key string) error
- func (s *Store) PutClean(ctx context.Context, key string, data []byte) (bool, error)
- func (s *Store) PutPin(ctx context.Context, key string, data []byte) error
- func (s *Store) Recover(pins map[string]int) error
- func (s *Store) Stats() Stats
- func (s *Store) UnderPressure() bool
- func (s *Store) Unpin(key string)
Constants ¶
This section is empty.
Variables ¶
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
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
AppendReserved consumes a prior reservation even if encoding reduced the payload. Actual bytes must not exceed the original reserved payload size.
func (*Journal) Reserve ¶ added in v1.0.2
Reserve includes frame overhead. A failed reservation has no side effects.
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 ¶
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) OpenChunk ¶
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
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
Pin protects an already published object while an independent metadata snapshot is prepared. The caller must Unpin after copying/uploading it.
func (*Store) PutClean ¶
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 ¶
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 ¶
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) UnderPressure ¶
UnderPressure reports blocked disk admission so the uploader can expedite metadata retirement instead of waiting for the periodic group commit.