persistence

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MagicBytes    = "NRDB" // QubicDB magic identifier
	FormatVersion = 1
)

Binary format constants

View Source
const (
	FlagCompressed uint16 = 1 << 0
	FlagEncrypted  uint16 = 1 << 1
)
View Source
const (
	FsyncPolicyAlways   = "always"
	FsyncPolicyInterval = "interval"
	FsyncPolicyOff      = "off"
)

Variables

This section is empty.

Functions

func EncodeSnapshot

func EncodeSnapshot(s Snapshot) ([]byte, error)

EncodeSnapshot serializes a snapshot

Types

type Codec

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

Codec handles encoding/decoding of matrices

func NewCodec

func NewCodec(compress bool) *Codec

NewCodec creates a new codec

func (*Codec) Decode

func (c *Codec) Decode(raw []byte) (*core.Matrix, error)

Decode deserializes binary format to a matrix

func (*Codec) Encode

func (c *Codec) Encode(matrix *core.Matrix) ([]byte, error)

Encode serializes a matrix to binary format

type DurabilityConfig

type DurabilityConfig struct {
	WALEnabled                 bool
	FsyncPolicy                string
	FsyncInterval              time.Duration
	ChecksumValidationInterval time.Duration
	StartupRepair              bool
}

DurabilityConfig defines persistence durability controls.

func DefaultDurabilityConfig

func DefaultDurabilityConfig() DurabilityConfig

DefaultDurabilityConfig returns the default durability profile.

type Header struct {
	Magic      [4]byte
	Version    uint16
	Flags      uint16
	IndexIDLen uint32
	DataLen    uint64
	Checksum   uint32
}

Header for binary format

type IntegrityReport

type IntegrityReport struct {
	CheckedFiles    int
	CorruptFiles    int
	RepairedEntries int
}

IntegrityReport summarizes checksum validation results across persisted data files.

type Snapshot

type Snapshot struct {
	IndexID      core.IndexID `msgpack:"index_id"`
	Version      uint64       `msgpack:"version"`
	NeuronCount  int          `msgpack:"neuron_count"`
	SynapseCount int          `msgpack:"synapse_count"`
	CurrentDim   int          `msgpack:"current_dim"`
	TotalEnergy  float64      `msgpack:"total_energy"`
	ModifiedAt   int64        `msgpack:"modified_at"`
}

EncodeSnapshot creates a lightweight snapshot for quick persistence

func CreateSnapshot

func CreateSnapshot(matrix *core.Matrix) Snapshot

CreateSnapshot creates a snapshot from a matrix

func DecodeSnapshot

func DecodeSnapshot(data []byte) (Snapshot, error)

DecodeSnapshot deserializes a snapshot

type Store

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

Store handles file-based persistence of matrices

func NewStore

func NewStore(basePath string, compress bool) (*Store, error)

NewStore creates a new persistence store

func NewStoreWithDurability

func NewStoreWithDurability(basePath string, compress bool, durability DurabilityConfig) (*Store, error)

NewStoreWithDurability creates a new persistence store with durability settings.

func (*Store) Delete

func (s *Store) Delete(indexID core.IndexID) error

Delete removes a user's matrix from disk

func (*Store) Exists

func (s *Store) Exists(indexID core.IndexID) bool

Exists checks if a user's matrix exists on disk

func (*Store) FlushAll

func (s *Store) FlushAll() error

FlushAll writes all pending matrices

func (*Store) GetSnapshot

func (s *Store) GetSnapshot(indexID core.IndexID) (*Snapshot, bool)

GetSnapshot returns the cached snapshot for a user

func (*Store) ListIndexes

func (s *Store) ListIndexes() []core.IndexID

ListIndexes returns all persisted user IDs

func (*Store) Load

func (s *Store) Load(indexID core.IndexID) (*core.Matrix, error)

Load retrieves a matrix from disk

func (*Store) Save

func (s *Store) Save(matrix *core.Matrix) error

Save persists a matrix to disk

func (*Store) SaveAsync

func (s *Store) SaveAsync(matrix *core.Matrix) error

SaveAsync queues a matrix for async persistence.

func (*Store) StartChecksumValidationWorker

func (s *Store) StartChecksumValidationWorker(interval time.Duration) chan struct{}

StartChecksumValidationWorker starts periodic checksum validation over persisted data files.

func (*Store) StartFlushWorker

func (s *Store) StartFlushWorker(interval time.Duration) chan struct{}

StartFlushWorker starts background flush worker

func (*Store) Stats

func (s *Store) Stats() map[string]any

Stats returns persistence statistics

func (*Store) ValidateDataFiles

func (s *Store) ValidateDataFiles(repair bool) (IntegrityReport, error)

ValidateDataFiles verifies checksums/decoding of persisted .nrdb files. When repair=true, corrupt files are removed and index entries are repaired.

Jump to

Keyboard shortcuts

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