Fix benign race condition during shutdown

This commit is contained in:
alesapin 2020-06-08 19:34:42 +03:00 committed by Alexey Milovidov
parent bdeafe830b
commit de59629b38
2 changed files with 7 additions and 2 deletions

View File

@ -1865,7 +1865,7 @@ void MergeTreeData::removePartsFromWorkingSet(const MergeTreeData::DataPartsVect
part->remove_time.store(remove_time, std::memory_order_relaxed);
if (part->state != IMergeTreeDataPart::State::Outdated)
modifyPartState(part,IMergeTreeDataPart::State::Outdated);
modifyPartState(part, IMergeTreeDataPart::State::Outdated);
}
}

View File

@ -2961,7 +2961,6 @@ void StorageReplicatedMergeTree::startup()
void StorageReplicatedMergeTree::shutdown()
{
clearOldPartsFromFilesystem(true);
/// Cancel fetches, merges and mutations to force the queue_task to finish ASAP.
fetcher.blocker.cancelForever();
merger_mutator.merges_blocker.cancelForever();
@ -2997,6 +2996,12 @@ void StorageReplicatedMergeTree::shutdown()
std::unique_lock lock(data_parts_exchange_endpoint->rwlock);
}
data_parts_exchange_endpoint.reset();
/// We clear all parts after stopping all background operations. It's
/// important, because background operations can produce temporary parts
/// which will remove themselfs in their descrutors. If so, we may have race
/// condition between our remove call and background process.
clearOldPartsFromFilesystem(true);
}