pub struct BlockStorage { /* private fields */ }Implementations§
Source§impl BlockStorage
impl BlockStorage
Sourcepub fn enable_auto_sync(&mut self, interval_ms: u64)
pub fn enable_auto_sync(&mut self, interval_ms: u64)
Enable automatic background syncing of dirty blocks. Interval in milliseconds.
Sourcepub fn enable_auto_sync_with_policy(&mut self, policy: SyncPolicy)
pub fn enable_auto_sync_with_policy(&mut self, policy: SyncPolicy)
Enable automatic background syncing using a SyncPolicy
Sourcepub fn disable_auto_sync(&mut self)
pub fn disable_auto_sync(&mut self)
Disable automatic background syncing.
Sourcepub fn get_sync_count(&self) -> u64
pub fn get_sync_count(&self) -> u64
Get the number of completed sync operations (native only metric)
Sourcepub fn get_timer_sync_count(&self) -> u64
pub fn get_timer_sync_count(&self) -> u64
Get the number of timer-based background syncs
Sourcepub fn get_debounce_sync_count(&self) -> u64
pub fn get_debounce_sync_count(&self) -> u64
Get the number of debounce-based background syncs
Sourcepub fn get_last_sync_duration_ms(&self) -> u64
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
impl BlockStorage
pub async fn new(db_name: &str) -> Result<Self, DatabaseError>
pub async fn new_with_capacity( db_name: &str, capacity: usize, ) -> Result<Self, DatabaseError>
pub async fn new_with_recovery_options( db_name: &str, recovery_opts: RecoveryOptions, ) -> Result<Self, DatabaseError>
pub fn get_recovery_report(&self) -> &RecoveryReport
pub fn now_millis() -> u64
Sourcepub fn read_block_sync(
&mut self,
block_id: u64,
) -> Result<Vec<u8>, DatabaseError>
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)
pub async fn read_block( &mut self, block_id: u64, ) -> Result<Vec<u8>, DatabaseError>
Sourcepub fn write_block_sync(
&mut self,
block_id: u64,
data: Vec<u8>,
) -> Result<(), DatabaseError>
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)
pub async fn write_block( &mut self, block_id: u64, data: Vec<u8>, ) -> Result<(), DatabaseError>
Sourcepub fn write_blocks_sync(
&mut self,
items: Vec<(u64, Vec<u8>)>,
) -> Result<(), DatabaseError>
pub fn write_blocks_sync( &mut self, items: Vec<(u64, Vec<u8>)>, ) -> Result<(), DatabaseError>
Synchronous batch write of blocks
Sourcepub async fn write_blocks(
&mut self,
items: Vec<(u64, Vec<u8>)>,
) -> Result<(), DatabaseError>
pub async fn write_blocks( &mut self, items: Vec<(u64, Vec<u8>)>, ) -> Result<(), DatabaseError>
Async batch write wrapper
Sourcepub fn read_blocks_sync(
&mut self,
block_ids: &[u64],
) -> Result<Vec<Vec<u8>>, DatabaseError>
pub fn read_blocks_sync( &mut self, block_ids: &[u64], ) -> Result<Vec<Vec<u8>>, DatabaseError>
Synchronous batch read of blocks, preserving input order
Sourcepub async fn read_blocks(
&mut self,
block_ids: &[u64],
) -> Result<Vec<Vec<u8>>, DatabaseError>
pub async fn read_blocks( &mut self, block_ids: &[u64], ) -> Result<Vec<Vec<u8>>, DatabaseError>
Async batch read wrapper
Sourcepub fn get_block_checksum(&self, block_id: u64) -> Option<u32>
pub fn get_block_checksum(&self, block_id: u64) -> Option<u32>
Get block checksum for verification
pub async fn verify_block_checksum( &mut self, block_id: u64, ) -> Result<(), DatabaseError>
pub fn get_block_metadata_for_testing(&self) -> HashMap<u64, (u64, u32, u64)>
pub fn set_block_checksum_for_testing(&mut self, block_id: u64, checksum: u64)
pub async fn sync(&mut self) -> Result<(), DatabaseError>
Sourcepub fn sync_now(&mut self) -> Result<(), DatabaseError>
pub fn sync_now(&mut self) -> Result<(), DatabaseError>
Synchronous version of sync() for immediate persistence
Sourcepub fn drain_and_shutdown(&mut self)
pub fn drain_and_shutdown(&mut self)
Drain all pending dirty blocks and stop background auto-sync (if enabled). Safe to call multiple times.
pub fn clear_cache(&mut self)
Sourcepub async fn on_database_import(&mut self) -> Result<(), DatabaseError>
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 successfullyErr(DatabaseError)- If cache clearing fails
§Example
let mut storage = BlockStorage::new("mydb").await?;
// ... database is imported externally ...
storage.on_database_import().await?;pub fn get_cache_size(&self) -> usize
pub fn get_dirty_count(&self) -> usize
pub fn is_cached(&self, block_id: u64) -> bool
Sourcepub async fn allocate_block(&mut self) -> Result<u64, DatabaseError>
pub async fn allocate_block(&mut self) -> Result<u64, DatabaseError>
Allocate a new block and return its ID
Sourcepub async fn deallocate_block(
&mut self,
block_id: u64,
) -> Result<(), DatabaseError>
pub async fn deallocate_block( &mut self, block_id: u64, ) -> Result<(), DatabaseError>
Deallocate a block and mark it as available for reuse
Sourcepub fn get_allocated_count(&self) -> usize
pub fn get_allocated_count(&self) -> usize
Get the number of currently allocated blocks
Sourcepub fn get_metrics(&self) -> StorageMetrics
pub fn get_metrics(&self) -> StorageMetrics
Get comprehensive metrics for observability
Sourcepub fn set_sync_callbacks(
&mut self,
on_sync_start: SyncStartCallback,
on_sync_success: SyncSuccessCallback,
on_sync_failure: SyncFailureCallback,
)
pub fn set_sync_callbacks( &mut self, on_sync_start: SyncStartCallback, on_sync_success: SyncSuccessCallback, on_sync_failure: SyncFailureCallback, )
Set sync event callbacks
Sourcepub fn set_backpressure_callback(&mut self, callback: BackpressureCallback)
pub fn set_backpressure_callback(&mut self, callback: BackpressureCallback)
Set backpressure callback
Sourcepub fn set_error_callback(&mut self, callback: ErrorCallback)
pub fn set_error_callback(&mut self, callback: ErrorCallback)
Set error callback
Sourcepub fn is_auto_sync_enabled(&self) -> bool
pub fn is_auto_sync_enabled(&self) -> bool
Check if auto-sync is currently enabled
Sourcepub fn get_sync_policy(&self) -> Option<SyncPolicy>
pub fn get_sync_policy(&self) -> Option<SyncPolicy>
Get the current sync policy (if any)
Sourcepub async fn force_sync(&mut self) -> Result<(), DatabaseError>
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
impl BlockStorage
Sourcepub fn get_storage_info(&self) -> BlockStorageInfo
pub fn get_storage_info(&self) -> BlockStorageInfo
Get comprehensive block storage information for the viewer