Clean up code

Fixed Windows tests and also applied recent clippy suggestions
next
Sayan Nandan 3 years ago
parent cd1accd646
commit 14d9eb4bac
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -236,7 +236,7 @@ pub async fn start_repl() {
// continuation on next line
let cl = readln!(editor);
line.drain(line.len() - 2..);
line.extend(cl.chars());
line.push_str(&cl);
}
did_swap = line
.get(..3)

@ -26,8 +26,7 @@
use crate::util;
use crate::HarnessResult;
#[cfg(windows)]
use std::os::windows::process::CommandExt;
use std::path::Path;
use std::{path::PathBuf, process::Command};
use zip::CompressionMethod;
@ -68,7 +67,7 @@ impl ToString for BuildMode {
}
/// Returns the paths of the files for the given target folder
pub fn get_files_index(target_folder: &PathBuf) -> Vec<PathBuf> {
pub fn get_files_index(target_folder: &Path) -> Vec<PathBuf> {
let mut paths = Vec::with_capacity(BINARIES.len());
for binary in BINARIES {
let binary = util::add_extension(binary);
@ -81,12 +80,9 @@ pub fn get_files_index(target_folder: &PathBuf) -> Vec<PathBuf> {
pub fn build(mode: BuildMode) -> HarnessResult<PathBuf> {
let mut build_args = vec!["build".to_owned()];
let target_folder = util::get_target_folder(mode);
match util::get_var(util::VAR_TARGET) {
Some(t) => {
build_args.push("--target".to_owned());
build_args.push(t.to_string());
}
None => {}
if let Some(t) = util::get_var(util::VAR_TARGET) {
build_args.push("--target".to_owned());
build_args.push(t.to_string());
};
// assemble build args

@ -39,12 +39,9 @@ use zip::{write::FileOptions, ZipWriter};
/// Returns the bundle name
pub fn get_bundle_name() -> String {
let mut filename = format!("sky-bundle-v{VERSION}");
match util::get_var(util::VAR_ARTIFACT) {
Some(artifact) => {
filename.push('-');
filename.push_str(&artifact);
}
None => {}
if let Some(artifact) = util::get_var(util::VAR_ARTIFACT) {
filename.push('-');
filename.push_str(&artifact);
}
filename.push_str(".zip");
filename

@ -27,7 +27,6 @@
use crate::build::{self, BuildMode};
use crate::{util, HarnessResult};
use libsky::VERSION;
use std::process::Command;
/// The Linux package type
#[derive(Copy, Clone)]
@ -46,12 +45,9 @@ impl LinuxPackageType {
/// Returns the file name for the package
pub fn get_file_name(&self) -> String {
let mut filename = format!("skytable-v{VERSION}");
match util::get_var(util::VAR_ARTIFACT) {
Some(artifact) => {
filename.push('-');
filename.push_str(&artifact);
}
None => {}
if let Some(artifact) = util::get_var(util::VAR_ARTIFACT) {
filename.push('-');
filename.push_str(&artifact);
}
filename.push_str(&self.get_extension());
filename
@ -78,12 +74,9 @@ pub fn create_linuxpkg(package_type: LinuxPackageType) -> HarnessResult<()> {
util::handle_child("install cargo-deb", cmd!("cargo", "install", "cargo-deb"))?;
// assemble the command
let mut build_args = vec!["deb".to_owned()];
match util::get_var(util::VAR_TARGET) {
Some(t) => {
build_args.push("--target".to_string());
build_args.push(t);
}
None => {}
if let Some(t) = util::get_var(util::VAR_TARGET) {
build_args.push("--target".to_string());
build_args.push(t);
}
build_args.extend([
"--no-build".to_owned(),
@ -91,8 +84,7 @@ pub fn create_linuxpkg(package_type: LinuxPackageType) -> HarnessResult<()> {
"--output".to_owned(),
filename.to_owned(),
]);
let mut command = Command::new("cargo");
command.args(build_args);
let command = util::assemble_command_from_slice(build_args);
util::handle_child("build dpkg", command)?;
}
}

@ -65,12 +65,9 @@ pub fn run_test() -> HarnessResult<()> {
}
fn append_target(args: &mut Vec<String>) {
match util::get_var(util::VAR_TARGET) {
Some(target) => {
args.push("--target".into());
args.push(target);
}
None => {}
if let Some(target) = util::get_var(util::VAR_TARGET) {
args.push("--target".into());
args.push(target);
}
}

@ -29,6 +29,8 @@ use crate::{
HarnessError, HarnessResult,
};
use skytable::Connection;
#[cfg(windows)]
use std::os::windows::process::CommandExt;
use std::{
io::{Error as IoError, ErrorKind},
path::Path,

@ -35,7 +35,7 @@ action!(
/// Run a `GET` query
fn get(handle: &crate::corestore::Corestore, con: &mut T, mut act: ActionIter<'a>) {
ensure_length(act.len(), |len| len == 1)?;
let kve = handle.get_table_with::<KVE>()?;
let kve = handle.get_table_with::<KVEBlob>()?;
unsafe {
match kve.get_cloned(act.next_unchecked()) {
Ok(Some(val)) => writer::write_raw_mono(con, kve.get_value_tsymbol(), &val).await?,

@ -33,7 +33,7 @@ action!(
fn keylen(handle: &crate::corestore::Corestore, con: &mut T, mut act: ActionIter<'a>) {
ensure_length(act.len(), |len| len == 1)?;
let res: Option<usize> = {
let reader = handle.get_table_with::<KVE>()?;
let reader = handle.get_table_with::<KVEBlob>()?;
unsafe {
// UNSAFE(@ohsayan): this is completely safe as we've already checked
// the number of arguments is one

@ -49,10 +49,9 @@ impl Range {
self.stop = Some(stop);
}
pub fn into_vec(self, slice: &[Data]) -> Option<Vec<Data>> {
match slice.get(self.start..self.stop.unwrap_or(slice.len())) {
Some(slc) => Some(slc.iter().cloned().collect()),
None => None,
}
slice
.get(self.start..self.stop.unwrap_or(slice.len()))
.map(|slc| slc.to_vec())
}
}

@ -35,7 +35,7 @@ action!(
///
fn mget(handle: &crate::corestore::Corestore, con: &mut T, act: ActionIter<'a>) {
ensure_length(act.len(), |size| size != 0)?;
let kve = handle.get_table_with::<KVE>()?;
let kve = handle.get_table_with::<KVEBlob>()?;
let encoding_is_okay = ENCODING_LUT_ITER[kve.is_key_encoded()](act.as_ref());
if compiler::likely(encoding_is_okay) {
let mut writer = unsafe {

@ -37,7 +37,7 @@ action!(
fn mpop(handle: &corestore::Corestore, con: &mut T, act: ActionIter<'a>) {
ensure_length(act.len(), |len| len != 0)?;
if registry::state_okay() {
let kve = handle.get_table_with::<KVE>()?;
let kve = handle.get_table_with::<KVEBlob>()?;
let encoding_is_okay = ENCODING_LUT_ITER[kve.is_key_encoded()](act.as_ref());
if compiler::likely(encoding_is_okay) {
let mut writer = unsafe {

@ -34,21 +34,20 @@ action!(
fn mset(handle: &crate::corestore::Corestore, con: &mut T, mut act: ActionIter<'a>) {
let howmany = act.len();
ensure_length(howmany, |size| size & 1 == 0 && size != 0)?;
let kve = handle.get_table_with::<KVE>()?;
let kve = handle.get_table_with::<KVEBlob>()?;
let encoding_is_okay = ENCODING_LUT_ITER_PAIR[kve.get_encoding_tuple()](&act);
if compiler::likely(encoding_is_okay) {
let done_howmany: Option<usize>;
if registry::state_okay() {
let done_howmany: Option<usize> = if registry::state_okay() {
let mut didmany = 0;
while let (Some(key), Some(val)) = (act.next(), act.next()) {
didmany += kve
.set_unchecked(Data::copy_from_slice(key), Data::copy_from_slice(val))
as usize;
}
done_howmany = Some(didmany);
Some(didmany)
} else {
done_howmany = None;
}
None
};
if let Some(done_howmany) = done_howmany {
con.write_response(done_howmany as usize).await?;
} else {

@ -34,7 +34,7 @@ action!(
fn mupdate(handle: &crate::corestore::Corestore, con: &mut T, mut act: ActionIter<'a>) {
let howmany = act.len();
ensure_length(howmany, |size| size & 1 == 0 && size != 0)?;
let kve = handle.get_table_with::<KVE>()?;
let kve = handle.get_table_with::<KVEBlob>()?;
let encoding_is_okay = ENCODING_LUT_ITER_PAIR[kve.get_encoding_tuple()](&act);
let done_howmany: Option<usize>;
if compiler::likely(encoding_is_okay) {

@ -36,7 +36,7 @@ action! {
act.next_unchecked()
};
if registry::state_okay() {
let kve = handle.get_table_with::<KVE>()?;
let kve = handle.get_table_with::<KVEBlob>()?;
let tsymbol = kve.get_value_tsymbol();
match kve.pop(key) {
Ok(Some(val)) => unsafe {

@ -42,7 +42,7 @@ action!(
ensure_length(act.len(), |len| len == 2)?;
if registry::state_okay() {
let did_we = {
let writer = handle.get_table_with::<KVE>()?;
let writer = handle.get_table_with::<KVEBlob>()?;
match unsafe {
// UNSAFE(@ohsayan): This is completely safe as we've already checked
// that there are exactly 2 arguments

@ -38,7 +38,7 @@ action! {
/// `Nil`, which is code `1`
fn sdel(handle: &crate::corestore::Corestore, con: &mut T, act: ActionIter<'a>) {
ensure_length(act.len(), |len| len != 0)?;
let kve = handle.get_table_with::<KVE>()?;
let kve = handle.get_table_with::<KVEBlob>()?;
if registry::state_okay() {
// guarantee one check: consistency
let key_encoder = kve.get_key_encoder();

@ -41,7 +41,7 @@ action! {
fn sset(handle: &crate::corestore::Corestore, con: &mut T, act: ActionIter<'a>) {
let howmany = act.len();
ensure_length(howmany, |size| size & 1 == 0 && size != 0)?;
let kve = handle.get_table_with::<KVE>()?;
let kve = handle.get_table_with::<KVEBlob>()?;
if registry::state_okay() {
let encoder = kve.get_double_encoder();
let outcome = unsafe {

@ -41,7 +41,7 @@ action! {
fn supdate(handle: &crate::corestore::Corestore, con: &mut T, act: ActionIter<'a>) {
let howmany = act.len();
ensure_length(howmany, |size| size & 1 == 0 && size != 0)?;
let kve = handle.get_table_with::<KVE>()?;
let kve = handle.get_table_with::<KVEBlob>()?;
if registry::state_okay() {
let encoder = kve.get_double_encoder();
let outcome = unsafe {

@ -41,7 +41,7 @@ action!(
ensure_length(act.len(), |len| len == 2)?;
if registry::state_okay() {
let did_we = {
let writer = handle.get_table_with::<KVE>()?;
let writer = handle.get_table_with::<KVEBlob>()?;
match unsafe {
// UNSAFE(@ohsayan): This is completely safe as we've already checked
// that there are exactly 2 arguments

@ -37,7 +37,7 @@ action!(
fn uset(handle: &crate::corestore::Corestore, con: &mut T, mut act: ActionIter<'a>) {
let howmany = act.len();
ensure_length(howmany, |size| size & 1 == 0 && size != 0)?;
let kve = handle.get_table_with::<KVE>()?;
let kve = handle.get_table_with::<KVEBlob>()?;
let encoding_is_okay = ENCODING_LUT_ITER_PAIR[kve.get_encoding_tuple()](&act);
if compiler::likely(encoding_is_okay) {
if registry::state_okay() {

@ -62,15 +62,10 @@ pub async fn run(
) -> Result<Corestore, String> {
// Intialize the broadcast channel
let (signal, _) = broadcast::channel(1);
let engine;
match &snapshot {
SnapshotConfig::Enabled(SnapshotPref { atmost, .. }) => {
engine = SnapshotEngine::new(*atmost);
}
SnapshotConfig::Disabled => {
engine = SnapshotEngine::new_disabled();
}
}
let engine = match &snapshot {
SnapshotConfig::Enabled(SnapshotPref { atmost, .. }) => SnapshotEngine::new(*atmost),
SnapshotConfig::Disabled => SnapshotEngine::new_disabled(),
};
let engine = Arc::new(engine);
// restore data
services::restore_data(restore_filepath)

@ -76,7 +76,7 @@ action! {
Ok(())
}
AUTH_LOGOUT => {
ensure_boolean_or_aerr(iter.len() == 0)?; // nothing else
ensure_boolean_or_aerr(iter.is_empty())?; // nothing else
auth.provider_mut().logout()?;
auth.swap_executor_to_anonymous();
con.write_response(groups::OKAY).await?;
@ -95,12 +95,12 @@ action! {
}
}
fn auth_whoami(con: &mut T, auth: &mut AuthProviderHandle<'_, T, Strm>, iter: &mut ActionIter<'_>) {
ensure_boolean_or_aerr(iter.len() == 0)?;
ensure_boolean_or_aerr(ActionIter::is_empty(iter))?;
con.write_response(StringWrapper(auth.provider().whoami()?)).await?;
Ok(())
}
fn auth_listuser(con: &mut T, auth: &mut AuthProviderHandle<'_, T, Strm>, iter: &mut ActionIter<'_>) {
ensure_boolean_or_aerr(iter.len() == 0)?;
ensure_boolean_or_aerr(ActionIter::is_empty(iter))?;
let usernames = auth.provider().collect_usernames()?;
let mut array_writer = unsafe {
// The symbol is definitely correct, obvious from this context

@ -100,20 +100,20 @@ impl AuthProvider {
// 'root' user in test mode
slf.authmap.true_if_insert(
AuthID::try_from_slice(testsuite_data::TESTSUITE_ROOT_USER).unwrap(),
Authkey::from([
[
172, 143, 117, 169, 158, 156, 33, 106, 139, 107, 20, 106, 91, 219, 34, 157, 98,
147, 142, 91, 222, 238, 205, 120, 72, 171, 90, 218, 147, 2, 75, 67, 44, 108,
185, 124, 55, 40, 156, 252,
]),
],
);
// 'testuser' user in test mode
slf.authmap.true_if_insert(
AuthID::try_from_slice(testsuite_data::TESTSUITE_TEST_USER).unwrap(),
Authkey::from([
[
172, 183, 60, 221, 53, 240, 231, 217, 113, 112, 98, 16, 109, 62, 235, 95, 184,
107, 130, 139, 43, 197, 40, 31, 176, 127, 185, 22, 172, 124, 39, 225, 124, 71,
193, 115, 176, 162, 239, 93,
]),
],
);
}
slf

@ -414,9 +414,11 @@ impl<'de> Visitor<'de> for AuthSettingsVisitor {
where
E: de::Error,
{
AuthkeyWrapper::try_new(value).ok_or(E::custom(
"Invalid value for authkey. must be 40 ASCII characters with nonzero first char",
))
AuthkeyWrapper::try_new(value).ok_or_else(|| {
E::custom(
"Invalid value for authkey. must be 40 ASCII characters with nonzero first char",
)
})
}
}

@ -184,7 +184,7 @@ impl<'a, T: FromStr + 'a> TryFromConfigSource<T> for Result<String, VarError> {
}
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Default)]
/// Since we have conflicting trait implementations, we define a custom `Option<String>` type
pub struct OptString {
base: Option<String>,
@ -196,12 +196,6 @@ impl OptString {
}
}
impl Default for OptString {
fn default() -> Self {
Self { base: None }
}
}
impl From<Option<String>> for OptString {
fn from(base: Option<String>) -> Self {
Self { base }
@ -518,6 +512,7 @@ impl Configset {
}
// TLS settings
#[allow(clippy::too_many_arguments)]
impl Configset {
pub fn tls_settings(
&mut self,
@ -647,7 +642,7 @@ pub fn get_config() -> Result<ConfigType, ConfigError> {
Ok(ConfigType::new_default(restore_file))
} else {
cfg_from_file
.unwrap_or(cfg_from_env.and_then(cfg_from_cli))
.unwrap_or_else(|| cfg_from_env.and_then(cfg_from_cli))
.into_result(restore_file)
}
}

@ -231,11 +231,10 @@ impl Corestore {
let entity = entity.into_owned();
// first lock the global flush state
let flush_lock = registry::lock_flush_state();
let ret;
match entity {
let ret = match entity {
// Important: create table <tblname> is only ks
OwnedEntity::Single(tblid) | OwnedEntity::Partial(tblid) => {
ret = match &self.estate.ks {
match &self.estate.ks {
Some((_, ks)) => {
let tbl = Table::from_model_code(modelcode, volatile);
if let Some(tbl) = tbl {
@ -251,10 +250,10 @@ impl Corestore {
}
}
None => Err(DdlError::DefaultNotFound),
};
}
}
OwnedEntity::Full(ksid, tblid) => {
ret = match self.store.get_keyspace_atomic_ref(&ksid) {
match self.store.get_keyspace_atomic_ref(&ksid) {
Some(kspace) => {
let tbl = Table::from_model_code(modelcode, volatile);
if let Some(tbl) = tbl {
@ -272,7 +271,7 @@ impl Corestore {
None => Err(DdlError::ObjectNotFound),
}
}
}
};
// free the global flush lock
drop(flush_lock);
ret

@ -42,7 +42,7 @@ pub trait DescribeTable {
match store.estate.table {
Some((_, ref table)) => {
// so we do have a table
match Self::try_get(&table) {
match Self::try_get(table) {
Some(tbl) => Ok(tbl),
None => util::err(groups::WRONG_MODEL),
}
@ -52,9 +52,9 @@ pub trait DescribeTable {
}
}
pub struct KVE;
pub struct KVEBlob;
impl DescribeTable for KVE {
impl DescribeTable for KVEBlob {
type Table = KVEStandard;
fn try_get(table: &Table) -> Option<&Self::Table> {
if let DataModel::KV(ref kve) = table.model_store {
@ -187,7 +187,7 @@ impl Table {
pub const fn is_volatile(&self) -> bool {
self.volatile
}
/// Create a new KVE Table with the provided settings
/// Create a new KVEBlob Table with the provided settings
pub fn new_pure_kve_with_data(
data: Coremap<Data, Data>,
volatile: bool,

@ -95,10 +95,10 @@ where
}
}
pub fn provider_mut(&mut self) -> &mut AuthProvider {
&mut self.provider
self.provider
}
pub fn provider(&self) -> &AuthProvider {
&self.provider
self.provider
}
pub fn swap_executor_to_anonymous(&mut self) {
*self.executor = ConnectionHandler::execute_unauth;
@ -115,7 +115,7 @@ pub mod prelude {
pub use super::{AuthProviderHandle, ClientConnection, ProtocolConnectionExt, Stream};
pub use crate::actions::{ensure_boolean_or_aerr, ensure_cond_or_err, ensure_length};
pub use crate::corestore::{
table::{KVEList, KVE},
table::{KVEBlob, KVEList},
Corestore,
};
pub use crate::protocol::responses::{self, groups};

@ -167,6 +167,7 @@ macro_rules! bindaddr {
/// - The `Multi` variant holds both an `SslListener` and a `Listener`
/// This variant enables listening to both secure and insecure sockets at the same time
/// asynchronously
#[allow(clippy::large_enum_variant)]
pub enum MultiListener {
SecureOnly(SslListener),
InsecureOnly(Listener),

@ -59,6 +59,8 @@ use crate::corestore::booltable::TwoBitLUT;
use crate::protocol::iter::AnyArrayIter;
use crate::protocol::iter::BorrowedAnyArrayIter;
type PairFn = fn(&[u8], &[u8]) -> bool;
pub const ENCODING_LUT_ITER: BoolTable<fn(BorrowedAnyArrayIter) -> bool> =
BoolTable::new(is_okay_encoded_iter, is_okay_no_encoding_iter);
pub const ENCODING_LUT_ITER_PAIR: TwoBitLUT<fn(&AnyArrayIter) -> bool> = TwoBitLUT::new(
@ -69,7 +71,7 @@ pub const ENCODING_LUT_ITER_PAIR: TwoBitLUT<fn(&AnyArrayIter) -> bool> = TwoBitL
);
pub const ENCODING_LUT: BoolTable<fn(&[u8]) -> bool> =
BoolTable::new(self::is_okay_encoded, self::is_okay_no_encoding);
pub const ENCODING_LUT_PAIR: TwoBitLUT<fn(&[u8], &[u8]) -> bool> = TwoBitLUT::new(
pub const ENCODING_LUT_PAIR: TwoBitLUT<PairFn> = TwoBitLUT::new(
self::is_okay_encoded_pair_ff,
self::is_okay_encoded_pair_ft,
self::is_okay_encoded_pair_tf,
@ -148,7 +150,7 @@ pub fn pair_is_okay_encoded_iter_tt(inp: &AnyArrayIter<'_>) -> bool {
}
pub fn is_okay_encoded_iter(mut inp: BorrowedAnyArrayIter<'_>) -> bool {
inp.all(|v| self::is_okay_encoded(v))
inp.all(self::is_okay_encoded)
}
pub const fn is_okay_no_encoding_iter(_inp: BorrowedAnyArrayIter<'_>) -> bool {

@ -81,11 +81,11 @@ pub struct KVEngine<T> {
// basic method impls
impl<T> KVEngine<T> {
/// Create a new KVE
/// Create a new KVEBlob
pub fn new(e_k: bool, e_v: bool, data: Coremap<Data, T>) -> Self {
Self { data, e_k, e_v }
}
/// Create a new empty KVE
/// Create a new empty KVEBlob
pub fn init(e_k: bool, e_v: bool) -> Self {
Self::new(e_k, e_v, Default::default())
}
@ -200,7 +200,8 @@ impl<T: KVEValue> KVEngine<T> {
pub fn upsert(&self, key: Data, val: T) -> EncodingResult<()> {
self.check_key_encoding(&key)?;
val.verify_encoding(self.e_v)?;
Ok(self.upsert_unchecked(key, val))
self.upsert_unchecked(key, val);
Ok(())
}
/// Update or insert an entry without encoding checks
pub fn upsert_unchecked(&self, key: Data, val: T) {
@ -260,25 +261,22 @@ impl KVEListmap {
Ok(self.data.true_if_insert(listname, LockedVec::new(vec![])))
}
pub fn list_len(&self, listname: &[u8]) -> EncodingResult<Option<usize>> {
self.check_key_encoding(&listname)?;
self.check_key_encoding(listname)?;
Ok(self.data.get(listname).map(|list| list.read().len()))
}
pub fn list_cloned(&self, listname: &[u8], count: usize) -> EncodingResult<Option<Vec<Data>>> {
self.check_key_encoding(listname)?;
Ok(self.data.get(listname).map(|list| {
list.read()
.iter()
.map(|element| element.clone())
.take(count)
.collect()
}))
Ok(self
.data
.get(listname)
.map(|list| list.read().iter().cloned().take(count).collect()))
}
pub fn list_cloned_full(&self, listname: &[u8]) -> EncodingResult<Option<Vec<Data>>> {
self.check_key_encoding(listname)?;
Ok(self
.data
.get(listname)
.map(|list| list.read().iter().map(|element| element.clone()).collect()))
.map(|list| list.read().iter().cloned().collect()))
}
}

@ -111,16 +111,18 @@ impl<'a> AnyArrayIter<'a> {
Bytes::copy_from_slice(self.next_unchecked())
}
pub fn map_next<T>(&mut self, cls: fn(&[u8]) -> T) -> Option<T> {
self.next().map(|v| cls(v))
self.next().map(cls)
}
pub fn next_string_owned(&mut self) -> Option<String> {
self.map_next(|v| String::from_utf8_lossy(&v).to_string())
self.map_next(|v| String::from_utf8_lossy(v).to_string())
}
pub unsafe fn into_inner(self) -> Iter<'a, UnsafeSlice> {
self.iter
}
}
/// # Safety
/// Caller must ensure validity of the slice returned
pub unsafe trait DerefUnsafeSlice {
unsafe fn deref_slice(&self) -> &[u8];
}

@ -31,7 +31,7 @@ use crate::auth;
use crate::corestore::Corestore;
use crate::dbnet::connection::prelude::*;
use crate::protocol::{
element::UnsafeElement, iter::AnyArrayIter, responses, PipelineQuery, SimpleQuery, UnsafeSlice,
element::UnsafeElement, iter::AnyArrayIter, responses, PipelineQuery, SimpleQuery,
};
use crate::queryengine::parser::Entity;
use crate::{actions, admin};
@ -112,12 +112,10 @@ action! {
}
}
#[allow(clippy::needless_lifetimes)]
unsafe fn get_iter<'a>(buf: &'a UnsafeElement) -> AnyArrayIter<'a> {
let bufref: &'a Box<[UnsafeSlice]>;
let iter;
// this is the boxed slice
bufref = {
let bufref = {
// SAFETY: execute_simple is called by execute_query which in turn is called
// by ConnnectionHandler::run(). In all cases, the `Con` remains valid
// ensuring that the source buffer exists as long as the connection does
@ -128,7 +126,7 @@ unsafe fn get_iter<'a>(buf: &'a UnsafeElement) -> AnyArrayIter<'a> {
}
};
// this is our final iter
iter = {
let iter = {
// SAFETY: Again, this is guaranteed to be valid because the `con` is valid
AnyArrayIter::new(bufref.iter())
};

@ -121,7 +121,7 @@ pub(super) fn parse_table_args<'a>(
let key_ty = key_ty.as_bytes();
let val_ty = val_ty.as_bytes();
let model_code: u8 = match (key_ty, val_ty) {
// pure KVE
// pure KVEBlob
(BINSTR, BINSTR) => 0,
(BINSTR, STR) => 1,
(STR, STR) => 2,

@ -38,7 +38,7 @@ mod parser_ddl_tests {
};
}
fn parse_table_args_test(input: Vec<&'static [u8]>) -> Result<(Entity<'_>, u8), &'static [u8]> {
super::parser::parse_table_args(&input[0], &input[1])
super::parser::parse_table_args(input[0], input[1])
}
use crate::protocol::responses;
#[test]

@ -24,6 +24,8 @@
*
*/
#![allow(clippy::needless_lifetimes)]
//! Utilities for generating responses, which are only used by the `server`
//!
use crate::corestore::buffers::Integer64;

@ -38,25 +38,25 @@
// model
/*
* KVE:
* (1) Pure KVE: [0, 3]
* KVEBlob:
* (1) Pure KVEBlob: [0, 3]
* (2) KVExt/Listmap: [4, 7]
*/
/// KVE model bytemark with key:bin, val:bin
/// KVEBlob model bytemark with key:bin, val:bin
pub const BYTEMARK_MODEL_KV_BIN_BIN: u8 = 0;
/// KVE model bytemark with key:bin, val:str
/// KVEBlob model bytemark with key:bin, val:str
pub const BYTEMARK_MODEL_KV_BIN_STR: u8 = 1;
/// KVE model bytemark with key:str, val:str
/// KVEBlob model bytemark with key:str, val:str
pub const BYTEMARK_MODEL_KV_STR_STR: u8 = 2;
/// KVE model bytemark with key:str, val:bin
/// KVEBlob model bytemark with key:str, val:bin
pub const BYTEMARK_MODEL_KV_STR_BIN: u8 = 3;
/// KVE model bytemark with key:binstr, val: list<binstr>
/// KVEBlob model bytemark with key:binstr, val: list<binstr>
pub const BYTEMARK_MODEL_KV_BINSTR_LIST_BINSTR: u8 = 4;
/// KVE model bytemark with key:binstr, val: list<str>
/// KVEBlob model bytemark with key:binstr, val: list<str>
pub const BYTEMARK_MODEL_KV_BINSTR_LIST_STR: u8 = 5;
/// KVE model bytemark with key:str, val: list<binstr>
/// KVEBlob model bytemark with key:str, val: list<binstr>
pub const BYTEMARK_MODEL_KV_STR_LIST_BINSTR: u8 = 6;
/// KVE model bytemark with key:str, val: list<str>
/// KVEBlob model bytemark with key:str, val: list<str>
pub const BYTEMARK_MODEL_KV_STR_LIST_STR: u8 = 7;
// storage bym

@ -107,7 +107,7 @@ impl<'a> StorageTarget for RemoteSnapshot<'a> {
fn root(&self) -> String {
let mut p = String::from(interface::DIR_RSNAPROOT);
p.push('/');
p.push_str(&self.name);
p.push_str(self.name);
p
}
}

@ -551,6 +551,7 @@ mod de {
Some(list)
}
#[allow(clippy::needless_return)]
pub(super) unsafe fn transmute_len(start_ptr: *const u8) -> usize {
little_endian! {{
return self::transmute_len_le(start_ptr);

@ -265,7 +265,7 @@ mod bytemark_set_tests {
mod bytemark_actual_table_restore {
use crate::corestore::{
memstore::ObjectID,
table::{DescribeTable, KVEList, Table, KVE},
table::{DescribeTable, KVEList, Table, KVEBlob},
Data,
};
use crate::kvengine::LockedVec;
@ -276,7 +276,7 @@ mod bytemark_actual_table_restore {
macro_rules! insert {
($table:ident, $k:expr, $v:expr) => {
assert!(gtable::<KVE>(&$table)
assert!(gtable::<KVEBlob>(&$table)
.set(Data::from($k), Data::from($v))
.unwrap())
};
@ -326,7 +326,7 @@ mod bytemark_actual_table_restore {
}
for (index, (table, code)) in read_tables
.iter()
.map(|tbl| (gtable::<KVE>(tbl), tbl.get_model_code()))
.map(|tbl| (gtable::<KVEBlob>(tbl), tbl.get_model_code()))
.enumerate()
{
assert_eq!(index, code as usize);

@ -95,10 +95,11 @@ pub trait UnflushableTable: Sized {
fn unflush_table(filepath: impl AsRef<Path>, model_code: u8, volatile: bool) -> IoResult<Self>;
}
#[allow(clippy::transmute_int_to_bool)]
impl UnflushableTable for Table {
fn unflush_table(filepath: impl AsRef<Path>, model_code: u8, volatile: bool) -> IoResult<Self> {
let ret = match model_code {
// pure KVE: [0, 3]
// pure KVEBlob: [0, 3]
x if x < 4 => {
let data = decode(filepath, volatile)?;
let (k_enc, v_enc) = unsafe {

@ -61,9 +61,14 @@ pub const fn hot<T>(v: T) -> T {
v
}
/// # Safety
/// The caller is responsible for ensuring lifetime validity
pub const unsafe fn extend_lifetime<'a, 'b, T>(inp: &'a T) -> &'b T {
mem::transmute(inp)
}
/// # Safety
/// The caller is responsible for ensuring lifetime validity
pub unsafe fn extend_lifetime_mut<'a, 'b, T>(inp: &'a mut T) -> &'b mut T {
mem::transmute(inp)
}

@ -44,6 +44,9 @@ pub type FutureResult<'s, T> = Pin<Box<dyn Future<Output = T> + Send + Sync + 's
/// This trait provides a method `unsafe_unwrap` that is potentially unsafe and has
/// the ability to **violate multiple safety gurantees** that rust provides. So,
/// if you get `SIGILL`s or `SIGSEGV`s, by using this trait, blame yourself.
///
/// # Safety
/// Use this when you're absolutely sure that the error case is never reached
pub unsafe trait Unwrappable<T> {
/// Unwrap a _nullable_ (almost) type to get its value while asserting that the value
/// cannot ever be null
@ -80,10 +83,10 @@ pub trait UnwrapActionError<T> {
impl<T> UnwrapActionError<T> for Option<T> {
fn unwrap_or_custom_aerr(self, e: impl Into<ActionError>) -> ActionResult<T> {
self.ok_or(e.into())
self.ok_or_else(|| e.into())
}
fn unwrap_or_aerr(self) -> ActionResult<T> {
self.ok_or(groups::ACTION_ERR.into())
self.ok_or_else(|| groups::ACTION_ERR.into())
}
}

@ -58,6 +58,8 @@ mod unix {
if ret != 0 {
Err(IoError::last_os_error())
} else {
// clippy doesn't realize that rlimit has a different size on 32-bit
#[allow(clippy::useless_conversion)]
Ok(ResourceLimit::new(
rlim.rlim_cur.into(),
rlim.rlim_max.into(),

@ -369,7 +369,7 @@ fn parse_dbtest_func_attrs(attrs: AttributeArgs) -> DBTestFunctionConfig {
let mut fcfg = DBTestFunctionConfig::default();
attrs.iter().for_each(|arg| {
if let syn::NestedMeta::Meta(syn::Meta::NameValue(namevalue)) = arg {
let (ident, lit, span) = util::get_metanamevalue_data(&namevalue);
let (ident, lit, span) = util::get_metanamevalue_data(namevalue);
parse_dbtest_func_args(&ident, lit, span, &mut fcfg)
}
});
@ -381,6 +381,5 @@ pub fn dbtest_func(args: TokenStream, item: TokenStream) -> TokenStream {
let attrs = syn::parse_macro_input!(args as AttributeArgs);
let mut rng = rand::thread_rng();
let fcfg = parse_dbtest_func_attrs(attrs);
let func = generate_dbtest(input, &mut rng, &fcfg).unwrap();
func
generate_dbtest(input, &mut rng, &fcfg).unwrap()
}

Loading…
Cancel
Save