physalis

package module
v0.0.0-...-27c388b Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 23 Imported by: 0

README

Physalis

An experimental state store built on an append-only event log.

Status: Early-stage research. Expect rapid iteration and breaking changes.

Warning: Not ready for production—do not use in your products yet.

Documentation

Index

Constants

View Source
const GlobalGroup = "."
View Source
const SkipEvent = ""

Variables

View Source
var ErrReducerAlreadyExists = errors.New("reducer already exists")

Functions

func BlobView

func BlobView(tx *bolt.Tx, key string) []byte

Slice returned by BlobView is valid only during the transaction lifetime.

func CBORMarshal

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

func CBORUnmarshal

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

func RestoreDatabase

func RestoreDatabase(
	ctx context.Context,
	dbFile string,
	r io.Reader,
) error

func VersionFromFS

func VersionFromFS(fsys fs.FS) string

VersionFromFS returns a deterministic "version" string for the contents of the provided filesystem (fs.FS). The version is derived from every file's bytes together with its relative path, so any change to file contents or to the set of files (add/remove/rename) results in a different version.

Intended for use with embed.FS, but works with any fs.FS.

On any traversal or read error, the function panics.

Types

type Event

type Event[EV any] struct {
	Payload   EV    `cbor:"1,keyasint"`
	Timestamp int64 `cbor:"2,keyasint"`
}

func (*Event[EV]) ReadTimestamp

func (ev *Event[EV]) ReadTimestamp() time.Time

type KType

type KType interface {
	~int32 | ~int64 | ~uint32 | ~uint64 | ~string
}

type Physalis

type Physalis[EV any] struct {
	// contains filtered or unexported fields
}

func Open

func Open[EV any](dbFile string, registry *ReducerRegistry[EV]) (*Physalis[EV], error)

func (*Physalis[EV]) BackupTo

func (phs *Physalis[EV]) BackupTo(
	ctx context.Context,
	zstdCompressionLevel int,
	w io.Writer,
) error

func (*Physalis[EV]) Close

func (phs *Physalis[EV]) Close() error

func (*Physalis[EV]) View

func (phs *Physalis[EV]) View(vf func(tx *bolt.Tx) error) error

func (*Physalis[EV]) Write

func (phs *Physalis[EV]) Write(transaction Transaction[EV]) error

type Reducer

type Reducer[ST any, EV any] interface {
	Version() string
	// Возвращает
	// 1. ключ группы событий, если он пустой то событие пропускается (SkipEvent)
	// 2. опционально может вернуть другое событие, которое будет использовано вместо текущего. Менять исходное нельзя! Оно шариться между всеми редюссерами!
	Prepare(*Event[EV]) (string, *Event[EV])
	Apply(runtime *ReducerRuntime, state *ST, groupKey string,
		evs iter.Seq2[uint64, *Event[EV]]) *ST
}

type ReducerReader

type ReducerReader[ST any] struct {
	// contains filtered or unexported fields
}

func AddReducer

func AddReducer[ST any, EV any](
	reg *ReducerRegistry[EV],
	name string,
	reducer Reducer[ST, EV],
) (*ReducerReader[ST], error)

func (*ReducerReader[ST]) AllStates

func (rr *ReducerReader[ST]) AllStates(tx *bolt.Tx) SortedKVView[string, ST]

func (*ReducerReader[ST]) State

func (rr *ReducerReader[ST]) State(
	tx *bolt.Tx,
	groupKey string,
) (*ST, error)

type ReducerRegistry

type ReducerRegistry[EV any] struct {
	// contains filtered or unexported fields
}

func NewReducerRegistry

func NewReducerRegistry[EV any]() *ReducerRegistry[EV]

type ReducerRuntime

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

type SortedKV

type SortedKV[K KType, V any] interface {
	Get(key K) *V
	Delete(key K)
	Put(key K, data *V)
	AscendRange(greaterOrEqual, lessThan K) iter.Seq2[K, *V]
	Ascend() iter.Seq2[K, *V]
	Descend() iter.Seq2[K, *V]
	AscendGreaterOrEqual(greaterOrEqual K) iter.Seq2[K, *V]
	AscendLessThan(lessThan K) iter.Seq2[K, *V]
	DescendRange(lessOrEqual, greaterThan K) iter.Seq2[K, *V]
	DescendGreaterThan(greaterThan K) iter.Seq2[K, *V]
	DescendLessOrEqual(lessOrEqual K) iter.Seq2[K, *V]
}

func OpenKV

func OpenKV[K KType, V any](rr *ReducerRuntime, kvName string) SortedKV[K, V]

type SortedKVView

type SortedKVView[K KType, V any] interface {
	Get(key K) *V
	AscendRange(greaterOrEqual, lessThan K) iter.Seq2[K, *V]
	Ascend() iter.Seq2[K, *V]
	Descend() iter.Seq2[K, *V]
	AscendGreaterOrEqual(greaterOrEqual K) iter.Seq2[K, *V]
	AscendLessThan(lessThan K) iter.Seq2[K, *V]
	DescendRange(lessOrEqual, greaterThan K) iter.Seq2[K, *V]
	DescendGreaterThan(greaterThan K) iter.Seq2[K, *V]
	DescendLessOrEqual(lessOrEqual K) iter.Seq2[K, *V]
}

func OpenKVView

func OpenKVView[K KType, V any, ST any](
	reader *ReducerReader[ST],
	tx *bolt.Tx,
	groupKey string,
	kvName string,
) SortedKVView[K, V]

type Transaction

type Transaction[EV any] struct {
	Events      []*Event[EV]
	BlobStorage map[string][]byte // nil - для удаления
}

Directories

Path Synopsis
log

Jump to

Keyboard shortcuts

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