Skip to content

Commit

Permalink
[util] switch to using std::shared_lock
Browse files Browse the repository at this point in the history
Since Kudu switched to using C++17 long time ago, the home-grown
kudu::shared_lock is no longer needed.

Change-Id: Idcda724a3bdab86f593d0241e062dd40bcd26af1
Reviewed-on: http://gerrit.cloudera.org:8080/21349
Reviewed-by: Wang Xixu <[email protected]>
Tested-by: Alexey Serbin <[email protected]>
Reviewed-by: Abhishek Chennaka <[email protected]>
  • Loading branch information
alexeyserbin committed Apr 25, 2024
1 parent b236d53 commit a0a5230
Show file tree
Hide file tree
Showing 42 changed files with 134 additions and 114 deletions.
2 changes: 2 additions & 0 deletions src/kudu/client/meta_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <mutex>
#include <ostream>
#include <set>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -79,6 +80,7 @@ using kudu::security::SignedTokenPB;
using kudu::tserver::TabletServerAdminServiceProxy;
using kudu::tserver::TabletServerServiceProxy;
using std::set;
using std::shared_lock;
using std::shared_ptr;
using std::string;
using std::unique_ptr;
Expand Down
3 changes: 3 additions & 0 deletions src/kudu/clock/builtin_ntp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
#include <memory>
#include <mutex>
#include <ostream>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -150,6 +152,7 @@ using kudu::clock::internal::kIntervalNone;
using kudu::clock::internal::RecordedResponse;
using std::deque;
using std::lock_guard;
using std::shared_lock;
using std::string;
using std::unique_ptr;
using std::vector;
Expand Down
2 changes: 2 additions & 0 deletions src/kudu/common/generic_iterators.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <numeric>
#include <optional>
#include <ostream>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <typeinfo>
Expand Down Expand Up @@ -74,6 +75,7 @@ template <class T> struct compare;

using std::deque;
using std::get;
using std::shared_lock;
using std::sort;
using std::string;
using std::unique_ptr;
Expand Down
2 changes: 2 additions & 0 deletions src/kudu/consensus/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <memory>
#include <mutex>
#include <ostream>
#include <shared_mutex>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -179,6 +180,7 @@ DEFINE_validator(log_min_segments_to_retain, &ValidateLogsToRetain);
using kudu::consensus::CommitMsg;
using kudu::consensus::OpId;
using kudu::consensus::ReplicateRefPtr;
using std::shared_lock;
using std::string;
using std::unique_ptr;
using std::vector;
Expand Down
4 changes: 3 additions & 1 deletion src/kudu/consensus/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include <limits>
#include <map>
#include <memory>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <vector>

#include <glog/logging.h>
Expand Down Expand Up @@ -162,7 +164,7 @@ class SegmentAllocator {
FRIEND_TEST(LogTest, TestAutoStopIdleAppendThread);
FRIEND_TEST(LogTest, TestWriteAndReadToAndFromInProgressSegment);
SegmentAllocationState allocation_state() {
shared_lock<RWMutex> l(allocation_lock_);
std::shared_lock<RWMutex> l(allocation_lock_);
return allocation_state_;
}

Expand Down
13 changes: 6 additions & 7 deletions src/kudu/fs/data_dirs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include <ostream>
#include <random>
#include <set>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
Expand Down Expand Up @@ -126,14 +128,9 @@ METRIC_DEFINE_gauge_uint64(server, data_dirs_full,
DECLARE_bool(enable_data_block_fsync);
DECLARE_string(block_manager);

namespace kudu {

namespace fs {

using internal::DataDirGroup;
using kudu::fs::internal::DataDirGroup;
using std::default_random_engine;
using std::pair;
using std::set;
using std::shared_lock;
using std::shuffle;
using std::string;
using std::unique_ptr;
Expand All @@ -143,6 +140,8 @@ using std::vector;
using strings::Substitute;
using strings::SubstituteAndAppend;

namespace kudu {
namespace fs {

////////////////////////////////////////////////////////////
// DataDirMetrics
Expand Down
5 changes: 3 additions & 2 deletions src/kudu/fs/dir_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

#include "kudu/fs/dir_manager.h"

#include <errno.h>

#include <algorithm>
#include <cerrno>
#include <functional>
#include <iterator>
#include <memory>
#include <ostream>
#include <set>
#include <shared_mutex>
#include <string>
#include <unordered_set>
#include <utility>
Expand Down Expand Up @@ -58,6 +58,7 @@
#include "kudu/util/threadpool.h"

using std::set;
using std::shared_lock;
using std::shared_ptr;
using std::string;
using std::unique_ptr;
Expand Down
6 changes: 4 additions & 2 deletions src/kudu/fs/dir_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include <mutex>
#include <optional>
#include <set>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -305,12 +307,12 @@ class DirManager {
bool IsTabletInFailedDir(const std::string& tablet_id) const;

std::set<int> GetFailedDirs() const {
shared_lock<rw_spinlock> group_lock(dir_group_lock_.get_lock());
std::shared_lock<rw_spinlock> group_lock(dir_group_lock_.get_lock());
return failed_dirs_;
}

bool AreAllDirsFailed() const {
shared_lock<rw_spinlock> group_lock(dir_group_lock_.get_lock());
std::shared_lock<rw_spinlock> group_lock(dir_group_lock_.get_lock());
return failed_dirs_.size() == dirs_.size();
}

Expand Down
6 changes: 4 additions & 2 deletions src/kudu/fs/fs_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <initializer_list>
#include <iostream>
#include <mutex>
#include <shared_mutex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
Expand Down Expand Up @@ -186,6 +188,7 @@ using kudu::security::DefaultKeyProvider;
using kudu::security::RangerKMSKeyProvider;
using std::optional;
using std::ostream;
using std::shared_lock;
using std::shared_ptr;
using std::string;
using std::unique_ptr;
Expand Down Expand Up @@ -730,8 +733,7 @@ Status FsManager::InitAndOpenBlockManager(FsReport* report,
return Status::OK();
}

void FsManager::CopyMetadata(
unique_ptr<InstanceMetadataPB>* metadata) {
void FsManager::CopyMetadata(unique_ptr<InstanceMetadataPB>* metadata) {
shared_lock<rw_spinlock> md_lock(metadata_rwlock_.get_lock());
(*metadata)->CopyFrom(*metadata_);
}
Expand Down
2 changes: 2 additions & 0 deletions src/kudu/fs/log_block_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <optional>
#include <ostream>
#include <set>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <unordered_map>
Expand Down Expand Up @@ -228,6 +229,7 @@ using std::accumulate;
using std::map;
using std::optional;
using std::set;
using std::shared_lock;
using std::shared_ptr;
using std::string;
using std::unique_ptr;
Expand Down
2 changes: 2 additions & 0 deletions src/kudu/master/catalog_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <optional>
#include <ostream>
#include <set>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <unordered_map>
Expand Down Expand Up @@ -494,6 +495,7 @@ using std::nullopt;
using std::optional;
using std::pair;
using std::set;
using std::shared_lock;
using std::shared_ptr;
using std::string;
using std::unique_ptr;
Expand Down
8 changes: 5 additions & 3 deletions src/kudu/master/catalog_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include <mutex>
#include <optional>
#include <set>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
Expand Down Expand Up @@ -392,7 +394,7 @@ class TableInfo : public RefCountedThreadSafe<TableInfo> {

// Returns a snapshot copy of the table info's tablet map.
TabletInfoMap tablet_map() const {
shared_lock<rw_spinlock> l(lock_);
std::shared_lock<rw_spinlock> l(lock_);
TabletInfoMap ret;
for (const auto& e : tablet_map_) {
ret.emplace(e.first, make_scoped_refptr(e.second));
Expand All @@ -402,7 +404,7 @@ class TableInfo : public RefCountedThreadSafe<TableInfo> {

// Returns the number of tablets.
int num_tablets() const {
shared_lock<rw_spinlock> l(lock_);
std::shared_lock<rw_spinlock> l(lock_);
return tablet_map_.size();
}

Expand Down Expand Up @@ -615,7 +617,7 @@ class CatalogManager : public tserver::TabletReplicaLookupIf {

private:
CatalogManager* catalog_;
shared_lock<RWMutex> leader_shared_lock_;
std::shared_lock<RWMutex> leader_shared_lock_;
Status catalog_status_;
Status leader_status_;
int64_t initial_term_;
Expand Down
3 changes: 3 additions & 0 deletions src/kudu/master/location_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

#include <cstdio>
#include <mutex>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -48,6 +50,7 @@ METRIC_DEFINE_counter(server, location_mapping_cache_queries,
"Number of queries to the location mapping cache",
kudu::MetricLevel::kDebug);

using std::shared_lock;
using std::string;
using std::vector;
using strings::Substitute;
Expand Down
2 changes: 2 additions & 0 deletions src/kudu/master/ts_descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <mutex>
#include <optional>
#include <ostream>
#include <shared_mutex>
#include <unordered_set>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -55,6 +56,7 @@ TAG_FLAG(tserver_last_replica_creations_halflife_ms, hidden);
using kudu::pb_util::SecureDebugString;
using kudu::pb_util::SecureShortDebugString;
using std::optional;
using std::shared_lock;
using std::shared_ptr;
using std::string;
using std::vector;
Expand Down
15 changes: 8 additions & 7 deletions src/kudu/master/ts_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <memory>
#include <mutex>
#include <optional>
#include <shared_mutex>
#include <string>
#include <type_traits> // IWYU pragma: keep
#include <unordered_map>
Expand Down Expand Up @@ -206,7 +207,7 @@ class TSDescriptor : public enable_make_shared<TSDescriptor> {
// If dimension is none, return the total number of replicas in the tablet server.
// Otherwise, return the number of replicas in the dimension.
int num_live_replicas(const std::optional<std::string>& dimension = std::nullopt) const {
shared_lock<rw_spinlock> l(lock_);
std::shared_lock<rw_spinlock> l(lock_);
if (dimension) {
int32_t num_live_tablets = 0;
if (num_live_tablets_by_dimension_) {
Expand All @@ -220,18 +221,18 @@ class TSDescriptor : public enable_make_shared<TSDescriptor> {
// Return the number of live replicas (i.e. running or bootstrapping)
// in the given range for the given table.
int num_live_replicas_by_range(const std::string& range_key, const std::string& table_id) const {
shared_lock<rw_spinlock> l(lock_);
std::shared_lock<rw_spinlock> l(lock_);
int32_t num_live_tablets_by_range = 0;
if (ContainsKey(num_live_tablets_by_range_per_table_, table_id)) {
auto ranges = FindOrDie(num_live_tablets_by_range_per_table_, table_id);
ignore_result(FindCopy(ranges, range_key, &num_live_tablets_by_range));
if (const auto* ranges = FindOrNull(
num_live_tablets_by_range_per_table_, table_id); ranges != nullptr) {
ignore_result(FindCopy(*ranges, range_key, &num_live_tablets_by_range));
}
return num_live_tablets_by_range;
}

// Return the number of live replicas (i.e. running or bootstrapping) in the given table.
int num_live_replicas_by_table(const std::string& table_id) const {
shared_lock<rw_spinlock> l(lock_);
std::shared_lock<rw_spinlock> l(lock_);
int32_t num_live_tablets_by_table = 0;
if (ContainsKey(num_live_tablets_by_range_per_table_, table_id)) {
auto ranges = FindOrDie(num_live_tablets_by_range_per_table_, table_id);
Expand All @@ -246,7 +247,7 @@ class TSDescriptor : public enable_make_shared<TSDescriptor> {
// since the location could change at any time if the tablet server
// re-registers.
std::optional<std::string> location() const {
shared_lock<rw_spinlock> l(lock_);
std::shared_lock<rw_spinlock> l(lock_);
return location_;
}

Expand Down
2 changes: 2 additions & 0 deletions src/kudu/master/ts_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <mutex>
#include <optional>
#include <ostream>
#include <shared_mutex>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -63,6 +64,7 @@ METRIC_DEFINE_gauge_int32(server, cluster_replica_skew,
using kudu::pb_util::SecureShortDebugString;
using std::lock_guard;
using std::unordered_set;
using std::shared_lock;
using std::shared_ptr;
using std::string;
using strings::Substitute;
Expand Down
2 changes: 2 additions & 0 deletions src/kudu/rpc/messenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <functional>
#include <mutex>
#include <ostream>
#include <shared_mutex>
#include <string>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -66,6 +67,7 @@ METRIC_DEFINE_gauge_int32(server, rpc_pending_connections,
using kudu::security::RpcAuthentication;
using kudu::security::RpcEncryption;
using std::string;
using std::shared_lock;
using std::shared_ptr;
using std::unique_ptr;
using strings::Substitute;
Expand Down
Loading

0 comments on commit a0a5230

Please sign in to comment.