Merge pull request #16047 from ClickHouse/suggest-destruction-order

Fix destruction order of Suggest #16035
This commit is contained in:
alexey-milovidov 2020-10-29 09:10:23 +03:00 committed by GitHub
commit ae4d66ac9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 12 deletions

View File

@ -218,6 +218,8 @@ private:
QueryFuzzer fuzzer; QueryFuzzer fuzzer;
int query_fuzzer_runs = 0; int query_fuzzer_runs = 0;
std::optional<Suggest> suggest;
/// We will format query_id in interactive mode in various ways, the default is just to print Query id: ... /// We will format query_id in interactive mode in various ways, the default is just to print Query id: ...
std::vector<std::pair<String, String>> query_id_formats; std::vector<std::pair<String, String>> query_id_formats;
@ -577,10 +579,11 @@ private:
if (print_time_to_stderr) if (print_time_to_stderr)
throw Exception("time option could be specified only in non-interactive mode", ErrorCodes::BAD_ARGUMENTS); throw Exception("time option could be specified only in non-interactive mode", ErrorCodes::BAD_ARGUMENTS);
suggest.emplace();
if (server_revision >= Suggest::MIN_SERVER_REVISION && !config().getBool("disable_suggestion", false)) if (server_revision >= Suggest::MIN_SERVER_REVISION && !config().getBool("disable_suggestion", false))
{ {
/// Load suggestion data from the server. /// Load suggestion data from the server.
Suggest::instance().load(connection_parameters, config().getInt("suggestion_limit")); suggest->load(connection_parameters, config().getInt("suggestion_limit"));
} }
/// Load command history if present. /// Load command history if present.
@ -607,7 +610,7 @@ private:
highlight_callback = highlight; highlight_callback = highlight;
ReplxxLineReader lr( ReplxxLineReader lr(
Suggest::instance(), *suggest,
history_file, history_file,
config().has("multiline"), config().has("multiline"),
query_extenders, query_extenders,
@ -615,7 +618,7 @@ private:
highlight_callback); highlight_callback);
#elif defined(USE_READLINE) && USE_READLINE #elif defined(USE_READLINE) && USE_READLINE
ReadlineLineReader lr(Suggest::instance(), history_file, config().has("multiline"), query_extenders, query_delimiters); ReadlineLineReader lr(*suggest, history_file, config().has("multiline"), query_extenders, query_delimiters);
#else #else
LineReader lr(history_file, config().has("multiline"), query_extenders, query_delimiters); LineReader lr(history_file, config().has("multiline"), query_extenders, query_delimiters);
#endif #endif

View File

@ -18,10 +18,11 @@ namespace ErrorCodes
class Suggest : public LineReader::Suggest, boost::noncopyable class Suggest : public LineReader::Suggest, boost::noncopyable
{ {
public: public:
static Suggest & instance() Suggest();
~Suggest()
{ {
static Suggest instance; if (loading_thread.joinable())
return instance; loading_thread.join();
} }
void load(const ConnectionParameters & connection_parameters, size_t suggestion_limit); void load(const ConnectionParameters & connection_parameters, size_t suggestion_limit);
@ -30,12 +31,6 @@ public:
static constexpr int MIN_SERVER_REVISION = 54406; static constexpr int MIN_SERVER_REVISION = 54406;
private: private:
Suggest();
~Suggest()
{
if (loading_thread.joinable())
loading_thread.join();
}
void loadImpl(Connection & connection, const ConnectionTimeouts & timeouts, size_t suggestion_limit); void loadImpl(Connection & connection, const ConnectionTimeouts & timeouts, size_t suggestion_limit);
void fetch(Connection & connection, const ConnectionTimeouts & timeouts, const std::string & query); void fetch(Connection & connection, const ConnectionTimeouts & timeouts, const std::string & query);

View File

@ -0,0 +1,12 @@
#!/usr/bin/expect -f
log_user 1
set timeout 5
match_max 100000
if ![info exists env(CLICKHOUSE_PORT_TCP)] {set env(CLICKHOUSE_PORT_TCP) 9000}
spawn bash -c "clickhouse-client --port $env(CLICKHOUSE_PORT_TCP) && echo $?"
expect ":) "
send -- "\4"
expect eof

View File

@ -0,0 +1 @@
Loaded 10000 queries.

View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CURDIR"/../shell_config.sh
# Create a huge amount of tables, so Suggest will take a time to load
${CLICKHOUSE_CLIENT} -q "SELECT 'CREATE TABLE test_' || hex(randomPrintableASCII(40)) || '(x UInt8) Engine=Memory;' FROM numbers(10000)" --format=TSVRaw | ${CLICKHOUSE_BENCHMARK} -c32 -i 10000 -d 0 2>&1 | grep -F 'Loaded 10000 queries'
function stress()
{
while true; do
"${CURDIR}"/01526_client_start_and_exit.expect | grep -v -P 'ClickHouse client|Connecting|Connected|:\) Bye\.|^\s*$|spawn bash|^0\s*$'
done
}
export CURDIR
export -f stress
for _ in {1..10}; do
timeout 3 bash -c stress &
done
wait