Skip to content

Commit 7d8b860

Browse files
alchemist51alamb
andauthored
Change CacheAccessor::remove to take &self rather than &mut self (#18726)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #18725 ## Rationale for this change The change make the cache accessor remove API interface inline with other APIs <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? Change the remove API for non mut type <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? Covered in existing changes <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? The CacheAccessor trait will be slightly different now. <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Signed-off-by: Arpit Bandejiya <abandeji@amazon.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent 1833093 commit 7d8b860

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

datafusion/execution/src/cache/cache_unit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl CacheAccessor<Path, Arc<Statistics>> for DefaultFileStatisticsCache {
8787
.map(|x| x.1)
8888
}
8989

90-
fn remove(&mut self, k: &Path) -> Option<Arc<Statistics>> {
90+
fn remove(&self, k: &Path) -> Option<Arc<Statistics>> {
9191
self.statistics.remove(k).map(|x| x.1 .1)
9292
}
9393

@@ -151,7 +151,7 @@ impl CacheAccessor<Path, Arc<Vec<ObjectMeta>>> for DefaultListFilesCache {
151151
panic!("Not supported DefaultListFilesCache put_with_extra")
152152
}
153153

154-
fn remove(&mut self, k: &Path) -> Option<Arc<Vec<ObjectMeta>>> {
154+
fn remove(&self, k: &Path) -> Option<Arc<Vec<ObjectMeta>>> {
155155
self.statistics.remove(k).map(|x| x.1)
156156
}
157157

@@ -399,7 +399,7 @@ impl CacheAccessor<ObjectMeta, Arc<dyn FileMetadata>> for DefaultFilesMetadataCa
399399
self.put(key, value)
400400
}
401401

402-
fn remove(&mut self, k: &ObjectMeta) -> Option<Arc<dyn FileMetadata>> {
402+
fn remove(&self, k: &ObjectMeta) -> Option<Arc<dyn FileMetadata>> {
403403
let mut state = self.state.lock().unwrap();
404404
state.remove(k)
405405
}
@@ -542,7 +542,7 @@ mod tests {
542542
metadata: "retrieved_metadata".to_owned(),
543543
});
544544

545-
let mut cache = DefaultFilesMetadataCache::new(1024 * 1024);
545+
let cache = DefaultFilesMetadataCache::new(1024 * 1024);
546546
assert!(cache.get(&object_meta).is_none());
547547

548548
// put
@@ -610,7 +610,7 @@ mod tests {
610610

611611
#[test]
612612
fn test_default_file_metadata_cache_with_limit() {
613-
let mut cache = DefaultFilesMetadataCache::new(1000);
613+
let cache = DefaultFilesMetadataCache::new(1000);
614614
let (object_meta1, metadata1) = generate_test_metadata_with_size("1", 100);
615615
let (object_meta2, metadata2) = generate_test_metadata_with_size("2", 500);
616616
let (object_meta3, metadata3) = generate_test_metadata_with_size("3", 300);
@@ -726,7 +726,7 @@ mod tests {
726726

727727
#[test]
728728
fn test_default_file_metadata_cache_entries_info() {
729-
let mut cache = DefaultFilesMetadataCache::new(1000);
729+
let cache = DefaultFilesMetadataCache::new(1000);
730730
let (object_meta1, metadata1) = generate_test_metadata_with_size("1", 100);
731731
let (object_meta2, metadata2) = generate_test_metadata_with_size("2", 200);
732732
let (object_meta3, metadata3) = generate_test_metadata_with_size("3", 300);

datafusion/execution/src/cache/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait CacheAccessor<K, V>: Send + Sync {
3636
/// Put value into cache. Returns the old value associated with the key if there was one.
3737
fn put_with_extra(&self, key: &K, value: V, e: &Self::Extra) -> Option<V>;
3838
/// Remove an entry from the cache, returning value if they existed in the map.
39-
fn remove(&mut self, k: &K) -> Option<V>;
39+
fn remove(&self, k: &K) -> Option<V>;
4040
/// Check if the cache contains a specific key.
4141
fn contains_key(&self, k: &K) -> bool;
4242
/// Fetch the total number of cache entries.

docs/source/library-user-guide/upgrading.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ SELECT median(c1) IGNORE NULLS FROM table
6767

6868
Instead of silently succeeding.
6969

70+
### API change for `CacheAccessor` trait
71+
72+
The remove API no longer requires a mutable instance
73+
7074
## DataFusion `51.0.0`
7175

7276
### `arrow` / `parquet` updated to 57.0.0

0 commit comments

Comments
 (0)