fix(java): preserve shared sessions when opening namespace datasets #10239
Claude Code Review
This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.
✅ Gate recommendation: approve.
Namespace opens now reuse the caller’s session, with explicit builder sessions retaining precedence and caller ownership preserved. No blocking issues found.
@claude review
Hi @jischeng Thanks for this PR. Can we simplify the test cases as much as possible?
Thanks for the suggestion! Simplified in 811d8bb04: the three tests are now one focused 30-line regression test. It creates a small table and opens it twice with a ReadOptions session, checking session identity, metadata-cache reuse, and that closing the dataset leaves the caller's session open. The version/fragment setup and separate precedence/ownership tests have been removed.
Formatting checks and all 23 relevant Java tests passed locally. The PR description has also been updated to match.
✅ Gate recommendation: approve.
The simplified regression still detects the dropped session and verifies cache reuse and caller ownership. Explicit builder sessions retain precedence. No blocking issues found.
LGTM. Thanks!
zhangyue19921010
jischeng
Problem
OpenDatasetBuilder.buildFromNamespaceClient()rebuildsReadOptionswhen applying namespace-resolved storage options, but drops the caller's optionalSession. Each dataset open then creates an independent session, preventing metadata and index cache reuse across opens. Direct URI opens preserve the supplied session.This affects callers such as Spark readers that supply a shared session through
ReadOptionsand repeatedly open datasets through a namespace.Fix and regression coverage
Copy the optional session into the rebuilt options. The existing session-selection logic still gives an explicit builder session precedence, and caller-provided sessions remain owned by the caller.
Add one focused
DirectoryNamespaceTestcase that opens a small table twice using a session supplied throughReadOptions, verifies session identity and metadata-cache reuse, and checks that closing the dataset leaves the caller's session open.Supporting observations
In a local probe with a temporary BTREE dataset, three repeated opens at a fixed version and filter returned identical results. Index loads changed from
1/1/1before the fix to1/0/0after the fix, matching direct URI opens.In one production Spark replay of an indexed query over approximately 2,400 fragments, both variants used the same catalog SQL, pinned data versions, resource policy, and 64 executors. Query duration decreased from approximately 1,359 seconds to 85 seconds, and index-partition loads decreased from 38,784 to 1,024. Results matched and both runs completed without failed tasks. The fixed variant ran first.
These are single-run observations, not a general performance guarantee. A separate workload without an index predicate showed no improvement. Reported byte/request counters did not establish a reduction in network I/O, and S3 performance was not benchmarked.
Validation
Validated locally with JDK 17 and the repository-pinned Rust toolchain:
./mvnw -Dskip.build.jni=true spotless:check— passed../mvnw -Dskip.build.jni=true test-compile— passed../mvnw -Dskip.build.jni=true '-Dtest=SessionTest,DirectoryNamespaceTest#testRepeatedOpensShareReadOptionsSession' test— passed after simplifying the regression test: 23 Java tests, using JNI previously built from this checkout.Related work
Related to #6536, which proposed the same fix with a regression test and was closed due to inactivity.