fix unexpected outdated parts

This commit is contained in:
Alexander Tokmakov 2023-11-22 20:29:57 +01:00
parent 9f1a9826af
commit d9eb68ba35
2 changed files with 10 additions and 14 deletions

View File

@ -1432,6 +1432,7 @@ bool StorageReplicatedMergeTree::checkPartsImpl(bool skip_sanity_checks)
NameSet expected_parts(expected_parts_vec.begin(), expected_parts_vec.end());
/// There are no PreActive parts at startup.
bool incomplete_list_of_outdated_parts = !outdated_data_parts_loading_finished;
auto parts = getDataParts({MergeTreeDataPartState::Active, MergeTreeDataPartState::Outdated});
/** Local parts that are not in ZK.
@ -1469,6 +1470,11 @@ bool StorageReplicatedMergeTree::checkPartsImpl(bool skip_sanity_checks)
if (part->rows_count || part->getState() != MergeTreeDataPartState::Active || expected_parts.contains(part->name))
continue;
if (incomplete_list_of_outdated_parts)
{
LOG_INFO(log, "Outdated parts are not loaded yet, but we may need them to handle dropped parts. Need retry.");
return false;
}
set_of_empty_unexpected_parts.add(part->name);
}
if (auto empty_count = set_of_empty_unexpected_parts.size())
@ -1520,15 +1526,12 @@ bool StorageReplicatedMergeTree::checkPartsImpl(bool skip_sanity_checks)
/// We have uncovered unexpected parts, and we are not sure if we can restore them or not.
/// So we have to exit, load all Outdated parts, and check again.
{
std::lock_guard lock(outdated_data_parts_mutex);
if (!outdated_data_parts_loading_finished)
if (incomplete_list_of_outdated_parts)
{
LOG_INFO(log, "Outdated parts are not loaded yet, but we may need them to check if unexpected parts can be recovered. "
"Need retry.");
return false;
}
}
/// Part is unexpected and we don't have covering part: it's suspicious
uncovered_unexpected_parts.insert(part->name);

View File

@ -27,13 +27,6 @@ system sync replica rmt1;
select *, _table from merge(currentDatabase(), '') order by _table, (*,);
select 0;
drop table rmt sync;
drop table rmt1 sync;
create table rmt (n int) engine=ReplicatedMergeTree('/test/02468/{database}', '1') order by tuple() partition by n % 2 settings replicated_max_ratio_of_wrong_parts=0, max_suspicious_broken_parts=0, max_suspicious_broken_parts_bytes=0;
create table rmt1 (n int) engine=ReplicatedMergeTree('/test/02468/{database}', '2') order by tuple() partition by n % 2 settings replicated_max_ratio_of_wrong_parts=0, max_suspicious_broken_parts=0, max_suspicious_broken_parts_bytes=0;
insert into rmt values (1);
insert into rmt1 values (2);
create table rmt2 (n int) engine=ReplicatedMergeTree('/test/02468/{database}2', '1') order by tuple() partition by n % 2 settings replicated_max_ratio_of_wrong_parts=0, max_suspicious_broken_parts=0, max_suspicious_broken_parts_bytes=0;
system stop cleanup rmt;