Repository navigation
Keeper Nodes with TTL - #100397
Keeper Nodes with TTL#100397
Conversation
|
Workflow [PR], commit [f45a401] Summary: ❌
AI ReviewSummaryThis PR adds Keeper TTL znodes, including Findings❌ Blockers
💡 Nits
Tests
Final VerdictStatus: ❌ Block Minimum required actions: remove the GC |
| { | ||
| std::vector<std::pair<String, bool>> nodes; | ||
|
|
||
| for (const auto & ttl_path : ttl_paths) |
There was a problem hiding this comment.
collectExpiredTTLPaths does a full scan of ttl_paths and calls container.find for each path on every GC tick. On KeeperRocksStorage, RocksDBContainer::find is a DB lookup/deserialize per key, so this turns into periodic O(N) RocksDB reads every ttl_gc_period_ms (default 250 ms), which can become a hot background load and starve foreground requests on large trees.
Please avoid full key-by-key lookups in the periodic path. A practical fix is to maintain an in-memory TTL index keyed by destroy_time (updated on create/set/remove/snapshot load), so each tick only pops entries with destroy_time <= now and verifies node existence/version before enqueueing TryRemove.
There was a problem hiding this comment.
This is still an O(N) scan over ttl_paths on every GC tick in collectExpiredTTLPaths: we call container.find(ttl_path) for each tracked path and only stop after collecting batch_size expired nodes. If only a small fraction is expired, the loop still walks almost the whole set each period.
For KeeperRocksStorage, each find is a RocksDB lookup, so this remains a potentially heavy periodic background load. Can we switch to an expiry-ordered index (or another due-time driven structure) so per-tick work scales with expired nodes instead of total TTL nodes?
kssenii
left a comment
There was a problem hiding this comment.
LGTM, but please remove mutex from KeeperStorage<Container>::updateStats as I wrote in the above comments
Port the Keeper TTL feature onto master's refactored KeeperStorage: - createNode/prepareCreateNode now take ACLId acl_id plus optional ttl; prepareCreateNode sets the uncommitted node's TTL and carries it in CreateNodeDelta. - Drop the obsolete UncommittedState::applyDelta / materializeACL (master applies create deltas via prepareCreateNode; UncommittedNode no longer stores acls). - create preprocess returns Coordination::Error (master convention) instead of building a Delta list; keep the TTL validation and the reject-on-TTL parent check. - remove preprocess: re-add the internal TTL garbage-collector session ACL bypass under master's inlined check_acl flow. - Adapt the TTL gtests to master's getNode -> UncommittedNodeRef API. Co-Authored-By: Claude Opus 4.8 <[email protected]>
| DB::setThreadName(ThreadName::KEEPER_TTL_GARBAGE_COLLECTOR); | ||
|
|
||
| const auto & shutdown_called = keeper_context->isShutdownCalled(); | ||
| Int32 next_gc_xid = 0; |
There was a problem hiding this comment.
next_gc_xid is a signed 32-bit counter that is incremented once per TTL GC TryRemove. On a leader that is continuously expiring TTL nodes, the default ttl_gc_batch_size=256 and ttl_gc_period_ms=250 allow roughly 1024 increments per second, so this reaches signed overflow in about 24 days; a larger configured batch reaches it sooner. Signed overflow is undefined behavior, and after wrap the internal request identity also stops being unique.
Please make the GC request id use a non-overflowing representation, e.g. keep an Int64/UInt64 counter and send these internal requests with 64-bit xids, or otherwise implement explicit bounded wrap semantics that preserve the dispatcher dependency invariant.
| created_node.data = data; | ||
| created_node.is_ephemeral = is_ephemeral; | ||
| created_node.is_sequental = is_sequential; | ||
| created_node.is_ttl = include_ttl; |
There was a problem hiding this comment.
TestKeeper now records include_ttl, but its create path still accepts combinations that production Keeper rejects: creating a child under an existing TTL node, include_ttl && is_ephemeral, and invalid TTL ranges. The real storage path rejects those before creating the node, so tests that use TestKeeper can pass with behavior that fails against Keeper. Please mirror the production CreateTTL validation here before setting created_node.is_ttl.
| Reconfig = 16, | ||
| CheckWatch = 17, | ||
| RemoveWatch = 18, | ||
| CreateTTL = 21, |
There was a problem hiding this comment.
Adding CreateTTL here makes Keeper accept op code 21, but the ZooKeeper transaction-log importer has a separate decoder and still rejects transaction type 21 in ZooKeeperDataReader::deserializeTxnImpl. That means importing/restoring ZooKeeper data that already contains TTL nodes fails with NOT_IMPLEMENTED even though the server now advertises TTL-node support. Please add a CreateTTL transaction decoder there that preserves the TTL value, or explicitly keep this feature unsupported for ZooKeeper-log import with a clear user-facing guard.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 718/895 (80.22%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 8 line(s) · Uncovered code |
|
The failures in the private CI seem unrelated, so I'll merge PR |
Resolve conflicts from the Keeper TTL garbage-collector feature (#100397, #100397), the only PR that conflicted with the Keeper RocksDB storage removal. Resolution: - Keep this branch's de-templated, RocksDB-free `KeeperStorage` / `KeeperStateMachine` while preserving the new TTL feature: `ttl` parameter on `createNode`, `ttl_paths` / `committed_ttl_nodes` bookkeeping in `removeNode`, `collectExpiredTTLPaths`, `containsTTLPath`, and `getExpiredTTLPathsForGarbageCollector` (now concrete methods, the `TSA_NO_THREAD_SAFETY_ANALYSIS` annotations retained). - `processWatches` for `Remove` now iterates `deltas` (no longer ignored). - Keep `RocksDBContainer.h` deleted (modify/delete conflict). - Port the new TTL unit tests in `gtest_coordination_storage.cpp` and `gtest_coordination_snapshot.cpp` to the single memory-storage fixture: drop the `setRocksDBDirectory` / `ChangelogDirTest rocks` setup and the `KeeperSnapshotManager<Storage>` / `KeeperStorageSnapshot<Storage>` template arguments, matching this branch's conventions. All touched Coordination translation units pass `-fsyntax-only` against the merged headers. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Fixes from PR ClickHouse#100397 review (comment 4118957777). All seven addressed behaviour gaps are independently triggerable; no protocol or on-disk version was bumped, so the change preserves rolling-upgrade safety. * B1 (snapshot-version gate): refuse to start with `CREATE_TTL` enabled while `write_snapshot_version < 8`. Older snapshot formats drop the `destroy_time`/`ttl` fields entirely, which would silently turn TTL nodes into permanent persistent nodes on the next snapshot. The bump must be explicit because the setting can only be raised after the whole cluster has been upgraded. * B3 (TTL-GC scan locking): `collectExpiredTTLPaths` now takes `storage_mutex` in shared mode while iterating `ttl_paths`/`container`. Commits hold the same mutex exclusively, so the scan no longer races with concurrent state mutations. * B4 (TTL value validation): reject `ttl <= 0` and `ttl > MAX_KEEPER_TTL_MS` (matching ZK's `EphemeralType.TTL.maxValue() = 0x00FFFFFFFFFFFFFFL`). The bound keeps `time + ttl` from overflowing signed 64-bit when computing `destroy_time`. * B5 (create-mode classification): reject unknown create-mode flag values with `ZBADARGUMENTS` and reject the inconsistent combinations `Create2 + TTL-create-mode` and `CreateTTL-opnum / non-TTL-create-mode` at wire-read time, so feature-gating cannot be bypassed by mismatched opnum and flags. `getOpNum` now classifies CreateTTL ahead of Create2. * B6 (TTL-GC bypasses ACL check): short-circuit `checkAuth` for `try_remove` requests issued by `keeper_internal_ttl_garbage_collector_session_id`. The server-internal session has no ACLs and must be able to expire user nodes regardless of user-level Delete denies. * B7 (validate TTL+ephemeral before mutating state): move the `include_ttl && is_ephemeral` reject above the `uncommitted_state.ephemerals` insert so a rejected `Create` inside a `Multi` no longer leaves an orphan ephemeral entry behind. * B8 (rollback restores `destroy_time`): capture `old_destroy_time` alongside the existing `old_stats`/`old_num_children` in `UpdateNodeStatDelta` and restore it on rollback. Otherwise a `Set` that refreshed the TTL deadline, when rolled back as part of a failed `Multi`, would leak the refreshed deadline into uncommitted state. B2 (digest must hash `destroy_time`/`ttl`) is deliberately deferred: it requires bumping `KEEPER_CURRENT_DIGEST_VERSION`, which by the same rolling-upgrade policy as `write_snapshot_version` must be operator-opted in after a full cluster upgrade, and is large enough to warrant its own change. CI report: ClickHouse#100397 (comment) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Regression tests for the blocker fixes in the previous commit, covering corner cases of the Keeper TTL feature: * TestCreateTTLRejectsInvalidValues — Create with ttl <= 0 or ttl > MAX_KEEPER_TTL_MS is rejected with ZBADARGUMENTS; boundary values (1 and MAX_KEEPER_TTL_MS) are accepted. * TestCreateTTLAndEphemeralDoesNotLeakEphemeral — a rejected Create with both include_ttl and is_ephemeral set does not leave an entry behind in uncommitted_state.ephemerals. * TestFailedMultiRollsBackTTLDestroyTime — when a Multi containing a Set on a TTL node fails on a later subrequest, the uncommitted destroy_time is restored to its original value. Each test runs across all four storage variants (memory/rocks × digest-enabled/disabled). The previously added TestTTLGCDoesNotRemoveRecreatedNode (race against delete+recreate) remains the regression test for the deleteContainer-semantics fix. CI report: ClickHouse#100397 (comment) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Keeper Nodes with TTL
Resolve conflicts from the Keeper TTL garbage-collector feature (ClickHouse#100397, ClickHouse#100397), the only PR that conflicted with the Keeper RocksDB storage removal. Resolution: - Keep this branch's de-templated, RocksDB-free `KeeperStorage` / `KeeperStateMachine` while preserving the new TTL feature: `ttl` parameter on `createNode`, `ttl_paths` / `committed_ttl_nodes` bookkeeping in `removeNode`, `collectExpiredTTLPaths`, `containsTTLPath`, and `getExpiredTTLPathsForGarbageCollector` (now concrete methods, the `TSA_NO_THREAD_SAFETY_ANALYSIS` annotations retained). - `processWatches` for `Remove` now iterates `deltas` (no longer ignored). - Keep `RocksDBContainer.h` deleted (modify/delete conflict). - Port the new TTL unit tests in `gtest_coordination_storage.cpp` and `gtest_coordination_snapshot.cpp` to the single memory-storage fixture: drop the `setRocksDBDirectory` / `ChangelogDirTest rocks` setup and the `KeeperSnapshotManager<Storage>` / `KeeperStorageSnapshot<Storage>` template arguments, matching this branch's conventions. All touched Coordination translation units pass `-fsyntax-only` against the merged headers. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Continuation of #79071
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support TTL nodes in ClickHouse Keeper. ClickHouse-specific notes:
create_ttlfeature flag; requireswrite_snapshot_version >= 8on every replica (snapshotV8persists ttl, digest bumped toV5).seq_numslot in the node union, so creating a child under a TTL node returnsZBADARGUMENTS.destroy_time = mtime + ttl, refreshed on every set; ttl bounded byMAX_KEEPER_TTL_MS.ttl_gc_period_ms,ttl_gc_batch_size) submitsTryRemovethrough Raft, re-validated deterministically at commit so all replicas agree.Documentation entry for user-facing changes
Version info
26.6.1.1170