Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Oct 13, 2020
1 parent 7525b42 commit 00c5805
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ edition = "2018"

[dependencies]
anyhow = "1.0.33"
log = "0.4.11"
4 changes: 3 additions & 1 deletion src/db_2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;
use anyhow::Result;
use log::warn;

#[path = "db_3.rs"]
mod imp;
Expand Down Expand Up @@ -54,7 +55,8 @@ impl Db {
impl Drop for WriteBatch {
fn drop(&mut self) {
if !self.destructed {
panic!("write batch not committed or aborted");
warn!("write batch dropped without committing or aborting. aborting now");
self.db.abort_batch(self.batch);
}
}
}
Expand Down
39 changes: 36 additions & 3 deletions src/db_3.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use std::sync::Arc;
use std::fs::File;
use std::path::PathBuf;
use std::path::{PathBuf, Path};
use std::collections::BTreeMap;
use anyhow::Result;

mod fs_thread;

use fs_thread::FsThread;

pub struct DbConfig {
pub path: PathBuf,
pub trees: Vec<String>,
Expand All @@ -11,6 +16,7 @@ pub struct DbConfig {
pub struct Db {
config: DbConfig,
stores: BTreeMap<String, Store>,
fs_thread: Arc<FsThread>,
}

struct Store {
Expand All @@ -20,15 +26,36 @@ struct Store {
}

struct Log {
file: File,
path: PathBuf,
fs_thread: Arc<FsThread>,
}

struct Index {
location: BTreeMap<Vec<u8>, u64>,
}

impl Db {
pub async fn open(config: DbConfig) -> Result<Db> { panic!() }
pub async fn open(config: DbConfig) -> Result<Db> {
let fs_thread = FsThread::start()?;
let fs_thread = Arc::new(fs_thread);
let mut stores = BTreeMap::new();

for tree in &config.trees {
let path = tree_path(&config.path, tree)?;
let store = Store::new(path, fs_thread.clone()).await?;
stores.insert(tree.clone(), store);
}

return Ok(Db {
config,
stores,
fs_thread,
});

fn tree_path(dir: &Path, tree: &str) -> Result<PathBuf> {
panic!()
}
}
}

impl Db {
Expand All @@ -50,3 +77,9 @@ impl Db {

pub fn close_view(&self, view: u64) { panic!() }
}

impl Store {
async fn new(path: PathBuf, fs_thread: Arc<FsThread>) -> Result<Store> {
panic!()
}
}
30 changes: 30 additions & 0 deletions src/fs_thread.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use anyhow::Result;

pub struct FsThread;

pub struct FsThreadContext;

impl Drop for FsThread {
fn drop(&mut self) {
self.shutdown();
}
}

impl FsThread {
pub fn start() -> Result<FsThread> {
panic!()
}

pub async fn run<F, R>(&self, f: F) -> Result<R>
where F: FnOnce(&mut FsThreadContext) -> Result<R> + Send,
R: Send,
{
panic!()
}
}

impl FsThread {
fn shutdown(&mut self) {
panic!()
}
}

0 comments on commit 00c5805

Please sign in to comment.