Repository navigation
Cherry pick #125165 to 26.9: Do not wait for a running statistics refresh when a MergeTree table is shut down - #125478
Conversation
`refreshStatistics` walks every active part and reads its statistics, one or more object storage reads per part, with no stop check. Every deactivation of `refresh_stats_task` (table shutdown, `DROP`/`DETACH`, the destructor, and `ALTER ... MODIFY SETTING refresh_statistics_interval`) joins the running walk in `BackgroundSchedulePoolTaskInfo::deactivate`, so on object storage with thousands of parts each of them waited minutes, and a server restart with many such tables did not finish. `refresh_stats_stopped` cannot be used for this: it is guarded by the mutex the deactivating thread holds while it waits, and the `ALTER` path must not set it. Add an atomic `refresh_stats_cancelled`, set before both `deactivate` calls and reset only when `startStatisticsCache` arms a new task (under the same mutex, after the old task has been joined). The walk checks it before each part and returns without publishing the partial estimator, so a deactivation waits for at most one part. Closes #125136 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the refresh_stats_cancelled member comment to its one-line contract. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e GET limit The CI test profile (`tests/config/users.d/enable_blobs_check.xml`) enables `s3_check_objects_after_upload`, which sends two HEAD requests per uploaded part. They count against the disk's `s3_max_get_rps = 2`, so each 120-part INSERT took about 120 s and every CI run 250 to 310 s (over the 180 s limit). The disk access check at CREATE adds a few more HEAD/GET requests, and it runs under `Context::getOrCreateDisk`'s server-wide `storage_policies_mutex`, which in the flaky check serialized the parallel runs (CREATE up to 15 s) and delayed their DROPs. Disable `s3_check_objects_after_upload` for the inserts and skip the access check of the ad hoc disks. With the CI user profile installed locally (debug build): a run takes 8 to 11 s instead of 250 s, INSERTs make no throttled requests, the 50 randomized runs (half at -j 8) pass with ALTER <= 0.9 s and DROP <= 1.2 s, master still waits 58 s for both, and the four deletion mutants still fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The flaky checks on release and debug builds still ran the test for 150-200 s at 3e2d7fa: with 8 copies in parallel, every one-row part cost about 650 ms of S3 uploads in CI, so each 120-part INSERT took 70-97 s, and one DROP of 120 parts waited 110 s in the shared parts cleanup pool. A statistics refresh reads every statistic of a part with its own GET request, so 24 parts with 5 statistics each keep the throttled walk at 120 requests or more, like 120 parts with one, while the number of parts written and removed is 5 times smaller. Local, debug build, CI user profile: master ALTER/DROP 57.8-69.9 s (5 runs), fix 83/83 OK with ALTER max 2.5 s and DROP max 1.9 s (25 sequential, 25 at -j 8, 32 at -j 16, 9-15 s per run); the four deletion mutants still fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…does-not-block-shutdown Do not wait for a running statistics refresh when a MergeTree table is shut down
Resolve the cherry-pick of #125165 to 26.9. The conflicts come from #121671 and #121672, which are not on 26.9: on master the statistics refresh task is stopped through `stopStatisticsCache` under `refresh_stats_task_mutex`, and the `refreshStatistics` loop no longer takes the parts lock per part. On 26.9 the task is deactivated directly in `startStatisticsCache`, `~MergeTreeData` and the `shutdown` of `StorageMergeTree` and `StorageReplicatedMergeTree`, so `refresh_stats_cancelled` is set before each of those four `deactivate` calls, reset when `startStatisticsCache` arms a new task, and checked before each part in `refreshStatistics`. Neither the mutex nor `stopStatisticsCache` is ported, and the `LoadedStatistics` profile event that master's loop also increments is left out. The `05361_statistics_refresh_does_not_block_drop` test is ported unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
I pushed a resolution of this cherry-pick to my fork, branch The conflicts come from #121671 and #121672, which are not on 26.9: there is no The cherry-pick of #124420 (#125186) changes the next line of the same loop: it removes I tested a Debug build of the resolved tree with clang-22, running the 26.9
@alexey-milovidov, I have After that the robot merges this PR and opens the 26.9 backport PR itself. |
|
🕵 Reviewed and applied the resolution from |
Original pull-request #125165
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job