stores

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpInsert      uint8 = 1
	OpDelete      uint8 = 2
	OpUpdate      uint8 = 3
	OpCreateIndex uint8 = 4
	OpDropIndex   uint8 = 5
	OpSetDefaults uint8 = 6
)

Variables

View Source
var ErrStoreClosed = errors.New("store closed")

Functions

func SyncDir

func SyncDir(dir string) error

SyncDir fsyncs a directory so that entries created or renamed in it are durable.

Types

type Store

type Store interface {
	Append(op uint8, id int64, data []byte, sync bool) error
	Flush() error
	Sync() error
	Close() error
	Replay(fn func(op uint8, id int64, data []byte) error) error
}

type StoreAsync

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

StoreAsync is a wrapper that implements a sharded buffered queue and Group Commit pattern. Producers append to the shard of the record id, so operations on the same id keep their order in the WAL. The worker sweeps all shards, drains them, and writes to disk in batches.

The first write or sync error is sticky: every later operation fails with it, because after a failed fsync the state of the file is unknown.

func NewStoreAsync

func NewStoreAsync(store Store) *StoreAsync

func (*StoreAsync) Append

func (s *StoreAsync) Append(op uint8, id int64, data []byte, fsync bool) error

Append pushes the operation to the shard of id. If fsync is true, it blocks until physically persisted.

func (*StoreAsync) Close

func (s *StoreAsync) Close() error

Close triggers a shutdown of the worker and waits for it to drain before closing the underlying store.

func (*StoreAsync) Flush

func (s *StoreAsync) Flush() error

func (*StoreAsync) Replay

func (s *StoreAsync) Replay(fn func(op uint8, id int64, data []byte) error) error

func (*StoreAsync) Sync

func (s *StoreAsync) Sync() error

type StoreCrazy

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

StoreCrazy is a high-speed variant of StoreDisk that omits CRC checksums. It trades corruption guarantees for pure raw throughput.

func NewStoreCrazy

func NewStoreCrazy(path string) (*StoreCrazy, error)

func (*StoreCrazy) Append

func (s *StoreCrazy) Append(op uint8, id int64, data []byte, sync bool) error

Append writes the operation to the WAL. Header (13 bytes) = OpCode(1) + ID(8) + Length(4) (NO CRC)

func (*StoreCrazy) Close

func (s *StoreCrazy) Close() error

func (*StoreCrazy) Flush

func (s *StoreCrazy) Flush() error

func (*StoreCrazy) Replay

func (s *StoreCrazy) Replay(fn func(op uint8, id int64, data []byte) error) error

func (*StoreCrazy) Sync

func (s *StoreCrazy) Sync() error

type StoreDisk

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

func NewStoreDisk

func NewStoreDisk(path string) (*StoreDisk, error)

func (*StoreDisk) Append

func (s *StoreDisk) Append(op uint8, id int64, data []byte, sync bool) error

Append escribe la operación en el WAL. Header (17 bytes) = OpCode(1) + ID(8) + Length(4) + CRC32(4)

func (*StoreDisk) Close

func (s *StoreDisk) Close() error

Close cierra el Journal de forma segura

func (*StoreDisk) Flush

func (s *StoreDisk) Flush() error

Flush vacía el buffer de Go hacia el Sistema Operativo

func (*StoreDisk) Replay

func (s *StoreDisk) Replay(fn func(op uint8, id int64, data []byte) error) error

Replay lee el WAL de principio a fin y ejecuta la función fn por cada registro. Si encuentra un registro corrupto, se detiene y avisa.

func (*StoreDisk) Sync

func (s *StoreDisk) Sync() error

Sync asegura que los datos pasen del Sistema Operativo al disco físico (fsync)

type StoreFlusher

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

StoreFlusher is a wrapper that periodically calls Flush() and Sync() on the underlying store in a background goroutine.

func NewStoreFlusher

func NewStoreFlusher(store Store, interval time.Duration) *StoreFlusher

func (*StoreFlusher) Append

func (s *StoreFlusher) Append(op uint8, id int64, data []byte, sync bool) error

func (*StoreFlusher) Close

func (s *StoreFlusher) Close() error

func (*StoreFlusher) Flush

func (s *StoreFlusher) Flush() error

func (*StoreFlusher) Replay

func (s *StoreFlusher) Replay(fn func(op uint8, id int64, data []byte) error) error

func (*StoreFlusher) Sync

func (s *StoreFlusher) Sync() error

type StoreJson

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

func NewStoreJson

func NewStoreJson(path string) (*StoreJson, error)

func (*StoreJson) Append

func (s *StoreJson) Append(op uint8, id int64, data []byte, sync bool) error

func (*StoreJson) Close

func (s *StoreJson) Close() error

func (*StoreJson) Flush

func (s *StoreJson) Flush() error

func (*StoreJson) Replay

func (s *StoreJson) Replay(fn func(op uint8, id int64, data []byte) error) error

func (*StoreJson) Sync

func (s *StoreJson) Sync() error

type StoreSnappy

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

StoreSnappy is a wrapper that compresses payloads using the fast Snappy algorithm. It encodes payload data on Append and decodes it on Replay, leaving headers intact.

func NewStoreSnappy

func NewStoreSnappy(store Store) *StoreSnappy

func (*StoreSnappy) Append

func (s *StoreSnappy) Append(op uint8, id int64, data []byte, wait bool) error

Append compresses the supplied data and passes it to the underlying store.

func (*StoreSnappy) Close

func (s *StoreSnappy) Close() error

func (*StoreSnappy) Flush

func (s *StoreSnappy) Flush() error

func (*StoreSnappy) Replay

func (s *StoreSnappy) Replay(fn func(op uint8, id int64, data []byte) error) error

Replay reads the underlying store's raw data, decompressing the payloads before yielding.

func (*StoreSnappy) Sync

func (s *StoreSnappy) Sync() error

Jump to

Keyboard shortcuts

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