Merge pull request #39477 from azat/fix-mv-drop-race

Fix LOGICAL_ERROR on race between DROP and INSERT with materialized views
This commit is contained in:
Nikolai Kochetov 2022-08-05 17:19:45 +02:00 committed by GitHub
commit 0005c37acc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View File

@ -410,6 +410,14 @@ Chain buildPushingToViewsChain(
if (result_chain.empty())
result_chain.addSink(std::make_shared<NullSinkToStorage>(storage_header));
if (result_chain.getOutputHeader().columns() != 0)
{
/// Convert result header to empty block.
auto dag = ActionsDAG::makeConvertingActions(result_chain.getOutputHeader().getColumnsWithTypeAndName(), {}, ActionsDAG::MatchColumnsMode::Name);
auto actions = std::make_shared<ExpressionActions>(std::move(dag));
result_chain.addSink(std::make_shared<ConvertingTransform>(result_chain.getOutputHeader(), std::move(actions)));
}
return result_chain;
}

View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Tags: long, race
# Regression test for INSERT into table with MV attached,
# to avoid possible errors if some table will disappears,
# in case of multiple streams was used (i.e. max_insert_threads>1)
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
$CLICKHOUSE_CLIENT -nm -q "
DROP TABLE IF EXISTS null;
CREATE TABLE null (key Int) ENGINE = Null;
DROP TABLE IF EXISTS mv;
CREATE MATERIALIZED VIEW mv ENGINE = Null() AS SELECT * FROM null;
"
$CLICKHOUSE_CLIENT -q "INSERT INTO null SELECT * FROM numbers_mt(1000) settings max_threads=1000, max_insert_threads=1000, max_block_size=1" |& {
# To avoid handling stacktrace here, get only first line (-m1)
# this should be OK, since you cannot have multiple exceptions from the client anyway.
grep -m1 -F 'DB::Exception:' | grep -F -v -e 'UNKNOWN_TABLE'
} &
sleep 0.05
$CLICKHOUSE_CLIENT -q "DETACH TABLE mv"
wait