Skip to content

Commit

Permalink
fix lints in the 1.81 toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
wlqm committed Sep 26, 2024
1 parent 43a7dae commit cb85ca0
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 80 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ resolver = "2"
[workspace.dependencies]
ruc = "6.0.0"
rand = "0.8.5"
once_cell = "1.13.1"
parking_lot = "0.12.1"

serde = { version = "1.0.136", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![GitHub top language](https://img.shields.io/github/languages/top/rust-util-collections/vsdb)
[![Rust](https://github.com/rust-util-collections/vsdb/actions/workflows/rust.yml/badge.svg)](https://github.com/rust-util-collections/vsdb/actions/workflows/rust.yml)
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.70+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements)
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.81+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements)

# vsdb

Expand Down
3 changes: 1 addition & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vsdb_core"
version = "1.0.1"
version = "1.0.2"
authors = ["[email protected]"]
edition = "2021"
description = "A std-collection-like database"
Expand All @@ -14,7 +14,6 @@ license = "GPL-3.0"
ruc = { workspace = true }
serde = { workspace = true }
rand = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }

threadpool = { workspace = true } # used in a background cleaner
Expand Down
8 changes: 4 additions & 4 deletions core/src/basic/mapx_raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ impl MapxRaw {
}

#[inline(always)]
pub fn get_le(&self, key: &[u8]) -> Option<(RawKey, RawValue)> {
self.range(..=Cow::Borrowed(key)).next_back()
pub fn get_le(&self, key: impl AsRef<[u8]>) -> Option<(RawKey, RawValue)> {
self.range(..=Cow::Borrowed(key.as_ref())).next_back()
}

#[inline(always)]
pub fn get_ge(&self, key: &[u8]) -> Option<(RawKey, RawValue)> {
self.range(Cow::Borrowed(key)..).next()
pub fn get_ge(&self, key: impl AsRef<[u8]>) -> Option<(RawKey, RawValue)> {
self.range(Cow::Borrowed(key.as_ref())..).next()
}

#[inline(always)]
Expand Down
6 changes: 3 additions & 3 deletions core/src/common/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use crate::common::{
BranchIDBase as BranchID, Pre, PreBytes, RawKey, RawValue,
VersionIDBase as VersionID, PREFIX_SIZE, VSDB,
};
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use ruc::*;
use serde::{de, Deserialize, Serialize};
Expand All @@ -39,10 +38,11 @@ use std::{
mem::transmute,
ops::{Deref, DerefMut, RangeBounds},
result::Result as StdResult,
sync::LazyLock,
};

static LEN_LK: Lazy<Vec<Mutex<()>>> =
Lazy::new(|| (0..VSDB.db.area_count()).map(|_| Mutex::new(())).collect());
static LEN_LK: LazyLock<Vec<Mutex<()>>> =
LazyLock::new(|| (0..VSDB.db.area_count()).map(|_| Mutex::new(())).collect());

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 9 additions & 7 deletions core/src/common/engines/parity_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ use crate::common::{
PreBytes, RawBytes, RawKey, RawValue, VersionIDBase as VersionID, INITIAL_BRANCH_ID,
PREFIX_SIZE, RESERVED_ID_CNT,
};
use once_cell::sync::Lazy;
use parity_db::{BTreeIterator, CompressionType, Db as DB, Options};
use parking_lot::Mutex;
use ruc::*;
use std::{
borrow::Cow,
ops::{Bound, RangeBounds},
sync::atomic::{AtomicUsize, Ordering},
sync::{
atomic::{AtomicUsize, Ordering},
LazyLock,
},
};

// NOTE:
Expand All @@ -26,7 +28,7 @@ const META_KEY_VERSION_ID: [u8; 1] = [u8::MAX - 2];
const META_KEY_PREFIX_ALLOCATOR: [u8; 1] = [u8::MIN];
const META_KEY_NULL: [u8; 0] = [0; 0];

static HDR: Lazy<DB> = Lazy::new(|| paritydb_open().unwrap());
static HDR: LazyLock<DB> = LazyLock::new(|| paritydb_open().unwrap());

pub struct ParityEngine {
hdr: &'static DB,
Expand Down Expand Up @@ -54,7 +56,7 @@ impl ParityEngine {

#[inline(always)]
fn get_upper_bound_value(&self, hdr_prefix: PreBytes) -> Vec<u8> {
static BUF: Lazy<RawBytes> = Lazy::new(|| vec![u8::MAX; 512]);
static BUF: LazyLock<RawBytes> = LazyLock::new(|| vec![u8::MAX; 512]);

let mut max_guard = hdr_prefix.to_vec();

Expand Down Expand Up @@ -132,7 +134,7 @@ impl Engine for ParityEngine {
// so we use a `Mutex` lock for thread safe.
#[allow(unused_variables)]
fn alloc_prefix(&self) -> Pre {
static LK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
static LK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
let x = LK.lock();

// step 1
Expand All @@ -159,7 +161,7 @@ impl Engine for ParityEngine {
// so we use a `Mutex` lock for thread safe.
#[allow(unused_variables)]
fn alloc_br_id(&self) -> BranchID {
static LK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
static LK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
let x = LK.lock();

// step 1
Expand Down Expand Up @@ -187,7 +189,7 @@ impl Engine for ParityEngine {
// so we use a `Mutex` lock for thread safe.
#[allow(unused_variables)]
fn alloc_ver_id(&self) -> VersionID {
static LK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
static LK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
let x = LK.lock();

// step 1
Expand Down
16 changes: 9 additions & 7 deletions core/src/common/engines/rocks_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::common::{
PreBytes, RawBytes, RawKey, RawValue, VersionIDBase as VersionID, GB,
INITIAL_BRANCH_ID, MB, PREFIX_SIZE, RESERVED_ID_CNT,
};
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use rocksdb::{
ColumnFamily, ColumnFamilyDescriptor, DBCompressionType, DBIterator, Direction,
Expand All @@ -15,7 +14,10 @@ use std::{
fs,
mem::size_of,
ops::{Bound, RangeBounds},
sync::atomic::{AtomicUsize, Ordering},
sync::{
atomic::{AtomicUsize, Ordering},
LazyLock,
},
thread::available_parallelism,
};

Expand All @@ -28,7 +30,7 @@ const META_KEY_BRANCH_ID: [u8; 1] = [u8::MAX - 1];
const META_KEY_VERSION_ID: [u8; 1] = [u8::MAX - 2];
const META_KEY_PREFIX_ALLOCATOR: [u8; 1] = [u8::MIN];

static HDR: Lazy<(DB, Vec<String>)> = Lazy::new(|| rocksdb_open().unwrap());
static HDR: LazyLock<(DB, Vec<String>)> = LazyLock::new(|| rocksdb_open().unwrap());

pub struct RocksEngine {
meta: &'static DB,
Expand Down Expand Up @@ -58,7 +60,7 @@ impl RocksEngine {

#[inline(always)]
fn get_upper_bound_value(&self, meta_prefix: PreBytes) -> Vec<u8> {
static BUF: Lazy<RawBytes> = Lazy::new(|| vec![u8::MAX; 512]);
static BUF: LazyLock<RawBytes> = LazyLock::new(|| vec![u8::MAX; 512]);

let mut max_guard = meta_prefix.to_vec();

Expand Down Expand Up @@ -120,7 +122,7 @@ impl Engine for RocksEngine {
// so we use a `Mutex` lock for thread safe.
#[allow(unused_variables)]
fn alloc_prefix(&self) -> Pre {
static LK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
static LK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
let x = LK.lock();

// step 1
Expand All @@ -140,7 +142,7 @@ impl Engine for RocksEngine {
// so we use a `Mutex` lock for thread safe.
#[allow(unused_variables)]
fn alloc_br_id(&self) -> BranchID {
static LK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
static LK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
let x = LK.lock();

// step 1
Expand All @@ -161,7 +163,7 @@ impl Engine for RocksEngine {
// so we use a `Mutex` lock for thread safe.
#[allow(unused_variables)]
fn alloc_ver_id(&self) -> VersionID {
static LK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
static LK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
let x = LK.lock();

// step 1
Expand Down
17 changes: 10 additions & 7 deletions core/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
pub(crate) mod engines;

use engines::Engine;
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use ruc::*;
use serde::{Deserialize, Serialize};
use std::{
env, fs,
mem::size_of,
path::{Path, PathBuf},
sync::atomic::{AtomicBool, Ordering},
sync::{
atomic::{AtomicBool, Ordering},
LazyLock,
},
};
use threadpool::ThreadPool;

Expand Down Expand Up @@ -73,9 +75,10 @@ pub const RESERVED_VERSION_NUM_DEFAULT: usize = 10;

const BASE_DIR_VAR: &str = "VSDB_BASE_DIR";

static VSDB_BASE_DIR: Lazy<Mutex<PathBuf>> = Lazy::new(|| Mutex::new(gen_data_dir()));
static VSDB_BASE_DIR: LazyLock<Mutex<PathBuf>> =
LazyLock::new(|| Mutex::new(gen_data_dir()));

static VSDB_CUSTOM_DIR: Lazy<PathBuf> = Lazy::new(|| {
static VSDB_CUSTOM_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
let mut d = VSDB_BASE_DIR.lock().clone();
d.push("__CUSTOM__");
pnk!(fs::create_dir_all(&d));
Expand All @@ -84,13 +87,13 @@ static VSDB_CUSTOM_DIR: Lazy<PathBuf> = Lazy::new(|| {
});

#[cfg(feature = "rocks_backend")]
pub static VSDB: Lazy<VsDB<engines::RocksDB>> = Lazy::new(|| pnk!(VsDB::new()));
pub static VSDB: LazyLock<VsDB<engines::RocksDB>> = LazyLock::new(|| pnk!(VsDB::new()));

#[cfg(feature = "parity_backend")]
pub static VSDB: Lazy<VsDB<engines::ParityDB>> = Lazy::new(|| pnk!(VsDB::new()));
pub static VSDB: LazyLock<VsDB<engines::ParityDB>> = LazyLock::new(|| pnk!(VsDB::new()));

/// Clean orphan instances in background.
pub static TRASH_CLEANER: Lazy<Mutex<ThreadPool>> = Lazy::new(|| {
pub static TRASH_CLEANER: LazyLock<Mutex<ThreadPool>> = LazyLock::new(|| {
let pool = threadpool::Builder::new()
.num_threads(1)
.thread_stack_size(512 * MB as usize) // use large stack size
Expand Down
3 changes: 1 addition & 2 deletions wrappers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vsdb"
version = "1.0.1"
version = "1.0.2"
authors = ["[email protected]"]
edition = "2021"
description = "A std-collection-like database"
Expand All @@ -15,7 +15,6 @@ features = []

[dependencies]
serde = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }

msgpack = { workspace = true, optional = true }
Expand Down
4 changes: 2 additions & 2 deletions wrappers/src/basic/mapx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ where

#[inline(always)]
pub fn remove(&mut self, key: &K) -> Option<V> {
self.inner.remove(&key.encode())
self.inner.remove(key.encode())
}

#[inline(always)]
pub fn unset_value(&mut self, key: &K) {
self.inner.unset_value(&key.encode());
self.inner.unset_value(key.encode());
}

#[inline(always)]
Expand Down
8 changes: 4 additions & 4 deletions wrappers/src/basic/mapx_ord/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ where
key: &K,
value: impl AsRef<[u8]>,
) -> Option<V> {
self.inner.insert_encoded_value(&key.to_bytes(), value)
self.inner.insert_encoded_value(key.to_bytes(), value)
}

#[inline(always)]
pub fn set_value(&mut self, key: &K, value: &V) {
self.inner.insert(&key.to_bytes(), value);
self.inner.insert(key.to_bytes(), value);
}

#[inline(always)]
Expand Down Expand Up @@ -258,12 +258,12 @@ where

#[inline(always)]
pub fn remove(&mut self, key: &K) -> Option<V> {
self.inner.remove(&key.to_bytes())
self.inner.remove(key.to_bytes())
}

#[inline(always)]
pub fn unset_value(&mut self, key: &K) {
self.inner.remove(&key.to_bytes());
self.inner.remove(key.to_bytes());
}

#[inline(always)]
Expand Down
4 changes: 2 additions & 2 deletions wrappers/src/basic/mapx_ord_rawkey/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ where
#[inline(always)]
pub fn insert(&mut self, key: impl AsRef<[u8]>, value: &V) -> Option<V> {
self.inner
.insert(key.as_ref(), &value.encode())
.insert(key.as_ref(), value.encode())
.map(|v| <V as ValueEnDe>::decode(&v).unwrap())
}

Expand All @@ -168,7 +168,7 @@ where

#[inline(always)]
pub fn set_value(&mut self, key: impl AsRef<[u8]>, value: &V) {
self.inner.insert(key.as_ref(), &value.encode());
self.inner.insert(key.as_ref(), value.encode());
}

#[inline(always)]
Expand Down
12 changes: 6 additions & 6 deletions wrappers/src/basic/mapx_ord_rawvalue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ where
#[inline(always)]
pub fn get_le(&self, key: &K) -> Option<(K, RawValue)> {
self.inner
.get_le(&key.to_bytes())
.get_le(key.to_bytes())
.map(|(k, v)| (pnk!(K::from_bytes(k)), v))
}

#[inline(always)]
pub fn get_ge(&self, key: &K) -> Option<(K, RawValue)> {
self.inner
.get_ge(&key.to_bytes())
.get_ge(key.to_bytes())
.map(|(k, v)| (pnk!(K::from_bytes(k)), v))
}

Expand All @@ -145,12 +145,12 @@ where

#[inline(always)]
pub fn insert(&mut self, key: &K, value: impl AsRef<[u8]>) -> Option<RawValue> {
self.inner.insert(&key.to_bytes(), value.as_ref())
self.inner.insert(key.to_bytes(), value.as_ref())
}

#[inline(always)]
pub fn set_value(&mut self, key: &K, value: impl AsRef<[u8]>) {
self.inner.insert(&key.to_bytes(), value.as_ref());
self.inner.insert(key.to_bytes(), value.as_ref());
}

#[inline(always)]
Expand Down Expand Up @@ -247,12 +247,12 @@ where

#[inline(always)]
pub fn remove(&mut self, key: &K) -> Option<RawValue> {
self.inner.remove(&key.to_bytes())
self.inner.remove(key.to_bytes())
}

#[inline(always)]
pub fn unset_value(&mut self, key: &K) {
self.inner.remove(&key.to_bytes());
self.inner.remove(key.to_bytes());
}

#[inline(always)]
Expand Down
Loading

0 comments on commit cb85ca0

Please sign in to comment.