storage

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Unlicense Imports: 53 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// DefaultMaxIdleConns is the default maximum number of idle connections across all hosts
	DefaultMaxIdleConns = 100
	// DefaultMaxIdleConnsPerHost is the default maximum number of idle connections per host
	DefaultMaxIdleConnsPerHost = 100
	// DefaultIdleConnTimeout is the default timeout for idle connections
	DefaultIdleConnTimeout = 90 * time.Second
)

Connection pool default settings for S3 backend

Variables

This section is empty.

Functions

func AdviseDontNeed

func AdviseDontNeed(f *os.File) error

AdviseDontNeed advises the kernel that the file data is not needed in cache.

func AdviseWillNeed

func AdviseWillNeed(f *os.File, off int64, length int64) error

AdviseWillNeed advises the kernel to read ahead the specified range into page cache.

func DecryptWALFrames

func DecryptWALFrames(ctx context.Context, r io.Reader, ce *CipherEngine) ([][]byte, error)

DecryptWALFrames reads and decrypts all encrypted WAL frames from r.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if an error is a NotFoundError

func NewRateLimitedWriter

func NewRateLimitedWriter(w io.Writer, limitBytesPerSec int, ctx context.Context) io.Writer

NewRateLimitedWriter creates a new rate limited writer. If limitBytesPerSec is <= 0, valid writes are passed through without limiting.

func NewS3Error

func NewS3Error(op, bucket, key string, cause error) error

NewS3Error creates an S3 error with timestamp.

func NewWALError

func NewWALError(op, path string, offset int64, cause error) error

NewWALError creates a WAL error with timestamp.

func OpenFileDirect

func OpenFileDirect(path string, flags int, perm os.FileMode) (*os.File, error)

OpenFileDirect opens a file with Direct I/O enabled (O_DIRECT on Linux).

func PutBuffer

func PutBuffer(b *PatchableBuffer)

Types

type AdaptiveIntervalCalculator

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

AdaptiveIntervalCalculator computes optimal flush intervals based on load

func NewAdaptiveIntervalCalculator

func NewAdaptiveIntervalCalculator(cfg AdaptiveWALConfig) *AdaptiveIntervalCalculator

NewAdaptiveIntervalCalculator creates a new calculator with the given config

func (*AdaptiveIntervalCalculator) CalculateInterval

func (c *AdaptiveIntervalCalculator) CalculateInterval(writeRate float64) time.Duration

CalculateInterval returns the optimal flush interval for the given write rate

type AdaptiveWALConfig

type AdaptiveWALConfig struct {
	MinInterval   time.Duration // Minimum flush interval under high load (e.g., 1ms)
	MaxInterval   time.Duration // Maximum flush interval under low load (e.g., 100ms)
	TargetLatency time.Duration // Target p99 latency for writes (e.g., 5ms)
	Enabled       bool          // Whether adaptive batching is enabled
}

AdaptiveWALConfig configures adaptive batching behavior

func NewAdaptiveWALConfig

func NewAdaptiveWALConfig() AdaptiveWALConfig

NewAdaptiveWALConfig returns sensible defaults for adaptive batching

func (*AdaptiveWALConfig) Validate

func (c *AdaptiveWALConfig) Validate() error

Validate checks the configuration for consistency

type ApplierFunc

type ApplierFunc func(name string, rec arrow.RecordBatch, seq uint64, ts int64) error

ApplierFunc is a callback for applying WAL entries during replay.

type ArrowIOUringBackend

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

ArrowIOUringBackend implements WALBackend using custom io_uring library with double-buffering and async completion handling

func (*ArrowIOUringBackend) Close

func (b *ArrowIOUringBackend) Close() error

Close implements WALBackend.Close

func (*ArrowIOUringBackend) File

func (b *ArrowIOUringBackend) File() *os.File

File implements WALBackend.File

func (*ArrowIOUringBackend) Name

func (b *ArrowIOUringBackend) Name() string

Name implements WALBackend.Name

func (*ArrowIOUringBackend) Stats

func (b *ArrowIOUringBackend) Stats() Stats

Stats returns current statistics

func (*ArrowIOUringBackend) Sync

func (b *ArrowIOUringBackend) Sync() error

Sync implements WALBackend.Sync

func (*ArrowIOUringBackend) Write

func (b *ArrowIOUringBackend) Write(p []byte) (int, error)

Write implements WALBackend.Write with double-buffering and async completion

func (*ArrowIOUringBackend) WriteSync

func (b *ArrowIOUringBackend) WriteSync(p []byte) (int, error)

WriteSync performs a synchronous write (waits for completion)

type AsyncFsyncConfig

type AsyncFsyncConfig struct {
	DirtyThreshold   int64
	MaxPendingFsyncs int
	FsyncTimeout     time.Duration
	Enabled          bool
	FallbackToSync   bool
}

AsyncFsyncConfig configures asynchronous fsync behavior for WAL

func DefaultAsyncFsyncConfig

func DefaultAsyncFsyncConfig() AsyncFsyncConfig

DefaultAsyncFsyncConfig returns sensible defaults

func (AsyncFsyncConfig) IsAsyncEnabled

func (c AsyncFsyncConfig) IsAsyncEnabled() bool

IsAsyncEnabled returns whether async fsync is enabled

func (AsyncFsyncConfig) ShouldFsync

func (c AsyncFsyncConfig) ShouldFsync(dirtyBytes int64) bool

ShouldFsync returns true if dirty bytes exceed threshold

func (AsyncFsyncConfig) Validate

func (c AsyncFsyncConfig) Validate() error

Validate checks if the configuration is valid

type AsyncFsyncer

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

AsyncFsyncer manages asynchronous fsync operations

func NewAsyncFsyncer

func NewAsyncFsyncer(cfg AsyncFsyncConfig) *AsyncFsyncer

NewAsyncFsyncer creates a new async fsyncer

func (*AsyncFsyncer) AddDirtyBytes

func (a *AsyncFsyncer) AddDirtyBytes(n int64)

AddDirtyBytes adds to the dirty byte counter

func (*AsyncFsyncer) Config

func (a *AsyncFsyncer) Config() AsyncFsyncConfig

Config returns the configuration

func (*AsyncFsyncer) DirtyBytes

func (a *AsyncFsyncer) DirtyBytes() int64

DirtyBytes returns current dirty byte count

func (*AsyncFsyncer) ForceFsync

func (a *AsyncFsyncer) ForceFsync() error

ForceFsync performs a synchronous fsync (fallback)

func (*AsyncFsyncer) IsRunning

func (a *AsyncFsyncer) IsRunning() bool

IsRunning returns whether the fsyncer is active

func (*AsyncFsyncer) RequestFsyncIfNeeded

func (a *AsyncFsyncer) RequestFsyncIfNeeded() bool

RequestFsyncIfNeeded requests fsync if dirty threshold exceeded

func (*AsyncFsyncer) Start

func (a *AsyncFsyncer) Start(f *os.File) error

Start begins the async fsync goroutine

func (*AsyncFsyncer) Stats

func (a *AsyncFsyncer) Stats() AsyncFsyncerStats

Stats returns current statistics

func (*AsyncFsyncer) Stop

func (a *AsyncFsyncer) Stop() error

Stop gracefully shuts down the fsyncer

func (*AsyncFsyncer) WaitForPendingFsyncs

func (a *AsyncFsyncer) WaitForPendingFsyncs()

WaitForPendingFsyncs waits for all pending fsync requests to complete

type AsyncFsyncerStats

type AsyncFsyncerStats struct {
	TotalRequests   int64
	CompletedFsyncs int64
	FailedFsyncs    int64
	SyncFallbacks   int64
	QueueFullDrops  int64
}

AsyncFsyncerStats holds statistics for the async fsyncer

type AsyncS3Backend

type AsyncS3Backend struct {
	*S3Backend
	// contains filtered or unexported fields
}

AsyncS3Backend wraps S3Backend for background execution

func (*AsyncS3Backend) Bucket

func (b *AsyncS3Backend) Bucket() string

func (*AsyncS3Backend) Close

func (b *AsyncS3Backend) Close()

Close gracefully shuts down workers

func (*AsyncS3Backend) DeleteSnapshot

func (b *AsyncS3Backend) DeleteSnapshot(ctx context.Context, name string) error

func (*AsyncS3Backend) GetHTTPClient

func (b *AsyncS3Backend) GetHTTPClient() *http.Client

func (*AsyncS3Backend) GetHTTPTransport

func (b *AsyncS3Backend) GetHTTPTransport() *http.Transport

func (*AsyncS3Backend) ListSnapshots

func (b *AsyncS3Backend) ListSnapshots(ctx context.Context) ([]string, error)

func (*AsyncS3Backend) Prefix

func (b *AsyncS3Backend) Prefix() string

func (*AsyncS3Backend) ReadSnapshot

func (b *AsyncS3Backend) ReadSnapshot(ctx context.Context, name string) (io.ReadCloser, error)

func (*AsyncS3Backend) ReadSnapshotFile

func (b *AsyncS3Backend) ReadSnapshotFile(ctx context.Context, name, ext string) (io.ReadCloser, error)

func (*AsyncS3Backend) WriteSnapshot

func (b *AsyncS3Backend) WriteSnapshot(ctx context.Context, name string, data []byte) error

func (*AsyncS3Backend) WriteSnapshotAsync

func (b *AsyncS3Backend) WriteSnapshotAsync(name string, data []byte)

WriteSnapshotAsync queues a snapshot for background upload

func (*AsyncS3Backend) WriteSnapshotFile

func (b *AsyncS3Backend) WriteSnapshotFile(ctx context.Context, name, ext string, r io.Reader) error

type BufferedWAL

type BufferedWAL struct {
	ErrCh chan error
	// contains filtered or unexported fields
}

BufferedWAL is an asynchronous WAL implementation that buffers writes in memory. It trades a small window of durability (flushInterval) for high throughput. It uses lock-free double-buffering to allow writes to continue while flushing.

func NewBufferedWAL

func NewBufferedWAL(backend WALBackend, maxBatchSize int, flushDelay time.Duration) *BufferedWAL

NewBufferedWAL creates a new buffered WAL.

func (*BufferedWAL) Close

func (w *BufferedWAL) Close() error

Close flushes ensuring all data is written and closes the background loop.

func (*BufferedWAL) SetOnError

func (w *BufferedWAL) SetOnError(fn func(error))

SetOnError sets a callback function to be invoked when a flush error occurs.

func (*BufferedWAL) Sync

func (w *BufferedWAL) Sync() error

Sync forces a flush to disk and waits for the *current* writes to be persisted. Uses group-commit batching: concurrent Sync callers register as waiters and a single flush drains all pending work at once, reducing total IOPS.

func (*BufferedWAL) Write

func (w *BufferedWAL) Write(name string, seq uint64, ts int64, record arrow.RecordBatch) error

Write writes a record to the in-memory buffer.

type CipherEngine

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

CipherEngine performs AES-256-GCM envelope encryption backed by a security.KeyProvider.

func NewCipherEngine

func NewCipherEngine(ctx context.Context, kp security.KeyProvider) (*CipherEngine, error)

NewCipherEngine creates a CipherEngine and provisions an initial Data Encryption Key.

func (*CipherEngine) Open

func (ce *CipherEngine) Open(ctx context.Context, ciphertext, aad []byte) ([]byte, error)

Open verifies envelope metadata and decrypts sealed ciphertext with AAD binding.

func (*CipherEngine) RotateDEK

func (ce *CipherEngine) RotateDEK(ctx context.Context) error

RotateDEK generates a new DEK via the configured KeyProvider while retaining previous keys for decryption.

func (*CipherEngine) Seal

func (ce *CipherEngine) Seal(plaintext, aad []byte) ([]byte, error)

Seal encrypts plaintext with AES-256-GCM and embeds an envelope header binding aad.

type DecodedWALEntry

type DecodedWALEntry struct {
	Name   string
	Record arrow.RecordBatch
	Seq    uint64
	Ts     int64
	Err    error
}

DecodedWALEntry represents a fully decoded entry ready for application

func DecodeWALBlock

func DecodeWALBlock(data []byte, mem memory.Allocator) ([]DecodedWALEntry, error)

DecodeWALBlock decodes a single raw WAL block (as written to disk) into entries.

type EncryptedSnapshotBackend

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

EncryptedSnapshotBackend transparently encrypts snapshots before delegating to inner SnapshotBackend.

func (*EncryptedSnapshotBackend) Bucket

func (s *EncryptedSnapshotBackend) Bucket() string

func (*EncryptedSnapshotBackend) DeleteSnapshot

func (s *EncryptedSnapshotBackend) DeleteSnapshot(ctx context.Context, name string) error

func (*EncryptedSnapshotBackend) GetHTTPClient

func (s *EncryptedSnapshotBackend) GetHTTPClient() *http.Client

func (*EncryptedSnapshotBackend) GetHTTPTransport

func (s *EncryptedSnapshotBackend) GetHTTPTransport() *http.Transport

func (*EncryptedSnapshotBackend) ListSnapshots

func (s *EncryptedSnapshotBackend) ListSnapshots(ctx context.Context) ([]string, error)

func (*EncryptedSnapshotBackend) Prefix

func (s *EncryptedSnapshotBackend) Prefix() string

func (*EncryptedSnapshotBackend) ReadSnapshot

func (s *EncryptedSnapshotBackend) ReadSnapshot(ctx context.Context, name string) (io.ReadCloser, error)

func (*EncryptedSnapshotBackend) ReadSnapshotFile

func (s *EncryptedSnapshotBackend) ReadSnapshotFile(ctx context.Context, name, ext string) (io.ReadCloser, error)

func (*EncryptedSnapshotBackend) WriteSnapshot

func (s *EncryptedSnapshotBackend) WriteSnapshot(ctx context.Context, name string, data []byte) error

func (*EncryptedSnapshotBackend) WriteSnapshotAsync

func (s *EncryptedSnapshotBackend) WriteSnapshotAsync(name string, data []byte)

func (*EncryptedSnapshotBackend) WriteSnapshotFile

func (s *EncryptedSnapshotBackend) WriteSnapshotFile(ctx context.Context, name, ext string, r io.Reader) error

type EncryptedStorageBackend

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

EncryptedStorageBackend provides fixed-page authenticated encryption over StorageBackend so random-access positional ReadAt/WriteAt works for disk vector spill.

func NewEncryptedStorageBackend

func NewEncryptedStorageBackend(inner StorageBackend, ce *CipherEngine, blockSize int) *EncryptedStorageBackend

NewEncryptedStorageBackend wraps a StorageBackend with page-level AES-256-GCM encryption.

func (*EncryptedStorageBackend) Close

func (b *EncryptedStorageBackend) Close() error

func (*EncryptedStorageBackend) Name

func (b *EncryptedStorageBackend) Name() string

func (*EncryptedStorageBackend) ReadAt

func (b *EncryptedStorageBackend) ReadAt(p []byte, off int64) (int, error)

func (*EncryptedStorageBackend) Readv

func (b *EncryptedStorageBackend) Readv(iovs [][]byte, off int64) (int, error)

func (*EncryptedStorageBackend) Size

func (b *EncryptedStorageBackend) Size() (int64, error)

func (*EncryptedStorageBackend) Sync

func (b *EncryptedStorageBackend) Sync() error

func (*EncryptedStorageBackend) WriteAt

func (b *EncryptedStorageBackend) WriteAt(p []byte, off int64) (int, error)

func (*EncryptedStorageBackend) Writev

func (b *EncryptedStorageBackend) Writev(iovs [][]byte, off int64) (int, error)

type EncryptedWALBackend

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

EncryptedWALBackend wraps any WALBackend with length-prefixed AES-256-GCM frames.

func NewEncryptedWALBackend

func NewEncryptedWALBackend(inner WALBackend, ce *CipherEngine) *EncryptedWALBackend

NewEncryptedWALBackend wraps a WALBackend with encryption at rest.

func (*EncryptedWALBackend) Close

func (w *EncryptedWALBackend) Close() error

func (*EncryptedWALBackend) File

func (w *EncryptedWALBackend) File() *os.File

func (*EncryptedWALBackend) Name

func (w *EncryptedWALBackend) Name() string

func (*EncryptedWALBackend) Sync

func (w *EncryptedWALBackend) Sync() error

func (*EncryptedWALBackend) Write

func (w *EncryptedWALBackend) Write(p []byte) (int, error)

type EnvelopeHeader

type EnvelopeHeader struct {
	KeyID      string
	WrappedDEK []byte
}

EnvelopeHeader stores metadata needed to unwrap a chunk's DEK without external state.

type FSBackend

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

FSBackend is a standard os.File backed implementation.

func NewFSBackend

func NewFSBackend(path string) (*FSBackend, error)

func NewFSBackendWithDirectIO

func NewFSBackendWithDirectIO(path string) (*FSBackend, error)

func (*FSBackend) Close

func (b *FSBackend) Close() error

func (*FSBackend) File

func (b *FSBackend) File() *os.File

func (*FSBackend) Name

func (b *FSBackend) Name() string

func (*FSBackend) Sync

func (b *FSBackend) Sync() error

func (*FSBackend) Write

func (b *FSBackend) Write(p []byte) (int, error)

type FSStorageBackend

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

FSStorageBackend is a standard os.File implementation.

func NewFSStorageBackend

func NewFSStorageBackend(path string, directIO bool) (*FSStorageBackend, error)

func (*FSStorageBackend) Close

func (b *FSStorageBackend) Close() error

func (*FSStorageBackend) Name

func (b *FSStorageBackend) Name() string

func (*FSStorageBackend) Prefetch

func (b *FSStorageBackend) Prefetch(off int64, length int64) error

Prefetch advises the kernel to read ahead file data into page cache asynchronously.

func (*FSStorageBackend) ReadAt

func (b *FSStorageBackend) ReadAt(p []byte, off int64) (int, error)

func (*FSStorageBackend) Readv

func (b *FSStorageBackend) Readv(iovs [][]byte, off int64) (int, error)

func (*FSStorageBackend) Size

func (b *FSStorageBackend) Size() (int64, error)

func (*FSStorageBackend) Sync

func (b *FSStorageBackend) Sync() error

func (*FSStorageBackend) WriteAt

func (b *FSStorageBackend) WriteAt(p []byte, off int64) (int, error)

func (*FSStorageBackend) Writev

func (b *FSStorageBackend) Writev(iovs [][]byte, off int64) (int, error)

type FileSnapshotBackend

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

func (*FileSnapshotBackend) Bucket

func (b *FileSnapshotBackend) Bucket() string

func (*FileSnapshotBackend) DeleteSnapshot

func (b *FileSnapshotBackend) DeleteSnapshot(ctx context.Context, name string) error

func (*FileSnapshotBackend) GetHTTPClient

func (b *FileSnapshotBackend) GetHTTPClient() *http.Client

func (*FileSnapshotBackend) GetHTTPTransport

func (b *FileSnapshotBackend) GetHTTPTransport() *http.Transport

func (*FileSnapshotBackend) ListSnapshots

func (b *FileSnapshotBackend) ListSnapshots(ctx context.Context) ([]string, error)

func (*FileSnapshotBackend) Prefix

func (b *FileSnapshotBackend) Prefix() string

func (*FileSnapshotBackend) ReadSnapshot

func (b *FileSnapshotBackend) ReadSnapshot(ctx context.Context, name string) (io.ReadCloser, error)

func (*FileSnapshotBackend) ReadSnapshotFile

func (b *FileSnapshotBackend) ReadSnapshotFile(ctx context.Context, name, ext string) (io.ReadCloser, error)

func (*FileSnapshotBackend) WriteSnapshot

func (b *FileSnapshotBackend) WriteSnapshot(ctx context.Context, name string, data []byte) error

func (*FileSnapshotBackend) WriteSnapshotAsync

func (b *FileSnapshotBackend) WriteSnapshotAsync(name string, data []byte)

func (*FileSnapshotBackend) WriteSnapshotFile

func (b *FileSnapshotBackend) WriteSnapshotFile(ctx context.Context, name, ext string, r io.Reader) error

type GCSBackend

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

GCSBackend implements SnapshotBackend for Google Cloud Storage

func (*GCSBackend) Bucket

func (b *GCSBackend) Bucket() string

func (*GCSBackend) DeleteSnapshot

func (b *GCSBackend) DeleteSnapshot(ctx context.Context, name string) error

func (*GCSBackend) GetHTTPClient

func (b *GCSBackend) GetHTTPClient() *http.Client

func (*GCSBackend) GetHTTPTransport

func (b *GCSBackend) GetHTTPTransport() *http.Transport

func (*GCSBackend) ListSnapshots

func (b *GCSBackend) ListSnapshots(ctx context.Context) ([]string, error)

func (*GCSBackend) Prefix

func (b *GCSBackend) Prefix() string

func (*GCSBackend) ReadSnapshot

func (b *GCSBackend) ReadSnapshot(ctx context.Context, name string) (io.ReadCloser, error)

func (*GCSBackend) ReadSnapshotFile

func (b *GCSBackend) ReadSnapshotFile(ctx context.Context, name, ext string) (io.ReadCloser, error)

func (*GCSBackend) WriteSnapshot

func (b *GCSBackend) WriteSnapshot(ctx context.Context, name string, data []byte) error

func (*GCSBackend) WriteSnapshotAsync

func (b *GCSBackend) WriteSnapshotAsync(name string, data []byte)

func (*GCSBackend) WriteSnapshotFile

func (b *GCSBackend) WriteSnapshotFile(ctx context.Context, name, ext string, r io.Reader) error

type GCSBackendConfig

type GCSBackendConfig struct {
	Bucket          string // Bucket name
	Prefix          string // Optional key prefix for all snapshots
	CredentialsFile string // Path to Google service account key file
	ProjectID       string // Google Cloud Project ID
}

GCSBackendConfig holds configuration for the GCS backend

type GCSRemoteStorage

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

GCSRemoteStorage is a GCP Cloud Storage implementation of RemoteStorage.

func NewGCSRemoteStorage

func NewGCSRemoteStorage(ctx context.Context, bucketName string, opts ...option.ClientOption) (*GCSRemoteStorage, error)

NewGCSRemoteStorage constructs a GCS-backed RemoteStorage.

func (*GCSRemoteStorage) Close

func (g *GCSRemoteStorage) Close() error

Close closes the underlying GCP storage client connections.

func (*GCSRemoteStorage) Delete

func (g *GCSRemoteStorage) Delete(ctx context.Context, key string) error

Delete removes an object from Google Cloud Storage.

func (*GCSRemoteStorage) Exists

func (g *GCSRemoteStorage) Exists(ctx context.Context, key string) (bool, error)

Exists checks if an object exists by retrieving its attributes.

func (*GCSRemoteStorage) Get

Get downloads an object from Google Cloud Storage.

func (*GCSRemoteStorage) Put

func (g *GCSRemoteStorage) Put(ctx context.Context, key string, r io.Reader) error

Put uploads an object to Google Cloud Storage. GCS allows streaming directly via the ObjectHandle Writer.

type GraphEdgeRecord

type GraphEdgeRecord struct {
	Subject   uint32  `parquet:"subject"`
	Predicate string  `parquet:"predicate"`
	Object    uint32  `parquet:"object"`
	Weight    float32 `parquet:"weight"`
}

GraphEdgeRecord represents a graph edge for Parquet serialization

type LRUCache

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

LRUCache is a simple thread-safe LRU cache.

func NewLRUCache

func NewLRUCache(maxBytes int64) *LRUCache

func (*LRUCache) Get

func (c *LRUCache) Get(key string) ([]byte, bool)

func (*LRUCache) Put

func (c *LRUCache) Put(key string, value []byte)

type MmapOptions

type MmapOptions struct {
	Dimension   int
	InitialSize int64
	ReadOnly    bool
	Populate    bool
	Directory   string
}

type MmapVectorStorage

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

func NewMmapVectorStorage

func NewMmapVectorStorage(name string, opts MmapOptions) (*MmapVectorStorage, error)

func (*MmapVectorStorage) Close

func (m *MmapVectorStorage) Close() error

func (*MmapVectorStorage) Count

func (m *MmapVectorStorage) Count() int

func (*MmapVectorStorage) Dimension

func (m *MmapVectorStorage) Dimension() int

func (*MmapVectorStorage) ReadVector

func (m *MmapVectorStorage) ReadVector(id int) ([]float32, error)

func (*MmapVectorStorage) ReadVectorInto

func (m *MmapVectorStorage) ReadVectorInto(id int, vector []float32) error

func (*MmapVectorStorage) Size

func (m *MmapVectorStorage) Size() int64

func (*MmapVectorStorage) Sync

func (m *MmapVectorStorage) Sync() error

func (*MmapVectorStorage) WriteVector

func (m *MmapVectorStorage) WriteVector(id int, vector []float32) error

type MockRemoteStorage

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

MockRemoteStorage is an in-memory implementation of RemoteStorage for testing.

func NewMockRemoteStorage

func NewMockRemoteStorage(provider string) *MockRemoteStorage

func (*MockRemoteStorage) Delete

func (m *MockRemoteStorage) Delete(ctx context.Context, key string) error

func (*MockRemoteStorage) Exists

func (m *MockRemoteStorage) Exists(ctx context.Context, key string) (bool, error)

func (*MockRemoteStorage) Get

func (*MockRemoteStorage) Put

func (m *MockRemoteStorage) Put(ctx context.Context, key string, r io.Reader) error

type NotFoundError

type NotFoundError struct {
	Name string
}

NotFoundError indicates a snapshot was not found

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type PatchableBuffer

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

PatchableBuffer is a buffer that supports appending and random-access writes (patching). It is used to write data sequentially (like a standard buffer) but allows going back to fill in reserved headers once the payload size/checksum is known.

func GetBuffer

func GetBuffer(capacity int) *PatchableBuffer

func NewPatchableBuffer

func NewPatchableBuffer(capacity int) *PatchableBuffer

NewPatchableBuffer creates a new PatchableBuffer with initial capacity.

func (*PatchableBuffer) Bytes

func (b *PatchableBuffer) Bytes() []byte

Bytes returns the slice holding the unread portion of the buffer. The slice is valid for use only until the next buffer modification.

func (*PatchableBuffer) Grow

func (b *PatchableBuffer) Grow(n int)

Grow guarantees that n bytes can be written to the buffer without another allocation.

func (*PatchableBuffer) Len

func (b *PatchableBuffer) Len() int

Len returns the number of bytes of the unread portion of the buffer.

func (*PatchableBuffer) Reset

func (b *PatchableBuffer) Reset()

Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes.

func (*PatchableBuffer) Write

func (b *PatchableBuffer) Write(p []byte) (n int, err error)

Write appends p to the buffer, implementing io.Writer.

func (*PatchableBuffer) WriteAt

func (b *PatchableBuffer) WriteAt(p []byte, off int64) (n int, err error)

WriteAt writes p starting at offset off, overwriting existing data. It implements io.WriterAt but limits writes to the current length of the buffer. It returns an error if the write extends beyond the current buffer length.

type Prefetcher

type Prefetcher interface {
	Prefetch(off int64, length int64) error
}

Prefetcher defines optional asynchronous kernel read-ahead capabilities for storage backends.

type RateLimitedWriter

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

RateLimitedWriter wraps an io.Writer and limits the write throughput.

func (*RateLimitedWriter) Write

func (rw *RateLimitedWriter) Write(p []byte) (n int, err error)

type RemoteStorage

type RemoteStorage interface {
	Put(ctx context.Context, key string, r io.Reader) error
	Get(ctx context.Context, key string) (io.ReadCloser, error)
	Delete(ctx context.Context, key string) error
	Exists(ctx context.Context, key string) (bool, error)
}

type S3Backend

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

S3Backend implements SnapshotBackend for S3-compatible storage

func (*S3Backend) Bucket

func (b *S3Backend) Bucket() string

Bucket returns the S3 bucket name

func (*S3Backend) DeleteSnapshot

func (b *S3Backend) DeleteSnapshot(ctx context.Context, name string) error

DeleteSnapshot removes a snapshot from S3

func (*S3Backend) GetHTTPClient

func (b *S3Backend) GetHTTPClient() *http.Client

GetHTTPClient returns the HTTP client used by this S3 backend

func (*S3Backend) GetHTTPTransport

func (b *S3Backend) GetHTTPTransport() *http.Transport

GetHTTPTransport returns the underlying HTTP transport used for connection pooling

func (*S3Backend) ListSnapshots

func (b *S3Backend) ListSnapshots(ctx context.Context) ([]string, error)

ListSnapshots returns all collection names that have snapshots

func (*S3Backend) Prefix

func (b *S3Backend) Prefix() string

Prefix returns the S3 key prefix

func (*S3Backend) ReadSnapshot

func (b *S3Backend) ReadSnapshot(ctx context.Context, name string) (io.ReadCloser, error)

ReadSnapshot downloads snapshot data from S3

func (*S3Backend) ReadSnapshotFile

func (b *S3Backend) ReadSnapshotFile(ctx context.Context, name, ext string) (io.ReadCloser, error)

ReadSnapshotFile downloads snapshot data with custom extension from S3

func (*S3Backend) WriteSnapshot

func (b *S3Backend) WriteSnapshot(ctx context.Context, name string, data []byte) error

WriteSnapshot uploads snapshot data to S3

func (*S3Backend) WriteSnapshotAsync

func (b *S3Backend) WriteSnapshotAsync(name string, data []byte)

WriteSnapshotAsync on sync backend is just a wrapper

func (*S3Backend) WriteSnapshotFile

func (b *S3Backend) WriteSnapshotFile(ctx context.Context, name, ext string, r io.Reader) error

WriteSnapshotFile writes a snapshot file with a custom extension

type S3BackendConfig

type S3BackendConfig struct {
	Endpoint        string // S3-compatible endpoint URL (e.g., "http://localhost:9000" for MinIO)
	Bucket          string // Bucket name
	Prefix          string // Optional key prefix for all snapshots
	AccessKeyID     string // AWS access key
	SecretAccessKey string // AWS secret key
	Region          string // AWS region (default: us-east-1)
	UsePathStyle    bool   // Use path-style addressing (required for MinIO)

	// Connection pool settings
	MaxIdleConns        int           // Maximum idle connections (0 = use default)
	MaxIdleConnsPerHost int           // Maximum idle connections per host (0 = use default)
	IdleConnTimeout     time.Duration // Idle connection timeout (0 = use default)

	// Async settings
	AsyncEnabled   bool // Enable background uploads
	WorkerCount    int  // Number of parallel upload workers
	QueueSize      int  // Buffer size for pending uploads
	AsyncMultipart bool // Use multipart upload for large files
}

S3BackendConfig holds configuration for the S3 backend

func (*S3BackendConfig) Validate

func (c *S3BackendConfig) Validate() error

Validate checks the configuration for required fields

type S3ClientAPI

type S3ClientAPI interface {
	PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
	GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
	DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
	ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
}

S3ClientAPI defines the subset of s3.Client methods used by S3Backend

type S3Error

type S3Error struct {
	Op        string    // Operation: "upload", "download", "list", "delete"
	Bucket    string    // S3 bucket name
	Key       string    // S3 object key
	Cause     error     // Underlying error
	Timestamp time.Time // When the error occurred
}

S3Error provides rich context for S3 backend operations.

func (*S3Error) Error

func (e *S3Error) Error() string

func (*S3Error) Unwrap

func (e *S3Error) Unwrap() error

type S3RemoteStorage

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

S3RemoteStorage is an AWS S3 implementation of RemoteStorage.

func NewS3RemoteStorage

func NewS3RemoteStorage(ctx context.Context, region, bucket, endpoint, accessKey, secretKey string) (*S3RemoteStorage, error)

NewS3RemoteStorage constructs an S3-backed RemoteStorage.

func (*S3RemoteStorage) Delete

func (s *S3RemoteStorage) Delete(ctx context.Context, key string) error

Delete permanently removes an object from S3.

func (*S3RemoteStorage) Exists

func (s *S3RemoteStorage) Exists(ctx context.Context, key string) (bool, error)

Exists checks if an object is present in S3 without downloading it.

func (*S3RemoteStorage) Get

func (s *S3RemoteStorage) Get(ctx context.Context, key string) (io.ReadCloser, error)

Get downloads an object from S3. The caller is responsible for closing the ReadCloser.

func (*S3RemoteStorage) Put

func (s *S3RemoteStorage) Put(ctx context.Context, key string, r io.Reader) error

Put uploads an object to S3. For larger payloads it buffers in memory since PutObject expects a stream with known length or seekable reader. In production, consider s3manager.Uploader.

type SnapshotBackend

type SnapshotBackend interface {
	// WriteSnapshot writes snapshot data for a collection
	WriteSnapshot(ctx context.Context, name string, data []byte) error
	// ReadSnapshot returns a reader for snapshot data
	ReadSnapshot(ctx context.Context, name string) (io.ReadCloser, error)
	// ListSnapshots returns all collection names with snapshots
	ListSnapshots(ctx context.Context) ([]string, error)
	// DeleteSnapshot removes a snapshot
	DeleteSnapshot(ctx context.Context, name string) error
	// WriteSnapshotAsync performs a non-blocking upload
	WriteSnapshotAsync(name string, data []byte)

	// WriteSnapshotFile writes a snapshot file with a custom extension
	WriteSnapshotFile(ctx context.Context, name, ext string, r io.Reader) error
	// ReadSnapshotFile reads a snapshot file with a custom extension
	ReadSnapshotFile(ctx context.Context, name, ext string) (io.ReadCloser, error)

	// Expose properties for testing/coordination (optional/nullable)
	Bucket() string
	Prefix() string
	GetHTTPTransport() *http.Transport
	GetHTTPClient() *http.Client
}

SnapshotBackend defines the interface for snapshot storage backends

func NewEncryptedSnapshotBackend

func NewEncryptedSnapshotBackend(inner SnapshotBackend, ce *CipherEngine) SnapshotBackend

NewEncryptedSnapshotBackend wraps a SnapshotBackend with AES-256-GCM envelope encryption.

func NewFileSnapshotBackend

func NewFileSnapshotBackend(baseDir string) (SnapshotBackend, error)

func NewGCSBackend

func NewGCSBackend(ctx context.Context, cfg *GCSBackendConfig) (SnapshotBackend, error)

NewGCSBackend creates a new GCS backend from configuration

func NewS3Backend

func NewS3Backend(cfg *S3BackendConfig) (SnapshotBackend, error)

NewS3Backend creates a new S3 backend from configuration

type SnapshotItem

type SnapshotItem struct {
	Name             string
	Records          []arrow.RecordBatch
	GraphRecords     []arrow.RecordBatch
	PQCodebook       []byte
	IndexConfigIndex int // Deprecated or internal? No, IndexConfig is []byte.
	IndexConfig      []byte

	// IndexConfigWriter is a callback to stream index config directly to the output.
	// If set, recursive buffering is avoided.
	IndexConfigWriter func(io.Writer) error

	// OnSnapshot is a callback to handle custom snapshot logic (e.g. large file streaming)
	// It is called with the active snapshot backend if one is configured.
	OnSnapshot func(backend SnapshotBackend) error

	// Cleanup is called after the item has been processed (either successfully or with error).
	Cleanup func()
}

SnapshotItem represents a dataset snapshot.

type SnapshotSource

type SnapshotSource interface {
	Iterate(func(SnapshotItem) error) error
}

type Stats

type Stats struct {
	PendingOps  int64
	CQReady     uint32
	BufferedOps int64
}

Stats provides backend statistics

type StdWAL

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

StdWAL is a standard file-based WAL implementation (fallback).

func NewStdWAL

func NewStdWAL(dir string) *StdWAL

func (*StdWAL) Close

func (w *StdWAL) Close() error

func (*StdWAL) Sync

func (w *StdWAL) Sync() error

func (*StdWAL) Write

func (w *StdWAL) Write(name string, seq uint64, ts int64, record arrow.RecordBatch) error

type StorageBackend

type StorageBackend interface {
	io.ReaderAt
	io.WriterAt

	// Readv reads into multiple buffers at the given offset.
	Readv(iovs [][]byte, off int64) (int, error)
	// Writev writes from multiple buffers at the given offset.
	Writev(iovs [][]byte, off int64) (int, error)

	Sync() error
	Close() error
	Size() (int64, error)
	Name() string
}

StorageBackend defines the interface for high-performance vector/graph I/O. It supports positional reads/writes and vectored I/O.

func NewStorageBackend

func NewStorageBackend(path string, preferUring, directIO bool) (StorageBackend, error)

NewStorageBackend creates a StorageBackend based on the platform and configuration.

func NewUringStorageBackend

func NewUringStorageBackend(path string) (StorageBackend, error)

type StorageConfig

type StorageConfig struct {
	DataPath            string
	SnapshotInterval    time.Duration
	AsyncFsync          bool
	DoPutBatchSize      int
	UseIOUring          bool
	UseDirectIO         bool
	WALCompression      bool
	WALCompressionType  string // "snappy", "zstd", "lz4". Default "snappy".
	SnapshotRateLimit   int    // Bytes per second. 0 = unlimited.
	SnapshotCompression string // "zstd", "lz4", "uncompressed". Default "zstd".
}

StorageConfig holds configuration for persistence

type StorageEngine

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

StorageEngine manages the persistence layer (WAL and Snapshots).

func NewStorageEngine

func NewStorageEngine(cfg StorageConfig, mem memory.Allocator) (*StorageEngine, error)

NewStorageEngine creates and initializes a new storage engine.

func (*StorageEngine) AppendReplicatedWAL

func (e *StorageEngine) AppendReplicatedWAL(data []byte) error

AppendReplicatedWAL writes a raw replicated WAL block directly to disk.

func (*StorageEngine) Close

func (e *StorageEngine) Close() error

Close closes the engine.

func (*StorageEngine) CreateSnapshot

func (e *StorageEngine) CreateSnapshot(item *SnapshotItem) error

func (*StorageEngine) ErrCh

func (e *StorageEngine) ErrCh() <-chan error

ErrCh returns a channel that signals background WAL errors. Returns nil if the current WAL configuration is synchronous.

func (*StorageEngine) FlushWAL

func (e *StorageEngine) FlushWAL() error

func (*StorageEngine) GetAllocator

func (e *StorageEngine) GetAllocator() memory.Allocator

GetAllocator returns the memory allocator used by the engine.

func (*StorageEngine) GetSnapshotBackend

func (e *StorageEngine) GetSnapshotBackend() SnapshotBackend

func (*StorageEngine) GetWALQueueDepth

func (e *StorageEngine) GetWALQueueDepth() (pending, capacity int)

GetWALQueueDepth returns the current pending and capacity of the WAL queue.

func (*StorageEngine) InitWAL

func (e *StorageEngine) InitWAL() error

InitWAL initializes the WAL and Batcher.

func (*StorageEngine) LoadSnapshots

func (e *StorageEngine) LoadSnapshots(loader func(*SnapshotItem) error) error

LoadSnapshots reads all snapshots and calls loader for each item.

func (*StorageEngine) RLockSnapshot

func (e *StorageEngine) RLockSnapshot()

RLockSnapshot acquires a read lock that prevents concurrent snapshots. All write operations that modify both memory and WAL must hold this lock to ensure consistency between snapshots and WAL replay.

func (*StorageEngine) RUnlockSnapshot

func (e *StorageEngine) RUnlockSnapshot()

RUnlockSnapshot releases the snapshot read lock.

func (*StorageEngine) ReplayWAL

func (e *StorageEngine) ReplayWAL(applier ApplierFunc) (uint64, error)

ReplayWAL reads the WAL and calls the applier for each entry. Utilizes a pipelined architecture (Reader -> Decoders -> Applier) to maximize throughput. Returns the maximum sequence number encountered.

func (*StorageEngine) SetReplicator

func (e *StorageEngine) SetReplicator(r WALReplicator)

SetReplicator injects the WAL Replicator for HA deployments.

func (*StorageEngine) SetSnapshotBackend

func (e *StorageEngine) SetSnapshotBackend(backend SnapshotBackend)

func (*StorageEngine) Snapshot

func (e *StorageEngine) Snapshot(source SnapshotSource) error

func (*StorageEngine) SyncWAL

func (e *StorageEngine) SyncWAL() error

SyncWAL forces WAL to flush to disk

func (*StorageEngine) TruncateWAL

func (e *StorageEngine) TruncateWAL(seq uint64) error

func (*StorageEngine) WriteToWAL

func (e *StorageEngine) WriteToWAL(name string, rec arrow.RecordBatch, seq uint64, ts int64) error

WriteToWAL writes a record to the WAL.

func (*StorageEngine) WriteWAL

func (e *StorageEngine) WriteWAL(name string, rec arrow.RecordBatch, seq uint64, ts int64) error

type StorageTier

type StorageTier = Tier

type Tier

type Tier string
const (
	TierHot  Tier = "hot"
	TierWarm Tier = "warm"
	TierCold Tier = "cold"
	TierGPU  Tier = "gpu"
)

type TierAccessStats

type TierAccessStats struct {
	AccessCount     int64
	LastAccess      time.Time
	TotalReadBytes  int64
	TotalWriteBytes int64
}

type TierManager

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

func NewTierManager

func NewTierManager(config TieredStorageConfig, logger *zerolog.Logger) (*TierManager, error)

func (*TierManager) GetStorage

func (tm *TierManager) GetStorage(tier Tier) *TierStorage

func (*TierManager) GetTier

func (tm *TierManager) GetTier(key string) Tier

func (*TierManager) MigrateToTier

func (tm *TierManager) MigrateToTier(key string, targetTier Tier) error

func (*TierManager) RecordAccess

func (tm *TierManager) RecordAccess(key string, bytesRead int64)

func (*TierManager) RecordWrite

func (tm *TierManager) RecordWrite(key string, bytesWritten int64)

func (*TierManager) RunTierMigration

func (tm *TierManager) RunTierMigration(ctx context.Context)

type TierStorage

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

type TieredStorageConfig

type TieredStorageConfig struct {
	HotDirectory    string
	WarmDirectory   string
	ColdDirectory   string
	CacheSizeMB     int64
	AccessThreshold int
	AgeThreshold    time.Duration
	EvictBatchSize  int
}

type TieredVectorStore

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

func NewTieredVectorStore

func NewTieredVectorStore(tierManager *TierManager, gpuEnabled bool, gpuMemLimit int64) *TieredVectorStore

func (*TieredVectorStore) GetTierForVector

func (tv *TieredVectorStore) GetTierForVector(id string, vectorSize int) Tier

func (*TieredVectorStore) ShouldUseGPU

func (tv *TieredVectorStore) ShouldUseGPU(vectorSize int) bool

type VectorRecord

type VectorRecord struct {
	ID     int32     `parquet:"id"`
	Vector []float32 `parquet:"vector"`
}

VectorRecord represents a single row for Parquet serialization

type WAL

type WAL interface {
	Write(name string, seq uint64, ts int64, record arrow.RecordBatch) error
	Close() error
	Sync() error
}

WAL defines the interface for Write-Ahead Logging.

func NewWAL

func NewWAL(dir string) WAL

type WALBackend

type WALBackend interface {
	// Write writes the data to the WAL.
	// Implementations should handle offset tracking if necessary (e.g. for io_uring pwrite).
	Write(p []byte) (n int, err error)

	// Sync explicitly flushes data to disk.
	Sync() error

	// Close closes the underlying resource.
	Close() error

	// Name returns the file name or identifier.
	Name() string

	// File returns the underlying *os.File if available.
	File() *os.File
}

WALBackend defines the interface for low-level WAL I/O. Implementations must be thread-safe or serialization must be handled by caller. WALBatcher currently handles serialization (single writer in flush loop).

func NewIOUringBackend

func NewIOUringBackend(path string) (WALBackend, error)

NewIOUringBackend creates a new WALBackend using our custom io_uring library

func NewUringBackend

func NewUringBackend(path string) (WALBackend, error)

NewUringBackend returns an error on non-Linux systems.

func NewWALBackend

func NewWALBackend(path string, preferAsync, directIO bool) (WALBackend, error)

NewWALBackend creates a new WALBackend. It attempts to use io_uring if preferAsync is true and the platform supports it. If directIO is true, it attempts to use Direct I/O (O_DIRECT/F_NOCACHE).

type WALBatcher

type WALBatcher struct {
	ErrCh chan error // Channel for async flush errors
	// contains filtered or unexported fields
}

WALBatcher batches WAL writes for improved performance Instead of fsync on every write, it groups writes and flushes periodically

func NewWALBatcher

func NewWALBatcher(dataPath string, config *WALBatcherConfig) *WALBatcher

NewWALBatcher creates a new batched WAL writer

func (*WALBatcher) AsyncFsyncStats

func (w *WALBatcher) AsyncFsyncStats() *AsyncFsyncerStats

AsyncFsyncStats returns stats from the async fsyncer, or nil if not enabled

func (*WALBatcher) Flush

func (w *WALBatcher) Flush() error

Flush synchronously flushes all pending writes to disk

func (*WALBatcher) FlushError

func (w *WALBatcher) FlushError() error

FlushError returns the last flush error if any

func (*WALBatcher) GetCurrentInterval

func (w *WALBatcher) GetCurrentInterval() time.Duration

GetCurrentInterval returns the current flush interval

func (*WALBatcher) IsAdaptiveEnabled

func (w *WALBatcher) IsAdaptiveEnabled() bool

IsAdaptiveEnabled returns whether adaptive batching is enabled

func (*WALBatcher) IsAsyncFsyncEnabled

func (w *WALBatcher) IsAsyncFsyncEnabled() bool

IsAsyncFsyncEnabled returns true if async fsync is configured and running

func (*WALBatcher) QueueStatus

func (w *WALBatcher) QueueStatus() (pending, batchSize int)

QueueDepth returns the current number of pending entries and the capacity.

func (*WALBatcher) SetReplicator

func (w *WALBatcher) SetReplicator(r WALReplicator)

SetReplicator injects the synchronous WAL replicator for HA deployments.

func (*WALBatcher) Start

func (w *WALBatcher) Start() error

Start initializes the WAL file and starts the background flush goroutine

func (*WALBatcher) Stop

func (w *WALBatcher) Stop() error

Stop gracefully shuts down the batcher, flushing pending writes

func (*WALBatcher) Write

func (w *WALBatcher) Write(rec arrow.RecordBatch, name string, seq uint64, ts int64) error

Write queues a record for batched WAL writing (non-blocking)

type WALBatcherConfig

type WALBatcherConfig struct {
	FlushInterval      time.Duration     // Time between flushes (e.g., 10ms)
	MaxBatchSize       int               // Max entries before forced flush (e.g., 100)
	Adaptive           AdaptiveWALConfig // Adaptive batching configuration
	AsyncFsync         AsyncFsyncConfig  // Async fsync configuration
	UseIOUring         bool              // Use io_uring backend if available
	UseDirectIO        bool              // Use Direct I/O if available
	WALCompression     bool              // Enable block compression
	WALCompressionType string            // "snappy", "zstd", "lz4"
}

WALBatcherConfig configures the batched WAL writer

func DefaultWALBatcherConfig

func DefaultWALBatcherConfig() WALBatcherConfig

DefaultWALBatcherConfig returns sensible defaults

type WALEntry

type WALEntry struct {
	Record    arrow.RecordBatch
	Name      string
	Seq       uint64
	Timestamp int64
}

WALEntry represents a single entry to be written to the WAL

type WALError

type WALError struct {
	Op        string    // Operation: "write", "read", "flush", "truncate"
	Path      string    // WAL file path
	Offset    int64     // Byte offset where error occurred
	Cause     error     // Underlying error
	Timestamp time.Time // When the error occurred
}

WALError provides rich context for Write-Ahead Log operations.

func (*WALError) Error

func (e *WALError) Error() string

func (*WALError) Unwrap

func (e *WALError) Unwrap() error

type WALIterator

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

WALIterator iterators over WAL entries, supporting seeking by Sequence ID and snappy compression.

func NewWALIterator

func NewWALIterator(dir string, mem memory.Allocator) (*WALIterator, error)

func (*WALIterator) Close

func (it *WALIterator) Close() error

func (*WALIterator) Next

func (it *WALIterator) Next() (seq uint64, ts int64, name string, rec arrow.RecordBatch, err error)

Next reads the next entry. Returns io.EOF if done.

func (*WALIterator) NextRaw

func (it *WALIterator) NextRaw() (seq uint64, ts int64, name string, recBytes []byte, err error)

NextRaw returns the raw IPC record bytes without full deserialization where possible.

func (*WALIterator) Seek

func (it *WALIterator) Seek(seq uint64) error

Seek fast-forwards the iterator to the first entry with Sequence > seq. Note: Seek on compressed WALs might be less efficient if it has to decompress blocks. For now, it only seeks file positions between blocks/entries.

type WALReplicator

type WALReplicator interface {
	// Replicate synchronously replicates a WAL batch to remote nodes.
	// It returns an error if the replication fails to meet the quorum.
	// data is the serialized (and potentially compressed) WAL batch.
	Replicate(ctx context.Context, data []byte) error
}

WALReplicator defines the interface for replicating WAL batches to remote nodes.

type WALRingBuffer

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

WALRingBuffer is a lock-free single-producer single-consumer ring buffer optimized for batching WAL entries with minimal contention.

func NewWALRingBuffer

func NewWALRingBuffer(capacity int) *WALRingBuffer

NewWALRingBuffer creates a new ring buffer with the given capacity. Capacity must be a power of 2 for efficient modulo operations.

func (*WALRingBuffer) Cap

func (rb *WALRingBuffer) Cap() int

Cap returns the capacity of the ring buffer.

func (*WALRingBuffer) Drain

func (rb *WALRingBuffer) Drain(dest *[]WALEntry) int

Drain removes all entries from the ring buffer and appends them to the provided slice. Returns the number of entries drained.

func (*WALRingBuffer) Len

func (rb *WALRingBuffer) Len() int

Len returns the current number of entries in the buffer.

func (*WALRingBuffer) Push

func (rb *WALRingBuffer) Push(entry WALEntry) bool

Push adds an entry to the ring buffer. Returns false if the buffer is full.

type WriteRateTracker

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

WriteRateTracker tracks write rate using exponential moving average

func NewWriteRateTracker

func NewWriteRateTracker(window time.Duration) *WriteRateTracker

NewWriteRateTracker creates a tracker with the given averaging window

func (*WriteRateTracker) GetRate

func (t *WriteRateTracker) GetRate() float64

GetRate returns the current estimated write rate (writes per second)

func (*WriteRateTracker) RecordWrite

func (t *WriteRateTracker) RecordWrite()

RecordWrite records a single write operation

Jump to

Keyboard shortcuts

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