Re: [PR] [rust] Replace BLOB index entry limit with a memory budget [paimon-rust]

2026-10-03 Thread via GitHub


JingsongLi merged PR #998:
URL: https://github.com/apache/paimon-rust/pull/998


-- 
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]



Re: [PR] [rust] Replace BLOB index entry limit with a memory budget [paimon-rust]

2026-10-03 Thread via GitHub


JingsongLi commented on code in PR #998:
URL: https://github.com/apache/paimon-rust/pull/998#discussion_r4173341701


##
crates/paimon/src/io/file_io.rs:
##
@@ -676,17 +826,40 @@ fn status_path(base_path: &str, entry_path: &str) -> 
String {
 }
 }
 
-fn cache_object_path(op: &Operator, relative_path: &str) -> String {
+fn cache_object_path(namespace: &str, op: &Operator, relative_path: &str) -> 
String {
 let info = op.info();
 format!(
-"{}\0{}\0{}\0{}",
+"{}\0{}\0{}\0{}\0{}",
+namespace,
 info.scheme(),
 info.name(),
 info.root(),
 relative_path.trim_start_matches('/')
 )
 }
 
+fn storage_cache_namespace(scheme: &str, props: &HashMap) -> 
Arc {
+// Credentials may rotate while the storage namespace stays unchanged.
+// Endpoints identify storage without coupling cache reuse to credentials.
+let mut endpoints = props
+.iter()
+.filter(|(key, _)| key.to_ascii_lowercase().ends_with("endpoint"))
+.collect::>();
+endpoints.sort_unstable_by_key(|(key, _)| *key);
+
+let mut digest = Sha256::new();
+digest.update(scheme.to_ascii_lowercase());

Review Comment:
   [P2] Canonicalize storage aliases before hashing the cache namespace
   
   This hashes the raw builder scheme, although `Storage::build` maps `file`, 
`fs`, and the empty scheme to the same Fs backend. Two FileIOs created with 
`FileIOBuilder::new("file")` and `FileIOBuilder::new("fs")`, then attached to 
the same `Arc` through the public `with_file_block_cache` 
API, therefore use different keys for the same physical file. After the first 
FileIO caches `snapshot-1`, a successful overwrite through the second 
invalidates only its own namespace; a fresh read through the first still 
returns the old metadata.
   
   I reproduced this with an equal-length overwrite: the backing file contains 
`new metadata`, but the fresh cached read returns `old metadata` on ee631f97. 
The identical test passes on the exact d57e85a9 base, whose block-cache keys 
use the canonical OpenDAL identity. This is a sequential invalidation failure, 
not an in-flight-reader race. The existing overwrite/delete-recreate tests 
establish that FileIO mutations must invalidate cached metadata.
   
   Please derive this part of the namespace from the canonical storage identity 
(including supported aliases), while retaining endpoint/account isolation, and 
add a cross-FileIO shared-cache regression test.



-- 
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]



Re: [PR] [rust] Replace BLOB index entry limit with a memory budget [paimon-rust]

2026-10-03 Thread via GitHub


JingsongLi commented on code in PR #998:
URL: https://github.com/apache/paimon-rust/pull/998#discussion_r4172455801


##
crates/paimon/src/arrow/format/blob.rs:
##
@@ -1785,6 +1809,45 @@ impl BlobFileIndex {
 }
 }
 
+#[derive(Debug)]
+struct SharedBlobIndexError(Arc);
+
+impl std::fmt::Display for SharedBlobIndexError {
+fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+std::fmt::Display::fmt(self.0.as_ref(), f)
+}
+}
+
+impl std::error::Error for SharedBlobIndexError {
+fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+Some(self.0.as_ref())
+}
+}
+
+fn clone_blob_index_error(error: &Arc) -> Error {
+let source = || {
+Some(Box::new(SharedBlobIndexError(Arc::clone(error)))
+as Box)
+};
+match error.as_ref() {
+Error::DataInvalid { message, .. } => Error::DataInvalid {
+message: message.clone(),
+source: source(),
+},
+Error::Unsupported { message } => Error::Unsupported {
+message: message.clone(),
+},
+Error::UnexpectedError { message, .. } => Error::UnexpectedError {
+message: message.clone(),
+source: source(),
+},
+_ => Error::UnexpectedError {

Review Comment:
   [P2] Preserve the I/O error category when sharing BLOB load failures
   
   A cold index read that exhausts storage retries returns 
`Error::IoUnexpected`, but this fallback converts it to `UnexpectedError`. 
Before this change, `load_cached` propagated the original I/O variant. This 
reaches `paimon_record_batch_reader_next`, whose C adapter maps `IoUnexpected` 
to public `IoError = 5` and `UnexpectedError` to `Unexpected = 0`; Go exposes 
those same codes. The caller therefore loses the I/O category used for 
storage-specific retry/handling. A targeted `FileRead` failure confirms 
`load()` preserves `IoUnexpected` while `load_cached()` loses it with both a 64 
MiB budget and budget 0. Keeping the cause chain fixes fork detection but does 
not fix adapters that classify the outer variant. Please preserve the storage 
error variant during sharing, or consistently recover its typed cause in the 
public error adapters, and cover the cached and disabled paths.



-- 
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]



Re: [PR] [rust] Replace BLOB index entry limit with a memory budget [paimon-rust]

2026-10-02 Thread via GitHub


JingsongLi commented on code in PR #998:
URL: https://github.com/apache/paimon-rust/pull/998#discussion_r4166223199


##
crates/paimon/src/arrow/format/blob.rs:
##
@@ -1688,36 +1677,68 @@ async fn read_blob_range(reader: &dyn FileRead, range: 
Range) -> crate::Res
 Ok(bytes)
 }
 
-impl BlobFileIndex {
-async fn load_cached(
-reader: &dyn FileRead,
-file_size: u64,
-file_path: &str,
-) -> crate::Result> {
-let cache_key = reader
-.cache_namespace()
-.filter(|_| !file_path.is_empty())
-.map(|namespace| BlobIndexCacheKey {
-namespace,
-file_path: file_path.to_string(),
-});
-if let Some(cache_key) = &cache_key {
-let mut cache = BLOB_INDEX_CACHE
-.lock()
-.unwrap_or_else(|error| error.into_inner());
-if let Some(index) = cache.get(cache_key) {
-return Ok(index.clone());
-}
+type BlobIndexLoadResult = Result, Arc>;
+
+struct BlobIndexCache {
+entries: FileMetadataCache,
+}
+
+impl BlobIndexCache {
+fn new(max_bytes: usize) -> Self {
+Self {
+entries: FileMetadataCache::new(max_bytes, usize::MAX),
 }
+}
+}
 
-let index = Arc::new(Self::load(reader, file_size).await?);
-if let Some(cache_key) = cache_key {
-BLOB_INDEX_CACHE
-.lock()
-.unwrap_or_else(|error| error.into_inner())
-.put(cache_key, index.clone());
+impl BlobFileIndex {
+async fn load_cached(reader: &dyn FileRead, file_size: u64) -> 
crate::Result> {
+let Some(context) = reader
+.blob_index_cache()
+.and_then(|cache| cache.downcast_ref::())
+else {
+return Ok(Arc::new(Self::load(reader, file_size).await?));
+};
+let cache = context.get_or_init(BlobIndexCache::new);
+let cache_key = reader.cache_key().map(ToOwned::to_owned);
+let key_heap_bytes = cache_key.as_ref().map_or(0, String::capacity);
+let load = cache
+.entries
+.get_or_try_insert_with_admission(
+cache_key,

Review Comment:
   [P1] Reset process-local BLOB cache state before joining inherited loads
   
   If a parent thread is awaiting a BLOB index read when another thread calls 
`fork()`, the child inherits this key's pending `OnceCell` with its 
initialization permit held. A new child read using the inherited Table/FileIO 
and preplanned splits joins that entry and waits indefinitely: the parent's 
initializer cannot finish in the child. This is reachable from Python because 
TableRead releases the GIL while collecting, and the PID-aware runtime creates 
a fresh runtime without resetting FileIO caches. For matching schema IDs with 
no deletion vector/predicate and local block caching disabled, BLOB readers use 
the manifest's file size without a prior stat; Jindo reader creation is lazy, 
so #999's range-read PID check is never reached either.
   
   I reproduced this with an actual `libc::fork()` and a process-bound test 
FileRead on the current combined heads: with `cache.blob-index.max-size=0`, the 
child immediately returns the fork-specific error; with the default `64 MiB`, 
the same child load times out after 500 ms without reaching the reader. This is 
a synthetic reader test, not a real-SDK or end-to-end Python run. Normal 
direct/wrapped cached failures still preserve fork classification, so the 
earlier error-cloning fix does not prevent this wait. The baseline BLOB cache 
inserts only completed indexes and has no pending entry to inherit. Please 
select a fresh per-process cache or bypass inherited cache contexts before 
touching their OnceLock/entry synchronization, and add a bounded 
fork-during-load regression.



-- 
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]



Re: [PR] [rust] Replace BLOB index entry limit with a memory budget [paimon-rust]

2026-10-02 Thread via GitHub


JingsongLi commented on code in PR #998:
URL: https://github.com/apache/paimon-rust/pull/998#discussion_r4164983034


##
crates/paimon/src/io/file_io.rs:
##
@@ -198,15 +277,28 @@ impl FileIO {
 /// subsequently created by [`Self::new_input`] and [`Self::new_output`].
 pub fn with_provider(mut self, provider: Arc) -> Self {
 self.backend = FileIOBackend::Provider(provider);
-self.cache_namespace = next_file_io_cache_namespace();
 self

Review Comment:
   [P1] Restore cache isolation when replacing a FileIO provider
   
   `with_provider()` no longer renews the namespace, and FileIO clones share 
the new BLOB cache context. For providers implementing the existing `create()` 
API, the default namespace hook returns `None`, so replacing a provider retains 
the same fallback namespace. Standard OpenDAL OSS/S3 operators at different 
endpoints can report the same scheme, bucket name, root, and relative key. I 
reproduced this with two real OSS operators serving equal-size files at the 
same bucket/key: after caching `[NULL, value]` from endpoint A, endpoint B's 
`[value, NULL]` file returned NULL for row 0 instead of `"value"`. Previously 
the fresh numeric namespace prevented this BLOB collision. Please preserve 
provider-attachment isolation in the fallback namespace while keeping the 
catalog budget shared, and cover provider replacement with a regression test.



##
crates/paimon/src/arrow/format/blob.rs:
##
@@ -1779,6 +1800,26 @@ impl BlobFileIndex {
 }
 }
 
+fn clone_blob_index_error(error: &Error) -> Error {
+match error {
+Error::DataInvalid { message, .. } => Error::DataInvalid {
+message: message.clone(),
+source: None,
+},
+Error::Unsupported { message } => Error::Unsupported {
+message: message.clone(),
+},
+Error::UnexpectedError { message, .. } => Error::UnexpectedError {
+message: message.clone(),
+source: None,
+},
+_ => Error::UnexpectedError {
+message: error.to_string(),
+source: None,

Review Comment:
   [P1] Preserve fork-safety errors when combining this cache with #999
   
   This is an integration issue with #999: `ProcessForkUnsupported` falls 
through to this arm and becomes `UnexpectedError` with no source. The 
`UnexpectedError` arm above also discards a wrapped fork cause. `load_cached()` 
invokes this helper even for the first failing cold load, so rejecting failed 
entries does not preserve the error for the caller. Python then receives 
`ValueError` instead of `ForkSafetyError`, defeating the dedicated interception 
in apache/paimon#10328 and allowing fallback to inherited Jindo state. A 
targeted interface-combination test using this PR's actual cache code and 
#999's `error.rs` reproduced `is_process_fork_unsupported() == false`; this was 
not a full merged-branch test. Please retain fork classification for both 
direct and wrapped failures and test propagation with the BLOB cache enabled.



##
crates/paimon/src/arrow/format/blob.rs:
##
@@ -1673,36 +1662,68 @@ struct BlobFileIndex {
 entries: Vec,
 }
 
-impl BlobFileIndex {
-async fn load_cached(
-reader: &dyn FileRead,
-file_size: u64,
-file_path: &str,
-) -> crate::Result> {
-let cache_key = reader
-.cache_namespace()
-.filter(|_| !file_path.is_empty())
-.map(|namespace| BlobIndexCacheKey {
-namespace,
-file_path: file_path.to_string(),
-});
-if let Some(cache_key) = &cache_key {
-let mut cache = BLOB_INDEX_CACHE
-.lock()
-.unwrap_or_else(|error| error.into_inner());
-if let Some(index) = cache.get(cache_key) {
-return Ok(index.clone());
-}
+type BlobIndexLoadResult = Result, Arc>;
+
+struct BlobIndexCache {
+entries: FileMetadataCache,
+}
+
+impl BlobIndexCache {
+fn new(max_bytes: usize) -> Self {
+Self {
+entries: FileMetadataCache::new(max_bytes, usize::MAX),
 }
+}
+}
 
-let index = Arc::new(Self::load(reader, file_size).await?);
-if let Some(cache_key) = cache_key {
-BLOB_INDEX_CACHE
-.lock()
-.unwrap_or_else(|error| error.into_inner())
-.put(cache_key, index.clone());
+impl BlobFileIndex {
+async fn load_cached(reader: &dyn FileRead, file_size: u64) -> 
crate::Result> {
+let Some(context) = reader
+.blob_index_cache()
+.and_then(|cache| cache.downcast_ref::())
+else {
+return Ok(Arc::new(Self::load(reader, file_size).await?));
+};
+let cache = context.get_or_init(BlobIndexCache::new);
+let cache_key = reader.cache_key().map(ToOwned::to_owned);

Review Comment:
   [P1] Include the Azure 

[PR] [rust] Replace BLOB index entry limit with a memory budget [paimon-rust]

2026-10-01 Thread via GitHub


XiaoHongbo-Hope opened a new pull request, #998:
URL: https://github.com/apache/paimon-rust/pull/998

   (no comment)


-- 
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]