DiskDriver

Struct DiskDriver 

Source
pub struct DiskDriver<T: Clone> { /* private fields */ }
Expand description

MST walker that reads from disk instead of an in-memory hashmap

Implementations§

Source§

impl<T: Processable + Send + 'static> DiskDriver<T>

Source

pub async fn next_chunk( &mut self, n: usize, ) -> Result<Option<BlockChunk<T>>, DriveError>

Walk the MST returning up to n rkey + record pairs

while let Some(pairs) = disk_driver.next_chunk(256).await? {
    for (rkey, record) in pairs {
        println!("{rkey}: size={}", record.len());
    }
}
let store = disk_driver.reset_store().await?;
Source

pub fn to_channel( self, n: usize, ) -> (Receiver<Result<BlockChunk<T>, DriveError>>, JoinHandle<Self>)

Spawn the disk reading task into a tokio blocking thread

The idea is to avoid so much sending back and forth to the blocking thread, letting a blocking task do all the disk reading work and sending records and rkeys back through an mpsc channel instead.

This might also allow the disk work to continue while processing the records. It’s still not yet clear if this method actually has much benefit over just using .next_chunk(n).

let (mut rx, join) = disk_driver.to_channel(512);
while let Some(recvd) = rx.recv().await {
    let pairs = recvd?;
    for (rkey, record) in pairs {
        println!("{rkey}: size={}", record.len());
    }

}
let store = join.await?.reset_store().await?;
Source

pub async fn reset_store(self) -> Result<DiskStore, DriveError>

Reset the disk storage so it can be reused. You must call this.

Ideally we’d put this in an impl Drop, but since it makes blocking calls, that would be risky in an async context. For now you just have to carefully make sure you call it.

The sqlite store is returned, so it can be reused for another DiskDriver.

Auto Trait Implementations§

§

impl<T> !Freeze for DiskDriver<T>

§

impl<T> !RefUnwindSafe for DiskDriver<T>

§

impl<T> Send for DiskDriver<T>

§

impl<T> !Sync for DiskDriver<T>

§

impl<T> Unpin for DiskDriver<T>

§

impl<T> !UnwindSafe for DiskDriver<T>

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> Same for T

Source§

type Output = T

Should always be Self
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.