Skip to content

Commit

Permalink
[docdb] Add Clang thread safety annotations to catalog_entity_info (#…
Browse files Browse the repository at this point in the history
…8186)

Adds thread safety annotations to catalog_entity_info.h
Modifies catalog_entity_info.cc to use SharedLock instead of std::shared_lock.
Adds jackstenglein to CONTRIBUTORS.md.
  • Loading branch information
jackstenglein committed May 21, 2021
1 parent 1320d05 commit 10214bd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Expand Up @@ -136,5 +136,6 @@ This is a list of people who have contributed code to the [YugabyteDB](https://g
* [fitcs01](https://github.com/fitcs01)
* [mrajcevic01](https://github.com/mrajcevic01)
* [YintongMa](https://github.com/YintongMa)
* [jackstenglein](https://github.com/jackstenglein)
* [BozhiYou](https://github.com/bozhiyou)
* [pkj415](https://github.com/pkj415)
34 changes: 17 additions & 17 deletions src/yb/master/catalog_entity_info.cc
Expand Up @@ -375,7 +375,7 @@ void TableInfo::GetTabletsInRange(const GetTableLocationsRequestPB* req, TabletI
void TableInfo::GetTabletsInRange(
const std::string& partition_key_start, const std::string& partition_key_end,
TabletInfos* ret, const int32_t max_returned_locations) const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);

TableInfo::TabletInfoMap::const_iterator it, it_end;
if (partition_key_start.empty()) {
Expand All @@ -400,7 +400,7 @@ void TableInfo::GetTabletsInRange(
}

bool TableInfo::IsAlterInProgress(uint32_t version) const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
for (const TableInfo::TabletInfoMap::value_type& e : tablet_map_) {
if (e.second->reported_schema_version(table_id_) < version) {
VLOG(3) << "Table " << table_id_ << " ALTER in progress due to tablet "
Expand All @@ -413,12 +413,12 @@ bool TableInfo::IsAlterInProgress(uint32_t version) const {
}

bool TableInfo::HasTablets() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
return !tablet_map_.empty();
}

bool TableInfo::AreAllTabletsDeletedOrHidden() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
for (const auto& e : tablet_map_) {
auto tablet_lock = e.second->LockForRead();
if (!tablet_lock->is_deleted() && !tablet_lock->is_hidden()) {
Expand All @@ -429,7 +429,7 @@ bool TableInfo::AreAllTabletsDeletedOrHidden() const {
}

bool TableInfo::AreAllTabletsDeleted() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
for (const auto& e : tablet_map_) {
if (!e.second->LockForRead()->is_deleted()) {
return false;
Expand All @@ -439,7 +439,7 @@ bool TableInfo::AreAllTabletsDeleted() const {
}

bool TableInfo::IsCreateInProgress() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
for (const TableInfo::TabletInfoMap::value_type& e : tablet_map_) {
if (!e.second->LockForRead()->is_running()) {
return true;
Expand Down Expand Up @@ -475,29 +475,29 @@ void TableInfo::SetCreateTableErrorStatus(const Status& status) {
}

Status TableInfo::GetCreateTableErrorStatus() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
return create_table_error_;
}

std::size_t TableInfo::NumLBTasks() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
return std::count_if(pending_tasks_.begin(),
pending_tasks_.end(),
[](auto task) { return task->started_by_lb(); });
}

std::size_t TableInfo::NumTasks() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
return pending_tasks_.size();
}

bool TableInfo::HasTasks() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
return !pending_tasks_.empty();
}

bool TableInfo::HasTasks(MonitoredTask::Type type) const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
for (auto task : pending_tasks_) {
if (task->type() == type) {
return true;
Expand Down Expand Up @@ -567,7 +567,7 @@ void TableInfo::WaitTasksCompletion() {
while (1) {
std::vector<std::shared_ptr<MonitoredTask>> waiting_on_for_debug;
{
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
if (pending_tasks_.empty()) {
break;
} else if (VLOG_IS_ON(1)) {
Expand All @@ -584,25 +584,25 @@ void TableInfo::WaitTasksCompletion() {
}

std::unordered_set<std::shared_ptr<MonitoredTask>> TableInfo::GetTasks() {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
return pending_tasks_;
}

std::size_t TableInfo::NumTablets() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
return tablet_map_.size();
}

void TableInfo::GetAllTablets(TabletInfos *ret) const {
ret->clear();
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
for (const TableInfo::TabletInfoMap::value_type& e : tablet_map_) {
ret->push_back(make_scoped_refptr(e.second));
}
}

TabletInfoPtr TableInfo::GetColocatedTablet() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
if (colocated()) {
for (const TableInfo::TabletInfoMap::value_type& e : tablet_map_) {
return make_scoped_refptr(e.second);
Expand All @@ -627,7 +627,7 @@ bool TableInfo::UsesTablespacesForPlacement() const {
}

TablespaceId TableInfo::TablespaceIdForTableCreation() const {
shared_lock<decltype(lock_)> l(lock_);
SharedLock<decltype(lock_)> l(lock_);
return tablespace_id_for_table_creation_;
}

Expand Down
20 changes: 10 additions & 10 deletions src/yb/master/catalog_entity_info.h
Expand Up @@ -263,7 +263,7 @@ class TabletInfo : public RefCountedThreadSafe<TabletInfo>,
friend class LeaderChangeReporter;

~TabletInfo();
TSDescriptor* GetLeaderUnlocked() const;
TSDescriptor* GetLeaderUnlocked() const REQUIRES_SHARED(lock_);

const TabletId tablet_id_;
const scoped_refptr<TableInfo> table_;
Expand All @@ -274,16 +274,16 @@ class TabletInfo : public RefCountedThreadSafe<TabletInfo>,

// The last time the replica locations were updated.
// Also set when the Master first attempts to create the tablet.
MonoTime last_update_time_;
MonoTime last_update_time_ GUARDED_BY(lock_);

// The locations in the latest Raft config where this tablet has been
// reported. The map is keyed by tablet server UUID.
std::shared_ptr<ReplicaMap> replica_locations_;
std::shared_ptr<ReplicaMap> replica_locations_ GUARDED_BY(lock_);

// Reported schema version (in-memory only).
std::unordered_map<TableId, uint32_t> reported_schema_version_ = {};
std::unordered_map<TableId, uint32_t> reported_schema_version_ GUARDED_BY(lock_) = {};

LeaderStepDownFailureTimes leader_stepdown_failure_times_;
LeaderStepDownFailureTimes leader_stepdown_failure_times_ GUARDED_BY(lock_);

std::atomic<bool> initiated_election_{false};

Expand Down Expand Up @@ -508,7 +508,7 @@ class TableInfo : public RefCountedThreadSafe<TableInfo>,
friend class RefCountedThreadSafe<TableInfo>;
~TableInfo();

void AddTabletUnlocked(TabletInfo* tablet);
void AddTabletUnlocked(TabletInfo* tablet) REQUIRES_SHARED(lock_);
void AbortTasksAndCloseIfRequested(bool close);

const TableId table_id_;
Expand All @@ -518,7 +518,7 @@ class TableInfo : public RefCountedThreadSafe<TableInfo>,
// Sorted index of tablet start partition-keys to TabletInfo.
// The TabletInfo objects are owned by the CatalogManager.
typedef std::map<std::string, TabletInfo *> TabletInfoMap;
TabletInfoMap tablet_map_;
TabletInfoMap tablet_map_ GUARDED_BY(lock_);

// Protects tablet_map_ and pending_tasks_.
mutable rw_spinlock lock_;
Expand All @@ -532,7 +532,7 @@ class TableInfo : public RefCountedThreadSafe<TableInfo>,
std::atomic<bool> is_system_{false};

// List of pending tasks (e.g. create/alter tablet requests).
std::unordered_set<std::shared_ptr<MonitoredTask>> pending_tasks_;
std::unordered_set<std::shared_ptr<MonitoredTask>> pending_tasks_ GUARDED_BY(lock_);

// The last error Status of the currently running CreateTable. Will be OK, if freshly constructed
// object, or if the CreateTable was successful.
Expand Down Expand Up @@ -573,7 +573,7 @@ class DeletedTableInfo : public RefCountedThreadSafe<DeletedTableInfo> {
mutable simple_spinlock lock_;

typedef std::unordered_set<TabletKey, boost::hash<TabletKey>> TabletSet;
TabletSet tablet_set_;
TabletSet tablet_set_ GUARDED_BY(lock_);
};

// The data related to a namespace which is persisted on disk.
Expand Down Expand Up @@ -651,7 +651,7 @@ class TablegroupInfo : public RefCountedThreadSafe<TablegroupInfo>{

// Protects table_set_.
mutable simple_spinlock lock_;
std::unordered_set<TableId> table_set_;
std::unordered_set<TableId> table_set_ GUARDED_BY(lock_);

DISALLOW_COPY_AND_ASSIGN(TablegroupInfo);
};
Expand Down

0 comments on commit 10214bd

Please sign in to comment.