Repository navigation
Add file IO and integrate new keeper storage - #112378
alexey-milovidov wants to merge 39 commits into
Conversation
|
Workflow [PR], commit [9e2a535] AI ReviewSummaryThis PR wires the new Keeper LSMT storage into the server, adds optional file-backed runs, and flips the new backend on by default. Current head fixed many earlier lifecycle bugs, but I still see one fresh availability blocker in the default write path plus two previously-discussed concerns that remain real in the current code. PR Metadata
Findings❌ Blockers
Tests
Final VerdictRequest changes. The on-disk LSMT plumbing is much cleaner now, but the current default rollout still has an observed memory-limit abort path and an unresolved remote-disk data-loss gap. |
Findings from the `Build (arm_tidy)` CI check: - `KeeperLSMTNodesStorage::getCommittedNode` and `StorageState::writeInfoFile` can be made const - `NodeStreamForSnapshot` single-argument constructor must be explicit - `op` in `rollbackUncommittedDelta` can be `const auto &` - subscript instead of `.data()` in `NodePath::makeChildPath` https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112378&sha=a20a74aad4f6dd80dea609ab15c1c6c9cc1f6e3b&name_0=PR&name_1=Build%20%28arm_tidy%29 #112378 Co-Authored-By: Claude Fable 5 <[email protected]>
`prepareImpl` stored in `LSMTDelta` a `FullNode` whose `data_ptr` still
pointed at the caller's buffer (the request data), which often doesn't
survive until `commitDelta`. The commit then serialized bytes from freed
memory into the committed memtable, so subsequent reads of the node
returned garbage of the correct length. In the `Fast test` CI check this
broke 210 tests with errors like:
Cannot parse input: expected 'columns format version: 1\n' before:
'<garbage>'. (CANNOT_PARSE_INPUT_ASSERTION_FAILED)
Fix it in `BlockData::appendNodeNoResize`: after copying the data into
the block, re-point `node.data_ptr` at the immutable serialized copy,
which lives as long as the block is pinned by the returned `NodeRef`
(`LSMTDelta` keeps such a ref precisely for this). This matches the
documented intent of `LSMTDelta::new_node` ("deserialized node
corresponding to `new_node_ref`").
Add a unit test asserting that `appendNode` re-points the data into the
block and the node stays valid after the original buffer is destroyed.
Reproduced locally with a standalone `clickhouse keeper`: `create`
followed by `get` returned binary garbage instead of the stored value;
after the fix, `create`/`set`/`get` and `ReplicatedMergeTree`
metadata round-trips work correctly.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112378&sha=a20a74aad4f6dd80dea609ab15c1c6c9cc1f6e3b&name_0=PR&name_1=Fast%20test
#112378
Co-Authored-By: Claude Fable 5 <[email protected]>
| return create_local_disk(config.getString("keeper_server.data_storage_path")); | ||
|
|
||
| if (config.has("keeper_server.data_storage_disk")) | ||
| return config.getString("keeper_server.data_storage_disk"); |
There was a problem hiding this comment.
data_storage_disk currently points at the named disk root, but initializeDisks later iterates that root and removeRecursiveWithLimits every entry before startup. If an operator reuses the same disk for snapshot_storage_disk, log_storage_disk, or any shared object-storage disk, Keeper startup deletes unrelated files and can wipe its own persisted logs/snapshots before recovery. The LSMT files need their own subdirectory/prefix on named disks (like coordination/data) or this option needs to reject shared disks.
There was a problem hiding this comment.
🕵 Fixed in f76abee. initializeDisks now refuses to start when keeper_server.data_storage_disk names the same disk as the log, snapshot or state storage (including the old_* disks), instead of wiping it. The dedicated-path forms (data_storage_path, storage_path, the implicit coordination/data) always get a directory of their own, so only the named-disk case needed the guard.
There was a problem hiding this comment.
This still reproduces for the explicit-path forms. getDataPathFromConfig returns a DiskLocal rooted at keeper_server.data_storage_path verbatim in src/Coordination/KeeperContext.cpp:463-474, and initializeDisks still iterateDirectory("")/removeRecursiveWithLimits every entry in that root in src/Coordination/KeeperContext.cpp:224-226. So data_storage_path == snapshot_storage_path (or log_storage_path) still wipes those files on startup even though the named-disk case now throws.
There was a problem hiding this comment.
🕵 Fixed in 8ae0dbc. The guard is no longer limited to the named-disk case: initializeDisks now also resolves both the node storage and each log/snapshot/state storage to a local path and throws BAD_ARGUMENTS when the node storage directory is or contains one of them, so data_storage_path == snapshot_storage_path (or log_storage_path, or a parent of either) refuses to start instead of wiping. The opposite nesting is still allowed on purpose - it is the default layout, where the node storage is a subdirectory of the state directory and wiping it touches nothing outside.
There was a problem hiding this comment.
localDiskPath is nullopt for remote disks, so this guard still only rejects named disks when the names are literally equal. That leaves shared plain-object-storage roots uncovered: data_storage_disk = s3_plain_a and snapshot_storage_disk = s3_plain_b can point at the same bucket/prefix, but src/Coordination/KeeperContext.cpp:233-251 only compares disk names or canonical local paths. Startup still wipes the whole node-storage root in src/Coordination/KeeperContext.cpp:265-267, so the snapshot/log objects can still be deleted. This still needs either a dedicated subdirectory/prefix for named remote disks or a stronger same-root check for remote/plain disks.
There was a problem hiding this comment.
🕵 Re-applied in ce9efd3 (the guard from f76abee/8ae0dbcf104 was lost when the branch was rebuilt): initializeDataDisk now refuses to start with BAD_ARGUMENTS when the node storage names the same disk as the log, snapshot or state storage, or when a locally-resolved node-storage directory is or contains one of theirs. Opposite nesting stays allowed (default layout). Known limitation: two differently named remote disks pointing at the same bucket/prefix are not detected - disk configs can express the same remote location in too many ways to compare reliably, so that case remains the operator's responsibility.
| DECLARE(UInt64, raft_limits_reconnect_limit, 50, "If connection to a peer is silent longer than this limit * (multiplied by heartbeat interval), we re-establish the connection.", 0) \ | ||
| DECLARE(UInt64, raft_limits_response_limit, 20, "Total wait time for a response is calculated by multiplying response_limit with heart_beat_interval_ms", 0) \ | ||
| DECLARE(Bool, async_replication, true, "Enable async replication. All write and read guarantees are preserved while better performance is achieved.", 0) \ | ||
| DECLARE(Bool, use_new_storage, true, "Use LSM tree storage for nodes. Has about the same performance but lower memory usage.", 0) \ |
There was a problem hiding this comment.
Making use_new_storage default to true means every Keeper upgrade switches to the new LSM backend automatically, even though this PR is introducing its own flush/merge/recovery pipeline and the accompanying stress docs still describe it as a future opt-in replacement. That removes the safety gate entirely: any regression in the new backend becomes the default behavior for existing clusters. This should stay opt-in/experimental until the rollout evidence and migration docs exist.
There was a problem hiding this comment.
🕵 The changelog entry was misleading and is fixed - it now says the backend is on by default and how to opt out. Leaving the default itself as is: use_new_storage = true together with storage_memory_only = true is a deliberate rollout choice by the author, and note that with storage_memory_only the new backend does not write any node files to disk by default, so the on-disk pipeline is not what upgrades get. Flipping the default is a call for @alexey-milovidov / @al13n321.
…indings * The gtest `KeeperStorage.NodeCacheEraseReleasesBlockRef` held `storage_mutex` exclusively across `StorageState::shutdown`. The flush and merge threads take that mutex in shared mode at the top of their loops, so `shutdown` deadlocked in `join` and the job timed out after 45 minutes (Unit tests tsan/msan/asan_ubsan). * `KeeperNodeStats::getEphemeralOwner` reports `CONTAINER_EPHEMERAL_OWNER` (`INT64_MIN`) for container nodes, and `LSMTDelta` passed it through, so committing a container node registered it in `committed_ephemerals` under a nonexistent session. After a restart nothing registered it, and removing the container threw `Session -9223372036854775808 is expected to have ephemeral paths but no path is registered` (`test_keeper_container_nodes/test.py::test_container_preserved_after_restart`). * `std::current_exception` is null while unwinding towards a handler that has not been entered yet, so the `SCOPE_EXIT` in `preprocessRequest` could never print the in-flight exception and aborted with a bare `Finalize not called before returning`, destroying the only clue (Keeper Stress `write-multi-no-fault`). Don't abort while unwinding: let the exception reach `KeeperStateMachine::preprocess`, whose handler logs the message and the stack trace. * Address review: the startup wipe guard now also rejects a node storage directory that contains the log, snapshot or state directory, not only a shared named disk. * Address review: keep exporting `KeeperKeyArenaSize` in `system.asynchronous_metrics` (always 0), instead of silently dropping a documented metric. * Address review: the `lsmt` stress backend now turns `storage_memory_only` off, so it exercises the on-disk flush/merge/recovery path as the README describes. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112378&sha=f76abeec947de40eafffc826b289c001a9e2ee91&name_0=PR #112378
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
New events, all with the `KeeperLSMT` prefix, also registered in `KeeperConstants.cpp` for the standalone keeper build: * flushes and merges finished successfully; exceptions in flushes, merges, and file deletions; * compressed and uncompressed bytes written by flushes; * in merge's `publish_results`: published output files and their compressed and uncompressed bytes, consumed input files and their uncompressed bytes (i.e. read and write throughput measured in files and in bytes); * entries appended by `appendUncommittedNode` (count and serialized bytes, broken down by `NodeAction`), and serialized bytes appended by `appendCommittedNode`; * throttled writes; committed and uncommitted memtables created; * `getUncommittedNode` hits and misses in uncommitted memtables; * the three return cases of `getCommittedNode`, and node cache entries re-pointed at a freshly loaded block; * for list operations: names obtained from memtables and from files, blocks and entries scanned by `SortedFile::listChildrenNames`, and `parent_paths_filter` usage (skipped / false positive / true positive); * the three cases of `SortedFile::getOrLoadBlock` (from the block info weak pointer, from the block cache, loaded a group from disk); blocks and uncompressed bytes loaded by `loadBlockGroup`. Also add the `KeeperLSMTParentPathsFilterSize` asynchronous metric: total size of `parent_paths_filter` bloom filters across all files. Co-Authored-By: Claude Fable 5 <[email protected]>
…_runs` `flushThread` cleared `delete_when_destroyed` on the new run's files right after writing them, before the run was published. If the run then waited in the `flushed_files` reorder buffer (an earlier memtable still flushing), a shutdown or `KeeperStateMachine::apply_snapshot` destroying `BackgroundWork` in that window dropped the `SortedFile`s without deleting their files, leaking them on the node-storage disk across in-process snapshot installs. Now the flag is flipped only at the moment the run is moved into `storage->sorted_runs`, under the same locks. Files destroyed while still unpublished enqueue their own deletion in `~SortedFile`, and `StorageState::shutdown` drains that queue after `background.reset()`. #112378 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 @groeneai, investigate the three stress-test failures on commit 5a674f8 and provide fixes in separate PRs (if a fix is already in progress, link it here). All three are in query-execution code this Keeper PR does not touch:
|
|
Investigated all three. Confirmed unrelated to this PR: its 46 changed files are all Keeper, Coordination, keeper-bench and disk/IO; none of the three stacks enters that code. Resolved STIDs from the artifacts: 1. Trigger, from query id SELECT count() FROM t_04493_plain FINAL WHERE flag AND (value != 7)
SETTINGS move_all_conditions_to_prewhere = 0;That is
One correction that unblocks this: the artifacts are not 403. I asked you for them on 108096 in July after getting 403, and the cause was the path form, not permissions. 2. A link, not new work. The frame is 3. Trigger, from query id /* ddl_entry=query-0000000143 */ ALTER TABLE test_1.t_04545_po
(ADD COLUMN IF NOT EXISTS `c` Array(LowCardinality(UInt64)))The log names which of the two branches fired, and it narrows the search. On 113009 being only the Breadth, 30 days, master rows first: I will post each fixing-PR link here as it opens. Separate PRs, one per bullet, as you asked. |
Both `KeeperLSMTNodesStorage::visitUncommittedRecursive` and `KeeperMemNodesStorage::visitUncommittedRecursive` treated the root node as free: `RemoveRecursive` with `remove_nodes_limit = 0` still removed a single existing znode, diverging from `TestKeeper` and from the original `ToDeleteTreeCollector` (which initialized `nodes_observed = 1` for the root). Now the root counts toward the limit in both backends, and the zero-limit case is pinned by new cases in `TestRemoveRecursiveRequest` running on both backends. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Fixing PR for bullet 3 ( Root cause is a test-isolation defect, not product code: the assertion correctly detected a real disk-vs-memory divergence. In shared-database mode the stress lane points some clients at one long-lived database that is never recreated per test. Tests only, four files, no The other two bullets are still with me and I will post their links here as they open. |
|
🕵 CI on 964eb63 had three reds; analysis:
Merged current master (was 300 commits behind) and pushed 9e2a535; all 315 Coordination/Keeper gtests pass locally after the merge. |
|
Bullet 3: the fix is already open, #113750. It was created at 2026-08-07T00:33:15Z, about 19 hours before your comment, so it did exist when you looked; it is not linked from this thread, which is probably why the search missed it. I recovered the failing query from the arm_msan artifact for 964eb63 ( SELECT 1 GLOBAL IN (_data_17232541238428130802_3723440931786826121 AS __table1) AS s,
1 GLOBAL IN (_data_17232541238428130802_3723440931786826121 AS __table2) AS s
FROM clusterAllReplicas('test_cluster_five_shards_localhost', 'system', 'one') AS __table3
GROUP BY GROUPING SETS ((1 GLOBAL IN (_data_17232541238428130802_3723440931786826121 AS __table4) AS s))The crash report's Root cause: Confirming your unrelated call from the diff rather than from the stack: of this PR's 46 changed files, 35 are One correction to my own bookkeeping on your 2026-08-06 comment: I wrote yesterday that two of its bullets were still with me, but bullet 2 already carries a link (113534, yours), so only bullet 1 remains, the |
| std::abort(); | ||
| /// Put the exception message into the fatal report: the text log may not survive the | ||
| /// process death, and the crash report is often the only thing test harnesses collect. | ||
| DB::abortOnFailedAssertion(fmt::format( |
There was a problem hiding this comment.
appendUncommittedNode still converts MEMORY_LIMIT_EXCEEDED into a fatal assertion failure, and the comment above already acknowledges that this exception is expected here. With use_new_storage = 1 and storage_memory_only = 1 now the shipped defaults, that is an availability regression rather than an internal TODO: the current PR Keeper stress lane already hits this under write-multi-no-fault[default], so a write-heavy upgrade can turn memory pressure into Keeper self-termination.
Either the old storage needs to remain the default until this path can surface a controlled failure/backpressure, or MEMORY_LIMIT_EXCEEDED needs a dedicated non-fatal handling path here.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Keeper stores nodes in an LSM tree now. It has about the same performance as the previous storage and lower memory usage. It is enabled by default (
use_new_storage), and by default it keeps all data in memory without writing node files to disk (storage_memory_only); setuse_new_storageto0to go back to the previous storage. Continuation of #110065, which was created as a stacked PR.#107261 added new storage with memory-only mode. This PR