Skip to content

Commit

Permalink
chore: update license (#258)
Browse files Browse the repository at this point in the history
Signed-off-by: MrCroxx <[email protected]>
  • Loading branch information
MrCroxx authored Jan 19, 2024
1 parent eef8d78 commit e65b0a5
Show file tree
Hide file tree
Showing 65 changed files with 567 additions and 62 deletions.
2 changes: 1 addition & 1 deletion foyer-common/src/batch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion foyer-common/src/bits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion foyer-common/src/code.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion foyer-common/src/continuum.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion foyer-common/src/erwlock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion foyer-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion foyer-common/src/queue.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion foyer-common/src/range.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion foyer-common/src/rate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion foyer-common/src/rated_ticket.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion foyer-common/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 MrCroxx
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
111 changes: 111 additions & 0 deletions foyer-experimental/examples/tombstone-log-bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{
sync::Arc,
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
};

use clap::Parser;
use foyer_common::runtime::BackgroundShutdownRuntime;
use foyer_experimental::tombstone::{Tombstone, TombstoneLog, TombstoneLogConfig};
use itertools::Itertools;
use rand::{rngs::StdRng, Rng, SeedableRng};

#[derive(Parser, Debug, Clone)]
#[command(author, version, about)]
pub struct Args {
/// dir for cache data
#[arg(short, long)]
dir: String,

/// writer concurrency
#[arg(short, long, default_value_t = 1024)]
concurrency: usize,

/// time (s)
#[arg(short, long, default_value_t = 10)]
time: usize,
}

#[tokio::main]
async fn main() {
let args = Args::parse();

let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
let rt = BackgroundShutdownRuntime::from(rt);
let rt = Arc::new(rt);

let config = TombstoneLogConfig {
id: 0,
dir: args.dir.clone().into(),
};
let log = TombstoneLog::open(config).await.unwrap();

let handles = (0..args.concurrency)
.map(|_| {
let log = log.clone();
let args = args.clone();
let rt = rt.clone();
tokio::spawn(async move {
write(log.clone(), args, rt).await;
})
})
.collect_vec();

for handle in handles {
handle.await.unwrap();
}

println!("Bench finishes.");

log.close().await.unwrap();
}

async fn write(log: TombstoneLog<u64>, args: Args, rt: Arc<BackgroundShutdownRuntime>) {
let start = Instant::now();
let mut log = log;

let mut rng = StdRng::seed_from_u64(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_nanos() as _,
);
loop {
if start.elapsed() >= Duration::from_secs(args.time as _) {
return;
}

// let now = Instant::now();

let tombstone = Tombstone::new(rng.gen(), rng.gen());
log = rt
.spawn(async move {
log.append(tombstone).await.unwrap();
log
})
.await
.unwrap();

// let duration = now.elapsed();

// if duration.as_micros() >= 1000 {
// println!("slow: {:?}", duration);
// }
}
}
65 changes: 65 additions & 0 deletions foyer-experimental/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2024 MrCroxx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::backtrace::Backtrace;

#[derive(thiserror::Error, Debug)]
#[error("{0}")]
pub struct Error(Box<ErrorInner>);

#[derive(thiserror::Error, Debug)]
#[error("{source:?}")]
struct ErrorInner {
#[from]
source: ErrorKind,
backtrace: Backtrace,
}

#[derive(thiserror::Error, Debug)]
pub enum ErrorKind {
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("other error: {0}")]
Other(#[from] anyhow::Error),
}

impl From<ErrorKind> for Error {
fn from(value: ErrorKind) -> Self {
value.into()
}
}

impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
value.into()
}
}

impl From<anyhow::Error> for Error {
fn from(value: anyhow::Error) -> Self {
value.into()
}
}

pub type Result<T> = core::result::Result<T, Error>;

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_error_size() {
assert_eq!(std::mem::size_of::<Error>(), std::mem::size_of::<usize>());
}
}
Loading

0 comments on commit e65b0a5

Please sign in to comment.