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

[sync] Update to DashMap 6 (for mini-moka v0.11.x) #40

Merged
merged 5 commits into from
Sep 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
6 changes: 0 additions & 6 deletions .ci_extras/pin-crate-vers-msrv.sh

This file was deleted.

6 changes: 1 addition & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
rust:
- stable
- beta
- 1.61.0 # MSRV
- 1.76.0 # MSRV
- nightly # For checking minimum version dependencies.

steps:
Expand All @@ -42,10 +42,6 @@ jobs:
if: ${{ matrix.rust == 'nightly' }}
run: cargo update -Z minimal-versions

- name: Pin some dependencies to specific versions (MSRV only)
if: ${{ matrix.rust == '1.61.0' }}
run: ./.ci_extras/pin-crate-vers-msrv.sh

- name: Show cargo tree
run: cargo tree

Expand Down
24 changes: 9 additions & 15 deletions .github/workflows/LinuxCrossCompileTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ name: Linux cross compile tests
on:
push:
paths-ignore:
- '.devcontainer/**'
- '.gitpod.yml'
- '.vscode/**'
- 'tests/**'
- ".devcontainer/**"
- ".gitpod.yml"
- ".vscode/**"
- "tests/**"
pull_request:
paths-ignore:
- '.devcontainer/**'
- '.gitpod.yml'
- '.vscode/**'
- 'tests/**'
- ".devcontainer/**"
- ".gitpod.yml"
- ".vscode/**"
- "tests/**"
schedule:
# Run against the last commit on the default branch on Friday at 9pm (UTC?)
- cron: '0 21 * * 5'
- cron: "0 21 * * 5"

jobs:
linux-cross:
Expand All @@ -32,12 +32,6 @@ jobs:
rust-version: stable
- target: armv5te-unknown-linux-musleabi
rust-version: stable
- target: mips-unknown-linux-musl
rust-version: "1.72.1"
cargo-version: "+1.72.1"
- target: mipsel-unknown-linux-musl
rust-version: "1.72.1"
cargo-version: "+1.72.1"

steps:
- name: Checkout Mini Moka
Expand Down
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "mini-moka"
version = "0.10.3"
version = "0.11.0"
edition = "2018"
rust-version = "1.61"
rust-version = "1.76"

description = "A lighter edition of Moka, a fast and concurrent cache library"
license = "MIT OR Apache-2.0"
Expand All @@ -27,11 +27,10 @@ tagptr = "0.2"

# Opt-out serde and stable_deref_trait features
# https://github.com/Manishearth/triomphe/pull/5
# 0.1.12 requires Rust 1.76
triomphe = { version = ">=0.1.3, <0.1.12", default-features = false }
triomphe = { version = "0.1.13", default-features = false }

# Optional dependencies (enabled by default)
dashmap = { version = "5.2", optional = true }
dashmap = { version = "6.1", optional = true }

[dev-dependencies]
anyhow = "1.0.19"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Mini Moka's minimum supported Rust versions (MSRV) are the followings:

| Feature | MSRV |
|:-----------------|:--------------------------:|
| default features | Rust 1.61.0 (May 19, 2022) |
| default features | Rust 1.76.0 (Feb 8, 2024) |

It will keep a rolling MSRV policy of at least 6 months. If only the default features
are enabled, MSRV will be updated conservatively. When using other features, MSRV
Expand Down
8 changes: 2 additions & 6 deletions src/common/frequency_sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl FrequencySketch {
mod tests {
use super::FrequencySketch;
use once_cell::sync::Lazy;
use std::hash::{BuildHasher, Hash, Hasher};
use std::hash::{BuildHasher, Hash};

static ITEM: Lazy<u32> = Lazy::new(|| {
let mut buf = [0; 4];
Expand Down Expand Up @@ -316,11 +316,7 @@ mod tests {

fn hasher<K: Hash>() -> impl Fn(K) -> u64 {
let build_hasher = std::collections::hash_map::RandomState::default();
move |key| {
let mut hasher = build_hasher.build_hasher();
key.hash(&mut hasher);
hasher.finish()
}
move |key| build_hasher.hash_one(&key)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
//!
//! | Feature | MSRV |
//! |:-----------------|:--------------------------:|
//! | default features | Rust 1.61.0 (May 19, 2022) |
//! | default features | Rust 1.76.0 (Feb 8, 2024) |
//!
//! If only the default features are enabled, MSRV will be updated conservatively.
//! When using other features, MSRV might be updated more frequently, up to the
Expand Down
10 changes: 4 additions & 6 deletions src/sync/base_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use smallvec::SmallVec;
use std::{
borrow::Borrow,
collections::hash_map::RandomState,
hash::{BuildHasher, Hash, Hasher},
hash::{BuildHasher, Hash},
ptr::NonNull,
sync::{
atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -450,7 +450,7 @@ enum AdmissionResult<K> {

type CacheStore<K, V, S> = dashmap::DashMap<Arc<K>, TrioArc<ValueEntry<K, V>>, S>;

type CacheEntryRef<'a, K, V, S> = DashMapRef<'a, Arc<K>, TrioArc<ValueEntry<K, V>>, S>;
type CacheEntryRef<'a, K, V> = DashMapRef<'a, Arc<K>, TrioArc<ValueEntry<K, V>>>;

pub(crate) struct Inner<K, V, S> {
max_capacity: Option<u64>,
Expand Down Expand Up @@ -523,13 +523,11 @@ where
Arc<K>: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
let mut hasher = self.build_hasher.build_hasher();
key.hash(&mut hasher);
hasher.finish()
self.build_hasher.hash_one(key)
}

#[inline]
fn get<Q>(&self, key: &Q) -> Option<CacheEntryRef<'_, K, V, S>>
fn get<Q>(&self, key: &Q) -> Option<CacheEntryRef<'_, K, V>>
where
Arc<K>: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Expand Down
2 changes: 1 addition & 1 deletion src/sync/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ where
V: 'a,
S: BuildHasher + Clone,
{
type Item = EntryRef<'a, K, V, S>;
type Item = EntryRef<'a, K, V>;

type IntoIter = Iter<'a, K, V, S>;

Expand Down
2 changes: 1 addition & 1 deletion src/sync/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
K: Eq + Hash,
S: BuildHasher + Clone,
{
type Item = EntryRef<'a, K, V, S>;
type Item = EntryRef<'a, K, V>;

fn next(&mut self) -> Option<Self::Item> {
for map_ref in &mut self.map_iter {
Expand Down
22 changes: 8 additions & 14 deletions src/sync/mapref.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
use crate::common::concurrent::ValueEntry;

use std::{
hash::{BuildHasher, Hash},
sync::Arc,
};
use std::{hash::Hash, sync::Arc};
use triomphe::Arc as TrioArc;

type DashMapRef<'a, K, V, S> =
dashmap::mapref::multiple::RefMulti<'a, Arc<K>, TrioArc<ValueEntry<K, V>>, S>;
type DashMapRef<'a, K, V> =
dashmap::mapref::multiple::RefMulti<'a, Arc<K>, TrioArc<ValueEntry<K, V>>>;

pub struct EntryRef<'a, K, V, S>(DashMapRef<'a, K, V, S>);
pub struct EntryRef<'a, K, V>(DashMapRef<'a, K, V>);

unsafe impl<'a, K, V, S> Sync for EntryRef<'a, K, V, S>
unsafe impl<'a, K, V> Sync for EntryRef<'a, K, V>
where
K: Eq + Hash + Send + Sync,
V: Send + Sync,
S: BuildHasher,
{
}

impl<'a, K, V, S> EntryRef<'a, K, V, S>
impl<'a, K, V> EntryRef<'a, K, V>
where
K: Eq + Hash,
S: BuildHasher + Clone,
{
pub(crate) fn new(map_ref: DashMapRef<'a, K, V, S>) -> Self {
pub(crate) fn new(map_ref: DashMapRef<'a, K, V>) -> Self {
Self(map_ref)
}

Expand All @@ -41,10 +36,9 @@ where
}
}

impl<'a, K, V, S> std::ops::Deref for EntryRef<'a, K, V, S>
impl<'a, K, V> std::ops::Deref for EntryRef<'a, K, V>
where
K: Eq + Hash,
S: BuildHasher + Clone,
{
type Target = V;

Expand Down
6 changes: 2 additions & 4 deletions src/unsync/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{
borrow::Borrow,
collections::{hash_map::RandomState, HashMap},
fmt,
hash::{BuildHasher, Hash, Hasher},
hash::{BuildHasher, Hash},
ptr::NonNull,
rc::Rc,
time::Duration,
Expand Down Expand Up @@ -500,9 +500,7 @@ where
Rc<K>: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
let mut hasher = self.build_hasher.build_hasher();
key.hash(&mut hasher);
hasher.finish()
self.build_hasher.hash_one(key)
}

#[inline]
Expand Down