storage

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCompression is the default compression level
	DefaultCompression = 3
	// DefaultCacheSize is the default number of snapshots to cache
	DefaultCacheSize = 10
	// SnapshotFileExt is the file extension for snapshots
	SnapshotFileExt = ".snap"
	// DiffFileExt is the file extension for diff files
	DiffFileExt = ".diff"
)

Variables

View Source
var (
	// ErrSnapshotNotFound is returned when a snapshot is not found
	ErrSnapshotNotFound = errors.New("snapshot not found")
	// ErrInvalidSnapshot is returned when a snapshot is invalid
	ErrInvalidSnapshot = errors.New("invalid snapshot")
)

Functions

func ApplyExpiryPolicy

func ApplyExpiryPolicy(snapshots []SnapshotInfo, policy ExpiryPolicy) []string

ApplyExpiryPolicy applies the expiry policy to a list of snapshots and returns the names of snapshots that should be deleted

func ParseSnapshotName

func ParseSnapshotName(name string) (time.Time, error)

ParseSnapshotName extracts the timestamp from a snapshot name Snapshot names are expected to be in the format: name-YYYYMMDD-HHMMSS.snap

func TestRealWorldBenchmark added in v0.2.0

func TestRealWorldBenchmark(t *testing.T)

TestRealWorldBenchmark performs a real-world benchmark on a user's home directory This test is skipped in CI environments

Types

type BloomFilter

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

BloomFilter implements a simple bloom filter for quick file existence checks

func NewBloomFilter

func NewBloomFilter(size uint, numHash uint) *BloomFilter

NewBloomFilter creates a new bloom filter

func (*BloomFilter) Add

func (b *BloomFilter) Add(data []byte)

Add adds an item to the bloom filter

func (*BloomFilter) Contains

func (b *BloomFilter) Contains(data []byte) bool

Contains checks if an item might be in the bloom filter

type DataStore added in v0.2.0

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

DataStore handles the storage of actual snapshot and diff data using FlatBuffers

func NewDataStore added in v0.2.0

func NewDataStore(baseDir string) (*DataStore, error)

NewDataStore creates a new data store

func (*DataStore) AppendSnapshotData added in v0.2.0

func (d *DataStore) AppendSnapshotData(id string, data []byte) (string, error)

AppendSnapshotData appends data to an existing snapshot data file

func (*DataStore) Close added in v0.2.0

func (d *DataStore) Close() error

Close closes the data store

func (*DataStore) DeleteDiffData added in v0.2.0

func (d *DataStore) DeleteDiffData(baseID, targetID string) error

DeleteDiffData deletes diff data from the data store

func (*DataStore) DeleteSnapshotData added in v0.2.0

func (d *DataStore) DeleteSnapshotData(id string) error

DeleteSnapshotData deletes snapshot data from the data store

func (*DataStore) ReadDiffData added in v0.2.0

func (d *DataStore) ReadDiffData(ref string) ([]byte, error)

ReadDiffData reads diff data from the data store

func (*DataStore) ReadSnapshotData added in v0.2.0

func (d *DataStore) ReadSnapshotData(ref string) ([]byte, error)

ReadSnapshotData reads snapshot data from the data store

func (*DataStore) StreamDiffData added in v0.2.0

func (d *DataStore) StreamDiffData(ref string, writer io.Writer) error

StreamDiffData streams diff data from the data store

func (*DataStore) StreamSnapshotData added in v0.2.0

func (d *DataStore) StreamSnapshotData(ref string, writer io.Writer) error

StreamSnapshotData streams snapshot data from the data store

func (*DataStore) WriteDiffData added in v0.2.0

func (d *DataStore) WriteDiffData(baseID, targetID string, data []byte) (string, error)

WriteDiffData writes diff data to the data store

func (*DataStore) WriteSnapshotData added in v0.2.0

func (d *DataStore) WriteSnapshotData(id string, data []byte) (string, error)

WriteSnapshotData writes snapshot data to the data store

type ExpiryPolicy

type ExpiryPolicy struct {
	// MaxSnapshots is the maximum number of snapshots to keep (0 = unlimited)
	MaxSnapshots int
	// MaxAge is the maximum age of snapshots to keep (0 = unlimited)
	MaxAge time.Duration
	// KeepHourly defines how many hourly snapshots to keep (0 = none)
	KeepHourly int
	// KeepDaily defines how many daily snapshots to keep (0 = none)
	KeepDaily int
	// KeepWeekly defines how many weekly snapshots to keep (0 = none)
	KeepWeekly int
	// KeepMonthly defines how many monthly snapshots to keep (0 = none)
	KeepMonthly int
	// KeepYearly defines how many yearly snapshots to keep (0 = none)
	KeepYearly int
}

ExpiryPolicy defines how snapshots should be expired and rotated

func DefaultExpiryPolicy

func DefaultExpiryPolicy() ExpiryPolicy

DefaultExpiryPolicy returns a default expiry policy

type SnapshotInfo

type SnapshotInfo struct {
	Name      string
	Timestamp time.Time
	Size      int64
}

SnapshotInfo contains metadata about a snapshot

type SnapshotStore

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

SnapshotStore manages snapshot storage operations

func NewSnapshotStore

func NewSnapshotStore(baseDir string) (*SnapshotStore, error)

NewSnapshotStore creates a new snapshot store

func (*SnapshotStore) ApplyDiff

func (s *SnapshotStore) ApplyDiff(baseName, diffName string) ([]byte, error)

ApplyDiff applies a diff to a snapshot

func (*SnapshotStore) ApplyExpiryPolicy

func (s *SnapshotStore) ApplyExpiryPolicy() (int, error)

ApplyExpiryPolicy applies the current expiry policy to all snapshots

func (*SnapshotStore) Close

func (s *SnapshotStore) Close() error

Close closes the snapshot store

func (*SnapshotStore) ComputeDiff

func (s *SnapshotStore) ComputeDiff(oldName, newName string) ([]byte, error)

ComputeDiff computes the difference between two snapshots

func (*SnapshotStore) CreateBloomFilterFromSnapshot

func (s *SnapshotStore) CreateBloomFilterFromSnapshot(name string) (*BloomFilter, error)

CreateBloomFilterFromSnapshot creates a bloom filter from a snapshot

func (*SnapshotStore) CreateSnapshot

func (s *SnapshotStore) CreateSnapshot(name string, data []byte) error

CreateSnapshot creates a new snapshot with the given data and applies the expiry policy

func (*SnapshotStore) DeleteSnapshot

func (s *SnapshotStore) DeleteSnapshot(name string) error

DeleteSnapshot deletes a snapshot

func (*SnapshotStore) GetExpiryPolicy

func (s *SnapshotStore) GetExpiryPolicy() ExpiryPolicy

GetExpiryPolicy returns the current expiry policy

func (*SnapshotStore) ListSnapshots

func (s *SnapshotStore) ListSnapshots() ([]string, error)

ListSnapshots returns a list of available snapshots

func (*SnapshotStore) QuerySnapshot

func (s *SnapshotStore) QuerySnapshot(name string, filter func(*flashfs.FileEntry) bool) ([]*flashfs.FileEntry, error)

QuerySnapshot queries a snapshot for entries matching criteria

func (*SnapshotStore) ReadSnapshot

func (s *SnapshotStore) ReadSnapshot(name string) ([]byte, error)

ReadSnapshot reads a snapshot from disk or cache

func (*SnapshotStore) SetCacheSize

func (s *SnapshotStore) SetCacheSize(size int)

SetCacheSize sets the maximum number of snapshots to cache

func (*SnapshotStore) SetExpiryPolicy

func (s *SnapshotStore) SetExpiryPolicy(policy ExpiryPolicy)

SetExpiryPolicy sets the expiry policy for the snapshot store

func (*SnapshotStore) StoreDiff

func (s *SnapshotStore) StoreDiff(oldName, newName string) error

StoreDiff stores a diff between two snapshots

func (*SnapshotStore) WriteSnapshot

func (s *SnapshotStore) WriteSnapshot(name string, data []byte) error

WriteSnapshot writes a snapshot to disk with compression

type Store added in v0.2.0

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

Store represents a storage system that combines metadata and data storage

func NewStore added in v0.2.0

func NewStore(baseDir string, options StoreOptions) (*Store, error)

NewStore creates a new store

func (*Store) Close added in v0.2.0

func (s *Store) Close() error

Close closes the store

func (*Store) ComputeDiff added in v0.2.0

func (s *Store) ComputeDiff(oldID, newID string) ([]serializer.DiffEntry, error)

ComputeDiff computes the difference between two snapshots

func (*Store) CreateSnapshot added in v0.2.0

func (s *Store) CreateSnapshot(id string, description string, rootPath string, entries []walker.SnapshotEntry) error

CreateSnapshot creates a new snapshot

func (*Store) DeleteDiff added in v0.2.0

func (s *Store) DeleteDiff(oldID, newID string) error

DeleteDiff deletes a diff between two snapshots

func (*Store) DeleteSnapshot added in v0.2.0

func (s *Store) DeleteSnapshot(id string) error

DeleteSnapshot deletes a snapshot

func (*Store) FindFilesByHash added in v0.2.0

func (s *Store) FindFilesByHash(snapshotID, hash string) (map[string]metadata.FileMetadata, error)

FindFilesByHash finds files in a snapshot with a specific hash

func (*Store) FindFilesByModTime added in v0.2.0

func (s *Store) FindFilesByModTime(snapshotID string, startTime, endTime time.Time) (map[string]metadata.FileMetadata, error)

FindFilesByModTime finds files in a snapshot modified within a time range

func (*Store) FindFilesByPattern added in v0.2.0

func (s *Store) FindFilesByPattern(snapshotID, pattern string) (map[string]metadata.FileMetadata, error)

FindFilesByPattern finds files in a snapshot matching a pattern

func (*Store) FindFilesBySize added in v0.2.0

func (s *Store) FindFilesBySize(snapshotID string, minSize, maxSize int64) (map[string]metadata.FileMetadata, error)

FindFilesBySize finds files in a snapshot within a size range

func (*Store) GetDiff added in v0.2.0

func (s *Store) GetDiff(oldID, newID string) ([]serializer.DiffEntry, error)

GetDiff retrieves a diff between two snapshots

func (*Store) GetSnapshot added in v0.2.0

func (s *Store) GetSnapshot(id string) ([]walker.SnapshotEntry, error)

GetSnapshot retrieves a snapshot

func (*Store) ListSnapshots added in v0.2.0

func (s *Store) ListSnapshots() ([]metadata.SnapshotMetadata, error)

ListSnapshots lists all snapshots

func (*Store) StoreDiff added in v0.2.0

func (s *Store) StoreDiff(oldID, newID string) error

StoreDiff stores a diff between two snapshots

type StoreOptions added in v0.2.0

type StoreOptions struct {
	MetadataOptions metadata.Options
}

StoreOptions represents options for configuring the store

func DefaultStoreOptions added in v0.2.0

func DefaultStoreOptions() StoreOptions

DefaultStoreOptions returns the default options for the store

Jump to

Keyboard shortcuts

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