```sql
create table clickhouse (s String) engine=MergeTree() order by tuple();
ALTER TABLE clickhouse MODIFY SAMPLE BY tuple();
```

Master with thread sanitizer and my changes:
```
2021.10.11 17:31:23.899970 [ 2301863 ] {} <Trace> BaseDaemon: Received signal 11
2021.10.11 17:31:23.901224 [ 2302181 ] {} <Fatal> BaseDaemon: ########################################
2021.10.11 17:31:23.901911 [ 2302181 ] {} <Fatal> BaseDaemon: (version 21.11.1.1, build id: 5F2A32AAD3A93848) (from thread 2301993) (query_id: 580a0788-dfe6-4a29-ad02-2ad88aad4b9e) Received signal Segmentation fault (11)
2021.10.11 17:31:23.902262 [ 2302181 ] {} <Fatal> BaseDaemon: Address: 0x17 Access: read. Address not mapped to object.
2021.10.11 17:31:23.902619 [ 2302181 ] {} <Fatal> BaseDaemon: Stack trace: 0x9b9528d 0x150f9445 0x16852b4d 0x16866e19 0x157c0566 0x157be4d2 0x161186f0 0x161164c2 0x16bef8e4 0x16bffd88 0x1a0095a3 0x1a009db3 0x1a18a3f6 0x1a1885d0 0x1a186ca8 0x9a9b9fd 0x7f92c8ea2609 0x7f92c8dc9293
2021.10.11 17:31:23.999541 [ 2302181 ] {} <Fatal> BaseDaemon: 5.1. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/string:1444: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__is_long() const
2021.10.11 17:31:23.999936 [ 2302181 ] {} <Fatal> BaseDaemon: 5.2. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/string:1538: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__get_pointer() const
2021.10.11 17:31:24.000251 [ 2302181 ] {} <Fatal> BaseDaemon: 5.3. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/string:1264: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::data() const
2021.10.11 17:31:24.000478 [ 2302173 ] {} <Trace> AsynchronousMetrics: MemoryTracking: was 2.25 GiB, peak 2.27 GiB, will set to 2.28 GiB (RSS), difference: 21.97 MiB
2021.10.11 17:31:24.000650 [ 2302181 ] {} <Fatal> BaseDaemon: 5.4. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/string:4401: std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::operator()(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&
) const
2021.10.11 17:31:24.001128 [ 2302181 ] {} <Fatal> BaseDaemon: 5.5. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/unordered_map:471: std::__1::__unordered_map_hasher<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<ch
ar>, std::__1::allocator<char> >, unsigned long>, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>::operator()(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char
> > const&) const
2021.10.11 17:31:24.001568 [ 2302181 ] {} <Fatal> BaseDaemon: 5. /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/__hash_table:2420: std::__1::__hash_const_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long>, void*>*> std::__1::__hash_table
<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long>, std::__1::__unordered_map_hasher<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char
> >, unsigned long>, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::__unordered_map_equal<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std
::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long>, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::alloc
ator<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long> > >::find<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const @ 0x9b9528d in /home/jakallet
ti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:24.209149 [ 2302181 ] {} <Fatal> BaseDaemon: 6.1. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/__hash_table:475: std::__1::operator==(std::__1::__hash_const_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned lon
g>, void*>*> const&, std::__1::__hash_const_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long>, void*>*> const&)
2021.10.11 17:31:24.209596 [ 2302181 ] {} <Fatal> BaseDaemon: 6.2. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/__hash_table:479: std::__1::operator!=(std::__1::__hash_const_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned lon
g>, void*>*> const&, std::__1::__hash_const_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long>, void*>*> const&)
2021.10.11 17:31:24.209979 [ 2302181 ] {} <Fatal> BaseDaemon: 6.3. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/unordered_map:904: std::__1::operator!=(std::__1::__hash_map_const_iterator<std::__1::__hash_const_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std:
:__1::allocator<char> >, unsigned long>, void*>*> > const&, std::__1::__hash_map_const_iterator<std::__1::__hash_const_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long>, void*>*> > const&)
2021.10.11 17:31:24.210266 [ 2302181 ] {} <Fatal> BaseDaemon: 6. /home/jakalletti/ClickHouse/ClickHouse/src/Core/Block.cpp:282: DB::Block::has(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const @ 0x150f9445 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:26.093029 [ 2302181 ] {} <Fatal> BaseDaemon: 7. /home/jakalletti/ClickHouse/ClickHouse/src/Storages/MergeTree/MergeTreeData.cpp:140: DB::checkSampleExpression(DB::StorageInMemoryMetadata const&, bool, bool) @ 0x16852b4d in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:27.000267 [ 2302173 ] {} <Trace> AsynchronousMetrics: MemoryTracking: was 2.44 GiB, peak 2.44 GiB, will set to 2.44 GiB (RSS), difference: 4.75 MiB
2021.10.11 17:31:27.176130 [ 2302181 ] {} <Fatal> BaseDaemon: 8.1. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/memory:3100: shared_ptr
2021.10.11 17:31:27.176546 [ 2302181 ] {} <Fatal> BaseDaemon: 8.2. inlined from /home/jakalletti/ClickHouse/ClickHouse/src/Common/MultiVersion.h:43: MultiVersion<DB::MergeTreeSettings>::get() const
2021.10.11 17:31:27.176803 [ 2302181 ] {} <Fatal> BaseDaemon: 8.3. inlined from /home/jakalletti/ClickHouse/ClickHouse/src/Storages/MergeTree/MergeTreeData.h:686: DB::MergeTreeData::getSettings() const
2021.10.11 17:31:27.177092 [ 2302181 ] {} <Fatal> BaseDaemon: 8. /home/jakalletti/ClickHouse/ClickHouse/src/Storages/MergeTree/MergeTreeData.cpp:1788: DB::MergeTreeData::checkAlterIsPossible(DB::AlterCommands const&, std::__1::shared_ptr<DB::Context const>) const @ 0x16866e19 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:27.449336 [ 2302181 ] {} <Fatal> BaseDaemon: 9. /home/jakalletti/ClickHouse/ClickHouse/src/Interpreters/InterpreterAlterQuery.cpp:0: DB::InterpreterAlterQuery::executeToTable(DB::ASTAlterQuery const&) @ 0x157c0566 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:27.707933 [ 2302181 ] {} <Fatal> BaseDaemon: 10. /home/jakalletti/ClickHouse/ClickHouse/src/Interpreters/InterpreterAlterQuery.cpp:53: DB::InterpreterAlterQuery::execute() @ 0x157be4d2 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:28.083085 [ 2302181 ] {} <Fatal> BaseDaemon: 11. /home/jakalletti/ClickHouse/ClickHouse/src/Interpreters/executeQuery.cpp:0: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x161186f0 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:28.487477 [ 2302181 ] {} <Fatal> BaseDaemon: 12. /home/jakalletti/ClickHouse/ClickHouse/src/Interpreters/executeQuery.cpp:950: DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum) @ 0x161164c2 in /home/jakalletti/C
lickHouse/build/programs/clickhouse
2021.10.11 17:31:28.716407 [ 2302181 ] {} <Fatal> BaseDaemon: 13. /home/jakalletti/ClickHouse/ClickHouse/src/Server/TCPHandler.cpp:0: DB::TCPHandler::runImpl() @ 0x16bef8e4 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:29.093784 [ 2302181 ] {} <Fatal> BaseDaemon: 14. /home/jakalletti/ClickHouse/ClickHouse/src/Server/TCPHandler.cpp:1701: DB::TCPHandler::run() @ 0x16bffd88 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:29.119675 [ 2302181 ] {} <Fatal> BaseDaemon: 15. /home/jakalletti/ClickHouse/ClickHouse/contrib/poco/Net/src/TCPServerConnection.cpp:57: Poco::Net::TCPServerConnection::start() @ 0x1a0095a3 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:29.161198 [ 2302181 ] {} <Fatal> BaseDaemon: 16.1. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/memory:1397: std::__1::default_delete<Poco::Net::TCPServerConnection>::operator()(Poco::Net::TCPServerConnection*) const
2021.10.11 17:31:29.161576 [ 2302181 ] {} <Fatal> BaseDaemon: 16.2. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/memory:1658: std::__1::unique_ptr<Poco::Net::TCPServerConnection, std::__1::default_delete<Poco::Net::TCPServerConnection> >::reset(Poco::Net::TCPServerConnection*)
2021.10.11 17:31:29.161858 [ 2302181 ] {} <Fatal> BaseDaemon: 16.3. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/libcxx/include/memory:1612: ~unique_ptr
2021.10.11 17:31:29.162101 [ 2302181 ] {} <Fatal> BaseDaemon: 16. /home/jakalletti/ClickHouse/ClickHouse/contrib/poco/Net/src/TCPServerDispatcher.cpp:116: Poco::Net::TCPServerDispatcher::run() @ 0x1a009db3 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:29.205960 [ 2302181 ] {} <Fatal> BaseDaemon: 17. /home/jakalletti/ClickHouse/ClickHouse/contrib/poco/Foundation/src/ThreadPool.cpp:213: Poco::PooledThread::run() @ 0x1a18a3f6 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:29.252802 [ 2302181 ] {} <Fatal> BaseDaemon: 18. /home/jakalletti/ClickHouse/ClickHouse/contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() @ 0x1a1885d0 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:29.294515 [ 2302181 ] {} <Fatal> BaseDaemon: 19.1. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/poco/Foundation/include/Poco/SharedPtr.h:277: Poco::SharedPtr<Poco::Runnable, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::Runnable> >::get()
2021.10.11 17:31:29.294939 [ 2302181 ] {} <Fatal> BaseDaemon: 19.2. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/poco/Foundation/include/Poco/SharedPtr.h:156: Poco::SharedPtr<Poco::Runnable, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::Runnable> >::assign(Poco::Runnable*)
2021.10.11 17:31:29.295258 [ 2302181 ] {} <Fatal> BaseDaemon: 19.3. inlined from /home/jakalletti/ClickHouse/ClickHouse/contrib/poco/Foundation/include/Poco/SharedPtr.h:208: Poco::SharedPtr<Poco::Runnable, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::Runnable> >::operator=(Poco::Runnable*)
2021.10.11 17:31:29.295526 [ 2302181 ] {} <Fatal> BaseDaemon: 19. /home/jakalletti/ClickHouse/ClickHouse/contrib/poco/Foundation/src/Thread_POSIX.cpp:360: Poco::ThreadImpl::runnableEntry(void*) @ 0x1a186ca8 in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:35.364216 [ 2302181 ] {} <Fatal> BaseDaemon: 20. __tsan_thread_start_func @ 0x9a9b9fd in /home/jakalletti/ClickHouse/build/programs/clickhouse
2021.10.11 17:31:35.364651 [ 2302181 ] {} <Fatal> BaseDaemon: 21. start_thread @ 0x9609 in /usr/lib/x86_64-linux-gnu/libpthread-2.31.so
2021.10.11 17:31:35.364992 [ 2302181 ] {} <Fatal> BaseDaemon: 22. clone @ 0x122293 in /usr/lib/x86_64-linux-gnu/libc-2.31.so
```

Everything the same with 21.9.1.18 

{
    auto lock = lockParts();
    for (auto original_active_part : getDataPartsStateRange(DataPartState::Committed)) 
    {
        if (part_copy->name == original_active_part->name)
        {
            auto active_part_it = data_parts_by_info.find(original_active_part->info);
            if (active_part_it == data_parts_by_info.end())
                throw Exception("Cannot swap part '" + part_copy->name + "', no such active part.", ErrorCodes::NO_SUCH_DATA_PART);
            
            
            original_active_part->force_keep_shared_data = false;
            if (original_active_part->volume->getDisk()->supportZeroCopyReplication() &&
                part_copy->volume->getDisk()->supportZeroCopyReplication() &&
                original_active_part->getUniqueId() == part_copy->getUniqueId())
            {