diff --git a/libsky/src/lib.rs b/libsky/src/lib.rs index 937ccff9..00431bf3 100644 --- a/libsky/src/lib.rs +++ b/libsky/src/lib.rs @@ -27,7 +27,7 @@ #![deny(unused_crate_dependencies)] #![deny(unused_imports)] -//! The core library for the Skytable +//! The core library for Skytable //! //! This contains modules which are shared by both the `cli` and the `server` modules diff --git a/server/src/config/mod.rs b/server/src/config/mod.rs index 32bc35ec..7dc2583e 100644 --- a/server/src/config/mod.rs +++ b/server/src/config/mod.rs @@ -283,7 +283,7 @@ impl ParsedConfig { /// TOML file (represented as an object) fn from_config(cfg_info: Config) -> Self { ParsedConfig { - noart: libsky::option_unwrap_or!(cfg_info.server.noart, false), + noart: option_unwrap_or!(cfg_info.server.noart, false), bgsave: if let Some(bgsave) = cfg_info.bgsave { match (bgsave.enabled, bgsave.every) { // TODO: Show a warning that there are unused keys @@ -301,7 +301,7 @@ impl ParsedConfig { SnapshotConfig::Enabled(SnapshotPref::new( snapshot.every, snapshot.atmost, - libsky::option_unwrap_or!(snapshot.failsafe, true), + option_unwrap_or!(snapshot.failsafe, true), )) }) .unwrap_or_else(SnapshotConfig::default), @@ -332,7 +332,7 @@ impl ParsedConfig { port: cfg_info.server.port, } }, - maxcon: libsky::option_unwrap_or!(cfg_info.server.maxclient, MAXIMUM_CONNECTION_LIMIT), + maxcon: option_unwrap_or!(cfg_info.server.maxclient, MAXIMUM_CONNECTION_LIMIT), } } #[cfg(test)] @@ -562,7 +562,7 @@ pub fn get_config_file_or_return_cfg() -> Result None, }; - let failsafe = if let Ok(failsafe) = libsky::option_unwrap_or!( + let failsafe = if let Ok(failsafe) = option_unwrap_or!( matches .value_of("stop-write-on-fail") .map(|val| val.parse::()), diff --git a/server/src/coredb/mod.rs b/server/src/coredb/mod.rs index 589314a9..34056f07 100644 --- a/server/src/coredb/mod.rs +++ b/server/src/coredb/mod.rs @@ -153,7 +153,7 @@ impl CoreDB { snap_count = Some(atmost); } let snapcfg = - libsky::option_unwrap_or!(snap_count.map(|max| Some(SnapshotStatus::new(*max))), None); + option_unwrap_or!(snap_count.map(|max| Some(SnapshotStatus::new(*max))), None); let db = if let Some(coremap) = coremap { CoreDB { coremap, diff --git a/server/src/diskstore/snapshot.rs b/server/src/diskstore/snapshot.rs index d744023e..c98d7101 100644 --- a/server/src/diskstore/snapshot.rs +++ b/server/src/diskstore/snapshot.rs @@ -108,7 +108,7 @@ impl<'a> SnapshotEngine<'a> { } else { (maxtop, false) }; - let snap_dir = libsky::option_unwrap_or!(snap_dir, DIR_SNAPSHOT); + let snap_dir = option_unwrap_or!(snap_dir, DIR_SNAPSHOT); match fs::create_dir(snap_dir) { Ok(_) => (), Err(e) => match e.kind() { diff --git a/server/src/kvengine/encoding.rs b/server/src/kvengine/encoding.rs deleted file mode 100644 index c9f34d8c..00000000 --- a/server/src/kvengine/encoding.rs +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Created on Thu Jul 01 2021 - * - * This file is a part of Skytable - * Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source - * NoSQL database written by Sayan Nandan ("the Author") with the - * vision to provide flexibility in data modelling without compromising - * on performance, queryability or scalability. - * - * Copyright (c) 2021, Sayan Nandan - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * -*/ - -//! Functions for validating the encoding of objects - -use std::ptr; - -pub struct BufferBlockReader { - buffer_ptr: *const u8, - len: usize, - len_after_step: usize, - idx: usize, -} - -impl BufferBlockReader { - pub const fn new(buffer: &[u8]) -> Self { - Self { - buffer_ptr: buffer.as_ptr(), - len: buffer.len(), - len_after_step: if buffer.len() < N { - 0 - } else { - buffer.len() - N - }, - idx: 0, - } - } - pub const fn block_index(&self) -> usize { - self.idx - } - pub const fn has_full_block(&self) -> bool { - self.idx < self.len_after_step - } - pub fn full_block(&self) -> &u8 { - unsafe { - // UNSAFE(@ohsayan): We're dereferencing a ptr that we know will not be null - // because the len of the buffer gurantees that - &*self.buffer_ptr.add(self.idx) - } - } - pub unsafe fn get_remaining(&self, dst: *mut u8) -> usize { - if self.len == self.idx { - 0 - } else { - { - ptr::write_bytes(dst, 0x20, N); - ptr::copy_nonoverlapping(self.buffer_ptr.add(self.idx), dst, self.len - self.idx); - } - self.len - self.idx - } - } - pub fn advance(&mut self) { - self.idx += N - } -} diff --git a/server/src/kvengine/mod.rs b/server/src/kvengine/mod.rs index f63a4f4c..371841be 100644 --- a/server/src/kvengine/mod.rs +++ b/server/src/kvengine/mod.rs @@ -33,7 +33,6 @@ use crate::coredb::htable::MapSingleReference; use crate::coredb::htable::SharedValue; use core::sync::atomic::AtomicBool; use core::sync::atomic::Ordering; -mod encoding; const ORD_RELAXED: Ordering = Ordering::Relaxed; diff --git a/server/src/main.rs b/server/src/main.rs index cb5a56fb..06cf0ff9 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -45,6 +45,10 @@ use std::process; use std::sync::Arc; use std::thread; use std::time; +#[macro_use] +mod util; +#[macro_use] // HACK(@ohsayan): macro_use will only work with extern crate for some moon reasons +extern crate libsky; mod actions; mod admin; mod arbiter; @@ -60,7 +64,6 @@ mod resp; mod services; #[cfg(test)] mod tests; -mod util; const PATH: &str = ".sky_pid"; diff --git a/server/src/util.rs b/server/src/util.rs index 03018888..a15095b2 100644 --- a/server/src/util.rs +++ b/server/src/util.rs @@ -57,3 +57,19 @@ unsafe impl Unwrappable for Option { } } } + +#[macro_export] +macro_rules! consts { + ($($(#[$attr:meta])* $ident:ident : $ty:ty = $expr:expr;)*) => { + $( + $(#[$attr])* + const $ident: $ty = $expr; + )* + }; + ($($(#[$attr:meta])* $vis:vis $ident:ident : $ty:ty = $expr:expr;)*) => { + $( + $(#[$attr])* + $vis const $ident: $ty = $expr; + )* + }; +}