https://s3.amazonaws.com/clickhouse-test-reports/37650/217f492264f5526a2372f95c9144be162934a34c/stateless_tests__thread__actions__[2/3].html

<details>
<summary>Error message</summary>


```
2022-05-30 10:25:56 [e89d17b24d77] 2022.05.30 10:25:52.466531 [ 40175 ] {316371e3-cd4c-4c1b-9755-06affc23d6bb}  InterpreterSystemQuery: SYNC REPLICA test_8r9vin.src_10 (9e000aca-17ed-4ac9-ba47-28468bcf5a58): Timed out!
2022-05-30 10:25:56 [e89d17b24d77] 2022.05.30 10:25:52.467761 [ 40175 ] {316371e3-cd4c-4c1b-9755-06affc23d6bb}  executeQuery: Code: 159. DB::Exception: SYNC REPLICA test_8r9vin.src_10 (9e000aca-17ed-4ac9-ba47-28468bcf5a58): command timed out. See the 'receive_timeout' setting. (TIMEOUT_EXCEEDED) (version 22.6.1.1) (from [::1]:36136) (comment: 01154_move_partition_long.sh) (in query: SYSTEM SYNC REPLICA src_10), Stack trace (when copying this message, always include the lines below):
2022-05-30 10:25:56 
2022-05-30 10:25:56 0. ./build_docker/../contrib/libcxx/include/exception:0: Poco::Exception::Exception(std::__1::basic_string, std::__1::allocator > const&, int) @ 0x20897afb in /usr/bin/clickhouse
2022-05-30 10:25:56 1. ./build_docker/../src/Common/Exception.cpp:69: DB::Exception::Exception(std::__1::basic_string, std::__1::allocator > const&, int, bool) @ 0xb23001c in /usr/bin/clickhouse
2022-05-30 10:25:56 2. ./build_docker/../contrib/libcxx/include/string:1445: DB::Exception::Exception, std::__1::allocator > >(int, fmt::v8::basic_format_string, std::__1::allocator > >::type>, std::__1::basic_string, std::__1::allocator >&&) @ 0xb331e88 in /usr/bin/clickhouse
2022-05-30 10:25:56 3. ./build_docker/../src/Interpreters/InterpreterSystemQuery.cpp:0: DB::InterpreterSystemQuery::syncReplica(DB::ASTSystemQuery&) @ 0x1a87873f in /usr/bin/clickhouse
2022-05-30 10:25:56 4. ./build_docker/../src/Interpreters/InterpreterSystemQuery.cpp:441: DB::InterpreterSystemQuery::execute() @ 0x1a8726ae in /usr/bin/clickhouse
2022-05-30 10:25:56 5. ./build_docker/../src/Interpreters/executeQuery.cpp:0: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x1abc6122 in /usr/bin/clickhouse
2022-05-30 10:25:56 6. ./build_docker/../src/Interpreters/executeQuery.cpp:1069: DB::executeQuery(std::__1::basic_string, std::__1::allocator > const&, std::__1::shared_ptr, bool, DB::QueryProcessingStage::Enum) @ 0x1abc37c2 in /usr/bin/clickhouse
2022-05-30 10:25:56 7. ./build_docker/../src/Server/TCPHandler.cpp:0: DB::TCPHandler::runImpl() @ 0x1ba013e7 in /usr/bin/clickhouse
2022-05-30 10:25:56 8. ./build_docker/../src/Server/TCPHandler.cpp:1783: DB::TCPHandler::run() @ 0x1ba12088 in /usr/bin/clickhouse
2022-05-30 10:25:56 9. ./build_docker/../contrib/poco/Net/src/TCPServerConnection.cpp:57: Poco::Net::TCPServerConnection::start() @ 0x206d40a3 in /usr/bin/clickhouse
2022-05-30 10:25:56 10. ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:54: Poco::Net::TCPServerDispatcher::run() @ 0x206d4913 in /usr/bin/clickhouse
2022-05-30 10:25:56 11. ./build_docker/../contrib/poco/Foundation/src/ThreadPool.cpp:213: Poco::PooledThread::run() @ 0x209399f6 in /usr/bin/clickhouse
2022-05-30 10:25:56 12. ./build_docker/../contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() @ 0x20937b90 in /usr/bin/clickhouse
2022-05-30 10:25:56 13. ./build_docker/../contrib/poco/Foundation/include/Poco/SharedPtr.h:277: Poco::ThreadImpl::runnableEntry(void*) @ 0x20936208 in /usr/bin/clickhouse
2022-05-30 10:25:56 14. __tsan_thread_start_func @ 0xb17503d in /usr/bin/clickhouse
2022-05-30 10:25:56 15. ? @ 0x7f398fdd0609 in ?
2022-05-30 10:25:56 16. __clone @ 0x7f398fcf5163 in ?
2022-05-30 10:25:56 
2022-05-30 10:25:56 Received exception from server (version 22.6.1):
2022-05-30 10:25:56 Code: 159. DB::Exception: Received from localhost:9000. DB::Exception: SYNC REPLICA test_8r9vin.src_10 (9e000aca-17ed-4ac9-ba47-28468bcf5a58): command timed out. See the 'receive_timeout' setting. (TIMEOUT_EXCEEDED)
2022-05-30 10:25:56 (query: SYSTEM SYNC REPLICA src_10)
2022-05-30 10:25:56 [e89d17b24d77] 2022.05.30 10:25:52.467488 [ 40168 ] {c2df5ebd-2ad5-48c6-bdae-b39e741bd64c}  InterpreterSystemQuery: SYNC REPLICA test_8r9vin.src_13 (434057b5-5e94-4aef-97b9-439c39674883): Timed out!
2022-05-30 10:25:56 [e89d17b24d77] 2022.05.30 10:25:52.468703 [ 40168 ] {c2df5ebd-2ad5-48c6-bdae-b39e741bd64c}  executeQuery: Code: 159. DB::Exception: SYNC REPLICA test_8r9vin.src_13 (434057b5-5e94-4aef-97b9-439c39674883): command timed out. See the 'receive_timeout' setting. (TIMEOUT_EXCEEDED) (version 22.6.1.1) (from [::1]:36138) (comment: 01154_move_partition_long.sh) (in query: SYSTEM SYNC REPLICA src_13), Stack trace (when copying this message, always include the lines below):
2022-05-30 10:25:56 
2022-05-30 10:25:56 0. ./build_docker/../contrib/libcxx/include/exception:0: Poco::Exception::Exception(std::__1::basic_string, std::__1::allocator > const&, int) @ 0x20897afb in /usr/bin/clickhouse
2022-05-30 10:25:56 1. ./build_docker/../src/Common/Exception.cpp:69: DB::Exception::Exception(std::__1::basic_string, std::__1::allocator > const&, int, bool) @ 0xb23001c in /usr/bin/clickhouse
2022-05-30 10:25:56 2. ./build_docker/../contrib/libcxx/include/string:1445: DB::Exception::Exception, std::__1::allocator > >(int, fmt::v8::basic_format_string, std::__1::allocator > >::type>, std::__1::basic_string, std::__1::allocator >&&) @ 0xb331e88 in /usr/bin/clickhouse
2022-05-30 10:25:56 3. ./build_docker/../src/Interpreters/InterpreterSystemQuery.cpp:0: DB::InterpreterSystemQuery::syncReplica(DB::ASTSystemQuery&) @ 0x1a87873f in /usr/bin/clickhouse
2022-05-30 10:25:56 4. ./build_docker/../src/Interpreters/InterpreterSystemQuery.cpp:441: DB::InterpreterSystemQuery::execute() @ 0x1a8726ae in /usr/bin/clickhouse
2022-05-30 10:25:56 5. ./build_docker/../src/Interpreters/executeQuery.cpp:0: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x1abc6122 in /usr/bin/clickhouse
2022-05-30 10:25:56 6. ./build_docker/../src/Interpreters/executeQuery.cpp:1069: DB::executeQuery(std::__1::basic_string, std::__1::allocator > const&, std::__1::shared_ptr, bool, DB::QueryProcessingStage::Enum) @ 0x1abc37c2 in /usr/bin/clickhouse
2022-05-30 10:25:56 7. ./build_docker/../src/Server/TCPHandler.cpp:0: DB::TCPHandler::runImpl() @ 0x1ba013e7 in /usr/bin/clickhouse
2022-05-30 10:25:56 8. ./build_docker/../src/Server/TCPHandler.cpp:1783: DB::TCPHandler::run() @ 0x1ba12088 in /usr/bin/clickhouse
2022-05-30 10:25:56 9. ./build_docker/../contrib/poco/Net/src/TCPServerConnection.cpp:57: Poco::Net::TCPServerConnection::start() @ 0x206d40a3 in /usr/bin/clickhouse
2022-05-30 10:25:56 10. ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:54: Poco::Net::TCPServerDispatcher::run() @ 0x206d4913 in /usr/bin/clickhouse
2022-05-30 10:25:56 11. ./build_docker/../contrib/poco/Foundation/src/ThreadPool.cpp:213: Poco::PooledThread::run() @ 0x209399f6 in /usr/bin/clickhouse
2022-05-30 10:25:56 12. ./build_docker/../contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() @ 0x20937b90 in /usr/bin/clickhouse
2022-05-30 10:25:56 13. ./build_docker/../contrib/poco/Foundation/include/Poco/SharedPtr.h:277: Poco::ThreadImpl::runnableEntry(void*) @ 0x20936208 in /usr/bin/clickhouse
2022-05-30 10:25:56 14. __tsan_thread_start_func @ 0xb17503d in /usr/bin/clickhouse
2022-05-30 10:25:56 15. ? @ 0x7f398fdd0609 in ?
2022-05-30 10:25:56 16. __clone @ 0x7f398fcf5163 in ?
2022-05-30 10:25:56 
2022-05-30 10:25:56 Received exception from server (version 22.6.1):
2022-05-30 10:25:56 Code: 159. DB::Exception: Received from localhost:9000. DB::Exception: SYNC REPLICA test_8r9vin.src_13 (434057b5-5e94-4aef-97b9-439c39674883): command timed out. See the 'receive_timeout' setting. (TIMEOUT_EXCEEDED)
2022-05-30 10:25:56 (query: SYSTEM SYNC REPLICA src_13)
2022-05-30 10:25:56 
2022-05-30 10:25:56 stdout:
2022-05-30 10:25:56 Replication did not hang: synced all replicas of dst_
2022-05-30 10:25:56 Consistency: 1
2022-05-30 10:25:56 sync failed, queue:	default	src_10	r1_1340819367	1	queue-0000000354	REPLACE_RANGE	2022-05-30 10:18:37	0	r1_3691680433		[]	0	0	698	Code: 234. DB::Exception: Not found part 0_36_36_1 (or part covering it) neither source table neither remote replicas. (NO_REPLICA_HAS_PART) (version 22.6.1.1)	2022-05-30 10:25:52	22	Not executing log entry queue-0000000354 for part 0_37_37_1 because it is covered by part 0_37_42_2 that is currently executing.	2022-05-30 10:18:48	
2022-05-30 10:25:56 sync failed, queue:	default	src_10	r1_1340819367	0	queue-0000000355	DROP_RANGE	2022-05-30 10:18:37	0	r1_3691680433	0_36_36_1	[]	0	0	0		1969-12-31 18:00:00	1910	Not executing log entry queue-0000000355 of type DROP_RANGE for part 0_36_36_1 because another DROP_RANGE or REPLACE_RANGE entry are currently executing.	2022-05-30 10:25:52	
2022-05-30 10:25:56 sync failed, queue:	default	src_13	r1_75488309	1	queue-0000000354	REPLACE_RANGE	2022-05-30 10:18:37	0	r1_3691680433		[]	0	0	710	Code: 234. DB::Exception: Not found part 0_36_36_1 (or part covering it) neither source table neither remote replicas. (NO_REPLICA_HAS_PART) (version 22.6.1.1)	2022-05-30 10:25:52	13	Not executing log entry queue-0000000354 for part 0_37_37_1 because it is covered by part 0_37_42_2 that is currently executing.	2022-05-30 10:18:48	
2022-05-30 10:25:56 sync failed, queue:	default	src_13	r1_75488309	0	queue-0000000355	DROP_RANGE	2022-05-30 10:18:37	0	r1_3691680433	0_36_36_1	[]	0	0	0		1969-12-31 18:00:00	1991	Not executing log entry queue-0000000355 of type DROP_RANGE for part 0_36_36_1 because another DROP_RANGE or REPLACE_RANGE entry are currently executing.	2022-05-30 10:25:52	
2022-05-30 10:25:56 Replication did not hang: synced all replicas of src_
2022-05-30 10:25:56 
2022-05-30 10:25:56 
2022-05-30 10:25:56 Settings used in the test: --max_insert_threads=0 --group_by_two_level_threshold=100000 --group_by_two_level_threshold_bytes=50000000 --distributed_aggregation_memory_efficient=1 --fsync_metadata=1 --output_format_parallel_formatting=0 --input_format_parallel_parsing=1 --min_chunk_bytes_for_parallel_parsing=8615318 --max_read_buffer_size=796245 --prefer_localhost_replica=1 --max_block_size=21183 --max_threads=42 --optimize_or_like_chain=0
2022-05-30 10:25:56 
2022-05-30 10:25:56 Database: test_8r9vin
```



</details>
const String & source_replica_path, DiskPtr replaced_disk, String replaced_part_path)
{
    auto zookeeper = getZooKeeper();
    const auto part_info = MergeTreePartInfo::fromPartName(part_name, format_version);
    if (auto part = getPartIfExists(part_info, {IMergeTreeDataPart::State::Outdated, IMergeTreeDataPart::State::Deleting}))
    {
        LOG_DEBUG(log, "Part {} should be deleted after previous attempt before fetch", part->name);
        
        cleanup_thread.wakeup();
        return false;
    }
    {
        std::lock_guard lock(currently_fetching_parts_mutex);
        if (!currently_fetching_parts.insert(part_name).second)
        {
            LOG_DEBUG(log, "Part {} is already fetching right now", part_name);
            return false;
        }
    }
    SCOPE_EXIT_MEMORY