From 156a2473651ef776225f6202928aafa34a95bdf1 Mon Sep 17 00:00:00 2001 From: Yuhao Su <31772373+yuhao-su@users.noreply.github.com> Date: Sat, 11 May 2024 00:53:01 -0500 Subject: [PATCH] chore: remove stream lru dead code (#16669) --- .../estimate_size/src/collections/lru.rs | 159 ------------------ .../estimate_size/src/collections/mod.rs | 1 - 2 files changed, 160 deletions(-) delete mode 100644 src/common/estimate_size/src/collections/lru.rs diff --git a/src/common/estimate_size/src/collections/lru.rs b/src/common/estimate_size/src/collections/lru.rs deleted file mode 100644 index 4add8df754673..0000000000000 --- a/src/common/estimate_size/src/collections/lru.rs +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2024 RisingWave Labs -// -// 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::alloc::{Allocator, Global}; -use std::borrow::Borrow; -use std::hash::{BuildHasher, Hash}; - -use lru::{DefaultHasher, LruCache}; - -use super::{AtomicMutGuard, MutGuard}; -use crate::{EstimateSize, KvSize}; - -/// The managed cache is a lru cache that bounds the memory usage by epoch. -/// Should be used with `MemoryManager`. -pub struct EstimatedLruCache { - inner: LruCache, - kv_heap_size: KvSize, -} - -impl - EstimatedLruCache -{ - pub fn with_hasher_in(hasher: S, alloc: A) -> Self { - Self { - inner: LruCache::unbounded_with_hasher_in(hasher, alloc), - kv_heap_size: KvSize::new(), - } - } - - /// Evict epochs lower than the watermark - pub fn evict_by_epoch(&mut self, epoch: u64) { - while let Some((key, value, _)) = self.inner.pop_lru_by_epoch(epoch) { - self.kv_heap_size.sub(&key, &value); - } - } - - pub fn update_epoch(&mut self, epoch: u64) { - self.inner.update_epoch(epoch); - } - - pub fn current_epoch(&mut self) -> u64 { - self.inner.current_epoch() - } - - /// An iterator visiting all values in most-recently used order. The iterator element type is - /// &V. - pub fn values(&self) -> impl Iterator { - self.inner.iter().map(|(_k, v)| v) - } - - pub fn get_mut(&mut self, k: &K) -> Option> { - let v = self.inner.get_mut(k); - v.map(|inner| MutGuard::new(inner, &mut self.kv_heap_size)) - } - - pub fn get(&mut self, k: &Q) -> Option<&V> - where - K: Borrow, - Q: Hash + Eq + ?Sized, - { - self.inner.get(k) - } - - pub fn iter_mut( - &mut self, - ) -> impl ExactSizeIterator)> + '_ { - let kv_heap_size = &self.kv_heap_size; - self.inner.iter_mut().map(move |(k, v)| { - let guard = AtomicMutGuard::new(v, kv_heap_size); - (k, guard) - }) - } - - pub fn peek_mut(&mut self, k: &K) -> Option> { - let v = self.inner.peek_mut(k); - v.map(|inner| MutGuard::new(inner, &mut self.kv_heap_size)) - } - - pub fn push(&mut self, k: K, v: V) -> Option<(K, V)> { - self.kv_heap_size.add(&k, &v); - - let old_kv = self.inner.push(k, v); - - if let Some((old_key, old_val)) = &old_kv { - self.kv_heap_size.sub(old_key, old_val); - } - old_kv - } - - pub fn contains(&self, k: &Q) -> bool - where - K: Borrow, - Q: Hash + Eq + ?Sized, - { - self.inner.contains(k) - } - - pub fn len(&self) -> usize { - self.inner.len() - } - - pub fn is_empty(&self) -> bool { - self.inner.len() == 0 - } - - pub fn clear(&mut self) { - self.inner.clear(); - } -} - -impl EstimatedLruCache { - pub fn unbounded() -> Self { - Self { - inner: LruCache::unbounded(), - kv_heap_size: KvSize::new(), - } - } -} - -impl EstimatedLruCache { - pub fn unbounded_with_hasher(hasher: S) -> Self { - Self { - inner: LruCache::unbounded_with_hasher(hasher), - kv_heap_size: KvSize::new(), - } - } -} - -impl - EstimatedLruCache -{ - pub fn unbounded_with_hasher_in(hasher: S, allocator: A) -> Self { - Self { - inner: LruCache::unbounded_with_hasher_in(hasher, allocator), - kv_heap_size: KvSize::new(), - } - } -} - -impl - EstimateSize for EstimatedLruCache -{ - fn estimated_heap_size(&self) -> usize { - // TODO: Add lru cache internal size - // https://github.com/risingwavelabs/risingwave/issues/9713 - self.kv_heap_size.size() - } -} diff --git a/src/common/estimate_size/src/collections/mod.rs b/src/common/estimate_size/src/collections/mod.rs index f7cdff490a88d..5bffd5133eddc 100644 --- a/src/common/estimate_size/src/collections/mod.rs +++ b/src/common/estimate_size/src/collections/mod.rs @@ -16,7 +16,6 @@ use std::ops::{Deref, DerefMut}; use super::{EstimateSize, KvSize}; -pub mod lru; pub mod vecdeque; pub use vecdeque::EstimatedVecDeque; pub mod hashmap;