Merge pull request #48771 from azat/fix-skip_unavailable_shards

Fix skip_unavailable_shards in case of unavailable hosts
This commit is contained in:
Alexey Milovidov 2023-04-15 23:55:41 +03:00 committed by GitHub
commit a2793fcea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 9 deletions

View File

@ -216,7 +216,15 @@ void RemoteQueryExecutor::sendQuery(ClientInfo::QueryKind query_kind)
const auto & settings = context->getSettingsRef();
if (settings.skip_unavailable_shards && 0 == connections->size())
{
/// To avoid sending the query again in the read(), we need to update the following flags:
std::lock_guard guard(was_cancelled_mutex);
was_cancelled = true;
finished = true;
sent_query = true;
return;
}
/// Query cannot be canceled in the middle of the send query,
/// since there are multiple packets:

View File

@ -1 +1,10 @@
Connection failed at try №1,
255.255.255.255
HedgedConnectionsFactory: Connection failed at try №1
executeQuery: Code: 519.: All attempts to get table structure failed.
127.2,255.255.255.255
0
HedgedConnectionsFactory: Connection failed at try №1
255.255.255.255,127.2
0
HedgedConnectionsFactory: Connection failed at try №1
HedgedConnectionsFactory: Connection failed at try №1

View File

@ -1,14 +1,36 @@
#!/usr/bin/env bash
# Tags: shard
CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL=trace
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
opts=(
"--connections_with_failover_max_tries=1"
"--skip_unavailable_shards=1"
)
$CLICKHOUSE_CLIENT --query "select * from remote('255.255.255.255', system.one)" "${opts[@]}" 2>&1 | grep -o 'Connection failed at try.*,'
stderr="$(mktemp "$CURDIR/clickhouse.stderr.XXXXXX.log")"
trap 'rm -f "$stderr"' EXIT
function process_log_safe()
{
grep "^\\[" "$@" | sed -e 's/.*> //' -e 's/, reason.*//' -e 's/ DB::NetException//' -e 's/ Log: //'
}
function execute_query()
{
local hosts=$1 && shift
local opts=(
"--connections_with_failover_max_tries=1"
"--skip_unavailable_shards=1"
)
echo "$hosts"
# NOTE: we cannot use process substition here for simplicity because they are async, i.e.:
#
# clickhouse-client 2> >(wc -l)
#
# May dump output of "wc -l" after some other programs.
$CLICKHOUSE_CLIENT "${opts[@]}" --query "select * from remote('$hosts', system.one)" 2>"$stderr"
process_log_safe "$stderr"
}
execute_query 255.255.255.255
execute_query 127.2,255.255.255.255
# This will print two errors because there will be two attempts for 255.255.255.255:
# - first for obtaining structure of the table
# - second for the query
execute_query 255.255.255.255,127.2