/** * Storage Engine - Main orchestrator for WAL-based embedding storage. * * Implements the write path: data → fsync → WAL → fsync → index * Handles recovery on startup by rebuilding index from WAL. * * Uses operation-level locking: locks are acquired per write operation * and released immediately after, rather than held for the engine lifetime. */ import type { CompactionResult, DataRecord, RecordLocation, StorageEngineOptions, OpType } from './types'; export declare class StorageEngine { private readonly dataPath; private readonly walPath; private readonly lockPath; private readonly lockTimeout; private readonly dimension; private readonly readOnly; private wal; private index; private readonly writeMutex; private dataHandle; private dataHandlePromise; private sequenceCounter; private constructor(); /** * Create or open a storage engine. * Performs recovery if WAL exists. * * Note: Creating an engine does NOT acquire any lock. Locks are acquired * per write operation and released immediately after. */ static create(options: StorageEngineOptions): Promise; /** * Check if a database file needs migration from v1 format. */ private static checkNeedsMigration; /** * Write a record to storage. * Implements: lock → data → fsync → WAL → fsync → index → unlock * * Acquires a file lock for the duration of the write operation, * then releases it immediately after. */ writeRecord(key: string, embedding: Float32Array, op?: OpType): Promise; /** * Read a record by key. * O(1) lookup via index. */ readRecord(key: string): Promise; /** * Delete a record by key. * Logical delete - writes a delete marker to WAL. */ deleteRecord(key: string): Promise; /** * Check if a key exists. */ hasKey(key: string): boolean; /** * Get all keys. */ keys(): IterableIterator; /** * Iterate over all locations for search. */ locations(): IterableIterator<[string, RecordLocation]>; /** * Get the number of records. */ count(): number; /** * Read the embedding at a specific offset (for search optimization). */ readEmbeddingAt(offset: number): Promise; /** * Get the embedding dimension. */ getDimension(): number; /** * Compact the database by rewriting only live records. * Removes dead records (deletes, superseded updates) and rebuilds the WAL. */ compact(): Promise; /** * Count all records in the data file (including dead ones). */ private countAllRecords; /** * Close the storage engine. */ close(): Promise; /** * Check if the storage engine is in read-only mode. */ isReadOnly(): boolean; /** * Append data to the data file. */ private appendToDataFile; /** * Read a record at a specific offset. */ private readRecordAt; /** * Get or open the data file handle. * Uses promise-based locking to prevent race conditions in concurrent access. */ private getDataHandle; } //# sourceMappingURL=storage-engine.d.ts.map