diff --git a/server/Cargo.toml b/server/Cargo.toml index a02aa1ef..c93c3468 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -13,7 +13,6 @@ sky_macros = { path = "../sky-macros" } tokio = { version = "1.9.0", features = ["full"] } bytes = "1.0.1" libsky = { path = "../libsky" } -bincode = "1.3.3" dashmap = { version = "4.0.2", features = ["serde", "raw-api"] } serde = { version = "1.0.126", features = ["derive"] } toml = "0.5.8" @@ -46,6 +45,7 @@ skytable = { git = "https://github.com/skytable/client-rust", features = [ # external deps tokio = { version = "1.9.0", features = ["test-util"] } rand = "0.8.4" +bincode = "1.3.3" [target.'cfg(unix)'.dependencies] # external deps libc = "0.2.98" diff --git a/server/src/corestore/array.rs b/server/src/corestore/array.rs index d59ce06f..369b30b3 100644 --- a/server/src/corestore/array.rs +++ b/server/src/corestore/array.rs @@ -652,29 +652,6 @@ fn test_uninitialized() { assert_eq!(b.iter().count(), 1); } -#[cfg(test)] -macro_rules! array_from_string { - ($st:expr, $len:expr) => {{ - let mut array: Array = Array::new(); - $st.chars().into_iter().for_each(|ch| array.push(ch as u8)); - array - }}; -} - -#[test] -fn test_map_serialize_deserialize() { - use crate::corestore::htable::Coremap; - let map = Coremap::new(); - map.true_if_insert( - array_from_string!("hello", 5), - array_from_string!("sayan", 5), - ); - let ret = map.serialize().unwrap(); - let bc: Coremap, Array> = Coremap::deserialize_array(ret).unwrap(); - assert!(bc.len() == map.len()); - assert!(bc.into_iter().all(|(k, _v)| { map.contains_key(&k) })); -} - #[test] #[should_panic] fn test_array_overflow() { diff --git a/server/src/corestore/htable.rs b/server/src/corestore/htable.rs index c8b902ae..d8294405 100644 --- a/server/src/corestore/htable.rs +++ b/server/src/corestore/htable.rs @@ -24,9 +24,7 @@ * */ -use crate::corestore::array::Array; use bytes::Bytes; -use libsky::TResult; use serde::{Deserialize, Serialize}; use std::borrow::Borrow; use std::collections::hash_map::RandomState; @@ -177,17 +175,6 @@ where } } -impl Coremap -where - K: Eq + Hash + Serialize, - V: Serialize, -{ - /// Serialize the hashtable into a `Vec` that can be saved to a file - pub fn serialize(&self) -> TResult> { - bincode::serialize(&self.inner).map_err(|e| e.into()) - } -} - impl Coremap { /// Returns atleast `count` number of keys from the hashtable pub fn get_keys(&self, count: usize) -> Vec { @@ -198,19 +185,8 @@ impl Coremap { .for_each(|key| v.push(key)); v } - /// Returns a `Coremap` from the provided file (as a `Vec`) - pub fn deserialize(src: Vec) -> TResult { - let h: HashTable = bincode::deserialize(&src)?; - Ok(Self { inner: h }) - } -} -impl Coremap, Array> { - #[cfg(test)] - pub fn deserialize_array(bytes: Vec) -> TResult { - let h: HashTable, Array> = bincode::deserialize(&bytes)?; - Ok(Self { inner: h }) - } } + impl IntoIterator for Coremap { type Item = (K, V); type IntoIter = dashmap::iter::OwningIter; diff --git a/server/src/storage/unflush.rs b/server/src/storage/unflush.rs index 9816e829..d8de61a3 100644 --- a/server/src/storage/unflush.rs +++ b/server/src/storage/unflush.rs @@ -41,6 +41,7 @@ use crate::SnapshotConfig; use std::fs; use std::io::Error as IoError; use std::io::ErrorKind; +use std::path::Path; use std::sync::Arc; type PreloadSet = std::collections::HashSet; @@ -116,7 +117,7 @@ pub fn read_preload() -> IoResult { /// is also created. If this is an already initialized instance then the store /// is read and returned (and any possible errors that are encountered are returned) pub fn read_full(snapshot_config: &SnapshotConfig) -> IoResult { - if is_new_instance()? { + if is_new_instance() { // init an empty store let store = Memstore::new_default(); // fine, so we need to create the tree @@ -132,13 +133,8 @@ pub fn read_full(snapshot_config: &SnapshotConfig) -> IoResult { Ok(Memstore::init_with_all(ksmap, snapshot_config)) } -/// Check if the data directory exists (if not: we're on a new instance) -pub fn is_new_instance() -> IoResult { - match fs::read_dir("data") { - Ok(_) => Ok(false), - Err(e) => match e.kind() { - ErrorKind::NotFound => Ok(true), - _ => Err(e), - }, - } +/// Check if the data/PRELOAD file exists (if not: we're on a new instance) +pub fn is_new_instance() -> bool { + let path = Path::new("data/PRELOAD"); + !(path.exists() && path.is_file()) }