mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Fix
This commit is contained in:
parent
04e159b42c
commit
dabab85c60
@ -417,7 +417,13 @@ try
|
||||
{
|
||||
UseSSL use_ssl;
|
||||
MainThreadStatus::getInstance();
|
||||
signal(SIGINT, signalHandler);
|
||||
|
||||
struct sigaction new_act;
|
||||
struct sigaction old_act;
|
||||
new_act.sa_handler = interruptSignalHandler;
|
||||
sigemptyset(&new_act.sa_mask);
|
||||
new_act.sa_flags = 0;
|
||||
sigaction(SIGINT, &new_act, &old_act);
|
||||
|
||||
std::cout << std::fixed << std::setprecision(3);
|
||||
std::cerr << std::fixed << std::setprecision(3);
|
||||
|
@ -414,7 +414,13 @@ try
|
||||
{
|
||||
UseSSL use_ssl;
|
||||
ThreadStatus thread_status;
|
||||
signal(SIGINT, signalHandler);
|
||||
|
||||
struct sigaction new_act;
|
||||
struct sigaction old_act;
|
||||
new_act.sa_handler = interruptSignalHandler;
|
||||
sigemptyset(&new_act.sa_mask);
|
||||
new_act.sa_flags = 0;
|
||||
sigaction(SIGINT, &new_act, &old_act);
|
||||
|
||||
std::cout << std::fixed << std::setprecision(3);
|
||||
std::cerr << std::fixed << std::setprecision(3);
|
||||
|
@ -74,18 +74,13 @@ namespace ErrorCodes
|
||||
namespace DB
|
||||
{
|
||||
|
||||
volatile sig_atomic_t need_cancel_query = false;
|
||||
volatile sig_atomic_t query_cancelled = true;
|
||||
std::atomic<bool> catch_signal = false;
|
||||
|
||||
/// This signal handler is set only for sigint.
|
||||
void signalHandler(int signum)
|
||||
void interruptSignalHandler(int signum)
|
||||
{
|
||||
if (query_cancelled)
|
||||
return;
|
||||
/// Exit if it is a second sigint and query is not cancelled yet.
|
||||
if (need_cancel_query && !query_cancelled)
|
||||
exit(signum);
|
||||
need_cancel_query = true;
|
||||
if (!catch_signal.exchange(false))
|
||||
_exit(signum);
|
||||
}
|
||||
|
||||
|
||||
@ -469,7 +464,8 @@ void ClientBase::processOrdinaryQuery(const String & query_to_execute, ASTPtr pa
|
||||
/// Also checks if query execution should be cancelled.
|
||||
void ClientBase::receiveResult(ASTPtr parsed_query)
|
||||
{
|
||||
query_cancelled = false;
|
||||
bool cancelled = false;
|
||||
catch_signal.store(true);
|
||||
|
||||
// TODO: get the poll_interval from commandline.
|
||||
const auto receive_timeout = connection_parameters.timeouts.receive_timeout;
|
||||
@ -487,21 +483,21 @@ void ClientBase::receiveResult(ASTPtr parsed_query)
|
||||
/// Has the Ctrl+C been pressed and thus the query should be cancelled?
|
||||
/// If this is the case, inform the server about it and receive the remaining packets
|
||||
/// to avoid losing sync.
|
||||
if (!query_cancelled)
|
||||
if (!cancelled)
|
||||
{
|
||||
auto cancel_query = [&] {
|
||||
connection->sendCancel();
|
||||
query_cancelled = true;
|
||||
if (is_interactive)
|
||||
{
|
||||
progress_indication.clearProgressOutput();
|
||||
std::cout << "Cancelling query." << std::endl;
|
||||
}
|
||||
|
||||
need_cancel_query = false;
|
||||
cancelled = true;
|
||||
catch_signal.store(true);
|
||||
};
|
||||
|
||||
if (need_cancel_query)
|
||||
/// handler received sigint
|
||||
if (!catch_signal.load())
|
||||
{
|
||||
cancel_query();
|
||||
}
|
||||
@ -526,15 +522,14 @@ void ClientBase::receiveResult(ASTPtr parsed_query)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!receiveAndProcessPacket(parsed_query, query_cancelled))
|
||||
if (!receiveAndProcessPacket(parsed_query, cancelled))
|
||||
break;
|
||||
}
|
||||
|
||||
if (query_cancelled && is_interactive)
|
||||
if (cancelled && is_interactive)
|
||||
std::cout << "Query was cancelled." << std::endl;
|
||||
|
||||
/// Mark that there is no query in execution.
|
||||
query_cancelled = true;
|
||||
catch_signal.store(false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ enum MultiQueryProcessingStage
|
||||
PARSING_FAILED,
|
||||
};
|
||||
|
||||
void signalHandler(int signum);
|
||||
void interruptSignalHandler(int signum);
|
||||
|
||||
class ClientBase : public Poco::Util::Application
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user