Skip to content

Direct-mode load_table_context rebuilds the S3 client every call (skips the session storage cache the REST branch uses) #1498

Closed

Description

@aaj3f

Summary

In load_table_context, the CatalogConfig::Direct branch builds a fresh S3IcebergStorage (and therefore a fresh aws_config + S3 client) on every call. The CatalogConfig::Rest branch, by contrast, checks the query-scoped session storage cache first and stores the result for reuse.

Worse, direct mode builds the client before it consults its own metadata-location cache — so even a metadata cache hit pays the full from_default_chain cost.

Evidence

Verified at a8de70e0f (fluree-db-api/src/graph_source/r2rml.rs).

REST branch — caches:

  • :1201 — checks self.session.cached_storage(&lt_key) before constructing.
  • :1262-1263 — self.session.store_storage(lt_key.clone(), Arc::clone(&built)); after constructing.

Direct branch — does neither:

// r2rml.rs:1279-1289
let storage: Arc<S3IcebergStorage> = Arc::new(
    S3IcebergStorage::from_default_chain(
        iceberg_config.io.s3_region.as_deref(),
        iceberg_config.io.s3_endpoint.as_deref(),
        iceberg_config.io.s3_path_style,
    )
    .await
    .map_err(|e| QueryError::Internal(format!("Failed to create S3 storage: {e}")))?,
);

// r2rml.rs:1291-1293 — the metadata cache is only consulted AFTER the client is built
let cache = self.fluree.r2rml_cache();
let load_response = if let Some(metadata_location) =
    cache.get_direct_metadata_location(table_location).await
{ ... }

There is no cached_storage check and no store_storage call anywhere in the branch (:1269-1327).

Impact

Per load_table_context call in direct mode, this repeats:

  • AWS credential-chain resolution (from_default_chain, fluree-db-iceberg/src/io/storage.rs:268-315) — env → ~/.aws → IMDS/ECS/Lambda role. The IMDS/container legs are network round-trips.
  • S3 client + connection-pool construction, discarding warm connections.

The cost scales with the number of tables per query, so multi-table R2RML mappings (joins, crawls) pay it repeatedly. The Arc in the branch shares the client across one load_table_context call, not across calls within a query — so the comment at :1275 ("create storage once, share via Arc") is true only within a single call.

Note this is pure overhead: the constructed client is functionally identical between calls for a given config.

Severity / priority

Low-to-moderate, and lower than it first appears — direct mode cannot currently read Snowflake-written Iceberg tables at all (Snowflake publishes no version-hint.text; the pointer lives in the catalog by design), so the branch is not on the Snowflake path that dominates current usage. It matters for genuine object-store-catalog deployments (self-published version-hint.text, e.g. Spark/Flink writers, and the GCS S3-interop path called out at :1276-1278).

Filing it because it is a small, well-understood asymmetry with a clear fix, and because the two branches diverging silently is the kind of thing that gets re-introduced.

Suggested fix

Mirror the REST branch: check self.session.cached_storage(&lt_key) first, and store_storage after constructing — and move construction below the metadata-location cache check so a hit doesn't build a client it may not need (a hit still needs storage for the scan, so this is a reordering, not an elision; the win is that the cached-storage check can short-circuit it).

A regression test asserting that two load_table_context calls in one session yield the same Arc (pointer equality) for both Rest and Direct would keep the branches from drifting again.

Activity

  1. aaj3f commented on Aug 25, 2026

    @aaj3f
    ContributorAuthor

    Sweep-verified fixed: 16e5ed489 ("perf(r2rml): reuse session-cached S3 client in Direct mode (#1498)") landed on main via the #1505→#1514 consolidation (fdedb3660, merged 7/29).

    All three asks made it: the Direct branch uses the same lt_key/session cache as REST (cached-check-first, store-after), client construction moved below the metadata-location cache check, and the Arc-pointer-equality regression test this issue suggested exists (direct_session_storage_reuses_arc_across_calls) — I ran it at 47e96b7b6 and it passes, including the distinct-client-per-table assertion. Bonus beyond the ask: local file:// Direct tables now skip SDK/credential-chain construction entirely (IcebergStorageBackend::File, r2rml.rs:3410-3414).

    Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions