Skip to content

Commit

Permalink
Cargo.toml edition update to 2021
Browse files Browse the repository at this point in the history
cargo upgrade
fix gen_range
cargo fmt
cargo clippy
  • Loading branch information
gcxfd committed Jul 5, 2022
1 parent f3b4b3f commit 76c3c78
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 94 deletions.
38 changes: 17 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,38 @@
name = "agatedb"
version = "0.1.0"
authors = ["Jay Lee <busyjaylee@gmail.com>"]
edition = "2018"
edition = "2021"

[dependencies]
bytes = "1.0"
bytes = "1.1.0"
coarsetime = "0.1.22"
crc = "1.8"
crc32fast = "1.2"
crossbeam-channel = "0.5"
enum_dispatch = "0.3"
farmhash = "1.1"
crc = "3.0.0"
crc32fast = "1.3.2"
crossbeam-channel = "0.5.5"
enum_dispatch = "0.3.8"
farmhash = "1.1.5"
getset = "0.1.2"
lazy_static = "1.4.0"
log = "0.4.17"
memmap2 = "0.3"
parking_lot = "0.11"
prost = "0.8"
memmap2 = "0.5.4"
parking_lot = "0.12.1"
prost = "0.10.4"
proto = { path = "proto" }
rand = "0.7"
rand = "0.8.5"
skiplist = { path = "skiplist" }
tempdir = "0.3"
thiserror = "1.0"
tempdir = "0.3.7"
thiserror = "1.0.31"
yatp = { git = "https://github.com/tikv/yatp.git" }

[dev-dependencies]
criterion = "0.3"
tempfile = "3"
criterion = "0.3.5"
tempfile = "3.3.0"

[target.'cfg(not(target_env = "msvc"))'.dev-dependencies]
tikv-jemallocator = "0.4.0"
tikv-jemallocator = "0.5.0"

[workspace]
members = [
"agate_bench",
"proto",
"skiplist"
]
members = ["agate_bench", "proto", "skiplist"]

[[bench]]
name = "bench_common"
Expand Down
2 changes: 1 addition & 1 deletion agate_bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ threadpool = "1.8"
yatp = { git = "https://github.com/tikv/yatp.git" }

[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.4.0"
tikv-jemallocator = "0.5.0"
19 changes: 10 additions & 9 deletions agate_bench/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::{
path::PathBuf,
sync::{mpsc::channel, Arc},
time::{Duration, UNIX_EPOCH},
};

use agatedb::{AgateOptions, IteratorOptions};
use bytes::{Bytes, BytesMut};
use clap::clap_app;
use indicatif::{ProgressBar, ProgressStyle};
use rand::Rng;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::UNIX_EPOCH;
use std::{sync::mpsc::channel, time::Duration};

#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;

Expand Down Expand Up @@ -169,7 +170,7 @@ fn main() {
let (key, value) = if seq {
gen_kv_pair(j, value_size)
} else {
gen_kv_pair(rng.gen_range(0, key_nums), value_size)
gen_kv_pair(rng.gen_range(0..key_nums), value_size)
};
txn.set(key, value).unwrap();
write.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
Expand Down Expand Up @@ -236,7 +237,7 @@ fn main() {
let txn = agate.new_transaction_at(unix_time(), false);
let mut rng = rand::thread_rng();
for _ in range {
let (key, _) = gen_kv_pair(rng.gen_range(0, key_nums), value_size);
let (key, _) = gen_kv_pair(rng.gen_range(0..key_nums), value_size);
match txn.get(&key) {
Ok(item) => {
assert_eq!(item.value().len(), value_size);
Expand Down Expand Up @@ -369,7 +370,7 @@ fn main() {
let (key, value) = if seq {
gen_kv_pair(j, value_size)
} else {
gen_kv_pair(rng.gen_range(0, key_nums), value_size)
gen_kv_pair(rng.gen_range(0..key_nums), value_size)
};
batch.put(key, value);
write.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
Expand Down Expand Up @@ -431,7 +432,7 @@ fn main() {
let range = (i * chunk_size)..((i + 1) * chunk_size);
let mut rng = rand::thread_rng();
for _ in range {
let (key, _) = gen_kv_pair(rng.gen_range(0, key_nums), value_size);
let (key, _) = gen_kv_pair(rng.gen_range(0..key_nums), value_size);
match db.get(&key) {
Ok(Some(value)) => {
assert_eq!(value.len(), value_size);
Expand Down
16 changes: 6 additions & 10 deletions benches/bench_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
mod common;

use agatedb::util::unix_time;
use agatedb::AgateIterator;
use agatedb::AgateOptions;
use agatedb::ConcatIterator;
use agatedb::Iterators;
use agatedb::MergeIterator;

use agatedb::{
util::unix_time, AgateIterator, AgateOptions, ConcatIterator, Iterators, MergeIterator,
};
use bytes::Bytes;
use common::get_table_for_benchmark;
use criterion::{criterion_group, criterion_main, Criterion};
Expand Down Expand Up @@ -58,7 +54,7 @@ fn bench_iterator(c: &mut Criterion) {

c.bench_function("iterate noprefix single key", |b| {
let txn = db.new_transaction_at(unix_time(), false);
let key_id = thread_rng().gen_range(0, N);
let key_id = thread_rng().gen_range(0..N);
let seek_key = key(key_id);
let it_opts = agatedb::IteratorOptions {
all_versions: true,
Expand Down Expand Up @@ -110,7 +106,7 @@ fn bench_merge_iterator(c: &mut Criterion) {
c.bench_function("merge iterator random read", |b| {
b.iter_batched(
|| {
let i = rng.gen_range(0, n);
let i = rng.gen_range(0..n);
(
Bytes::from(format!("{:016x}", i)),
Bytes::from(i.to_string()),
Expand Down Expand Up @@ -149,7 +145,7 @@ fn bench_concat_iterator(c: &mut Criterion) {
c.bench_function("concat iterator random read", |b| {
b.iter_batched(
|| {
let i = rng.gen_range(0, n);
let i = rng.gen_range(0..n);
(
Bytes::from(format!("{:016x}", i)),
Bytes::from(i.to_string()),
Expand Down
2 changes: 1 addition & 1 deletion benches/bench_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn bench_table(c: &mut Criterion) {

b.iter_batched(
|| {
let i = rng.gen_range(0, n);
let i = rng.gen_range(0..n);
(
Bytes::from(format!("{:016x}", i)),
Bytes::from(i.to_string()),
Expand Down
4 changes: 3 additions & 1 deletion benches/common.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#![allow(dead_code)]
use std::ops::{Deref, DerefMut};

use agatedb::{
opt::build_table_options, AgateOptions, ChecksumVerificationMode::NoVerification, Table,
TableBuilder, Value,
};
use bytes::Bytes;
use rand::{distributions::Alphanumeric, Rng};
use std::ops::{Deref, DerefMut};
use tempdir::TempDir;

pub fn rand_value() -> String {
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(32)
.map(char::from)
.collect::<String>()
}

Expand Down
8 changes: 4 additions & 4 deletions proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
name = "proto"
version = "0.1.0"
authors = ["Jay Lee <busyjaylee@gmail.com>"]
edition = "2018"
edition = "2021"

[dependencies]
bytes = "1.0"
prost = "0.8"
bytes = "1.1.0"
prost = "0.10.4"

[build-dependencies]
prost-build = { version = "0.8" }
prost-build = "0.10.4"
10 changes: 5 additions & 5 deletions skiplist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
name = "skiplist"
version = "0.1.0"
authors = ["Jay Lee <busyjaylee@gmail.com>"]
edition = "2018"
edition = "2021"

[dependencies]
bytes = "1.0"
rand = "0.7"
bytes = "1.1.0"
rand = "0.8.5"

[dev-dependencies]
criterion = "0.3"
criterion = "0.3.5"
yatp = { git = "https://github.com/tikv/yatp.git" }

[target.'cfg(not(target_env = "msvc"))'.dev-dependencies]
tikv-jemallocator = "0.4.0"
tikv-jemallocator = "0.5.0"

[[bench]]
name = "bench"
Expand Down
8 changes: 4 additions & 4 deletions skiplist/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ fn bench_read_write_skiplist_frac(b: &mut Bencher<'_>, frac: &usize) {
let mut rng = rand::thread_rng();
while !s.load(Ordering::SeqCst) {
let key = random_key(&mut rng);
let case = (key, frac > rng.gen_range(0, 11));
let case = (key, frac > rng.gen_range(0..11));
skiplist_round(&l, &case, &v);
}
});
let mut rng = rand::thread_rng();
b.iter_batched_ref(
|| (random_key(&mut rng), frac > rng.gen_range(0, 11)),
|| (random_key(&mut rng), frac > rng.gen_range(0..11)),
|case| skiplist_round(&list, case, &value),
BatchSize::SmallInput,
);
Expand Down Expand Up @@ -104,15 +104,15 @@ fn bench_read_write_map_frac(b: &mut Bencher<'_>, frac: &usize) {
let h = thread::spawn(move || {
let mut rng = rand::thread_rng();
while !s.load(Ordering::SeqCst) {
let f = rng.gen_range(0, 11);
let f = rng.gen_range(0..11);
let case = (random_key(&mut rng), f < frac);
map_round(&m, &case, &v);
}
});
let mut rng = rand::thread_rng();
b.iter_batched_ref(
|| {
let f = rng.gen_range(0, 11);
let f = rng.gen_range(0..11);
(random_key(&mut rng), f < frac)
},
|case| map_round(&map, case, &value),
Expand Down
3 changes: 2 additions & 1 deletion src/checksum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{Error, Result};
use proto::meta::{checksum::Algorithm as ChecksumAlgorithm, Checksum};

use crate::{Error, Result};

pub fn calculate_checksum(data: &[u8], algo: ChecksumAlgorithm) -> u64 {
match algo {
ChecksumAlgorithm::Crc32c => {
Expand Down
6 changes: 3 additions & 3 deletions src/db/opt.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use skiplist::MAX_NODE_SIZE;
use std::cmp;

use super::*;
use getset::Setters;
use skiplist::MAX_NODE_SIZE;

use super::*;
use crate::{entry::Entry, opt};
use std::cmp;

#[derive(Clone, Setters)]
pub struct AgateOptions {
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub use iterator::IteratorOptions;
pub use iterator_trait::AgateIterator;
pub use opt::{ChecksumVerificationMode, Options as TableOptions};
pub use skiplist::Skiplist;
pub use table::merge_iterator::Iterators;
pub use table::ConcatIterator;
pub use table::MergeIterator;
pub use table::{builder::Builder as TableBuilder, Table};
pub use table::{
builder::Builder as TableBuilder, merge_iterator::Iterators, ConcatIterator, MergeIterator,
Table,
};
pub use value::Value;
6 changes: 2 additions & 4 deletions src/managed_db.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::db::Agate;
use crate::ops::transaction::Transaction;
use crate::Result;

use std::sync::Arc;

use crate::{db::Agate, ops::transaction::Transaction, Result};

impl crate::db::Core {
/// Follows the same logic as `new_transaction`, but uses the provided read timestamp.
pub fn new_transaction_at(self: &Arc<Self>, read_ts: u64, update: bool) -> Transaction {
Expand Down
10 changes: 6 additions & 4 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ use std::{
};

use bytes::{Buf, BufMut, BytesMut};
use crc::crc32;
use crc::{Crc, CRC_32_ISCSI};
use prost::Message;
use proto::meta::{
manifest_change::Operation as ManifestChangeOp, ManifestChange, ManifestChangeSet,
};

use crate::{util, AgateOptions, Error, Result};

pub const CRC32_CASTAGNOLI: Crc<u32> = Crc::<u32>::new(&CRC_32_ISCSI);

pub const MANIFEST_FILENAME: &str = "MANIFEST";
const MANIFEST_REWRITE_FILENAME: &str = "MANIFEST_REWRITE";
const MANIFEST_DELETION_REWRITE_THRESHOLD: usize = 10000;
Expand Down Expand Up @@ -134,7 +136,7 @@ impl Manifest {

offset += length;

if crc32::checksum_castagnoli(&buf) != (&len_crc_buf[4..]).get_u32() {
if CRC32_CASTAGNOLI.checksum(&buf) != (&len_crc_buf[4..]).get_u32() {
return Err(Error::CustomError("bad checksum".to_string()));
}

Expand Down Expand Up @@ -241,7 +243,7 @@ impl ManifestFile {

let mut len_crc_buf = vec![0; 8];
(&mut len_crc_buf[..4]).put_u32(change_buf.len() as u32);
(&mut len_crc_buf[4..]).put_u32(crc32::checksum_castagnoli(&change_buf));
(&mut len_crc_buf[4..]).put_u32(CRC32_CASTAGNOLI.checksum(&change_buf));

buf.extend_from_slice(&len_crc_buf);
buf.extend_from_slice(&change_buf);
Expand Down Expand Up @@ -294,7 +296,7 @@ impl ManifestFile {
} else {
let mut len_crc_buf = vec![0; 8];
(&mut len_crc_buf[..4]).put_u32(buf.len() as u32);
(&mut len_crc_buf[4..]).put_u32(crc32::checksum_castagnoli(&buf));
(&mut len_crc_buf[4..]).put_u32(CRC32_CASTAGNOLI.checksum(&buf));
len_crc_buf.extend_from_slice(&buf);

inner.file.as_mut().unwrap().write_all(&len_crc_buf)?;
Expand Down
8 changes: 2 additions & 6 deletions src/ops/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ impl Transaction {
let mut entries: Vec<_> = self.pending_writes.values().cloned().collect();
entries.sort_by(|x, y| {
let cmp = COMPARATOR.compare_key(&x.key, &y.key);
if reversed {
cmp.reverse()
} else {
cmp
}
if reversed { cmp.reverse() } else { cmp }
});

Some(PendingWritesIterator::new(self.read_ts, reversed, entries))
Expand Down Expand Up @@ -458,7 +454,7 @@ impl AgateIterator for PendingWritesIterator {
let key = user_key(key);
self.next_idx = crate::util::search(self.entries.len(), |idx| {
// Should not use COMPARATOR when compare without ts.
let cmp = (&self.entries[idx].key[..]).cmp(key);
let cmp = self.entries[idx].key[..].cmp(key);
if !self.reversed {
cmp != Less
} else {
Expand Down
Loading

0 comments on commit 76c3c78

Please sign in to comment.