Merge pull request #14320 from bharatnc/ncb/fix-alter-live-lock

fix ALTER LIVE VIEW  [REFRESH] lock issue
This commit is contained in:
alexey-milovidov 2020-09-02 04:52:35 +03:00 committed by GitHub
commit 08ed74732e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 4 deletions

View File

@ -101,7 +101,7 @@ BlockIO InterpreterAlterQuery::execute()
switch (command.type)
{
case LiveViewCommand::REFRESH:
live_view->refresh(context);
live_view->refresh();
break;
}
}

View File

@ -518,9 +518,10 @@ void StorageLiveView::drop()
condition.notify_all();
}
void StorageLiveView::refresh(const Context & context)
void StorageLiveView::refresh()
{
auto table_lock = lockExclusively(context.getCurrentQueryId(), context.getSettingsRef().lock_acquire_timeout);
// Lock is already acquired exclusively from InterperterAlterQuery.cpp InterpreterAlterQuery::execute() method.
// So, reacquiring lock is not needed and will result in an exception.
{
std::lock_guard lock(mutex);
if (getNewBlocks())

View File

@ -122,7 +122,7 @@ public:
void startup() override;
void shutdown() override;
void refresh(const Context & context);
void refresh();
Pipe read(
const Names & column_names,

View File

@ -0,0 +1 @@
ALTER LIVE VIEW live1 REFRESH

View File

@ -0,0 +1,10 @@
CREATE TABLE test0 (
c0 UInt64
) ENGINE = MergeTree() PARTITION BY c0 ORDER BY c0;
SET allow_experimental_live_view=1;
CREATE LIVE VIEW live1 AS SELECT * FROM test0;
select 'ALTER LIVE VIEW live1 REFRESH';
ALTER LIVE VIEW live1 REFRESH; -- success