Merge pull request #10422 from azat/fallback_to_stale_replicas-over-skip_unavailable_shards

Prefer fallback_to_stale_replicas over skip_unavailable_shards
This commit is contained in:
alexey-milovidov 2020-04-22 09:20:25 +03:00 committed by GitHub
commit 7065a8ba9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -274,12 +274,7 @@ PoolWithFailoverBase<TNestedPool>::getMany(
< std::forward_as_tuple(!right.is_up_to_date, right.staleness); < std::forward_as_tuple(!right.is_up_to_date, right.staleness);
}); });
if (up_to_date_count >= min_entries) if (fallback_to_stale_replicas)
{
/// There is enough up-to-date entries.
try_results.resize(up_to_date_count);
}
else if (fallback_to_stale_replicas)
{ {
/// There is not enough up-to-date entries but we are allowed to return stale entries. /// There is not enough up-to-date entries but we are allowed to return stale entries.
/// Gather all up-to-date ones and least-bad stale ones. /// Gather all up-to-date ones and least-bad stale ones.
@ -287,6 +282,11 @@ PoolWithFailoverBase<TNestedPool>::getMany(
size_t size = std::min(try_results.size(), max_entries); size_t size = std::min(try_results.size(), max_entries);
try_results.resize(size); try_results.resize(size);
} }
else if (up_to_date_count >= min_entries)
{
/// There is enough up-to-date entries.
try_results.resize(up_to_date_count);
}
else else
throw DB::Exception( throw DB::Exception(
"Could not find enough connections to up-to-date replicas. Got: " + std::to_string(up_to_date_count) "Could not find enough connections to up-to-date replicas. Got: " + std::to_string(up_to_date_count)

View File

@ -81,6 +81,14 @@ SELECT sum(x) FROM distributed SETTINGS
max_replica_delay_for_distributed_queries=1 max_replica_delay_for_distributed_queries=1
''').strip() == '3' ''').strip() == '3'
# Regression for skip_unavailable_shards in conjunction with skip_unavailable_shards
assert instance_with_dist_table.query('''
SELECT sum(x) FROM distributed SETTINGS
load_balancing='in_order',
skip_unavailable_shards=1,
max_replica_delay_for_distributed_queries=1
''').strip() == '3'
# If we forbid stale replicas, the query must fail. # If we forbid stale replicas, the query must fail.
with pytest.raises(Exception): with pytest.raises(Exception):
print instance_with_dist_table.query(''' print instance_with_dist_table.query('''