BlockStorage

Struct BlockStorage 

Source
pub struct BlockStorage { /* private fields */ }

Implementations§

Source§

impl BlockStorage

Source

pub fn enable_auto_sync(&mut self, interval_ms: u64)

Enable automatic background syncing of dirty blocks. Interval in milliseconds.

Source

pub fn enable_auto_sync_with_policy(&mut self, policy: SyncPolicy)

Enable automatic background syncing using a SyncPolicy

Source

pub fn disable_auto_sync(&mut self)

Disable automatic background syncing.

Source

pub fn get_sync_count(&self) -> u64

Get the number of completed sync operations (native only metric)

Source

pub fn get_timer_sync_count(&self) -> u64

Get the number of timer-based background syncs

Source

pub fn get_debounce_sync_count(&self) -> u64

Get the number of debounce-based background syncs

Source

pub fn get_last_sync_duration_ms(&self) -> u64

Get the duration in ms of the last sync operation (>=1 when a sync occurs)

Source§

impl BlockStorage

Source

pub async fn new(db_name: &str) -> Result<Self, DatabaseError>

Source

pub async fn new_with_capacity( db_name: &str, capacity: usize, ) -> Result<Self, DatabaseError>

Source

pub async fn new_with_recovery_options( db_name: &str, recovery_opts: RecoveryOptions, ) -> Result<Self, DatabaseError>

Source

pub fn get_recovery_report(&self) -> &RecoveryReport

Source

pub fn now_millis() -> u64

Source

pub fn read_block_sync( &mut self, block_id: u64, ) -> Result<Vec<u8>, DatabaseError>

Synchronous block read for environments that require sync access (e.g., VFS callbacks)

Source

pub async fn read_block( &mut self, block_id: u64, ) -> Result<Vec<u8>, DatabaseError>

Source

pub fn write_block_sync( &mut self, block_id: u64, data: Vec<u8>, ) -> Result<(), DatabaseError>

Synchronous block write for environments that require sync access (e.g., VFS callbacks)

Source

pub async fn write_block( &mut self, block_id: u64, data: Vec<u8>, ) -> Result<(), DatabaseError>

Source

pub fn write_blocks_sync( &mut self, items: Vec<(u64, Vec<u8>)>, ) -> Result<(), DatabaseError>

Synchronous batch write of blocks

Source

pub async fn write_blocks( &mut self, items: Vec<(u64, Vec<u8>)>, ) -> Result<(), DatabaseError>

Async batch write wrapper

Source

pub fn read_blocks_sync( &mut self, block_ids: &[u64], ) -> Result<Vec<Vec<u8>>, DatabaseError>

Synchronous batch read of blocks, preserving input order

Source

pub async fn read_blocks( &mut self, block_ids: &[u64], ) -> Result<Vec<Vec<u8>>, DatabaseError>

Async batch read wrapper

Source

pub fn get_block_checksum(&self, block_id: u64) -> Option<u32>

Get block checksum for verification

Source

pub async fn verify_block_checksum( &mut self, block_id: u64, ) -> Result<(), DatabaseError>

Source

pub fn get_block_metadata_for_testing(&self) -> HashMap<u64, (u64, u32, u64)>

Source

pub fn set_block_checksum_for_testing(&mut self, block_id: u64, checksum: u64)

Source

pub async fn sync(&mut self) -> Result<(), DatabaseError>

Source

pub fn sync_now(&mut self) -> Result<(), DatabaseError>

Synchronous version of sync() for immediate persistence

Source

pub fn drain_and_shutdown(&mut self)

Drain all pending dirty blocks and stop background auto-sync (if enabled). Safe to call multiple times.

Source

pub fn clear_cache(&mut self)

Source

pub async fn on_database_import(&mut self) -> Result<(), DatabaseError>

Handle notification that the database has been imported

This method should be called after a database import to ensure that any cached data is invalidated and fresh data is read from storage.

§Returns
  • Ok(()) - Cache cleared successfully
  • Err(DatabaseError) - If cache clearing fails
§Example
let mut storage = BlockStorage::new("mydb").await?;
// ... database is imported externally ...
storage.on_database_import().await?;
Source

pub fn get_cache_size(&self) -> usize

Source

pub fn get_dirty_count(&self) -> usize

Source

pub fn is_cached(&self, block_id: u64) -> bool

Source

pub async fn allocate_block(&mut self) -> Result<u64, DatabaseError>

Allocate a new block and return its ID

Source

pub async fn deallocate_block( &mut self, block_id: u64, ) -> Result<(), DatabaseError>

Deallocate a block and mark it as available for reuse

Source

pub fn get_allocated_count(&self) -> usize

Get the number of currently allocated blocks

Source

pub fn get_metrics(&self) -> StorageMetrics

Get comprehensive metrics for observability

Source

pub fn set_sync_callbacks( &mut self, on_sync_start: SyncStartCallback, on_sync_success: SyncSuccessCallback, on_sync_failure: SyncFailureCallback, )

Set sync event callbacks

Source

pub fn set_backpressure_callback(&mut self, callback: BackpressureCallback)

Set backpressure callback

Source

pub fn set_error_callback(&mut self, callback: ErrorCallback)

Set error callback

Source

pub fn is_auto_sync_enabled(&self) -> bool

Check if auto-sync is currently enabled

Source

pub fn get_sync_policy(&self) -> Option<SyncPolicy>

Get the current sync policy (if any)

Source

pub async fn force_sync(&mut self) -> Result<(), DatabaseError>

Force synchronization with durability guarantees

This method ensures that all dirty blocks are persisted to durable storage (IndexedDB in WASM, filesystem in native) and waits for the operation to complete. This is called by VFS xSync to provide SQLite’s durability guarantees.

Source§

impl BlockStorage

Source

pub fn get_storage_info(&self) -> BlockStorageInfo

Get comprehensive block storage information for the viewer

Trait Implementations§

Source§

impl Drop for BlockStorage

Available on non-WebAssembly only.
Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.