Repository navigation
Do not terminate the server on retryable errors while loading outdated parts - #117981
Conversation
…d parts `MergeTreeData::loadOutdatedDataParts` wraps its body in `catch (...)` that calls `std::terminate` to fail fast on an inconsistent set of parts on disk. The same `catch` fired for transient errors that have nothing to do with the parts: `MEMORY_LIMIT_EXCEEDED` from the memory tracker, `TABLE_IS_BEING_RESTARTED` from `lockForShare` racing with `SYSTEM RESTART REPLICA`, and permanent filesystem cache failpoints enabled by BuzzHouse. Take the table lock with `tryLockForShare` and reschedule the task when the table is being dropped or restarted. In the per-part worker, catch the exception from `loadDataPartWithRetries`: if `isRetryableException` classifies it as retryable, put the part back into the queue and reschedule the task with a backoff after all workers finish instead of marking the loading finished. Non-retryable errors still terminate. A simpler reimplementation of #107091. Closes: #106736 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [a97ae83] Summary: ✅
AI ReviewSummaryThis PR changes Findings
Final VerdictChanges requested. The new worker retry path and the deadlock fix are solid, but the lock-timeout variant of the restart race still violates the PR’s main contract. LLVM Coverage ReportMeasured on commit a97ae83.
Changed lines: Changed C/C++ lines covered: 67/73 (91.78%) · Uncovered code |
|
There is a lock-order problem between the cancellation branch and the new worker The cancellation branch of the dispatch loop waits for the in-flight workers while holding The sequence: The new failpoint makes the window directly reachable in a test: enable The fix is small: release the lock before waiting in the canceled branch (the following A smaller note on the unbounded-retries trade-off: the description mentions callers of |
|
Checked it. The fix is correct and it covers all three triggers from #106736:
The requeue is safe without the rollback bookkeeping I had in #107091. Two things:
On the windows you left as is: I have no observed occurrence and no reproduction for any of them, so I am not claiming that anything user-reachable is left unfixed. The guards I had for the post-load cleanup came out of review rounds, not out of CI evidence. One correction to the reasoning in the description: in |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+18.84 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units8 translation units recompiled, 40 s compile time in total, 8 of them have a recent master baseline. |
…arts-retryable-simple
The worker of `loadOutdatedDataParts` put a part that failed with a retryable error back into `outdated_unloaded_data_parts` under `outdated_data_parts_mutex`. The cancellation branch of the dispatch loop waits for all the workers while holding that mutex, so a worker failing after `DETACH TABLE`, `DROP TABLE`, shutdown or `SYSTEM RESTART REPLICA` cancelled the loading deadlocked with the dispatcher and the DDL query never returned. The failed parts are now collected under a dedicated local mutex and returned to the queue only after `waitForAllToFinishAndRethrowFirstError` returns, both in the cancellation branch and on the normal path. Add the pauseable failpoint `merge_tree_load_outdated_parts_pause` and the test `05228_load_outdated_parts_cancel_on_detach`, which cancels the loading with `DETACH TABLE` while the workers are paused and then lets them fail with the retryable error. Renumber `05076_load_outdated_parts_retryable_error` to `05227` and tag both tests `no-parallel`: `SYSTEM ENABLE FAILPOINT` is process-wide, and a concurrent copy of the test in the flaky check changed the number of loaded parts, see https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117981&sha=9416ab0f0ecd29c839f0b047ac9638e666a1cc17&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 (#117981). Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 @zlareb1, @groeneai, thanks. Addressed in a97ae83:
Master is merged in as well. |
| if (is_async) | ||
| shared_lock = lockForShare(RWLockImpl::NO_QUERY, (*getSettings())[MergeTreeSetting::lock_acquire_timeout_for_background_operations]); | ||
| { | ||
| shared_lock = tryLockForShare(RWLockImpl::NO_QUERY, (*getSettings())[MergeTreeSetting::lock_acquire_timeout_for_background_operations]); |
There was a problem hiding this comment.
tryLockForShare does not fully make the SYSTEM RESTART REPLICA race non-fatal here, because IStorage::tryLockForShare still calls tryLockTimed first. If the restart already owns drop_lock for longer than lock_acquire_timeout_for_background_operations, tryLockTimed throws DEADLOCK_AVOIDED before tryLockForShare gets a chance to turn the restart into a null holder.
That exception still falls into the terminating outer catch (...) below, so with a low supported lock_acquire_timeout_for_background_operations this background load can still bring the server down during a concurrent restart/detach instead of rescheduling itself. This branch needs to treat that timeout the same way as the !shared_lock case (or check the restart/drop state before waiting on the lock). A focused regression test for the timeout path would also help, because the new tests only exercise the per-part retryable-error branch.
|
Checked The deadlock is gone. The worker's Both tests carry Two windows outside your three bullets, neither observed and neither a regression, so I am not asking for anything here: The family is still live, and every occurrence is in the window you fixed: 48 runs in the last 90 days, on 41 distinct heads, 5 of them on master, the newest earlier today. All 48 terminate inside the schedule pool loader, none in |
Backport #117981 to 26.9: Do not terminate the server on retryable errors while loading outdated parts
Backport #117981 to 26.8: Do not terminate the server on retryable errors while loading outdated parts
Backport #117981 to 26.7: Do not terminate the server on retryable errors while loading outdated parts
…tryable errors while loading outdated parts
…tryable errors while loading outdated parts
…tryable errors while loading outdated parts
Closes: #106736
Related: #107091
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Do not terminate the server when a transient error (such as
MEMORY_LIMIT_EXCEEDED, a network error, orSYSTEM RESTART REPLICArunning at the same time) happens while outdated data parts are being loaded in the background. Such errors are not a sign of an inconsistent set of parts on disk, so the loading is now retried later instead of aborting the server.Description
A simpler reimplementation of #107091.
MergeTreeData::loadOutdatedDataPartswraps its whole body incatch (...)that callsstd::terminate, to fail fast when the on-disk set of parts is inconsistent. The samecatchalso fires for transient errors that have nothing to do with the parts on disk, and takes the whole server down. Three such triggers were observed in CI (see the issue):MEMORY_LIMIT_EXCEEDEDfrom the memory tracker (the stress-test fault injector) while a part is being loaded.TABLE_IS_BEING_RESTARTEDthrown bylockForShareat the top of the function whenSYSTEM RESTART REPLICAruns at the same time. This one needs no fault injection at all.loadDataPartWithRetries.The fix has two pieces, both in
loadOutdatedDataParts:tryLockForShare. When it returns no lock, the table is being dropped, detached or restarted, so the task is rescheduled with a backoff instead of terminating. If the table is going away, the task gets deactivated inshutdownanyway.loadDataPartWithRetries. IfisRetryableExceptionclassifies it as retryable (the same classifierloadDataPartWithRetriesalready uses), the part is collected into a local list of failed parts and the first such error is remembered. Non-retryable errors propagate to the terminatingcatchas before. After all workers finish, if a retryable error happened, the failed parts are returned tooutdated_unloaded_data_parts, the function logs a warning and reschedules itself with a backoff instead of marking the loading finished. The dispatch loop also stops handing out new parts once a retryable error is seen, so the server does not keep hammering a failing resource under memory pressure.The failed parts are collected under a dedicated local mutex rather than under
outdated_data_parts_mutex: the cancellation branch of the dispatch loop waits for all the workers while holdingoutdated_data_parts_mutex, so a worker that takes that mutex before its future becomes ready would deadlockDETACH,DROP, shutdown andSYSTEM RESTART REPLICA. Workers must not touch that mutex at all.Putting a part back into the queue is safe because
loadDataPartinserts a part intodata_parts_indexesonly as its very last step, and nothing that can throw a retryable exception runs after the insertion (logging blocks the memory tracker), so a part whose loading failed is never published and is simply loaded from scratch on the retry.What is intentionally left as is, to keep the change small:
preparePartForRemoval,remove,renameToDetached) still terminate. Retrying them safely requires the rollback and directory-move bookkeeping that made Do not terminate the server on retryable errors while loading outdated parts #107091 large, and none of the observed CI occurrences came from there.StorageReplicatedMergeTree::drophas no task to retry with, so a retryable error there still fails fast as before.loadUnexpectedDataPartsis unchanged:loadUnexpectedDataPartalready catches every exception itself and marks the part broken. Its detach ignores filesystem errors only for replicated tables, so on a plainMergeTreea filesystem error inrenameToDetachedstill reaches the terminatingcatch; it takes no table lock, soSYSTEM RESTART REPLICAcannot reach it, and no CI occurrence came from there.waitForOutdatedPartsToBeLoadedwaits until the resource recovers instead of failing fast. BesidesSYSTEM WAIT LOADING PARTS, these areexecuteDropRangeandexecuteReplaceRangein the replication queue,checkPartsat startup,truncate,restoreMetadataInZooKeeperandreplacePartitionFrom/movePartitionToTable, so a permanently failing resource now shows up as stalledDROP_RANGE/REPLACE_RANGEentries and growing replication lag instead of a terminated server. That is a deliberate trade-off: the parts are not lost, and the operations resume as soon as the loading succeeds.Two failpoints are added for the tests: a
REGULARmerge_tree_load_outdated_parts_retryable_errorthat throwsMEMORY_LIMIT_EXCEEDEDin the worker, and aPAUSEABLEmerge_tree_load_outdated_parts_pausethat blocks a worker until it is disabled.05227_load_outdated_parts_retryable_errorenables the first one, doesDETACH/ATTACHof a table with outdated parts, checks that the server is alive and that no outdated part could be loaded, then disables the failpoint and checks withSYSTEM WAIT LOADING PARTSthat all of them are loaded. Without the fix the server terminates onATTACH.05228_load_outdated_parts_cancel_on_detachblocks the loading workers with the pauseable failpoint, cancels the loading withDETACH TABLEwhile they are in flight, and then lets them fail with the retryable error. It uses more parts than the loading thread pool plus its queue, so the dispatcher is really in the cancellation branch when theDETACHarrives. Against a control build where the workers requeue the failed parts underoutdated_data_parts_mutextheDETACHnever returns and the test hangs.Both tests are tagged
no-parallel:SYSTEM ENABLE FAILPOINTis process-wide, and a concurrent copy of the test in the flaky check changes the number of parts loaded.Workflow [PR]
Sync PR [sync-upstream/pr/117981]
🤖 Generated with Claude Code
Version info
26.10.1.93(included in26.10and later)26.9.1.1606,26.8.8.4,26.7.12.4