Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The cache can hide newly synced bytes in under-construction blocks, while interrupting one reader can close the shared channel and cause unrelated readers to fail without recovery.
4 open issues
What changed in this PR
This PR adds a client-side cache of block metadata and file descriptors to reduce repeated GetBlock requests during short-circuit reads.
Changes:
- Adds a reference-counted cache with defaults of 256 entries and five-minute expiry.
- Integrates cache lookup, invalidation, and release into block reads and client-manager lifecycle, with new unit tests.
- Separately allows
hsync()for RATIS replication factor one.
| File | Description |
|---|---|
pom.xml |
Adds import-check exclusions for the cache and its tests. |
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/KeyOutputStream.java |
Relaxes the replication-factor restriction for hsync(). |
hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestShortCircuitStreamCache.java |
Tests cache reuse, eviction, reference counting, and retries. |
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientManager.java |
Creates, exposes, and closes the cache. |
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientFactory.java |
Adds cache-access and short-circuit readiness methods. |
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientCreator.java |
Separates configured enablement from service readiness. |
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ShortCircuitStreamCache.java |
Implements caching and reference-counted descriptor cleanup. |
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java |
Reuses cached replicas and manages invalidation and release. |
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java |
Adds cache-size and expiry settings. |
Review effort: Balanced
yandrey321
left a comment
There was a problem hiding this comment.
Few comments from Claude Opus in addition to Copilots findings.
| .removalListener((key, info, cause) -> onRemoval((Replica) info)) | ||
| .build(); | ||
| this.closeExecutor = closeExecutor; | ||
| cleanupExecutor.scheduleAtFixedRate(this::cleanUp, expiryMs, expiryMs, MILLISECONDS); |
There was a problem hiding this comment.
An expiry of 0 (or negative) makes every XceiverClientManager constructor throw.
Scenario: ozone.client.read.short-circuit.streams.cache.expiry=0 with short-circuit enabled and cache size > 0.
scheduleAtFixedRate(..., 0, 0, MILLISECONDS) throws IllegalArgumentException (period <= 0), so creating an OzoneClient fails. The existing client cache in XceiverClientManager guards the same call with staleThresholdMs > 0.
Fix option(-s): validate the expiry (treat <= 0 as "cache disabled" or reject it with a clear message), and only schedule the cleanup tasks when expiryMs > 0.
| closeAsync(replica); | ||
| } | ||
| } | ||
| Preconditions.checkState(replica.getRefCount().get() >= 0, |
There was a problem hiding this comment.
The over-release check runs after the decrement, so an over-release leaves refCount negative and
throws IllegalStateException from BlockInputStream#close.
Scenario: a double release (e.g. a future code path calling releaseCachedReplica twice) drives refCount to -1; the replica can no longer be closed (closeIfUnused requires 0), so its file descriptor leaks, and close() throws an unchecked exception to the caller.
Fix option(-s): check before decrementing (or use updateAndGet that refuses to go below 0) and log instead of throwing from the close path.


What changes were proposed in this pull request?
Add a block cache for short-circuit with default
ozone.client.read.short-circuit.streams.cache.size 256
ozone.client.read.short-circuit.streams.cache.expiry 5m
similar to HDFS default configuration
dfs.client.read.shortcircuit.streams.cache.size 256
dfs.client.read.shortcircuit.streams.cache.expiry.ms 5m
Vector search performance data
Before the patch
After the patch
S3 gateway related short-circuit stream cache logs
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-17912
How was this patch tested?
New unit tests