store

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("storage closed")

Functions

func Deserialize

func Deserialize(data []byte, v any) error

Deserialize decodes msgpack bytes into the provided value.

func Serialize

func Serialize(v any) ([]byte, error)

Serialize encodes a value to msgpack bytes.

Types

type ProxyIndex

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

ProxyIndex is a bidirectional flowID <-> offset map for proxy history entries. Thread-safe.

func NewProxyIndex

func NewProxyIndex(storage Storage) *ProxyIndex

NewProxyIndex creates a new ProxyIndex backed by the given storage.

func (*ProxyIndex) Clear

func (p *ProxyIndex) Clear()

Clear removes all entries.

func (*ProxyIndex) Close

func (p *ProxyIndex) Close()

Close releases storage resources.

func (*ProxyIndex) Count

func (p *ProxyIndex) Count() int

Count returns the number of registered flow IDs.

func (*ProxyIndex) Offset

func (p *ProxyIndex) Offset(flowID string) (uint32, bool)

Offset retrieves the proxy history offset for a flow_id.

func (*ProxyIndex) Register

func (p *ProxyIndex) Register(offset uint32) string

Register creates a new flow_id for the given offset. If an entry with the same offset already exists, it returns the existing flow_id.

type ReplayHistoryEntry

type ReplayHistoryEntry struct {
	FlowID          string    // Same as replay_id from replay_send
	CreatedAt       time.Time // When replay was executed
	ReferenceOffset uint32    // Max proxy offset at time of replay (for ordering)

	// Request data (for display and export)
	RawRequest []byte
	Method     string
	Host       string
	Path       string
	Protocol   string // "http/1.1" or "h2"

	// Response data
	RespHeaders []byte
	RespBody    []byte
	RespStatus  int
	Duration    time.Duration

	// Lineage
	SourceFlowID string // Original flow_id that was replayed (empty for request_send)
}

ReplayHistoryEntry stores a replay request/response with positioning info.

type ReplayHistoryMeta

type ReplayHistoryMeta struct {
	FlowID          string        `msgpack:"fid"`
	Method          string        `msgpack:"m"`
	Host            string        `msgpack:"h"`
	Path            string        `msgpack:"p"`
	Protocol        string        `msgpack:"pr"`
	SourceFlowID    string        `msgpack:"sf"`
	CreatedAt       time.Time     `msgpack:"ca"`
	ReferenceOffset uint32        `msgpack:"ro"`
	RespStatus      int           `msgpack:"rs"`
	RespLen         int           `msgpack:"rl"`
	Duration        time.Duration `msgpack:"d"`
}

ReplayHistoryMeta holds lightweight metadata for a replay entry. Used by summary/list paths to avoid deserializing full request/response bodies.

type ReplayHistoryPayload

type ReplayHistoryPayload struct {
	RawRequest  []byte `msgpack:"rq"`
	RespHeaders []byte `msgpack:"rh"`
	RespBody    []byte `msgpack:"rb"`
}

ReplayHistoryPayload holds the heavy request/response data for a replay entry.

type ReplayHistoryStore

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

ReplayHistoryStore manages replay entries with thread-safe access.

func NewReplayHistoryStore

func NewReplayHistoryStore(storage Storage) *ReplayHistoryStore

NewReplayHistoryStore creates a new ReplayHistoryStore backed by the given storage.

func (*ReplayHistoryStore) Clear

func (s *ReplayHistoryStore) Clear()

Clear removes all entries.

func (*ReplayHistoryStore) Close

func (s *ReplayHistoryStore) Close()

Close releases storage resources.

func (*ReplayHistoryStore) Count

func (s *ReplayHistoryStore) Count() int

Count returns the number of stored replay entries.

func (*ReplayHistoryStore) Get

func (s *ReplayHistoryStore) Get(flowID string) (*ReplayHistoryEntry, bool)

Get retrieves a replay entry by flow_id.

func (*ReplayHistoryStore) List

List returns all replay entries ordered by creation time.

func (*ReplayHistoryStore) ListMeta

func (s *ReplayHistoryStore) ListMeta() []ReplayHistoryMeta

ListMeta returns lightweight metadata for all replay entries, ordered by creation time.

func (*ReplayHistoryStore) Store

func (s *ReplayHistoryStore) Store(entry *ReplayHistoryEntry)

Store adds a replay entry. Called after successful replay_send/request_send.

func (*ReplayHistoryStore) UpdateReferenceOffset

func (s *ReplayHistoryStore) UpdateReferenceOffset(currentMaxOffset uint32) (uint32, bool)

UpdateReferenceOffset updates the max proxy offset and detects history clear. If history was cleared (offset decreased), marks all existing entries with ref=0. Returns the reference offset to use for new replay entries, and whether history was cleared.

type SpillStoreConfig

type SpillStoreConfig struct {
	Dir                 string  // optional, auto-created if empty
	FilePrefix          string  // optional prefix for data file name (e.g. "hist" → "hist.spill.bin")
	MaxHotBytes         int64   // max value bytes in hot cache
	EvictTargetRatio    float64 // evict to this ratio, higher values evict less
	CompactionThreshold int64   // rewrite file when dead bytes exceed this
	ZSTDLevel           int     // compression level (1-21)
}

SpillStoreConfig configures spillStore behavior.

func DefaultSpillStoreConfig

func DefaultSpillStoreConfig() SpillStoreConfig

DefaultSpillStoreConfig returns config with sensible defaults.

type Storage

type Storage interface {
	Set(key string, blob []byte) error
	Get(key string) ([]byte, bool, error)
	KeySet() []string
	Size() int
	Delete(key string) error
	DeleteAll() error
	Close() error
}

Storage defines the interface for key-value blob storage.

func NewMemStorage

func NewMemStorage() Storage

NewMemStorage returns an in-memory Storage implementation.

func NewSpillStore

func NewSpillStore(cfg SpillStoreConfig) (Storage, error)

NewSpillStore creates a new spillStore with the given config.

Jump to

Keyboard shortcuts

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