Skip to content

HDDS-17912. Add a stream cache for short-circuit read - #12150

Draft
ChenSammi wants to merge 3 commits into
apache:masterfrom
ChenSammi:ShortCircuitBlockCache
Draft

ChenSammi wants to merge 3 commits into
apache:masterfrom
ChenSammi:ShortCircuitBlockCache

Conversation

@ChenSammi

Copy link
Copy Markdown
Contributor

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

Random access: 1,009 rows/sec
Vector search: 73.8 QPS
nprobes=  1  QPS=  82.5  avg_latency=12.1ms
nprobes=  4  QPS=  88.8  avg_latency=11.3ms
nprobes=  8  QPS=  95.8  avg_latency=10.4ms
nprobes= 16  QPS=  90.2  avg_latency=11.1ms
nprobes= 32  QPS=  95.4  avg_latency=10.5ms

After the patch

Random access: 2,417 rows/sec
Vector search: 140.3 QPS
nprobes=  1  QPS= 180.0  avg_latency=5.6ms
nprobes=  4  QPS= 188.0  avg_latency=5.3ms
nprobes=  8  QPS= 212.9  avg_latency=4.7ms
nprobes= 16  QPS= 227.9  avg_latency=4.4ms
nprobes= 32  QPS= 180.3  avg_latency=5.5ms

S3 gateway related short-circuit stream cache logs

2026-11-24 13:15:11,591 [s3g-readiness-om-0] INFO org.apache.hadoop.hdds.scm.storage.ShortCircuitStreamCache: 24a506b5 is created with maxSize 256, expiryMs 300000
2026-11-24 13:15:26,934 [qtp1422273905-28] INFO org.apache.hadoop.hdds.scm.storage.ShortCircuitStreamCache: 6df9b40d is created with maxSize 256, expiryMs 300000
2026-11-24 13:20:11,588 [XceiverClientManager-cleanup-0] INFO org.apache.hadoop.hdds.scm.storage.ShortCircuitStreamCache: 24a506b5 Hits: 0, Misses: 0, HitRate: 1.0, MissRate: 0.0, AverageLoadPenalty(Ns): 0.0
2026-11-24 13:20:26,935 [XceiverClientManager-cleanup-0] INFO org.apache.hadoop.hdds.scm.storage.ShortCircuitStreamCache: 6df9b40d Hits: 752538, Misses: 11, HitRate: 0.9999853830116046, MissRate: 1.4616988395440031E-5, AverageLoadPenalty(Ns): 0.0

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-17912

How was this patch tested?

New unit tests

Copilot AI balanced review requested due to automatic review settings November 24, 2026 12:44
@ChenSammi
ChenSammi marked this pull request as draft November 24, 2026 12:44
@ChenSammi
ChenSammi requested a review from jojochuang November 24, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 yandrey321 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants