From fd117c8244919ee45f1284b067e79d9f718c71d3 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Mon, 31 Oct 2022 00:51:49 +0800 Subject: [PATCH] clippy --- Cargo.toml | 4 ++++ cozorocks/src/bridge/db.rs | 7 ++----- cozorocks/src/bridge/mod.rs | 4 ++-- cozorocks/src/lib.rs | 3 +++ docs/source/queries.rst | 2 +- docs/source/setup.rst | 3 +-- src/algo/jlines.rs | 2 +- src/lib.rs | 5 ++++- src/runtime/db.rs | 41 ++++++++----------------------------- 9 files changed, 26 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e4f2c676..115aa202 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,10 @@ edition = "2021" description = "A general-purpose, transactional, relational database that uses Datalog and focuses on graph data" authors = ["Ziyang Hu"] license = "AGPL-3.0-or-later" +exclude = [ + "docs/*", + "tests/*", +] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/cozorocks/src/bridge/db.rs b/cozorocks/src/bridge/db.rs index c38b20bc..2084379f 100644 --- a/cozorocks/src/bridge/db.rs +++ b/cozorocks/src/bridge/db.rs @@ -2,8 +2,6 @@ * Copyright 2022, The Cozo Project Authors. Licensed under MIT/Apache-2.0/BSD-3-Clause. */ -use std::borrow::Cow; - use cxx::*; use crate::bridge::ffi::*; @@ -11,7 +9,6 @@ use crate::bridge::tx::TxBuilder; #[derive(Default, Clone)] pub struct DbBuilder<'a> { - pub cmp_fn: Option i8>, pub opts: DbOpts<'a>, } @@ -120,8 +117,8 @@ pub struct RocksDb { } impl RocksDb { - pub fn db_path(&self) -> Cow { - self.inner.get_db_path().to_string_lossy() + pub fn db_path(&self) -> std::string::String { + self.inner.get_db_path().to_string_lossy().to_string() } pub fn transact(&self) -> TxBuilder { TxBuilder { diff --git a/cozorocks/src/bridge/mod.rs b/cozorocks/src/bridge/mod.rs index 95228ac8..6b28b8e2 100644 --- a/cozorocks/src/bridge/mod.rs +++ b/cozorocks/src/bridge/mod.rs @@ -116,8 +116,8 @@ pub(crate) mod ffi { type RocksDbBridge; fn get_db_path(self: &RocksDbBridge) -> &CxxString; - fn open_db( - builder: &DbOpts, + fn open_db<'a>( + builder: &'a DbOpts<'a>, status: &mut RocksDbStatus, ) -> SharedPtr; fn transact(self: &RocksDbBridge) -> UniquePtr; diff --git a/cozorocks/src/lib.rs b/cozorocks/src/lib.rs index a59ae607..cbbec752 100644 --- a/cozorocks/src/lib.rs +++ b/cozorocks/src/lib.rs @@ -2,6 +2,9 @@ * Copyright 2022, The Cozo Project Authors. Licensed under MIT/Apache-2.0/BSD-3-Clause. */ +#![warn(rust_2018_idioms, future_incompatible)] +#![allow(clippy::type_complexity)] + pub use bridge::db::DbBuilder; pub use bridge::db::RocksDb; pub use bridge::ffi::RocksDbStatus; diff --git a/docs/source/queries.rst b/docs/source/queries.rst index 2a4a8a06..1e8b7416 100644 --- a/docs/source/queries.rst +++ b/docs/source/queries.rst @@ -309,5 +309,5 @@ The rest of the query options are explained in the following. The query returns nothing if the output relation contains at least one row, otherwise, execution aborts with an error. - Execution of the query stops as soon as the first row is produced if possible. + Implies ``:limit 1`` to ensure early termination if possible. Useful for transactions and triggers. \ No newline at end of file diff --git a/docs/source/setup.rst b/docs/source/setup.rst index 030f9d26..be7ab0b1 100644 --- a/docs/source/setup.rst +++ b/docs/source/setup.rst @@ -224,5 +224,4 @@ you can use the library directly. For languages other than Rust, you will need to provide custom bindings, but again for `Python `_ and `NodeJS `_ this is trivial. - -Note that Cozo, with its underlying RocksDB storage, will always use multiple threads, embedded or not. \ No newline at end of file +Cozo will always use multiple threads, embedded or not. \ No newline at end of file diff --git a/src/algo/jlines.rs b/src/algo/jlines.rs index bc32e2f4..792453bf 100644 --- a/src/algo/jlines.rs +++ b/src/algo/jlines.rs @@ -172,7 +172,7 @@ impl AlgoImpl for JsonReader { } pub(crate) fn get_file_content_from_url(url: &str) -> Result { - minreq::get(&url as &str) + minreq::get(url as &str) .send() .map_err(|e| { error!("{:?}", e); diff --git a/src/lib.rs b/src/lib.rs index 8ce47595..8930c068 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,9 @@ */ #![warn(rust_2018_idioms, future_incompatible)] +#![warn(missing_docs)] +#![allow(clippy::type_complexity)] +#![allow(clippy::too_many_arguments)] pub use miette::Error; @@ -16,9 +19,9 @@ pub use runtime::db::Db; // #[global_allocator] // static GLOBAL: Jemalloc = Jemalloc; +pub(crate) mod algo; pub(crate) mod data; pub(crate) mod parse; pub(crate) mod query; pub(crate) mod runtime; pub(crate) mod utils; -pub(crate) mod algo; diff --git a/src/runtime/db.rs b/src/runtime/db.rs index f69a35db..07258367 100644 --- a/src/runtime/db.rs +++ b/src/runtime/db.rs @@ -5,7 +5,7 @@ use std::collections::BTreeMap; use std::fmt::{Debug, Formatter}; use std::path::PathBuf; -use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::{Arc, Mutex}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::{fs, thread}; @@ -62,19 +62,13 @@ const CURRENT_STORAGE_VERSION: u64 = 1; pub struct Db { db: RocksDb, relation_store_id: Arc, - n_sessions: Arc, queries_count: Arc, running_queries: Arc>>, - session_id: usize, } impl Debug for Db { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "Db", - self.session_id, self.n_sessions - ) + write!(f, "Db") } } @@ -131,46 +125,27 @@ impl Db { let ret = Self { db, relation_store_id: Arc::new(Default::default()), - n_sessions: Arc::new(Default::default()), queries_count: Arc::new(Default::default()), running_queries: Arc::new(Mutex::new(Default::default())), - session_id: Default::default(), }; ret.load_last_ids()?; Ok(ret) } - pub fn get_session_id(&self) -> usize { - self.session_id - } - - pub fn compact_relation(&self) -> Result<()> { + fn compact_relation(&self) -> Result<()> { let l = Tuple::default().encode_as_key(RelationId(0)); let u = Tuple(vec![DataValue::Bot]).encode_as_key(RelationId(u64::MAX)); self.db.range_compact(&l, &u)?; Ok(()) } - pub fn new_session(&self) -> Result { - let old_count = self.n_sessions.fetch_add(1, Ordering::AcqRel); - - Ok(Self { - db: self.db.clone(), - relation_store_id: self.relation_store_id.clone(), - n_sessions: self.n_sessions.clone(), - queries_count: self.queries_count.clone(), - running_queries: self.running_queries.clone(), - session_id: old_count + 1, - }) - } - fn load_last_ids(&self) -> Result<()> { let tx = self.transact()?; self.relation_store_id .store(tx.load_last_relation_store_id()?.0, Ordering::Release); Ok(()) } - pub fn transact(&self) -> Result { + fn transact(&self) -> Result { let ret = SessionTx { tx: self.db.transact().set_snapshot(true).start(), mem_store_id: Default::default(), @@ -178,7 +153,7 @@ impl Db { }; Ok(ret) } - pub fn transact_write(&self) -> Result { + fn transact_write(&self) -> Result { let ret = SessionTx { tx: self.db.transact().set_snapshot(true).start(), mem_store_id: Default::default(), @@ -611,7 +586,7 @@ impl Db { } else { Right(sorted_iter) }; - let sorted_iter = sorted_iter.map(|t| Ok(t)); + let sorted_iter = sorted_iter.map(Ok); if let Some((meta, relation_op)) = &input_program.out_opts.store_relation { let to_clear = tx .execute_relation( @@ -682,7 +657,7 @@ impl Db { .collect_vec(); Ok(json!({"rows": res, "headers": ["id", "started_at"]})) } - pub fn list_relation(&self, name: &str) -> Result { + fn list_relation(&self, name: &str) -> Result { let tx = self.transact()?; let handle = tx.get_relation(name, false)?; let mut ret = vec![]; @@ -709,7 +684,7 @@ impl Db { } Ok(json!({"rows": ret, "headers": ["column", "is_key", "index", "type", "has_default"]})) } - pub fn list_relations(&self) -> Result { + fn list_relations(&self) -> Result { let lower = Tuple(vec![DataValue::Str(SmartString::from(""))]).encode_as_key(RelationId::SYSTEM); let upper = Tuple(vec![DataValue::Str(SmartString::from(String::from(