Skip to content

Commit

Permalink
Fixup: messages and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbaden authored and andrewseidl committed May 5, 2020
1 parent 59e510e commit 2e35314
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
12 changes: 6 additions & 6 deletions LockMgr/LockMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class TableSchemaLockContainer<ReadLock>
static auto acquireTableDescriptor(const Catalog_Namespace::Catalog& cat,
const std::string& table_name,
const bool populate_fragmenter = true) {
VLOG(1) << "Table Schema Read Lock acquired for table: " << table_name;
VLOG(1) << "Acquiring Table Schema Read Lock for table: " << table_name;
return TableSchemaLockContainer<ReadLock>(
cat.getMetadataForTable(table_name, populate_fragmenter),
TableSchemaLockMgr::getReadLockForTable(cat, table_name));
Expand All @@ -123,7 +123,7 @@ class TableSchemaLockContainer<ReadLock>
throw std::runtime_error("Table/View ID " + std::to_string(table_id) +
" does not exist.");
}
VLOG(1) << "Table Schema Read Lock acquired for table: " << td->tableName;
VLOG(1) << "Acquiring Table Schema Read Lock for table: " << td->tableName;
return TableSchemaLockContainer<ReadLock>(
td, TableSchemaLockMgr::getReadLockForTable(cat, td->tableName));
}
Expand All @@ -142,7 +142,7 @@ class TableSchemaLockContainer<WriteLock>
static auto acquireTableDescriptor(const Catalog_Namespace::Catalog& cat,
const std::string& table_name,
const bool populate_fragmenter = true) {
VLOG(1) << "Table Schema Write Lock acquired for table: " << table_name;
VLOG(1) << "Acquiring Table Schema Write Lock for table: " << table_name;
return TableSchemaLockContainer<WriteLock>(
cat.getMetadataForTable(table_name, populate_fragmenter),
TableSchemaLockMgr::getWriteLockForTable(cat, table_name));
Expand All @@ -155,7 +155,7 @@ class TableSchemaLockContainer<WriteLock>
throw std::runtime_error("Table/View ID " + std::to_string(table_id) +
" does not exist.");
}
VLOG(1) << "Table Schema Write Lock acquired for table: " << td->tableName;
VLOG(1) << "Acquiring Table Schema Write Lock for table: " << td->tableName;
return TableSchemaLockContainer<WriteLock>(
td, TableSchemaLockMgr::getWriteLockForTable(cat, td->tableName));
}
Expand Down Expand Up @@ -185,7 +185,7 @@ class TableDataLockContainer<WriteLock>
static auto acquire(const int db_id, const TableDescriptor* td) {
CHECK(td);
ChunkKey chunk_key{db_id, td->tableId};
VLOG(1) << "Table Data Write Lock acquired for table: " << td->tableName;
VLOG(1) << "Acquiring Table Data Write Lock for table: " << td->tableName;
return TableDataLockContainer<WriteLock>(
td, TableDataLockMgr::getWriteLockForTable(chunk_key));
}
Expand All @@ -204,7 +204,7 @@ class TableDataLockContainer<ReadLock>
static auto acquire(const int db_id, const TableDescriptor* td) {
CHECK(td);
ChunkKey chunk_key{db_id, td->tableId};
VLOG(1) << "Table Data Read Lock acquired for table: " << td->tableName;
VLOG(1) << "Acquiring Table Data Read Lock for table: " << td->tableName;
return TableDataLockContainer<ReadLock>(
td, TableDataLockMgr::getReadLockForTable(chunk_key));
}
Expand Down
21 changes: 11 additions & 10 deletions LockMgr/LockMgrImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ using MutexTypeBase = mapd_shared_mutex;

using WriteLockBase = mapd_unique_lock<MutexTypeBase>;
using ReadLockBase = mapd_shared_lock<MutexTypeBase>;
class TrackedRefMutex {

class MutexTracker {
public:
TrackedRefMutex() : ref_count_(0u) {}
MutexTracker() : ref_count_(0u) {}

MutexTypeBase& lock() {
MutexTypeBase& acquire() {
ref_count_.fetch_add(1u);
return mutex_;
}
Expand All @@ -46,7 +47,7 @@ class TrackedRefMutex {
CHECK_GE(stored_ref_count, size_t(1));
}

bool isLocked() const { return ref_count_.load() > 0; }
bool isAcquired() const { return ref_count_.load() > 0; }

private:
std::atomic<size_t> ref_count_;
Expand All @@ -56,12 +57,12 @@ class TrackedRefMutex {
template <typename LOCK>
class TrackedRefLock {
public:
TrackedRefLock(TrackedRefMutex* m) : mutex_(m), lock_(mutex_->lock()) { CHECK(mutex_); }
TrackedRefLock(MutexTracker* m) : mutex_(m), lock_(mutex_->acquire()) { CHECK(mutex_); }

~TrackedRefLock() {
if (mutex_) {
// This call only decrements the ref count. The actual release is done once the
// mutex is destroyed.
// This call only decrements the ref count. The actual unlock is done once the
// lock is destroyed.
mutex_->release();
}
}
Expand All @@ -75,11 +76,11 @@ class TrackedRefLock {
TrackedRefLock& operator=(const TrackedRefLock&) = delete;

private:
TrackedRefMutex* mutex_;
MutexTracker* mutex_;
LOCK lock_;
}; // namespace lockmgr

using MutexType = TrackedRefMutex;
using MutexType = MutexTracker;

using WriteLock = TrackedRefLock<WriteLockBase>;
using ReadLock = TrackedRefLock<ReadLockBase>;
Expand Down Expand Up @@ -143,7 +144,7 @@ class TableLockMgrImpl {
std::set<ChunkKey> ret;
std::lock_guard<std::mutex> access_map_lock(map_mutex_);
for (const auto& kv : table_mutex_map_) {
if (kv.second->isLocked()) {
if (kv.second->isAcquired()) {
ret.insert(kv.first);
}
}
Expand Down

0 comments on commit 2e35314

Please sign in to comment.