memory

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package memory is the default in-process store: sharded, byte-weighted S3-FIFO (ADR-6). The design is in docs/05-storage-interface-spec.md §5.

This package imports only the standard library (NFR-6).

Index

Constants

View Source
const MaxEpochSlots = 1 << 26

MaxEpochSlots bounds Config.EpochSlots: 2^26 cells is 256 MiB per plane.

View Source
const MaxShards = 1 << 16

MaxShards bounds Config.Shards, so a mistyped count fails New instead of exhausting memory (NFR-2).

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	MaxBytes      int64         // 0: 256 MiB
	Shards        int           // 0: 16; a power of two, at most MaxShards
	MaxRetention  time.Duration // 0: 24h; caps every record's lifetime (E-11)
	MaxHardEpochs int           // 0: 10000 (E-6)
	EpochSlots    int           // 0: 1 << 19; a power of two, at most MaxEpochSlots (E-7)
	// OnEvict, when set, receives per-Set eviction counts by queue: "small",
	// "main" or "expired". It runs after the shard lock is released.
	OnEvict func(queue string, n int)
}

Config sizes a Store (05 §5.1).

type Store

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

Store is the in-process store. It implements store.Store and store.Sizer.

func New

func New(cfg Config) (*Store, error)

New returns an empty Store sized by cfg, or an error for a negative setting or a shard or slot count that is not a power of two within its bound.

func (*Store) Bytes

func (s *Store) Bytes() int64

Bytes returns the bytes currently accounted across all shards.

func (*Store) Close

func (s *Store) Close() error

Close marks the store closed. It is idempotent.

func (*Store) Delete

func (s *Store) Delete(_ context.Context, k store.Key) error

Delete removes the record at k, if any.

func (*Store) Get

func (s *Store) Get(_ context.Context, k store.Key) (*store.Entry, error)

Get returns the live record at k or store.ErrNotFound.

func (*Store) Info

func (s *Store) Info() store.Info

Info names the store; it is not remote.

func (*Store) MaxObjectBytes

func (s *Store) MaxObjectBytes() int64

MaxObjectBytes returns the largest record the store admits: the small queue's share of one shard, 10% (05 §5.1).

func (*Store) NewestEpoch

func (s *Store) NewestEpoch(_ context.Context, tags []store.Tag, since time.Time) (store.Epoch, bool, error)

NewestEpoch returns the most severe, then latest, epoch among tags at or after since (E-3). Soft and invalid times may be rounded up to the next whole second after the store was built (E-7).

func (*Store) Set

func (s *Store) Set(_ context.Context, k store.Key, e *store.Entry) error

Set stores e at k until e.Expires, clamped to MaxRetention after its request time (E-11). It declines, returning nil, a record past its Expires (a no-op, 05 §2.3) or larger than MaxObjectBytes (which also removes any record at k) (S-4).

func (*Store) SetEpoch

func (s *Store) SetEpoch(_ context.Context, t store.Tag, ep store.Epoch) error

SetEpoch records ep for t (E-2). A new hard tag beyond MaxHardEpochs returns an error wrapping store.ErrUnavailable (E-6).

Jump to

Keyboard shortcuts

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