Skip to content

Commit

Permalink
refactor: replace ritelinked with hashlink (#12254)
Browse files Browse the repository at this point in the history
* refactor: replace ritelinked with hashlink

Signed-off-by: Chojan Shang <psiace@apache.org>

* chore: make check happy

Signed-off-by: Chojan Shang <psiace@apache.org>

---------

Signed-off-by: Chojan Shang <psiace@apache.org>
PsiACE authored Jul 31, 2023
1 parent 78d46a6 commit 663ddd1
Showing 6 changed files with 38 additions and 42 deletions.
52 changes: 21 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/common/cache/Cargo.toml
Original file line number Diff line number Diff line change
@@ -12,12 +12,12 @@ test = false

[features]
heapsize = ["heapsize_"]
amortized = ["ritelinked/ahash-amortized", "ritelinked/inline-more-amortized"]

[dependencies]

# Crates.io dependencies
ritelinked = { version = "0.3.2", default-features = false, features = ["ahash", "inline-more"] }
hashbrown = "0.14"
hashlink = "0.8"

[target.'cfg(not(target_os = "macos"))'.dependencies]
heapsize_ = { package = "heapsize", version = "0.4.2", optional = true }
16 changes: 11 additions & 5 deletions src/common/cache/src/cache/lru.rs
Original file line number Diff line number Diff line change
@@ -58,9 +58,9 @@ use std::fmt;
use std::hash::BuildHasher;
use std::hash::Hash;

use ritelinked::linked_hash_map;
use ritelinked::DefaultHashBuilder;
use ritelinked::LinkedHashMap;
use hashbrown::hash_map::DefaultHashBuilder;
use hashlink::linked_hash_map;
use hashlink::LinkedHashMap;

use crate::cache::Cache;
use crate::meter::count_meter::Count;
@@ -195,7 +195,7 @@ impl<K: Eq + Hash, V, S: BuildHasher, M: CountableMeter<K, V>> Cache<K, V, S, M>
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
self.map.get_refresh(k).map(|v| v as &V)
self.get_mut(k).map(|v| &*v)
}

/// Returns a mutable reference to the value corresponding to the given key in the cache, if
@@ -224,7 +224,13 @@ impl<K: Eq + Hash, V, S: BuildHasher, M: CountableMeter<K, V>> Cache<K, V, S, M>
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
self.map.get_refresh(k)
match self.map.raw_entry_mut().from_key(k) {
linked_hash_map::RawEntryMut::Occupied(mut occupied) => {
occupied.to_back();
Some(occupied.into_mut())
}
linked_hash_map::RawEntryMut::Vacant(_) => None,
}
}

/// Returns a reference to the value corresponding to the key in the cache or `None` if it is
2 changes: 1 addition & 1 deletion src/common/cache/src/lib.rs
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ mod meter;

pub use cache::lru::LruCache;
pub use cache::Cache;
pub use hashbrown::hash_map::DefaultHashBuilder;
pub use meter::bytes_meter::BytesMeter;
pub use meter::count_meter::Count;
pub use meter::count_meter::CountableMeter;
@@ -32,4 +33,3 @@ pub use meter::file_meter::FileSize;
#[cfg(not(target_os = "macos"))]
pub use meter::heap_meter::HeapSize;
pub use meter::Meter;
pub use ritelinked::DefaultHashBuilder;
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ impl From<&DiskCacheKey> for PathBuf {
impl<C> DiskCache<C>
where C: Cache<String, u64, DefaultHashBuilder, FileSize>
{
/// Create an `DiskCache` with `ritelinked::DefaultHashBuilder` that stores files in `path`,
/// Create an `DiskCache` with `hashbrown::hash_map::DefaultHashBuilder` that stores files in `path`,
/// limited to `size` bytes.
///
/// Existing files in `path` will be stored with their last-modified time from the filesystem
4 changes: 2 additions & 2 deletions src/query/storages/common/cache/src/providers/memory_cache.rs
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ impl InMemoryCacheBuilder {
where
M: CountableMeter<String, Arc<V>>,
{
let cache = LruCache::with_meter_and_hasher(capacity, meter, DefaultHashBuilder::new());
let cache = LruCache::with_meter_and_hasher(capacity, meter, DefaultHashBuilder::default());
Arc::new(RwLock::new(cache))
}

@@ -53,7 +53,7 @@ impl InMemoryCacheBuilder {
// new cache that cache `Vec<u8>`, and metered by byte size
pub fn new_bytes_cache(capacity: u64) -> InMemoryBytesCacheHolder {
let cache =
LruCache::with_meter_and_hasher(capacity, BytesMeter, DefaultHashBuilder::new());
LruCache::with_meter_and_hasher(capacity, BytesMeter, DefaultHashBuilder::default());
Arc::new(RwLock::new(cache))
}
}

1 comment on commit 663ddd1

@vercel
Copy link

@vercel vercel bot commented on 663ddd1 Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

databend – ./

databend-databend.vercel.app
databend-git-main-databend.vercel.app
databend.rs
databend.vercel.app

Please sign in to comment.