storage

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRefreshUpstreamBadStatusCode = errors.New("invalid upstream status code")
)

Functions

func GetSingleMock added in v1.1.1

func GetSingleMock(i int, path []byte, cfg config.Config) *model.Entry

func GetSingleMockWith added in v1.4.3

func GetSingleMockWith(i int, path []byte, cfg config.Config, brotli bool) *model.Entry

GetSingleMockWith builds a single mock Entry for the given index/path/config. Brotli compression is controlled by the brotli flag.

func LoadMocks added in v0.9.8

func LoadMocks(ctx context.Context, cfg config.Config, storage Storage, num int)

func LoadMocksWith added in v1.4.3

func LoadMocksWith(ctx context.Context, cfg config.Config, storage Storage, num int, brotli bool)

LoadMocksWith generates and stores num mock entries asynchronously.

func StreamEntryPointersConsecutive added in v1.2.0

func StreamEntryPointersConsecutive(ctx context.Context, cfg config.Config, path []byte, num int) <-chan *model.Entry

func StreamEntryPointersConsecutiveWith added in v1.4.3

func StreamEntryPointersConsecutiveWith(ctx context.Context, cfg config.Config, path []byte, num int, brotli bool) <-chan *model.Entry

StreamEntryPointersConsecutiveWith streams num entries (ordered) with given brotli flag.

Types

type DB added in v1.3.0

type DB struct {
	*InMemoryStorage
	// contains filtered or unexported fields
}

DB wraps the LRU storage and supervises worker groups through a Governor.

func New added in v1.4.4

func New(ctx context.Context, cfg config.Config, up upstream.Upstream) *DB

New constructs the storage, wires workers and starts the governor. All transitions are done through the governor (no direct goroutine starts here).

func (*DB) Close added in v1.3.0

func (db *DB) Close() error

Close performs a graceful shutdown: dump (if enabled), stop LRU, then stop the governor.

func (*DB) Reload added in v1.4.4

func (db *DB) Reload(ctx context.Context, cfg config.Config) error

Reload applies a new config: toggles enable flags, intervals via Reload, and scales instances. Safe to call at runtime; Governor will converge services without panics.

type Dump

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

func (*Dump) Dump

func (d *Dump) Dump(ctx context.Context) error

func (*Dump) Load

func (d *Dump) Load(ctx context.Context) error

func (*Dump) LoadVersion added in v1.0.3

func (d *Dump) LoadVersion(ctx context.Context, v string) error

type Dumper

type Dumper interface {
	Dump(ctx context.Context) error
	Load(ctx context.Context) error
	LoadVersion(ctx context.Context, v string) error
}

type InMemoryStorage added in v1.4.4

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

InMemoryStorage — реализация поверх шардированной карты. Эвикт — random-sampling (Redis-style), без per-shard LRU.

func NewInMemory added in v1.4.4

func NewInMemory(
	ctx context.Context,
	cfg config.Config,
	meter metrics.Meter,
	upstream upstream.Upstream,
	shardedMap *sharded.Map[*model.Entry],
) *InMemoryStorage

func (*InMemoryStorage) Clear added in v1.4.4

func (s *InMemoryStorage) Clear()

func (*InMemoryStorage) Close added in v1.4.4

func (s *InMemoryStorage) Close() error

func (*InMemoryStorage) EvictN added in v1.4.4

func (s *InMemoryStorage) EvictN(n int) (freedBytes, items int64)

func (*InMemoryStorage) Get added in v1.4.4

func (s *InMemoryStorage) Get(req *model.Entry) (*model.Entry, bool)

Get — быстрый hot-path: нашли → touch (обновили TouchedAt).

func (*InMemoryStorage) Len added in v1.4.4

func (s *InMemoryStorage) Len() int64

func (*InMemoryStorage) Mem added in v1.4.4

func (s *InMemoryStorage) Mem() int64

func (*InMemoryStorage) Rand added in v1.4.4

func (s *InMemoryStorage) Rand() (*model.Entry, bool)

func (*InMemoryStorage) Refresh added in v1.4.4

func (s *InMemoryStorage) Refresh(entry *model.Entry) error

func (*InMemoryStorage) Remove added in v1.4.4

func (s *InMemoryStorage) Remove(entry *model.Entry) (freedBytes int64, hit bool)

func (*InMemoryStorage) ScanOutdated added in v1.4.4

func (s *InMemoryStorage) ScanOutdated() ([64]*model.Entry, bool)

func (*InMemoryStorage) Set added in v1.4.4

func (s *InMemoryStorage) Set(new *model.Entry) (persisted bool)

Set — вставка/обновление. Алгоритм:

  1. Если ключ уже есть: - payload совпал → touch и выход (persisted=true). - payload изменился → SwapPayloads + touch (persisted=true).
  2. Если достигнут лимит — эвикт через random-sampling под admission-фильтром: - берём дешёвого кандидата через Rand() (O(1)) для решения Allow(new, victim). - если admission запрещает — отказ (persisted=false). - иначе один раз вызываем EvictOne(). Если не удалось — отказ (persisted=false).
  3. Вставляем Set(key,new) (дельты считает шард), touch(new).

func (*InMemoryStorage) ShouldEvict added in v1.4.4

func (s *InMemoryStorage) ShouldEvict() (diffBytes int64, should bool)

func (*InMemoryStorage) Stat added in v1.4.4

func (s *InMemoryStorage) Stat() (bytes int64, length int64)

func (*InMemoryStorage) WalkShards added in v1.4.4

func (s *InMemoryStorage) WalkShards(ctx context.Context, fn func(key uint64, shard *sharded.Shard[*model.Entry]))

type Storage

type Storage interface {
	Get(*model.Entry) (entry *model.Entry, hit bool)
	Set(entry *model.Entry) (persisted bool)
	WalkShards(ctx context.Context, fn func(key uint64, shard *sharded.Shard[*model.Entry]))
	Remove(*model.Entry) (freedBytes int64, hit bool)
	Stat() (bytes int64, length int64)
	EvictN(n int) (freedBytes, items int64)
	ScanOutdated() ([64]*model.Entry, bool)
	ShouldEvict() (diffBytes int64, should bool)
	Clear()
	Close() error
}

Storage is a generic interface for cache storages.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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