Skip to content

Commit bd7ee08

Browse files
committed
renamed Store, State structs. Store is now lock protected
1 parent 1935cfd commit bd7ee08

File tree

12 files changed

+110
-80
lines changed

12 files changed

+110
-80
lines changed

crates/mojo-cli/src/commit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use anyhow::Error;
2-
use mojokv::KVStore;
2+
use mojokv::Store;
33

44
pub fn cmd(kvpath: &std::path::Path) -> Result<(), Error> {
5-
let mut st = KVStore::writable(&kvpath, false, None, None)?;
5+
let st = Store::writable(&kvpath, false, None, None)?;
66

77
println!("active version before commit: {}", st.active_ver());
88
let new_ver = st.commit()?;

crates/mojo-cli/src/iget.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use anyhow::Error;
2-
use mojokv::{KVStore,BucketOpenMode};
2+
use mojokv::{Store,BucketOpenMode};
33

44
pub fn cmd(kvpath: &std::path::Path, bucket: &str, ver: u32, key: u32) -> Result<(), Error> {
5-
let mut st = KVStore::readonly(&kvpath, ver)?;
5+
let st = Store::readonly(&kvpath, ver)?;
66
let b = st.open(bucket, BucketOpenMode::Read)?;
77

88
println!("Max key: {}", b.max_key());

crates/mojo-cli/src/iview.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use anyhow::Error;
2-
use mojokv::{KVStore};
2+
use mojokv::{Store};
33

44
pub fn cmd(kvpath: &std::path::Path, name: &str, ver: u32, additional: bool, keys: bool) -> Result<(), Error> {
5-
let st = KVStore::readonly(kvpath, ver)?;
5+
let st = Store::readonly(kvpath, ver)?;
66
let ret = st.get_index(name)?; //Bucket::load_index(&kvpath, name, ver)?;
77

88
if ret.is_none() {
@@ -14,7 +14,7 @@ pub fn cmd(kvpath: &std::path::Path, name: &str, ver: u32, additional: bool, key
1414
let h = i.header();
1515

1616
let st = if additional {
17-
Some(KVStore::load_state(kvpath)?)
17+
Some(Store::load_state(kvpath)?)
1818
}else{
1919
None
2020
};

crates/mojo-cli/src/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use anyhow::Error;
2-
use mojokv::{self, KVStore};
2+
use mojokv::{self, Store};
33
use std::mem::size_of;
44

55
pub fn cmd(kvpath: &std::path::Path, additional: bool) -> Result<(), Error> {
6-
let st = KVStore::load_state(kvpath)?;
6+
let st = Store::load_state(kvpath)?;
77

88
println!("Format version : {}", st.format_ver());
99
println!("Minimum version : {}", st.min_ver());
@@ -14,7 +14,7 @@ pub fn cmd(kvpath: &std::path::Path, additional: bool) -> Result<(), Error> {
1414

1515
if additional {
1616
println!("----------------------------");
17-
println!("Size of KVStore : {} bytes", size_of::<KVStore>());
17+
println!("Size of KVStore : {} bytes", size_of::<Store>());
1818
println!("Size of MemIndex : {} bytes", size_of::<mojokv::index::mem::MemIndex>());
1919
println!("Size of KeyMap : {} bytes", size_of::<mojokv::KeyMap>());
2020
println!("Size of Value : {} bytes", size_of::<mojokv::Value>());

crates/mojofs/src/vfs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::open_options::*;
55
use std::collections::HashMap;
66
use crate::kvfile::{KVFile, KVFileOpt};
77
use crate::vfsfile::FileImpl;
8-
use mojokv::{KVStore, BucketOpenMode};
8+
use mojokv::{Store, BucketOpenMode};
99

1010
use crate::vfsfile::VFSFile;
1111

@@ -17,7 +17,7 @@ pub enum AccessCheck {
1717

1818
#[derive(Default)]
1919
pub struct VFS {
20-
store: Option<KVStore>,
20+
store: Option<Store>,
2121
file_counter: usize,
2222
fopt: FSOptions,
2323
}
@@ -41,10 +41,10 @@ impl VFS {
4141
self.fopt = FSOptions::parse(params)?;
4242
let root_path = Path::new(root_path);
4343
if opt.access == OpenAccess::Read {
44-
self.store = Some(KVStore::readonly(root_path, self.fopt.ver)?);
44+
self.store = Some(Store::readonly(root_path, self.fopt.ver)?);
4545
log::debug!("store opened in readonly mode");
4646
}else{
47-
self.store = Some(KVStore::writable(root_path, true, Some(self.fopt.pagesz), Some(self.fopt.pps))?);
47+
self.store = Some(Store::writable(root_path, true, Some(self.fopt.pagesz), Some(self.fopt.pps))?);
4848
log::debug!("store opened writable mode");
4949
}
5050

crates/mojokv/src/bmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct BucketMap {
1313
}
1414

1515
impl BucketMap {
16-
pub fn add(&mut self, name: &str, ver: u32) {
16+
pub fn add(&self, name: &str, ver: u32) {
1717
log::debug!("add name={} ver={} {:?}", name, ver, self.map);
1818
let mut map = self.map.write();
1919
//self.buckets.insert(name.to_owned(), b);
@@ -31,7 +31,7 @@ impl BucketMap {
3131
map.get(name).map(|v| *v)
3232
}
3333

34-
pub fn delete(&mut self, root_path: &Path, name: &str, ver: u32) -> Result<(), Error> {
34+
pub fn delete(&self, root_path: &Path, name: &str, ver: u32) -> Result<(), Error> {
3535
log::debug!("delete name={} {:?}", name, self.map);
3636
let mut map = self.map.write();
3737

crates/mojokv/src/bucket.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{Error, BucketMap};
55
use mojoio::nix::NixFile;
66
use crate::index::mem::MemIndex;
77
use crate::value::Value;
8-
use crate::state::KVState;
8+
use crate::state::State;
99

1010
pub struct BucketInner {
1111
name: String,
@@ -39,15 +39,15 @@ impl BucketInner {
3939
}
4040

4141
pub struct Bucket {
42-
state: KVState,
42+
state: State,
4343
//inner: Arc<RwLock<BucketInner>>,
4444
inner: BucketInner,
4545
bmap: BucketMap,
4646
is_write: bool,
4747
}
4848

4949
impl Bucket {
50-
fn with_inner(state: KVState, inner: BucketInner, bmap: BucketMap) -> Self {
50+
fn with_inner(state: State, inner: BucketInner, bmap: BucketMap) -> Self {
5151
Bucket {
5252
state,
5353
//inner: Arc::new(RwLock::new(inner)),
@@ -61,7 +61,7 @@ impl Bucket {
6161
self.is_write = true
6262
}
6363

64-
pub fn readonly(root_path: &Path, name: &str, ver: u32, state: KVState, bmap: BucketMap) -> Result<Bucket, Error> {
64+
pub fn readonly(root_path: &Path, name: &str, ver: u32, state: State, bmap: BucketMap) -> Result<Bucket, Error> {
6565
log::debug!("bucket name={} readonly at ver={}", name, ver);
6666

6767
let b = Self::load(root_path, name, state, bmap, ver)?;
@@ -87,7 +87,7 @@ impl Bucket {
8787
self.inner.is_modified
8888
}
8989

90-
pub fn writable(root_path: &Path, name: &str, state: KVState, bmap: BucketMap, load_ver: u32) -> Result<Bucket, Error> {
90+
pub fn writable(root_path: &Path, name: &str, state: State, bmap: BucketMap, load_ver: u32) -> Result<Bucket, Error> {
9191
log::debug!("mojo initing bucket pps={}", state.pps());
9292

9393
let aver = state.active_ver();
@@ -110,7 +110,7 @@ impl Bucket {
110110
Ok(b)
111111
}
112112

113-
pub fn load(root_path: &Path, name: &str, state: KVState, bmap: BucketMap, ver: u32) -> Result<Self, Error> {
113+
pub fn load(root_path: &Path, name: &str, state: State, bmap: BucketMap, ver: u32) -> Result<Self, Error> {
114114
log::debug!("loading bucket={} version={}", name, ver);
115115

116116
if ver < state.min_ver() || ver > state.active_ver() {
@@ -152,7 +152,7 @@ impl Bucket {
152152
Ok(index)
153153
}
154154

155-
pub fn new(root_path: &Path, name: &str, state: KVState, bmap: BucketMap) -> Result<Self, Error> {
155+
pub fn new(root_path: &Path, name: &str, state: State, bmap: BucketMap) -> Result<Self, Error> {
156156
log::debug!("creating new bucket name={} at ver={}", name, state.active_ver());
157157

158158
let _ = std::fs::create_dir_all(root_path)?;

crates/mojokv/src/index/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub mod mem;
2-
use std::{collections::HashSet, hash::Hash};
2+
use std::collections::HashSet;
33

44
use crate::Error;
55
use crate::value::Value;

crates/mojokv/src/keymap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
use std::{collections::HashSet, hash::Hash};
2+
use std::collections::HashSet;
33
use crate::value::{Value, Slot};
44
use serde::{Serialize, Deserialize};
55

crates/mojokv/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use bucket::Bucket;
1515
pub use bmap::BucketMap;
1616
pub use keymap::KeyMap;
1717
pub use value::{Value, Slot};
18-
pub use store::{KVStore, BucketOpenMode};
18+
pub use store::{Store, BucketOpenMode};
1919

2020

2121
//TODO: Pass pps from single place

0 commit comments

Comments
 (0)