This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 2dc76c5c io: honor explicit local cache options in FileIOBuilder 
(#1410)
2dc76c5c is described below

commit 2dc76c5cb84df016ba822a669b6400a7e18b2bda
Author: Yann Byron <[email protected]>
AuthorDate: Tue Nov 17 23:35:41 2026 +0800

    io: honor explicit local cache options in FileIOBuilder (#1410)
---
 crates/paimon/src/catalog/rest/fuse_support.rs     |   4 +-
 crates/paimon/src/catalog/rest/rest_catalog.rs     |  76 ++++++++++++++-
 .../paimon/src/catalog/rest/rest_token_file_io.rs  |   4 +-
 crates/paimon/src/io/file_io.rs                    | 106 ++++++++++++++++++++-
 crates/paimon/src/table/rest_env.rs                |  53 ++++++++++-
 5 files changed, 229 insertions(+), 14 deletions(-)

diff --git a/crates/paimon/src/catalog/rest/fuse_support.rs 
b/crates/paimon/src/catalog/rest/fuse_support.rs
index 7ba739c6..0e059907 100644
--- a/crates/paimon/src/catalog/rest/fuse_support.rs
+++ b/crates/paimon/src/catalog/rest/fuse_support.rs
@@ -79,9 +79,7 @@ impl FusePathResolver {
             let mut builder = FileIO::from_path(local.as_ref())?
                 .with_props(self.options.to_map())
                 .with_cache_context(file_io_cache);
-            if let Some(cache) = local_cache {
-                builder = builder.with_local_cache(cache);
-            }
+            builder = builder.with_local_cache(local_cache);
             Ok(Some(builder.build()?.with_fuse(original, &local)?))
         }
         #[cfg(not(feature = "storage-fs"))]
diff --git a/crates/paimon/src/catalog/rest/rest_catalog.rs 
b/crates/paimon/src/catalog/rest/rest_catalog.rs
index 018e2ba2..04513355 100644
--- a/crates/paimon/src/catalog/rest/rest_catalog.rs
+++ b/crates/paimon/src/catalog/rest/rest_catalog.rs
@@ -88,7 +88,8 @@ impl RESTCatalog {
             .get(CatalogOptions::WAREHOUSE)
             .cloned()
             .unwrap_or_default();
-        let local_cache = create_local_cache_with_namespace_async(&options, 
&api_options).await?;
+        let local_cache =
+            create_local_cache_with_namespace_async(&api_options, 
&api_options).await?;
         let file_io_cache = 
FileIOCacheContext::from_props(api_options.to_map())?;
 
         let fuse_resolver = 
Arc::new(super::FusePathResolver::new(&api_options));
@@ -1251,6 +1252,79 @@ mod tests {
         server.abort();
     }
 
+    #[tokio::test]
+    async fn 
test_server_cache_options_share_one_catalog_cache_across_table_loads() {
+        use crate::spec::{DataType, IntType};
+        use axum::routing::get;
+        use axum::{Json, Router};
+
+        let directory = tempfile::tempdir().unwrap();
+        let schema = Schema::builder()
+            .column("id", DataType::Int(IntType::new()))
+            .build()
+            .unwrap();
+        let response = serde_json::json!({
+            "id": "table-uuid", "database": "default", "name": "t",
+            "path": directory.path().to_str().unwrap(), "isExternal": false,
+            "schemaId": 0, "schema": schema
+        });
+        // Defaults are overridden by the client, while server overrides win 
over both.
+        for (client_enabled, server_override, expected_enabled) in [
+            (None, None, true),
+            (Some("false"), None, false),
+            (Some("true"), Some("false"), false),
+            (Some("false"), Some("true"), true),
+        ] {
+            let mut overrides = HashMap::new();
+            if let Some(value) = server_override {
+                overrides.insert(CatalogOptions::LOCAL_CACHE_ENABLED, value);
+            }
+            let config = serde_json::json!({
+                "defaults": {"local-cache.enabled": "true", 
"local-cache.max-size": "1 MiB"},
+                "overrides": overrides
+            });
+            let table_response = response.clone();
+            let app = Router::new()
+                .route("/v1/config", get(move || async move { Json(config) }))
+                .route(
+                    "/v1/databases/default/tables/t",
+                    get(move || async move { Json(table_response) }),
+                );
+            let listener = 
tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
+            let address = listener.local_addr().unwrap();
+            let server = tokio::spawn(async move { axum::serve(listener, 
app).await.unwrap() });
+            let mut options = Options::new();
+            options.set(CatalogOptions::URI, format!("http://{address}";));
+            options.set(CatalogOptions::TOKEN_PROVIDER, "bear");
+            options.set(CatalogOptions::TOKEN, "test-token");
+            if let Some(value) = client_enabled {
+                options.set(CatalogOptions::LOCAL_CACHE_ENABLED, value);
+            }
+            let catalog = RESTCatalog::new(options, true).await.unwrap();
+            let identifier = Identifier::new("default", "t");
+            let first = catalog.get_table(&identifier).await.unwrap();
+            let second = catalog.get_table(&identifier).await.unwrap();
+            let first_cache = first.file_io().local_cache();
+            let second_cache = second.file_io().local_cache();
+            assert_eq!(catalog.local_cache.is_some(), expected_enabled);
+            assert_eq!(first_cache.is_some(), expected_enabled);
+            assert_eq!(second_cache.is_some(), expected_enabled);
+            if let Some(cache) = &catalog.local_cache {
+                // Sharing this manager also shares its configured capacity 
budget.
+                assert!(Arc::ptr_eq(cache, first_cache.as_ref().unwrap()));
+                assert!(Arc::ptr_eq(cache, second_cache.as_ref().unwrap()));
+                assert_eq!(
+                    catalog
+                        .options
+                        .get(CatalogOptions::LOCAL_CACHE_MAX_SIZE)
+                        .unwrap(),
+                    "1 MiB"
+                );
+            }
+            server.abort();
+        }
+    }
+
     #[tokio::test]
     async fn test_rest_catalog_builds_local_cache_from_client_options() {
         let mut options = Options::new();
diff --git a/crates/paimon/src/catalog/rest/rest_token_file_io.rs 
b/crates/paimon/src/catalog/rest/rest_token_file_io.rs
index 6b115621..2ea33171 100644
--- a/crates/paimon/src/catalog/rest/rest_token_file_io.rs
+++ b/crates/paimon/src/catalog/rest/rest_token_file_io.rs
@@ -141,9 +141,7 @@ impl RESTTokenFileIO {
         let merged_props = 
RESTUtil::merge(Some(self.catalog_options.to_map()), Some(&token.token));
         let mut builder = 
FileIO::from_path(&self.path)?.with_props(merged_props);
         builder = builder.with_cache_context(self.file_io_cache.clone());
-        if let Some(local_cache) = &self.local_cache {
-            builder = builder.with_local_cache(local_cache.clone());
-        }
+        builder = builder.with_local_cache(self.local_cache.clone());
         builder.build()
     }
 
diff --git a/crates/paimon/src/io/file_io.rs b/crates/paimon/src/io/file_io.rs
index 42814fd8..edc472a1 100644
--- a/crates/paimon/src/io/file_io.rs
+++ b/crates/paimon/src/io/file_io.rs
@@ -1272,7 +1272,8 @@ pub(crate) fn looks_like_windows_drive_path(path: &str) 
-> bool {
 pub struct FileIOBuilder {
     scheme_str: Option<String>,
     props: HashMap<String, String>,
-    cache: Option<Arc<LocalCache>>,
+    // Unset uses properties; Some(None) preserves the caller's decision to 
disable caching.
+    cache: Option<Option<Arc<LocalCache>>>,
     file_format_metadata_cache: Option<Arc<FileFormatMetadataCacheContext>>,
     blob_index_cache: Option<Arc<BlobIndexCacheContext>>,
     operator: Option<Operator>,
@@ -1339,8 +1340,9 @@ impl FileIOBuilder {
         self
     }
 
-    pub(crate) fn with_local_cache(mut self, cache: Arc<LocalCache>) -> Self {
-        self.cache = Some(cache);
+    /// Use the caller's cache decision, including an explicitly disabled 
cache.
+    pub(crate) fn with_local_cache(mut self, cache: impl 
Into<Option<Arc<LocalCache>>>) -> Self {
+        self.cache = Some(cache.into());
         self
     }
 
@@ -1360,7 +1362,12 @@ impl FileIOBuilder {
     }
 
     pub fn build(mut self) -> crate::Result<FileIO> {
-        let cache = self.cache.clone();
+        let cache = match &self.cache {
+            Some(cache) => cache.clone(),
+            None => 
super::cache::create_local_cache(&crate::common::Options::from_map(
+                self.props.clone(),
+            ))?,
+        };
         let cache_namespace = storage_cache_namespace(&self.props);
         let file_format_metadata_cache = self
             .file_format_metadata_cache
@@ -2910,6 +2917,97 @@ mod input_output_test {
             .unwrap()
     }
 
+    #[tokio::test]
+    async fn test_builder_local_cache_options_and_injected_cache() {
+        for mode in ["default", "disabled", "configured", "injected"] {
+            let directory = tempfile::tempdir().unwrap();
+            let source = directory.path().join("manifest-test");
+            let path = source.to_string_lossy().into_owned();
+            std::fs::write(&source, b"metadata").unwrap();
+            let mut builder = FileIOBuilder::new("file");
+            if mode == "configured" {
+                builder = builder
+                    .with_prop(CatalogOptions::LOCAL_CACHE_ENABLED, "true")
+                    .with_prop(CatalogOptions::LOCAL_CACHE_WHITELIST, "meta")
+                    .with_prop(CatalogOptions::LOCAL_CACHE_MAX_SIZE, "1 MiB");
+            } else if mode == "disabled" {
+                builder = 
builder.with_prop(CatalogOptions::LOCAL_CACHE_ENABLED, "false");
+            } else if mode == "injected" {
+                let mut options = Options::new();
+                options.set(CatalogOptions::LOCAL_CACHE_ENABLED, "true");
+                options.set(CatalogOptions::LOCAL_CACHE_MAX_SIZE, "1 MiB");
+                let cache = crate::io::cache::create_local_cache(&options)
+                    .unwrap()
+                    .unwrap();
+                builder = builder
+                    .with_local_cache(cache)
+                    .with_prop(CatalogOptions::LOCAL_CACHE_ENABLED, "false");
+            }
+            let io = builder.build().unwrap();
+            assert_eq!(
+                io.new_input(&path).unwrap().read().await.unwrap(),
+                Bytes::from_static(b"metadata")
+            );
+            std::fs::remove_file(&source).unwrap();
+            // A clone must share the populated cache, including an injected 
cache
+            // whose settings take precedence over the builder's properties.
+            let second = io.clone().new_input(&path).unwrap().read().await;
+            if matches!(mode, "configured" | "injected") {
+                assert_eq!(second.unwrap(), Bytes::from_static(b"metadata"), 
"{mode}");
+                io.new_output(&path)
+                    .unwrap()
+                    .write(Bytes::from_static(b"new metadata"))
+                    .await
+                    .unwrap();
+                assert_eq!(
+                    io.new_input(&path).unwrap().read().await.unwrap(),
+                    Bytes::from_static(b"new metadata"),
+                    "{mode}"
+                );
+            } else {
+                assert!(second.is_err(), "{mode} must not enable caching");
+            }
+        }
+    }
+
+    #[tokio::test]
+    async fn 
test_builder_local_cache_does_not_cache_mutable_hints_or_payloads() {
+        let directory = tempfile::tempdir().unwrap();
+        let io = FileIOBuilder::new("file")
+            .with_prop(CatalogOptions::LOCAL_CACHE_ENABLED, "true")
+            .with_prop(CatalogOptions::LOCAL_CACHE_WHITELIST, "meta")
+            .with_prop(CatalogOptions::LOCAL_CACHE_MAX_SIZE, "1 MiB")
+            .build()
+            .unwrap();
+        for name in ["LATEST", "image.blob"] {
+            let source = directory.path().join(name);
+            let path = source.to_string_lossy().into_owned();
+            std::fs::write(&source, b"first").unwrap();
+            assert_eq!(
+                io.new_input(&path).unwrap().read().await.unwrap(),
+                Bytes::from_static(b"first")
+            );
+            std::fs::write(&source, b"updated").unwrap();
+            assert_eq!(
+                io.new_input(&path).unwrap().read().await.unwrap(),
+                Bytes::from_static(b"updated"),
+                "{name}"
+            );
+        }
+    }
+
+    #[test]
+    fn test_builder_local_cache_rejects_invalid_enabled_options() {
+        let error = FileIOBuilder::new("memory")
+            .with_prop(CatalogOptions::LOCAL_CACHE_ENABLED, "true")
+            .with_prop(CatalogOptions::LOCAL_CACHE_MAX_SIZE, "invalid")
+            .build()
+            .unwrap_err();
+        assert!(error
+            .to_string()
+            .contains(CatalogOptions::LOCAL_CACHE_MAX_SIZE));
+    }
+
     #[test]
     fn test_storage_cache_namespace_tracks_endpoint_not_credentials() {
         let first = HashMap::from([
diff --git a/crates/paimon/src/table/rest_env.rs 
b/crates/paimon/src/table/rest_env.rs
index f37dbb3a..bec6e0a4 100644
--- a/crates/paimon/src/table/rest_env.rs
+++ b/crates/paimon/src/table/rest_env.rs
@@ -603,9 +603,7 @@ impl RESTEnv {
 
         let mut builder = 
FileIO::from_path(path)?.with_props(options.to_map());
         builder = builder.with_cache_context(file_io_cache);
-        if let Some(local_cache) = local_cache {
-            builder = builder.with_local_cache(local_cache);
-        }
+        builder = builder.with_local_cache(local_cache);
         builder.build()
     }
 
@@ -869,6 +867,55 @@ mod tests {
         );
     }
 
+    #[tokio::test]
+    async fn test_file_io_paths_preserve_disabled_catalog_cache() {
+        let directory = tempfile::tempdir().unwrap();
+        for mode in ["plain", "token", "fuse"] {
+            let mut options = Options::new();
+            options.set(CatalogOptions::URI, "http://localhost:1";);
+            options.set(CatalogOptions::TOKEN_PROVIDER, "bear");
+            options.set(CatalogOptions::TOKEN, "test-token");
+            options.set(CatalogOptions::LOCAL_CACHE_ENABLED, "true");
+            let resolver = if mode == "fuse" {
+                options.set("fuse.enabled", "true");
+                options.set("fuse.root", directory.path().to_string_lossy());
+                options.set("fuse.validation-mode", "none");
+                Some(FusePathResolver::new(&options))
+            } else {
+                None
+            };
+            if mode == "token" {
+                options.set(CatalogOptions::LOCAL_CACHE_ENABLED, "false");
+            }
+            let api = Arc::new(RESTApi::new(options.clone(), 
false).await.unwrap());
+            let file_io_cache = 
FileIOCacheContext::from_props(options.to_map()).unwrap();
+            let initial_token = RESTToken::new(
+                std::collections::HashMap::from([(
+                    CatalogOptions::LOCAL_CACHE_ENABLED.to_string(),
+                    "true".to_string(),
+                )]),
+                i64::MAX,
+            );
+            let file_io = RESTEnv::build_file_io_with_token(
+                &Identifier::new("default", "t"),
+                directory.path().to_str().unwrap(),
+                api,
+                &options,
+                mode == "token",
+                None,
+                file_io_cache,
+                Some(initial_token),
+                resolver.as_ref(),
+            )
+            .await
+            .unwrap();
+            assert!(
+                !file_io.has_local_cache(),
+                "{mode} must keep the catalog cache disabled"
+            );
+        }
+    }
+
     #[tokio::test]
     async fn test_rest_env_clones_catalog_local_cache() {
         let cache_directory = tempfile::tempdir().unwrap();

Reply via email to