v.25.11Improvement

Introduced a LockGuardWithStopWatch class and used it

Introduced a LockGuardWithStopWatch class and used it in the background pool for executing merges. In case a mutex was held for a second or some thread was struggling to get it within a second a warning message will be printed. Moved the heavy code from the destructor of MergeMutateSelectedEntry to finalize method to avoid holding the lock in MergeTreeBackground executor for too long. #88898 (Nikita Mikhaylov).
Introduced a LockGuardWithStopWatch class to monitor and warn when mutexes are held too long in the background pool for merges; optimized merge task finalization by moving heavy code from destructor to a dedicated finalize method to reduce lock hold time in the MergeTreeBackground executor.

Why it matters

This feature addresses the issue of prolonged mutex lock holding during merge execution in the background pool, which can cause performance bottlenecks and thread contention. By detecting and warning about mutexes held for over one second, and by reducing the lock hold time through refactoring, it improves system stability and helps identify potential deadlocks or inefficiencies.

How to use it

This feature is automatically applied in the background merges process; no user intervention is needed. Users will receive warning messages in the logs if a mutex is held for more than one second or if some thread struggles to acquire the lock within that time.