Copilot commented on code in PR #3164:
URL: https://github.com/apache/iceberg-rust/pull/3164#discussion_r3947840462
##########
crates/integrations/cache-moka/src/lib.rs:
##########
@@ -16,13 +16,27 @@
// under the License.
use std::hash::Hash;
+use std::mem::size_of_val;
use std::sync::Arc;
use iceberg::cache::{ObjectCache, ObjectCacheProvide};
use iceberg::spec::{Manifest, ManifestList};
const DEFAULT_CACHE_SIZE_BYTES: u64 = 32 * 1024 * 1024; // 32MiB
+/// A cache whose `max_capacity` is a byte budget rather than an entry count.
+///
+/// Without a weigher `moka` treats `max_capacity` as a number of entries, so
passing a byte
+/// figure to `Cache::new` leaves the cache effectively unbounded. This
mirrors the weigher
+/// `iceberg::io::ObjectCache` uses.
+fn byte_bounded_cache<V>(max_capacity_bytes: u64) -> moka::sync::Cache<String,
Arc<V>>
+where V: Send + Sync + 'static {
+ moka::sync::Cache::builder()
+ .weigher(|_, value: &Arc<V>| size_of_val(value.as_ref()) as u32)
Review Comment:
`size_of_val(..) as u32` will truncate on overflow (values > 4GiB on
64-bit), under-weighing large cache entries and potentially letting the cache
exceed its intended byte budget. Prefer a saturating/checked conversion to
`u32`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]