waterWang opened a new pull request, #1306:
URL: https://github.com/apache/curator/pull/1306
## Summary
When a `CuratorCache` is built with the `SINGLE_NODE_CACHE` option, only one
node is ever cached (the root path). Today the cache still uses a
`ConcurrentHashMap`-backed `StandardCuratorCacheStorage`, which is overkill and
wastes memory for this case. This PR adds a dedicated
`SingleNodeCuratorCacheStorage` implementation backed by a single
`AtomicReference` and switches the default storage selection to it whenever
`SINGLE_NODE_CACHE` is set.
Fixes #1304
## Changes
- **New `SingleNodeCuratorCacheStorage`** — implements `CuratorCacheStorage`
with a single `AtomicReference<ChildData>`. All interface methods (`put`,
`remove`, `get`, `size`, `stream`, `clear`) behave identically to
`StandardCuratorCacheStorage` for the single-node case:
- `size()` returns `0` or `1`
- `stream()` yields at most one element
- `put`/`get`/`remove` match on the stored node's path, so a single-node
cache can never hold entries for multiple paths.
- Honors the `cacheBytes` flag the same way `StandardCuratorCacheStorage`
does.
- **`CuratorCacheStorage.java`** — adds two factory methods: `singleNode()`
and `singleNodeDataNotCached()`.
- **`CuratorCacheImpl.java`** — the constructor now selects
`CuratorCacheStorage.singleNode()` (instead of `standard()`) when
`SINGLE_NODE_CACHE` is set and no explicit storage was provided by the caller.
Calling `builder(client, path).withStorage(...)` still takes precedence.
## Behavioral compatibility
- `CuratorCacheStorage` is a public interface and the storage is only
switched when the caller did **not** supply a custom storage. Explicit
`withStorage()` calls are unchanged.
- The `SINGLE_NODE_CACHE` option previously only controlled watcher
recursion (`recursive = !options.contains(SINGLE_NODE_CACHE)`); this PR
additionally optimizes the backing store without changing any observable
semantics — `get`, `size`, `stream`, and events all behave the same.
## Test plan
Existing `TestCuratorCache` (incl. `testClearOnClose`,
`testGreaterThan64kZNodes`) and related cache tests cover the standard path and
should remain green. Single-node behavior is exercised by tests that build
caches with `SINGLE_NODE_CACHE` and verify `get`/`size`/stream semantics.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]