Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use crate allocator_api2 to make foyer build on stable #317

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/template/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ name:
on:

env:
RUST_TOOLCHAIN: nightly-2023-12-26
RUST_TOOLCHAIN: stable
RUST_TOOLCHAIN_NIGHTLY: nightly-2024-03-17
CARGO_TERM_COLOR: always
CACHE_KEY_SUFFIX: 20240306
CACHE_KEY_SUFFIX: 20240410-2

jobs:
misc-check:
Expand Down Expand Up @@ -132,7 +133,7 @@ jobs:
- name: Install rust toolchain@v1
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
toolchain: ${{ env.RUST_TOOLCHAIN_NIGHTLY }}
- name: Cache Cargo home
uses: actions/cache@v2
id: cache
Expand All @@ -149,14 +150,14 @@ jobs:
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Address Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo build --all --target x86_64-unknown-linux-gnu
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/asan
timeout 2m ./target/x86_64-unknown-linux-gnu/debug/foyer-storage-bench --dir $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/asan --capacity 256 --region-size 16 --lookup-range 1000 --w-rate 1 --r-rate 1 --ticket-insert-rate-limit 10 --time 60
lsan:
Expand All @@ -168,7 +169,7 @@ jobs:
- name: Install rust toolchain@v1
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
toolchain: ${{ env.RUST_TOOLCHAIN_NIGHTLY }}
- name: Cache Cargo home
uses: actions/cache@v2
id: cache
Expand All @@ -185,14 +186,14 @@ jobs:
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Leak Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo build --all --target x86_64-unknown-linux-gnu
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/lsan
timeout 2m ./target/x86_64-unknown-linux-gnu/debug/foyer-storage-bench --dir $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/lsan --capacity 256 --region-size 16 --lookup-range 1000 --w-rate 1 --r-rate 1 --ticket-insert-rate-limit 10 --time 60
deterministic-test:
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ on:
branches: [main]
workflow_dispatch:
env:
RUST_TOOLCHAIN: nightly-2023-12-26
RUST_TOOLCHAIN: stable
RUST_TOOLCHAIN_NIGHTLY: nightly-2024-03-17
CARGO_TERM_COLOR: always
CACHE_KEY_SUFFIX: 20240306
CACHE_KEY_SUFFIX: 20240410-2
jobs:
misc-check:
name: misc check
Expand Down Expand Up @@ -139,7 +140,7 @@ jobs:
- name: Install rust toolchain@v1
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
toolchain: ${{ env.RUST_TOOLCHAIN_NIGHTLY }}
- name: Cache Cargo home
uses: actions/cache@v2
id: cache
Expand All @@ -156,14 +157,14 @@ jobs:
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Address Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo build --all --target x86_64-unknown-linux-gnu
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/asan
timeout 2m ./target/x86_64-unknown-linux-gnu/debug/foyer-storage-bench --dir $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/asan --capacity 256 --region-size 16 --lookup-range 1000 --w-rate 1 --r-rate 1 --ticket-insert-rate-limit 10 --time 60
lsan:
Expand All @@ -175,7 +176,7 @@ jobs:
- name: Install rust toolchain@v1
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
toolchain: ${{ env.RUST_TOOLCHAIN_NIGHTLY }}
- name: Cache Cargo home
uses: actions/cache@v2
id: cache
Expand All @@ -192,14 +193,14 @@ jobs:
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Leak Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo build --all --target x86_64-unknown-linux-gnu
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/lsan
timeout 2m ./target/x86_64-unknown-linux-gnu/debug/foyer-storage-bench --dir $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/lsan --capacity 256 --region-size 16 --lookup-range 1000 --w-rate 1 --r-rate 1 --ticket-insert-rate-limit 10 --time 60
deterministic-test:
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ on:
pull_request:
branches: [main]
env:
RUST_TOOLCHAIN: nightly-2023-12-26
RUST_TOOLCHAIN: stable
RUST_TOOLCHAIN_NIGHTLY: nightly-2024-03-17
CARGO_TERM_COLOR: always
CACHE_KEY_SUFFIX: 20240306
CACHE_KEY_SUFFIX: 20240410-2
jobs:
misc-check:
name: misc check
Expand Down Expand Up @@ -138,7 +139,7 @@ jobs:
- name: Install rust toolchain@v1
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
toolchain: ${{ env.RUST_TOOLCHAIN_NIGHTLY }}
- name: Cache Cargo home
uses: actions/cache@v2
id: cache
Expand All @@ -155,14 +156,14 @@ jobs:
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Address Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo build --all --target x86_64-unknown-linux-gnu
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/asan
timeout 2m ./target/x86_64-unknown-linux-gnu/debug/foyer-storage-bench --dir $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/asan --capacity 256 --region-size 16 --lookup-range 1000 --w-rate 1 --r-rate 1 --ticket-insert-rate-limit 10 --time 60
lsan:
Expand All @@ -174,7 +175,7 @@ jobs:
- name: Install rust toolchain@v1
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
toolchain: ${{ env.RUST_TOOLCHAIN_NIGHTLY }}
- name: Cache Cargo home
uses: actions/cache@v2
id: cache
Expand All @@ -191,14 +192,14 @@ jobs:
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Leak Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
run: |-
cargo build --all --target x86_64-unknown-linux-gnu
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/lsan
timeout 2m ./target/x86_64-unknown-linux-gnu/debug/foyer-storage-bench --dir $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/lsan --capacity 256 --region-size 16 --lookup-range 1000 --w-rate 1 --r-rate 1 --ticket-insert-rate-limit 10 --time 60
deterministic-test:
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ check:
cargo sort -w
cargo fmt --all
cargo clippy --all-targets
cargo udeps --workspace --exclude foyer-workspace-hack
# TODO(MrCroxx): Restore udeps check after it doesn't requires nightly anymore.
# cargo udeps --workspace --exclude foyer-workspace-hack

check-all:
shellcheck ./scripts/*
Expand All @@ -28,7 +29,8 @@ check-all:
cargo clippy --all-targets --features tokio-console
cargo clippy --all-targets --features trace
cargo clippy --all-targets
cargo udeps --workspace --exclude foyer-workspace-hack
# TODO(MrCroxx): Restore udeps check after it doesn't requires nightly anymore.
# cargo udeps --workspace --exclude foyer-workspace-hack

test:
RUST_BACKTRACE=1 cargo nextest run --all
Expand Down
1 change: 0 additions & 1 deletion foyer-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![feature(bound_map)]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]

pub mod async_queue;
Expand Down
7 changes: 6 additions & 1 deletion foyer-experimental/src/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ impl<H: HashValue> TombstoneLog<H> {

path.push(format!("tombstone-{:08X}", config.id));

let file = OpenOptions::new().write(true).read(true).create(true).open(path)?;
let file = OpenOptions::new()
.write(true)
.read(true)
.create(true)
.truncate(true)
.open(path)?;

let inner = Arc::new(TombstoneLogInner {
inflights: Mutex::new(vec![]),
Expand Down
6 changes: 0 additions & 6 deletions foyer-intrusive/src/core/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ pub unsafe trait PriorityAdapter: Adapter {
/// # Examples
///
/// ```
/// #![feature(offset_of)]
///
/// use foyer_intrusive::{intrusive_adapter, key_adapter};
/// use foyer_intrusive::core::adapter::{Adapter, KeyAdapter, Link};
/// use foyer_intrusive::core::pointer::Pointer;
Expand Down Expand Up @@ -215,8 +213,6 @@ macro_rules! intrusive_adapter {
/// # Examples
///
/// ```
/// #![feature(offset_of)]
///
/// use foyer_intrusive::{intrusive_adapter, key_adapter};
/// use foyer_intrusive::core::adapter::{Adapter, KeyAdapter, Link};
/// use foyer_intrusive::core::pointer::Pointer;
Expand Down Expand Up @@ -286,8 +282,6 @@ macro_rules! key_adapter {
/// # Examples
///
/// ```
/// #![feature(offset_of)]
///
/// use foyer_intrusive::{intrusive_adapter, priority_adapter};
/// use foyer_intrusive::core::adapter::{Adapter, PriorityAdapter, Link};
/// use foyer_intrusive::core::pointer::Pointer;
Expand Down
3 changes: 0 additions & 3 deletions foyer-intrusive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![feature(offset_of)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#![allow(clippy::new_without_default)]

Expand All @@ -24,8 +23,6 @@ pub use memoffset::offset_of;
/// # Examples
///
/// ```
/// #![feature(offset_of)]
///
/// use foyer_intrusive::container_of;
///
/// struct S { x: u32, y: u32 };
Expand Down
2 changes: 0 additions & 2 deletions foyer-memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
//! The handle that does not appear in either the indexer or the eviction container, and has no external owner, will be
//! destroyed.
#![feature(offset_of)]

pub trait Key: Send + Sync + 'static + std::hash::Hash + Eq + Ord {}
pub trait Value: Send + Sync + 'static {}

Expand Down
1 change: 1 addition & 0 deletions foyer-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ homepage = "https://github.com/mrcroxx/foyer"
normal = ["foyer-workspace-hack"]

[dependencies]
allocator-api2 = "0.2" # TODO(MrCroxx): Remove this after `allocator_api` is stable.
anyhow = "1.0"
bitflags = "2.3.1"
bitmaps = "3.2"
Expand Down
15 changes: 9 additions & 6 deletions foyer-storage/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@

use std::fmt::Debug;

use allocator_api2::vec::Vec as VecA;
use foyer_common::{
bits::{align_up, is_aligned},
code::{Cursor, Key, Value},
};

use crate::{
compress::Compression,
device::{error::DeviceError, Device},
device::{allocator::WritableVecA, error::DeviceError, Device},
flusher::Entry,
generic::{checksum, EntryHeader},
region::{RegionHeader, RegionId, Version, REGION_MAGIC},
Expand Down Expand Up @@ -63,7 +64,7 @@ where
{
// TODO(MrCroxx): optimize buffer allocation
/// io buffer
buffer: Vec<u8, D::IoBufferAllocator>,
buffer: VecA<u8, D::IoBufferAllocator>,

/// current writing region
region: Option<RegionId>,
Expand Down Expand Up @@ -227,15 +228,17 @@ where
let mut vcursor = value.into_cursor();
match compression {
Compression::None => {
std::io::copy(&mut vcursor, &mut self.buffer).map_err(DeviceError::from)?;
std::io::copy(&mut vcursor, &mut WritableVecA(&mut self.buffer)).map_err(DeviceError::from)?;
}
Compression::Zstd => {
zstd::stream::copy_encode(&mut vcursor, &mut self.buffer, 0).map_err(DeviceError::from)?;
zstd::stream::copy_encode(&mut vcursor, &mut WritableVecA(&mut self.buffer), 0)
.map_err(DeviceError::from)?;
}
Compression::Lz4 => {
let buf = &mut WritableVecA(&mut self.buffer);
let mut encoder = lz4::EncoderBuilder::new()
.checksum(lz4::ContentChecksum::NoChecksum)
.build(&mut self.buffer)
.build(buf)
.map_err(DeviceError::from)?;
std::io::copy(&mut vcursor, &mut encoder).map_err(DeviceError::from)?;
let (_w, res) = encoder.finish();
Expand All @@ -247,7 +250,7 @@ where

// write key
let mut kcursor = key.into_cursor();
std::io::copy(&mut kcursor, &mut self.buffer).map_err(DeviceError::from)?;
std::io::copy(&mut kcursor, &mut WritableVecA(&mut self.buffer)).map_err(DeviceError::from)?;
let encoded_key_len = self.buffer.len() - cursor;
cursor = self.buffer.len();

Expand Down
Loading
Loading