You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by "waterWang (via GitHub)" <gi...@apache.org> on 2026/08/27 11:30:10 UTC

[PR] Optimize single-node CuratorCache storage with AtomicReference [curator]

waterWang opened a new pull request, #1305:
URL: https://github.com/apache/curator/pull/1305

   ## 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`** (`curator-recipes/.../cache/SingleNodeCuratorCacheStorage.java`): 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 (e.g. `TestCuratorCacheEdges`).


-- 
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: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Optimize single-node CuratorCache storage with AtomicReference [curator]

Posted by "waterWang (via GitHub)" <gi...@apache.org>.
waterWang closed pull request #1305: Optimize single-node CuratorCache storage with AtomicReference
URL: https://github.com/apache/curator/pull/1305


-- 
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: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org