Skip to content

Commit

Permalink
Set is_all_data_sent on exceptions too
Browse files Browse the repository at this point in the history
This will avoid clickhouse-test complains about left queries after the
test, like in [1].

  [1]: https://s3.amazonaws.com/clickhouse-test-reports/36258/9646487c093a75dc31e3e818417cfad83580b40f/stateful_tests__memory__actions_.html

Follow-up for: ClickHouse#36649
  • Loading branch information
azat committed Apr 30, 2022
1 parent 65f33a3 commit d82f2ff
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Interpreters/ProcessList.h
Expand Up @@ -102,7 +102,8 @@ class QueryStatus : public WithContext

std::atomic<bool> is_killed { false };

/// All data to the client already had been sent. Including EndOfStream.
/// All data to the client already had been sent.
/// Including EndOfStream or Exception.
std::atomic<bool> is_all_data_sent { false };

void setUserProcessList(ProcessListForUser * user_process_list_);
Expand Down
10 changes: 10 additions & 0 deletions src/QueryPipeline/BlockIO.cpp
Expand Up @@ -47,5 +47,15 @@ BlockIO::~BlockIO()
reset();
}

void BlockIO::setAllDataSent() const
{
/// The following queries does not have process_list_entry:
/// - internal
/// - SHOW PROCESSLIST
if (process_list_entry)
(*process_list_entry)->setAllDataSent();
}


}

3 changes: 3 additions & 0 deletions src/QueryPipeline/BlockIO.h
Expand Up @@ -48,6 +48,9 @@ struct BlockIO
pipeline.reset();
}

/// Set is_all_data_sent in system.processes for this query.
void setAllDataSent() const;

private:
void reset();
};
Expand Down
9 changes: 3 additions & 6 deletions src/Server/TCPHandler.cpp
Expand Up @@ -31,7 +31,6 @@
#include <Interpreters/InternalTextLogsQueue.h>
#include <Interpreters/OpenTelemetrySpanLog.h>
#include <Interpreters/Session.h>
#include <Interpreters/ProcessList.h>
#include <Server/TCPServer.h>
#include <Storages/StorageReplicatedMergeTree.h>
#include <Storages/MergeTree/MergeTreeDataPartUUID.h>
Expand Down Expand Up @@ -1702,6 +1701,8 @@ void TCPHandler::sendTableColumns(const ColumnsDescription & columns)

void TCPHandler::sendException(const Exception & e, bool with_stack_trace)
{
state.io.setAllDataSent();

writeVarUInt(Protocol::Server::Exception, *out);
writeException(e, *out, with_stack_trace);
out->next();
Expand All @@ -1711,11 +1712,7 @@ void TCPHandler::sendException(const Exception & e, bool with_stack_trace)
void TCPHandler::sendEndOfStream()
{
state.sent_all_data = true;
/// The following queries does not have process_list_entry:
/// - internal
/// - SHOW PROCESSLIST
if (state.io.process_list_entry)
(*state.io.process_list_entry)->setAllDataSent();
state.io.setAllDataSent();

writeVarUInt(Protocol::Server::EndOfStream, *out);
out->next();
Expand Down

0 comments on commit d82f2ff

Please sign in to comment.