helyim/helyim

Support async file operations

Opened this issue · 1 comments

To facilitate file operations with tokio_uring, it is essential to initially transform synchronous file operations into asynchronous ones, and then envelop the unified file operations of tokio and tokio_uring for integration.

tokio dont' have read_at/write_at methods, it hard to read/append file between multiple threads at same time. see Feature request: read_at/write_at for tokio::fs::File

At present, it should use std::os::unix::fs::FileExt when using tokio, just like this:

use std::{fs::File, os::unix::fs::FileExt};

pub async fn read_index_entry_at_offset(index_file: &File, offset: u64) -> Result<Vec<u8>, VolumeError> {
    let mut buf = vec![0u8; NEEDLE_INDEX_SIZE as usize];
    index_file.read_at(&mut buf, offset)?;
    Ok(buf)
}

when using tokio_uring, the code should be:

use tokio_uring::fs::File;

pub async fn read_index_entry_at_offset(index_file: &File, offset: u64) -> Result<Vec<u8>, VolumeError> {
    let mut buf = vec![0u8; NEEDLE_INDEX_SIZE as usize];
    index_file.read_at(&mut buf, offset).await?;
    Ok(buf)
}