Repository navigation
Do not refuse to start over a Filesystem database whose path cannot be accessed - #126772
Conversation
…e accessed The DatabaseFilesystem constructor probed its path with the throwing fs::exists and, on a server, with pathStartsWith (fs::relative, which canonicalizes). libc++ maps only ENOENT/ENOTDIR to "not found", so any other stat error (ELOOP, EACCES, ESTALE, EIO, ENAMETOOLONG) escaped as Code: 1001 STD_EXCEPTION before the startup-replay guard of ClickHouse#118684. loadMetadata stops at the first exception, so a server or a clickhouse-local --path store holding such a database refused to start, and the database could not be dropped. Probe once with fs::exists(path, ec). When stat works, containment keeps the canonical pathStartsWith check. When it fails, the path cannot be canonicalized, so containment is checked lexically with fileOrSymlinkPathStartsWith, the check every table resolution already uses, and a path outside user_files is still refused on replay. An unreachable path is then handled like a missing one: the replay logs the errno and attaches the database with no tables, and a user statement gets BAD_ARGUMENTS with the errno instead of STD_EXCEPTION. Missing and existing paths behave exactly as before. 05136 gains a symlink-loop restart sequence for clickhouse-local and two server arms with a component over NAME_MAX, inside and outside user_files. Closes ClickHouse#121705 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…user_files when stat fails When stat of the path fails for a reason other than "not found", the containment check compared the stored spelling with the canonical user_files lexically. A root spelled through a symlink to user_files (for example the configured path on a server whose data directory is a symlink) passed CREATE, which canonicalizes, but was refused on replay once the root became unreachable, so the server still did not start. Canonicalize the part of the path that resolves and keep the failing component as written, as weakly_canonical does for a missing path, and check containment on that. A path outside user_files is still refused. 05136: the server arms now assert the error code and message, and a new arm spells the root through /proc/self/root. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the canonicalizeResolvablePrefix doc comment to one line and drop the sentence narrating the containment fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings, then 0 on the re-review of the fix round) plus my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261019-182400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261019-175300 |
|
cc @tuanpach @tavplubix, could you review this and add the |
|
Workflow [PR], commit [b503d56] Summary: ✅
AI ReviewSummaryReviewed commit Final Verdict✅ Approve. No new inline findings. |
…at'ed When `stat` fails on the database path, containment in `user_files` was checked on the canonical prefix with the failing component kept as written. A path that is itself a symlink outside `user_files` pointing into it lost its target that way: for `/srv/imports -> <user_files>/locked/data` with `locked` no longer traversable, `fs::canonical` fails on the whole path, the symlink is stripped as the failing component, and the result `/srv/imports` is outside `user_files`. The startup replay then throws `Path must be inside user-files path` and the server does not start (measured: exit 36 on the previous head, 1001 on master). `canonicalizeResolvablePrefix` now follows a component that is a readable symlink before keeping it as written, bounded by the kernel's 40-symlink limit so a loop terminates. It uses the `error_code` overload of `fs::read_symlink`: `FS::readSymlink` throws, so a `readlink` failing after a successful `lstat` (EIO, ESTALE, a concurrent replace) would escape as `STD_EXCEPTION` again. `readlink` of `dir/link/` fails (the trailing separator makes the kernel follow the link), so that spelling is not followed with `parent_path` = the link itself; the loop strips the separator and follows `dir/link` against its real parent. A stored path of `PATH_MAX` bytes or more is returned as written without the walk: no such path can be accessed, so it can never be created or replayed, while stripping it one component at a time copied the path once per component (measured, debug build: a rejected `CREATE` with 130000 components took 2.29 s on the previous head, 0.08 s on master, 0.48 s now). Only the stored spelling is checked: a followed `parent/target` may exceed `PATH_MAX` and still resolve, because the kernel never builds that string (measured: a 4127-byte `parent/target` into `user_files` starts and drops). The test gains three server arms: a symlink from outside `user_files` to a path inside it that stat cannot follow (inside), the same to a path outside it (refused), and a symlink loop outside it (refused; an unbounded follow makes this arm time out). Reported by the AI review on the PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - 4d29de3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The other Session id: cron:our-pr-ci-monitor:20261020-133009 |
|
Fixing PR for test_temporary_lock_quota_is_retained_across_rounds created: #126965 |
Drop `canonicalizeResolvablePrefix`. Whatever it resolved, the outcome did not depend on it: a user statement over such a path is refused with `Cannot access path` either way, and the startup replay attaches the database with no tables. The containment that protects files is the one each table resolution already does (`checkTableFilePath`), before it touches a file: a root behind a symlink from outside `user_files` serves no table even while it is accessible (`File is not inside ...`). `fs::weakly_canonical` cannot replace the helper: libc++ stops at the first component whose stat fails for a reason other than ENOENT or ENOTDIR, which is exactly the case here. So a path stat fails on skips the containment check. A path outside `user_files` that stat refuses now reports `Cannot access path` instead of `Path must be inside user-files path`; master reports the same errno as `Code: 1001`. 05136 keeps one server arm, since the others only exercised the helper. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #121705
Related: #118684
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server or
clickhouse-local --pathrefusing to start withCode: 1001 STD_EXCEPTIONwhen the directory of aFilesystemdatabase cannot be accessed, for example because it became a symlink loop or lost traverse permission. Such a database now loads with no tables and logs a warning, the same as a missing directory.CREATE DATABASE ... ENGINE = Filesystem(...)over such a path, including one with a component longer thanNAME_MAX, now fails withBAD_ARGUMENTSinstead ofSTD_EXCEPTION. Closes #121705.Description
On 26.9.19.9, a server or
clickhouse-local --pathstore holding aFilesystemdatabase whose directory became a symlink loop or lost traverse permission refuses to start withCode: 1001 STD_EXCEPTION, and the database cannot be dropped. #118684 fixed only a missing directory.Root cause: the
DatabaseFilesystemconstructor probes its path with the throwingfs::existsand, on a server, withpathStartsWith(fs::relative). libc++ reports onlyENOENT/ENOTDIRas "not found". Every otherstaterror (ELOOP,EACCES,ENAMETOOLONG) throws before the startup-replay guard, andloadMetadatastops at the first exception.Change: probe once with
fs::exists(path, ec). Ifstatworks, containment keeps the canonicalpathStartsWithcheck. If it fails, where the path leads cannot be resolved, so it is treated like a missing path without a containment check: the startup replay logsCannot access path X: <errno>and attaches the database with no tables, and a user statement getsBAD_ARGUMENTSwith the errno (master reports the same errno asCode: 1001). Each table resolution still checks its own path againstuser_filesbefore touching a file. Missing and existing paths behave as before.Validation:
05136_database_filesystem_missing_path_on_loadgains a symlink-loop restart sequence (clickhouse-local) and a server arm with a component overNAME_MAX. They fail on master and pass with the fix, 50/50 under randomized settings. I also restarted a server overELOOP,EACCES, auser_files_pathconfigured through a symlink, and a symlink from outsideuser_filesinto a directory that lost traverse permission: master does not start, the fix starts and the database drops.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126772]
Version info
26.11.1.478-master(included in26.11and later)