mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-13 18:02:24 +00:00
4b3f90870d
This had been done in InterpreterSystemQuery explicitly, with grants checking. Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <Interpreters/Context_fwd.h>
|
|
#include <Interpreters/StorageID.h>
|
|
#include <Storages/IStorage_fwd.h>
|
|
#include <Common/ActionLock.h>
|
|
#include <base/types.h>
|
|
|
|
#include <mutex>
|
|
#include <unordered_map>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
/// Holds ActionLocks for tables
|
|
/// Does not store pointers to tables
|
|
class ActionLocksManager : WithContext
|
|
{
|
|
public:
|
|
explicit ActionLocksManager(ContextPtr context);
|
|
|
|
/// Add new lock for a table if it has not been already added
|
|
void add(const StorageID & table_id, StorageActionBlockType action_type);
|
|
void add(const StoragePtr & table, StorageActionBlockType action_type);
|
|
|
|
/// Removes a lock for a table if it exists
|
|
void remove(const StorageID & table_id, StorageActionBlockType action_type);
|
|
void remove(const StoragePtr & table, StorageActionBlockType action_type);
|
|
|
|
/// Removes all locks of non-existing tables
|
|
void cleanExpired();
|
|
|
|
private:
|
|
using StorageRawPtr = const IStorage *;
|
|
using Locks = std::unordered_map<size_t, ActionLock>;
|
|
using StorageLocks = std::unordered_map<StorageRawPtr, Locks>;
|
|
|
|
mutable std::mutex mutex;
|
|
StorageLocks storage_locks;
|
|
};
|
|
|
|
}
|