Skip to main content

BlockStore

Trait BlockStore 

Source
pub trait BlockStore: Send + Sync {
    // Required methods
    fn block_size(&self) -> usize;
    fn total_blocks(&self) -> u64;
    fn read_block(&self, block_id: u64) -> FsResult<Vec<u8>>;
    fn write_block(&self, block_id: u64, data: &[u8]) -> FsResult<()>;

    // Provided methods
    fn sync(&self) -> FsResult<()> { ... }
    fn read_blocks(&self, block_ids: &[u64]) -> FsResult<Vec<Vec<u8>>> { ... }
    fn write_blocks(&self, blocks: &[(u64, &[u8])]) -> FsResult<()> { ... }
}
Expand description

Trait for a fixed-size block store backend. All blocks are the same size. Block IDs are u64.

Required Methods§

Source

fn block_size(&self) -> usize

Block size in bytes.

Source

fn total_blocks(&self) -> u64

Total number of blocks in the store.

Source

fn read_block(&self, block_id: u64) -> FsResult<Vec<u8>>

Read a full block. Returns exactly block_size() bytes.

Source

fn write_block(&self, block_id: u64, data: &[u8]) -> FsResult<()>

Write a full block. data must be exactly block_size() bytes.

Provided Methods§

Source

fn sync(&self) -> FsResult<()>

Sync / flush all writes. No-op for in-memory stores.

Source

fn read_blocks(&self, block_ids: &[u64]) -> FsResult<Vec<Vec<u8>>>

Read multiple blocks in one call.

The default implementation reads them sequentially; network-backed stores should override this with pipelined I/O.

Source

fn write_blocks(&self, blocks: &[(u64, &[u8])]) -> FsResult<()>

Write multiple blocks in one call.

The default implementation writes them sequentially; network-backed stores should override this with pipelined I/O.

Implementors§