Remove unused deps

Also simplified new instance check
next
Sayan Nandan 3 years ago
parent 5a0d3017a5
commit 891f9a2e06

@ -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"

@ -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<u8, $len> = 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<u8, 5>, Array<u8, 5>> = 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() {

@ -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<K, V> Coremap<K, V>
where
K: Eq + Hash + Serialize,
V: Serialize,
{
/// Serialize the hashtable into a `Vec<u8>` that can be saved to a file
pub fn serialize(&self) -> TResult<Vec<u8>> {
bincode::serialize(&self.inner).map_err(|e| e.into())
}
}
impl Coremap<Data, Data> {
/// Returns atleast `count` number of keys from the hashtable
pub fn get_keys(&self, count: usize) -> Vec<Bytes> {
@ -198,19 +185,8 @@ impl Coremap<Data, Data> {
.for_each(|key| v.push(key));
v
}
/// Returns a `Coremap<Data, Data>` from the provided file (as a `Vec<u8>`)
pub fn deserialize(src: Vec<u8>) -> TResult<Self> {
let h: HashTable<Data, Data> = bincode::deserialize(&src)?;
Ok(Self { inner: h })
}
}
impl<const M: usize, const N: usize> Coremap<Array<u8, M>, Array<u8, N>> {
#[cfg(test)]
pub fn deserialize_array(bytes: Vec<u8>) -> TResult<Self> {
let h: HashTable<Array<u8, M>, Array<u8, N>> = bincode::deserialize(&bytes)?;
Ok(Self { inner: h })
}
}
impl<K: Eq + Hash, V> IntoIterator for Coremap<K, V> {
type Item = (K, V);
type IntoIter = dashmap::iter::OwningIter<K, V>;

@ -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<ObjectID>;
@ -116,7 +117,7 @@ pub fn read_preload() -> IoResult<PreloadSet> {
/// 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<Memstore> {
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<Memstore> {
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<bool> {
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())
}

Loading…
Cancel
Save