From 4fe0dda4539aab47836b531adc7ea96f7bb46fb6 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Fri, 25 Oct 2019 21:03:38 +0300 Subject: [PATCH] add cancel test --- dbms/src/Formats/FormatFactory.cpp | 4 +- dbms/src/IO/ReadHelpers.h | 2 +- .../01019_parallel_parsing_cancel.reference | 1 + .../01019_parallel_parsing_cancel.sh | 48 +++++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 dbms/tests/queries/0_stateless/01019_parallel_parsing_cancel.reference create mode 100755 dbms/tests/queries/0_stateless/01019_parallel_parsing_cancel.sh diff --git a/dbms/src/Formats/FormatFactory.cpp b/dbms/src/Formats/FormatFactory.cpp index ca1506b177d..e3a3217010a 100644 --- a/dbms/src/Formats/FormatFactory.cpp +++ b/dbms/src/Formats/FormatFactory.cpp @@ -108,7 +108,7 @@ BlockInputStreamPtr FormatFactory::getInput( const Settings & settings = context.getSettingsRef(); const auto & file_segmentation_engine = getCreators(name).file_segmentation_engine; - if (name != "Values" && settings.input_format_parallel_parsing && file_segmentation_engine) + if (settings.input_format_parallel_parsing && file_segmentation_engine) { const auto & input_getter = getCreators(name).input_processor_creator; if (!input_getter) @@ -125,8 +125,6 @@ BlockInputStreamPtr FormatFactory::getInput( row_input_format_params.timeout_overflow_mode = settings.timeout_overflow_mode; size_t max_threads_to_use = settings.max_threads_for_parallel_parsing; - if (!max_threads_to_use) - max_threads_to_use = settings.max_threads; auto params = ParallelParsingBlockInputStream::InputCreatorParams{sample, context, row_input_format_params, format_settings}; ParallelParsingBlockInputStream::Builder builder{buf, input_getter, params, file_segmentation_engine, max_threads_to_use, settings.min_chunk_size_for_parallel_parsing}; diff --git a/dbms/src/IO/ReadHelpers.h b/dbms/src/IO/ReadHelpers.h index 71a5647c469..341b2438912 100644 --- a/dbms/src/IO/ReadHelpers.h +++ b/dbms/src/IO/ReadHelpers.h @@ -916,6 +916,6 @@ void skipToUnescapedNextLineOrEOF(ReadBuffer & buf); * If there is no pending data in buffer or it was explicitly asked * save current state to memory. */ -bool eofWithSavingBufferState(ReadBuffer & buf, DB::Memory<> & memory, size_t & used_size, char * & begin_pos, bool save_buffer_state = false); +bool eofWithSavingBufferState(ReadBuffer & buf, DB::Memory<> & memory, size_t & used_size, char * & begin_pos, bool force_saving_buffer_state = false); } diff --git a/dbms/tests/queries/0_stateless/01019_parallel_parsing_cancel.reference b/dbms/tests/queries/0_stateless/01019_parallel_parsing_cancel.reference new file mode 100644 index 00000000000..d86bac9de59 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01019_parallel_parsing_cancel.reference @@ -0,0 +1 @@ +OK diff --git a/dbms/tests/queries/0_stateless/01019_parallel_parsing_cancel.sh b/dbms/tests/queries/0_stateless/01019_parallel_parsing_cancel.sh new file mode 100755 index 00000000000..646823e2821 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01019_parallel_parsing_cancel.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. $CURDIR/../shell_config.sh + +$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS a;" +$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS b;" + +$CLICKHOUSE_CLIENT --query="CREATE TABLE a (x UInt64) ENGINE = Memory;" +$CLICKHOUSE_CLIENT --query="CREATE TABLE b (x UInt64) ENGINE = Memory;" + +function thread1() +{ + while true; do + seq 1 11000000 | $CLICKHOUSE_CLIENT --query_id=11 --query="INSERT INTO a(x) FORMAT TSV" + sleep 1 + $CLICKHOUSE_CLIENT --query="kill query where query_id='22'" SYNC + + done +} + +function thread2() +{ + while true; do + seq 1 11000000 | $CLICKHOUSE_CLIENT --query_id=22 --query="INSERT INTO b(x) FORMAT TSV" + sleep 1 + $CLICKHOUSE_CLIENT --query="kill query where query_id='11'" SYNC + done +} + + +# https://stackoverflow.com/questions/9954794/execute-a-shell-function-with-timeout +export -f thread1; +export -f thread2; + +TIMEOUT=20 + +timeout $TIMEOUT bash -c thread1 2>&1 > /dev/null & +timeout $TIMEOUT bash -c thread2 2>&1 > /dev/null & + +wait + +echo OK + +$CLICKHOUSE_CLIENT --query "DROP TABLE a" +$CLICKHOUSE_CLIENT --query "DROP TABLE b" + +