23 #include <type_traits>
32 class TableSchemaLockMgr;
33 class TableDataLockMgr;
34 class InsertDataLockMgr;
40 MutexTracker(std::unique_ptr<heavyai::DistributedSharedMutex> dmutex)
56 std::unique_ptr<heavyai::DistributedSharedMutex>
dmutex_;
62 template <
typename LOCK>
64 static_assert(std::is_same_v<LOCK, ReadLockBase> ||
65 std::is_same_v<LOCK, WriteLockBase>);
72 other.mutex_ =
nullptr;
99 template <
typename T,
typename LOCK>
113 const std::string& tableName);
115 template <
typename LOCK_TYPE,
typename LOCK_MGR_TYPE>
118 return LOCK_TYPE(table_lock_mgr.getTableMutex(chunk_key));
121 template <
typename LOCK_TYPE,
typename LOCK_MGR_TYPE>
123 const std::string& table_name) {
127 return LOCK_TYPE(table_lock_mgr.getTableMutex(chunk_key));
133 class TableLockMgrImpl {
134 static_assert(std::is_same_v<T, TableSchemaLockMgr> ||
135 std::is_same_v<T, TableDataLockMgr> ||
136 std::is_same_v<T, InsertDataLockMgr>);
148 const std::string& table_name);
153 const std::string& table_name);
168 const std::string& table_name);
171 const std::string& table_name);
174 const std::string& table_name);
177 template <
typename T>
178 std::ostream& operator<<(std::ostream& os, const TableLockMgrImpl<T>& lock_mgr) {
179 for (
const auto& table_key : lock_mgr.getLockedTables()) {
180 for (
const auto& k : table_key) {
static MutexTracker * getMutexTracker(const Catalog_Namespace::Catalog &catalog, const std::string &table_name)
std::vector< int > ChunkKey
static int32_t validateAndGetExistingTableId(const Catalog_Namespace::Catalog &catalog, const std::string &table_name)
virtual std::unique_ptr< heavyai::DistributedSharedMutex > getClusterTableMutex(const ChunkKey &table_key) const
class for a per-database catalog. also includes metadata for the current database and the current use...
virtual bool try_lock_shared()
heavyai::unique_lock< MutexTracker > WriteLockBase
virtual ~AbstractLockContainer()
std::set< ChunkKey > getLockedTables() const
LOCK_TYPE getLockForKeyImpl(const ChunkKey &chunk_key)
T operator()() const final
static void validateExistingTable(const Catalog_Namespace::Catalog &catalog, const std::string &table_name)
heavyai::shared_mutex MutexTypeBase
std::shared_lock< T > shared_lock
This file contains the class specification and related data structures for Catalog.
TrackedRefLock< WriteLockBase > WriteLock
TrackedRefLock< ReadLockBase > ReadLock
virtual T operator()() const =0
std::map< ChunkKey, std::unique_ptr< MutexTracker > > table_mutex_map_
heavyai::shared_lock< MutexTracker > ReadLockBase
std::unique_lock< T > unique_lock
MutexTracker(std::unique_ptr< heavyai::DistributedSharedMutex > dmutex)
ChunkKey chunk_key_for_table(const Catalog_Namespace::Catalog &cat, const std::string &tableName)
TrackedRefLock(MutexTracker *m)
LOCK_TYPE getLockForTableImpl(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
virtual MutexTracker * getTableMutex(const ChunkKey &table_key)
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
virtual void unlock_shared()
virtual void lock_shared()
TrackedRefLock(TrackedRefLock &&other)
std::atomic< size_t > ref_count_
std::shared_timed_mutex shared_mutex
TrackedRefLock & operator=(const TrackedRefLock &)=delete
static MutexTracker * checkPointer(MutexTracker *m)
static ReadLock getReadLockForTable(Catalog_Namespace::Catalog &cat, const std::string &table_name)
virtual bool isAcquired() const
LockContainerImpl(T obj, LOCK &&lock)
virtual ~TableLockMgrImpl()=default