Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix skip_unavailable_shards in case of unavailable hosts #48771

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/QueryPipeline/RemoteQueryExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
azat marked this conversation as resolved.
Show resolved Hide resolved

return;
}

/// Query cannot be canceled in the middle of the send query,
/// since there are multiple packets:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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