StoragesInfoStreamBase refactoring, additional test, style fix

This commit is contained in:
Yakov Olkhovskiy 2023-12-23 03:47:43 +00:00
parent 2ad9c7d96d
commit d7fe86279f
6 changed files with 35 additions and 16 deletions

View File

@ -13,8 +13,6 @@ namespace DB
StoragesDroppedInfoStream::StoragesDroppedInfoStream(const SelectQueryInfo & query_info, ContextPtr context)
: StoragesInfoStreamBase(context)
{
needsLock = false;
/// Will apply WHERE to subset of columns and then add more columns.
/// This is kind of complicated, but we use WHERE to do less work.

View File

@ -10,6 +10,12 @@ class StoragesDroppedInfoStream : public StoragesInfoStreamBase
{
public:
StoragesDroppedInfoStream(const SelectQueryInfo & query_info, ContextPtr context);
protected:
bool tryLockTable(StoragesInfo &) override
{
// we don't need to lock a dropped table
return true;
}
};
class Context;

View File

@ -1,4 +1,4 @@
#include "Common/SipHash.h"
#include <Common/SipHash.h>
#include <Storages/ColumnsDescription.h>
#include <Storages/System/StorageSystemPartsBase.h>
#include <Common/escapeForFileName.h>

View File

@ -41,6 +41,9 @@ public:
: query_id(context->getCurrentQueryId()), settings(context->getSettingsRef()), next_row(0), rows(0)
{}
StoragesInfoStreamBase(const StoragesInfoStreamBase&) = default;
virtual ~StoragesInfoStreamBase() = default;
StoragesInfo next()
{
while (next_row < rows)
@ -68,16 +71,9 @@ public:
info.storage = storages.at(storage_uuid);
if (needsLock)
{
/// For table not to be dropped and set of columns to remain constant.
info.table_lock = info.storage->tryLockForShare(query_id, settings.lock_acquire_timeout);
if (info.table_lock == nullptr)
{
// Table was dropped while acquiring the lock, skipping table
continue;
}
}
/// For table not to be dropped and set of columns to remain constant.
if (!tryLockTable(info))
continue;
info.engine = info.storage->getName();
@ -90,7 +86,13 @@ public:
return {};
}
protected:
virtual bool tryLockTable(StoragesInfo & info)
{
info.table_lock = info.storage->tryLockForShare(query_id, settings.lock_acquire_timeout);
// nullptr means table was dropped while acquiring the lock
return info.table_lock != nullptr;
}
protected:
String query_id;
Settings settings;
@ -106,8 +108,6 @@ protected:
using StoragesMap = std::unordered_map<UUID, StoragePtr>;
StoragesMap storages;
bool needsLock = true;
};

View File

@ -0,0 +1,2 @@
default 02947_table_1 all_1_1_0
default 02947_table_2 all_1_1_0

View File

@ -0,0 +1,13 @@
DROP TABLE IF EXISTS 02947_table_1;
DROP TABLE IF EXISTS 02947_table_2;
CREATE TABLE 02947_table_1 (id Int32) Engine=MergeTree() ORDER BY id;
CREATE TABLE 02947_table_2 (id Int32) Engine=MergeTree() ORDER BY id;
INSERT INTO 02947_table_1 VALUES (1),(2);
INSERT INTO 02947_table_2 VALUES (3),(4);
SELECT database, table, name FROM system.parts WHERE database = currentDatabase() AND startsWith(table, '02947_table_');
DROP TABLE 02947_table_1;
DROP TABLE 02947_table_2;