Skip to content

Commit

Permalink
refactor(storage): cell writer for pesistent and shard states
Browse files Browse the repository at this point in the history
  • Loading branch information
pashinov committed Mar 5, 2024
1 parent ccf97f9 commit 2fccfea
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 489 deletions.
28 changes: 24 additions & 4 deletions storage/src/db/file_db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fs::File;
use std::io::Write;
use std::io::{Read, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};

use anyhow::{Context, Result};
Expand All @@ -10,8 +10,8 @@ pub use mapped_file::MappedFile;
mod mapped_file;

pub struct FileDb {
pub file: File,
pub path: PathBuf,
file: File,
path: PathBuf,
}

impl FileDb {
Expand All @@ -25,7 +25,7 @@ impl FileDb {
.truncate(true)
.read(true)
.open(&path)
.context("Failed to create file")?;
.context(format!("Failed to create file {:?}", path.as_ref()))?;

Ok(Self {
file,
Expand All @@ -47,4 +47,24 @@ impl FileDb {
self.file.flush()?;
Ok(())
}

pub fn seek(&mut self, pos: SeekFrom) -> Result<()> {
self.file.seek(pos)?;
Ok(())
}

pub fn file(&self) -> &File {
&self.file
}

pub fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
let bytes = self.file.read(buf)?;
Ok(bytes)
}
}

impl Into<File> for FileDb {
fn into(self) -> File {
self.file
}
}
Loading

0 comments on commit 2fccfea

Please sign in to comment.