v.22.2Improvement

Cancel Merges Before Table Lock to Prevent DEADLOCK_AVOIDED Error in TRUNCATE Query

Cancel merges before acquiring table lock for TRUNCATE query to avoid DEADLOCK_AVOIDED error in some cases. Fixes #34302. #34304 (tavplubix).
Cancel merges before acquiring table lock for TRUNCATE queries to prevent DEADLOCK_AVOIDED errors.

Why it matters

This feature addresses a deadlock scenario that occurs during TRUNCATE operations by cancelling ongoing merges before locking the table. It improves stability and reliability when truncating tables by avoiding deadlock errors.

How to use it

No special configuration is needed. The fix is applied automatically to TRUNCATE queries in ClickHouse to cancel merges before acquiring the table lock.