This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new a0a523018 [util] switch to using std::shared_lock
a0a523018 is described below

commit a0a523018983d5c28efed44ef85c7680e7ce8c03
Author: Alexey Serbin <[email protected]>
AuthorDate: Tue Apr 23 12:19:19 2024 -0700

    [util] switch to using std::shared_lock
    
    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]>
---
 src/kudu/client/meta_cache.cc              |  2 ++
 src/kudu/clock/builtin_ntp.cc              |  3 ++
 src/kudu/common/generic_iterators.cc       |  2 ++
 src/kudu/consensus/log.cc                  |  2 ++
 src/kudu/consensus/log.h                   |  4 ++-
 src/kudu/fs/data_dirs.cc                   | 13 ++++----
 src/kudu/fs/dir_manager.cc                 |  5 +--
 src/kudu/fs/dir_manager.h                  |  6 ++--
 src/kudu/fs/fs_manager.cc                  |  6 ++--
 src/kudu/fs/log_block_manager.cc           |  2 ++
 src/kudu/master/catalog_manager.cc         |  2 ++
 src/kudu/master/catalog_manager.h          |  8 +++--
 src/kudu/master/location_cache.cc          |  3 ++
 src/kudu/master/ts_descriptor.cc           |  2 ++
 src/kudu/master/ts_descriptor.h            | 15 ++++-----
 src/kudu/master/ts_manager.cc              |  2 ++
 src/kudu/rpc/messenger.cc                  |  2 ++
 src/kudu/rpc/messenger.h                   |  4 ++-
 src/kudu/rpc/rpcz_store.cc                 |  2 ++
 src/kudu/security/tls_context.cc           |  2 ++
 src/kudu/security/tls_context.h            | 11 ++++---
 src/kudu/security/token_signer.cc          |  3 +-
 src/kudu/security/token_verifier.cc        |  4 ++-
 src/kudu/server/webserver.cc               |  3 ++
 src/kudu/tablet/delta_tracker.cc           | 26 ++++++++--------
 src/kudu/tablet/diskrowset.cc              |  3 +-
 src/kudu/tablet/ops/write_op.cc            |  4 ++-
 src/kudu/tablet/ops/write_op.h             |  5 +--
 src/kudu/tablet/tablet.cc                  | 11 +++----
 src/kudu/tablet/tablet.h                   |  6 ++--
 src/kudu/tablet/txn_participant.cc         |  2 ++
 src/kudu/tablet/txn_participant.h          |  3 +-
 src/kudu/tools/rebalancer_tool.cc          |  2 ++
 src/kudu/transactions/txn_status_manager.h |  3 +-
 src/kudu/tserver/scanners.cc               |  7 +++--
 src/kudu/tserver/ts_tablet_manager.cc      |  2 ++
 src/kudu/tserver/ts_tablet_manager.h       |  4 ++-
 src/kudu/util/locks.h                      | 49 +-----------------------------
 src/kudu/util/rw_mutex-test.cc             |  4 ++-
 src/kudu/util/rw_mutex.h                   |  2 +-
 src/kudu/util/rw_semaphore-test.cc         |  4 ++-
 src/kudu/util/thread.cc                    |  3 ++
 42 files changed, 134 insertions(+), 114 deletions(-)

diff --git a/src/kudu/client/meta_cache.cc b/src/kudu/client/meta_cache.cc
index 232e1900b..2ddfdf6c4 100644
--- a/src/kudu/client/meta_cache.cc
+++ b/src/kudu/client/meta_cache.cc
@@ -23,6 +23,7 @@
 #include <mutex>
 #include <ostream>
 #include <set>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>
 #include <utility>
@@ -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;
diff --git a/src/kudu/clock/builtin_ntp.cc b/src/kudu/clock/builtin_ntp.cc
index 348a85e8b..29b64f541 100644
--- a/src/kudu/clock/builtin_ntp.cc
+++ b/src/kudu/clock/builtin_ntp.cc
@@ -31,7 +31,9 @@
 #include <memory>
 #include <mutex>
 #include <ostream>
+#include <shared_mutex>
 #include <string>
+#include <type_traits>
 #include <utility>
 #include <vector>
 
@@ -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;
diff --git a/src/kudu/common/generic_iterators.cc 
b/src/kudu/common/generic_iterators.cc
index af4b4d9bc..3ca481ac9 100644
--- a/src/kudu/common/generic_iterators.cc
+++ b/src/kudu/common/generic_iterators.cc
@@ -29,6 +29,7 @@
 #include <numeric>
 #include <optional>
 #include <ostream>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>
 #include <typeinfo>
@@ -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;
diff --git a/src/kudu/consensus/log.cc b/src/kudu/consensus/log.cc
index 062b496e2..ed861d252 100644
--- a/src/kudu/consensus/log.cc
+++ b/src/kudu/consensus/log.cc
@@ -23,6 +23,7 @@
 #include <memory>
 #include <mutex>
 #include <ostream>
+#include <shared_mutex>
 #include <type_traits>
 #include <utility>
 
@@ -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;
diff --git a/src/kudu/consensus/log.h b/src/kudu/consensus/log.h
index b755d2f38..76ed041a6 100644
--- a/src/kudu/consensus/log.h
+++ b/src/kudu/consensus/log.h
@@ -24,7 +24,9 @@
 #include <limits>
 #include <map>
 #include <memory>
+#include <shared_mutex>
 #include <string>
+#include <type_traits>
 #include <vector>
 
 #include <glog/logging.h>
@@ -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_;
   }
 
diff --git a/src/kudu/fs/data_dirs.cc b/src/kudu/fs/data_dirs.cc
index 59584237f..730d284a9 100644
--- a/src/kudu/fs/data_dirs.cc
+++ b/src/kudu/fs/data_dirs.cc
@@ -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>
@@ -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;
@@ -143,6 +140,8 @@ using std::vector;
 using strings::Substitute;
 using strings::SubstituteAndAppend;
 
+namespace kudu {
+namespace fs {
 
 ////////////////////////////////////////////////////////////
 // DataDirMetrics
diff --git a/src/kudu/fs/dir_manager.cc b/src/kudu/fs/dir_manager.cc
index d24225462..cc5282c11 100644
--- a/src/kudu/fs/dir_manager.cc
+++ b/src/kudu/fs/dir_manager.cc
@@ -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>
@@ -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;
diff --git a/src/kudu/fs/dir_manager.h b/src/kudu/fs/dir_manager.h
index fd445ac82..ffefc391c 100644
--- a/src/kudu/fs/dir_manager.h
+++ b/src/kudu/fs/dir_manager.h
@@ -24,7 +24,9 @@
 #include <mutex>
 #include <optional>
 #include <set>
+#include <shared_mutex>
 #include <string>
+#include <type_traits>
 #include <unordered_map>
 #include <vector>
 
@@ -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();
   }
 
diff --git a/src/kudu/fs/fs_manager.cc b/src/kudu/fs/fs_manager.cc
index 49e67de23..b6cb50fa4 100644
--- a/src/kudu/fs/fs_manager.cc
+++ b/src/kudu/fs/fs_manager.cc
@@ -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>
@@ -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;
@@ -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_);
 }
diff --git a/src/kudu/fs/log_block_manager.cc b/src/kudu/fs/log_block_manager.cc
index adeda77d9..830bd1e78 100644
--- a/src/kudu/fs/log_block_manager.cc
+++ b/src/kudu/fs/log_block_manager.cc
@@ -31,6 +31,7 @@
 #include <optional>
 #include <ostream>
 #include <set>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>
 #include <unordered_map>
@@ -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;
diff --git a/src/kudu/master/catalog_manager.cc 
b/src/kudu/master/catalog_manager.cc
index 891ef0320..4dc260801 100644
--- a/src/kudu/master/catalog_manager.cc
+++ b/src/kudu/master/catalog_manager.cc
@@ -54,6 +54,7 @@
 #include <optional>
 #include <ostream>
 #include <set>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>
 #include <unordered_map>
@@ -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;
diff --git a/src/kudu/master/catalog_manager.h 
b/src/kudu/master/catalog_manager.h
index 6821bf534..136ccbaab 100644
--- a/src/kudu/master/catalog_manager.h
+++ b/src/kudu/master/catalog_manager.h
@@ -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>
@@ -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));
@@ -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();
   }
 
@@ -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_;
diff --git a/src/kudu/master/location_cache.cc 
b/src/kudu/master/location_cache.cc
index 9c8a8e4f4..81f7b366d 100644
--- a/src/kudu/master/location_cache.cc
+++ b/src/kudu/master/location_cache.cc
@@ -19,7 +19,9 @@
 
 #include <cstdio>
 #include <mutex>
+#include <shared_mutex>
 #include <string>
+#include <type_traits>
 #include <unordered_map>
 #include <utility>
 #include <vector>
@@ -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;
diff --git a/src/kudu/master/ts_descriptor.cc b/src/kudu/master/ts_descriptor.cc
index 5057a92d8..2ce308402 100644
--- a/src/kudu/master/ts_descriptor.cc
+++ b/src/kudu/master/ts_descriptor.cc
@@ -21,6 +21,7 @@
 #include <mutex>
 #include <optional>
 #include <ostream>
+#include <shared_mutex>
 #include <unordered_set>
 #include <utility>
 #include <vector>
@@ -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;
diff --git a/src/kudu/master/ts_descriptor.h b/src/kudu/master/ts_descriptor.h
index 667b9a6a1..6d6a97b19 100644
--- a/src/kudu/master/ts_descriptor.h
+++ b/src/kudu/master/ts_descriptor.h
@@ -20,6 +20,7 @@
 #include <memory>
 #include <mutex>
 #include <optional>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>  // IWYU pragma: keep
 #include <unordered_map>
@@ -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_) {
@@ -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);
@@ -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_;
   }
 
diff --git a/src/kudu/master/ts_manager.cc b/src/kudu/master/ts_manager.cc
index aede186cb..93565360c 100644
--- a/src/kudu/master/ts_manager.cc
+++ b/src/kudu/master/ts_manager.cc
@@ -25,6 +25,7 @@
 #include <mutex>
 #include <optional>
 #include <ostream>
+#include <shared_mutex>
 #include <type_traits>
 #include <utility>
 
@@ -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;
diff --git a/src/kudu/rpc/messenger.cc b/src/kudu/rpc/messenger.cc
index 24da3f0e8..929459809 100644
--- a/src/kudu/rpc/messenger.cc
+++ b/src/kudu/rpc/messenger.cc
@@ -21,6 +21,7 @@
 #include <functional>
 #include <mutex>
 #include <ostream>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>
 #include <utility>
@@ -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;
diff --git a/src/kudu/rpc/messenger.h b/src/kudu/rpc/messenger.h
index 65dcfc01f..774c5887b 100644
--- a/src/kudu/rpc/messenger.h
+++ b/src/kudu/rpc/messenger.h
@@ -21,7 +21,9 @@
 #include <memory>
 #include <mutex>
 #include <optional>
+#include <shared_mutex>
 #include <string>
+#include <type_traits>
 #include <unordered_map>
 #include <utility>
 #include <vector>
@@ -437,7 +439,7 @@ class Messenger {
   }
 
   bool closing() const {
-    shared_lock<rw_spinlock> l(lock_.get_lock());
+    std::shared_lock<rw_spinlock> l(lock_.get_lock());
     return state_ == kClosing;
   }
 
diff --git a/src/kudu/rpc/rpcz_store.cc b/src/kudu/rpc/rpcz_store.cc
index 70b38d72c..d2425e52a 100644
--- a/src/kudu/rpc/rpcz_store.cc
+++ b/src/kudu/rpc/rpcz_store.cc
@@ -25,6 +25,7 @@
 #include <map>
 #include <mutex> // for unique_lock
 #include <ostream>
+#include <shared_mutex>
 #include <string>
 #include <tuple>
 #include <type_traits>
@@ -62,6 +63,7 @@ TAG_FLAG(rpc_duration_too_long_ms, advanced);
 TAG_FLAG(rpc_duration_too_long_ms, runtime);
 
 using std::pair;
+using std::shared_lock;
 using std::string;
 using std::vector;
 using std::unique_ptr;
diff --git a/src/kudu/security/tls_context.cc b/src/kudu/security/tls_context.cc
index 3e91e86ad..c28647587 100644
--- a/src/kudu/security/tls_context.cc
+++ b/src/kudu/security/tls_context.cc
@@ -33,6 +33,7 @@
 #include <mutex>
 #include <optional>
 #include <ostream>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>
 #include <vector>
@@ -90,6 +91,7 @@
 using kudu::security::ca::CertRequestGenerator;
 using std::nullopt;
 using std::optional;
+using std::shared_lock;
 using std::string;
 using std::unique_lock;
 using std::vector;
diff --git a/src/kudu/security/tls_context.h b/src/kudu/security/tls_context.h
index a092de939..4606df566 100644
--- a/src/kudu/security/tls_context.h
+++ b/src/kudu/security/tls_context.h
@@ -19,12 +19,13 @@
 
 #include <cstdint>
 #include <optional>
+#include <shared_mutex>
 #include <string>
+#include <type_traits>
 #include <vector>
 
 #include "kudu/gutil/port.h"
 #include "kudu/security/cert.h" // IWYU pragma: keep
-#include "kudu/util/locks.h"
 #include "kudu/util/openssl_util.h"
 #include "kudu/util/rw_mutex.h"
 #include "kudu/util/status.h"
@@ -89,7 +90,7 @@ class TlsContext {
   // Returns true if this TlsContext has been configured with a cert and key 
for
   // use with TLS-encrypted connections.
   bool has_cert() const {
-    shared_lock<RWMutex> lock(lock_);
+    std::shared_lock<RWMutex> lock(lock_);
     return has_cert_;
   }
 
@@ -97,13 +98,13 @@ class TlsContext {
   // cert and key for use with TLS-encrypted connections. If this method 
returns
   // true, then 'has_trusted_cert' will also return true.
   bool has_signed_cert() const {
-    shared_lock<RWMutex> lock(lock_);
+    std::shared_lock<RWMutex> lock(lock_);
     return has_cert_ && !csr_;
   }
 
   // Returns true if this TlsContext has at least one certificate in its trust 
store.
   bool has_trusted_cert() const {
-    shared_lock<RWMutex> lock(lock_);
+    std::shared_lock<RWMutex> lock(lock_);
     return trusted_cert_count_ > 0;
   }
 
@@ -174,7 +175,7 @@ class TlsContext {
   // Return the number of certs that have been marked as trusted.
   // Used by tests.
   int trusted_cert_count_for_tests() const {
-    shared_lock<RWMutex> lock(lock_);
+    std::shared_lock<RWMutex> lock(lock_);
     return trusted_cert_count_;
   }
 
diff --git a/src/kudu/security/token_signer.cc 
b/src/kudu/security/token_signer.cc
index c01475100..ad97db6ef 100644
--- a/src/kudu/security/token_signer.cc
+++ b/src/kudu/security/token_signer.cc
@@ -22,6 +22,7 @@
 #include <map>
 #include <memory>
 #include <mutex>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>
 #include <utility>
@@ -37,7 +38,6 @@
 #include "kudu/security/token_signing_key.h"
 #include "kudu/security/token_verifier.h"
 #include "kudu/util/flag_tags.h"
-#include "kudu/util/locks.h"
 #include "kudu/util/status.h"
 
 DEFINE_int32(tsk_num_rsa_bits, 2048,
@@ -46,6 +46,7 @@ TAG_FLAG(tsk_num_rsa_bits, experimental);
 
 using std::lock_guard;
 using std::map;
+using std::shared_lock;
 using std::shared_ptr;
 using std::string;
 using std::unique_lock;
diff --git a/src/kudu/security/token_verifier.cc 
b/src/kudu/security/token_verifier.cc
index 155ecfa1c..14708ddec 100644
--- a/src/kudu/security/token_verifier.cc
+++ b/src/kudu/security/token_verifier.cc
@@ -21,7 +21,9 @@
 #include <iterator>
 #include <mutex>
 #include <ostream>
+#include <shared_mutex>
 #include <string>
+#include <type_traits>
 #include <utility>
 #include <vector>
 
@@ -32,11 +34,11 @@
 #include "kudu/gutil/walltime.h"
 #include "kudu/security/token.pb.h"
 #include "kudu/security/token_signing_key.h"
-#include "kudu/util/locks.h"
 #include "kudu/util/logging.h"
 #include "kudu/util/status.h"
 
 using std::lock_guard;
+using std::shared_lock;
 using std::string;
 using std::transform;
 using std::unique_ptr;
diff --git a/src/kudu/server/webserver.cc b/src/kudu/server/webserver.cc
index c5c18715f..b505995a8 100644
--- a/src/kudu/server/webserver.cc
+++ b/src/kudu/server/webserver.cc
@@ -32,8 +32,10 @@
 #include <functional>
 #include <map>
 #include <mutex>
+#include <shared_mutex>
 #include <sstream>
 #include <string>
+#include <type_traits>
 #include <unordered_map>
 #include <unordered_set>
 #include <utility>
@@ -77,6 +79,7 @@ typedef sig_t sighandler_t;
 using mustache::RenderTemplate;
 using std::ostringstream;
 using std::pair;
+using std::shared_lock;
 using std::stringstream;
 using std::string;
 using std::unordered_set;
diff --git a/src/kudu/tablet/delta_tracker.cc b/src/kudu/tablet/delta_tracker.cc
index 2e994b00a..a1f31ca54 100644
--- a/src/kudu/tablet/delta_tracker.cc
+++ b/src/kudu/tablet/delta_tracker.cc
@@ -22,6 +22,7 @@
 #include <optional>
 #include <ostream>
 #include <set>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>
 #include <utility>
@@ -71,25 +72,26 @@ DEFINE_uint64(all_delete_op_delta_file_cnt_for_compaction, 
1,
               "Otherwise, it is recommended to keep the default value to 
release "
               "storage space efficiently.");
 
-namespace kudu {
-
-class RowChangeList;
-
-namespace tablet {
-
-using cfile::ReaderOptions;
-using fs::CreateBlockOptions;
-using fs::IOContext;
-using fs::ReadableBlock;
-using fs::WritableBlock;
-using log::LogAnchorRegistry;
+using kudu::cfile::ReaderOptions;
+using kudu::fs::CreateBlockOptions;
+using kudu::fs::IOContext;
+using kudu::fs::ReadableBlock;
+using kudu::fs::WritableBlock;
+using kudu::log::LogAnchorRegistry;
 using std::set;
+using std::shared_lock;
 using std::shared_ptr;
 using std::string;
 using std::unique_ptr;
 using std::vector;
 using strings::Substitute;
 
+namespace kudu {
+
+class RowChangeList;
+
+namespace tablet {
+
 Status DeltaTracker::Open(const shared_ptr<RowSetMetadata>& rowset_metadata,
                           LogAnchorRegistry* log_anchor_registry,
                           const TabletMemTrackers& mem_trackers,
diff --git a/src/kudu/tablet/diskrowset.cc b/src/kudu/tablet/diskrowset.cc
index b05b6fcd3..f6c92c9ed 100644
--- a/src/kudu/tablet/diskrowset.cc
+++ b/src/kudu/tablet/diskrowset.cc
@@ -21,6 +21,7 @@
 #include <map>
 #include <optional>
 #include <ostream>
+#include <shared_mutex>
 #include <vector>
 
 #include <gflags/gflags.h>
@@ -56,7 +57,6 @@
 #include "kudu/util/compression/compression.pb.h"
 #include "kudu/util/debug/trace_event.h"
 #include "kudu/util/flag_tags.h"
-#include "kudu/util/locks.h"
 #include "kudu/util/logging.h"
 #include "kudu/util/monotime.h"
 #include "kudu/util/scoped_cleanup.h"
@@ -90,6 +90,7 @@ using kudu::fs::IOContext;
 using kudu::fs::WritableBlock;
 using kudu::log::LogAnchorRegistry;
 using std::optional;
+using std::shared_lock;
 using std::shared_ptr;
 using std::string;
 using std::unique_ptr;
diff --git a/src/kudu/tablet/ops/write_op.cc b/src/kudu/tablet/ops/write_op.cc
index 816969a11..d53ce15b0 100644
--- a/src/kudu/tablet/ops/write_op.cc
+++ b/src/kudu/tablet/ops/write_op.cc
@@ -24,7 +24,9 @@
 #include <new>
 #include <optional>
 #include <ostream>
+#include <shared_mutex>
 #include <type_traits>
+#include <utility>
 #include <vector>
 
 #include <boost/container/small_vector.hpp>
@@ -62,7 +64,6 @@
 #include "kudu/util/memory/arena.h"
 #include "kudu/util/metrics.h"
 #include "kudu/util/pb_util.h"
-#include "kudu/util/rw_semaphore.h"
 #include "kudu/util/slice.h"
 #include "kudu/util/trace.h"
 
@@ -81,6 +82,7 @@ TAG_FLAG(tablet_inject_latency_on_prepare_write_op_ms, 
runtime);
 DECLARE_bool(enable_txn_partition_lock);
 
 using std::optional;
+using std::shared_lock;
 using std::string;
 using std::unique_ptr;
 using std::vector;
diff --git a/src/kudu/tablet/ops/write_op.h b/src/kudu/tablet/ops/write_op.h
index 9bf4e6603..c794a8a49 100644
--- a/src/kudu/tablet/ops/write_op.h
+++ b/src/kudu/tablet/ops/write_op.h
@@ -22,6 +22,7 @@
 #include <memory>
 #include <mutex>
 #include <optional>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>
 #include <vector>
@@ -320,7 +321,7 @@ class WriteOpState : public OpState {
 
   // A lock held on the tablet's schema. Prevents concurrent schema change
   // from racing with a write.
-  shared_lock<rw_semaphore> schema_lock_;
+  std::shared_lock<rw_semaphore> schema_lock_;
 
   // The Schema of the tablet when the op was first decoded. This is verified
   // at APPLY time to ensure we don't have races against schema change.
@@ -337,7 +338,7 @@ class WriteOpState : public OpState {
 
   // Lock protecting the transaction's state, ensuring it remains open for the
   // duration of this write.
-  shared_lock<rw_semaphore> txn_lock_;
+  std::shared_lock<rw_semaphore> txn_lock_;
 
   DISALLOW_COPY_AND_ASSIGN(WriteOpState);
 };
diff --git a/src/kudu/tablet/tablet.cc b/src/kudu/tablet/tablet.cc
index c7da4a58d..ca452d210 100644
--- a/src/kudu/tablet/tablet.cc
+++ b/src/kudu/tablet/tablet.cc
@@ -26,6 +26,7 @@
 #include <optional>
 #include <ostream>
 #include <random>
+#include <shared_mutex>
 #include <type_traits>
 #include <unordered_map>
 #include <unordered_set>
@@ -101,12 +102,6 @@
 #include "kudu/util/trace.h"
 #include "kudu/util/url-coding.h"
 
-namespace kudu {
-namespace tablet {
-class RowSetMetadata;
-}  // namespace tablet
-}  // namespace kudu
-
 DEFINE_bool(prevent_kudu_2233_corruption, true,
             "Whether or not to prevent KUDU-2233 corruptions. Used for testing 
only!");
 TAG_FLAG(prevent_kudu_2233_corruption, unsafe);
@@ -274,6 +269,7 @@ using std::nullopt;
 using std::optional;
 using std::ostream;
 using std::pair;
+using std::shared_lock;
 using std::shared_ptr;
 using std::string;
 using std::unique_ptr;
@@ -281,7 +277,6 @@ using std::unordered_set;
 using std::vector;
 using strings::Substitute;
 
-
 namespace {
 
 bool ValidateAncientDeltaMaxRatio(const char* flag, double val) {
@@ -319,6 +314,8 @@ struct IteratorStats;
 
 namespace tablet {
 
+class RowSetMetadata;
+
 ////////////////////////////////////////////////////////////
 // TabletComponents
 ////////////////////////////////////////////////////////////
diff --git a/src/kudu/tablet/tablet.h b/src/kudu/tablet/tablet.h
index 05ef62d6f..c7094756d 100644
--- a/src/kudu/tablet/tablet.h
+++ b/src/kudu/tablet/tablet.h
@@ -24,7 +24,9 @@
 #include <memory>
 #include <mutex>
 #include <ostream>
+#include <shared_mutex>
 #include <string>
+#include <type_traits>
 #include <unordered_map>
 #include <unordered_set>
 #include <utility>
@@ -721,12 +723,12 @@ class Tablet {
                                  const RowSetVector &to_add);
 
   void GetComponents(scoped_refptr<TabletComponents>* comps) const {
-    shared_lock<rw_spinlock> l(component_lock_);
+    std::shared_lock<rw_spinlock> l(component_lock_);
     *comps = CHECK_NOTNULL(components_.get());
   }
 
   void GetComponentsOrNull(scoped_refptr<TabletComponents>* comps) const {
-    shared_lock<rw_spinlock> l(component_lock_);
+    std::shared_lock<rw_spinlock> l(component_lock_);
     *comps = components_;
   }
 
diff --git a/src/kudu/tablet/txn_participant.cc 
b/src/kudu/tablet/txn_participant.cc
index 352182d2c..3472ef3da 100644
--- a/src/kudu/tablet/txn_participant.cc
+++ b/src/kudu/tablet/txn_participant.cc
@@ -20,6 +20,7 @@
 #include <algorithm>
 #include <cstdint>
 #include <ostream>
+#include <shared_mutex>
 #include <type_traits>
 #include <unordered_map>
 #include <utility>
@@ -35,6 +36,7 @@ DECLARE_bool(enable_txn_partition_lock);
 
 using kudu::log::LogAnchorRegistry;
 using kudu::tserver::TabletServerErrorPB;
+using std::shared_lock;
 using std::vector;
 
 namespace kudu {
diff --git a/src/kudu/tablet/txn_participant.h 
b/src/kudu/tablet/txn_participant.h
index 0f7e14389..34f534a30 100644
--- a/src/kudu/tablet/txn_participant.h
+++ b/src/kudu/tablet/txn_participant.h
@@ -21,6 +21,7 @@
 #include <memory>
 #include <mutex>
 #include <optional>
+#include <shared_mutex>
 #include <unordered_map>
 #include <utility>
 #include <vector>
@@ -107,7 +108,7 @@ class Txn : public RefCountedThreadSafe<Txn> {
   // driven via an op driver, lock acquisition is expected to be serialized in
   // a single thread.
   void AcquireWriteLock(std::unique_lock<rw_semaphore>* txn_lock);
-  void AcquireReadLock(shared_lock<rw_semaphore>* txn_lock);
+  void AcquireReadLock(std::shared_lock<rw_semaphore>* txn_lock);
 
   // Adopts the input partition lock, maintaining it until the transaction is
   // complete (aborted or finalized). Rather than maintaining multiple
diff --git a/src/kudu/tools/rebalancer_tool.cc 
b/src/kudu/tools/rebalancer_tool.cc
index fac029e06..34456a0f1 100644
--- a/src/kudu/tools/rebalancer_tool.cc
+++ b/src/kudu/tools/rebalancer_tool.cc
@@ -29,6 +29,7 @@
 #include <optional>
 #include <random>
 #include <set>
+#include <shared_mutex>
 #include <string>
 #include <tuple>
 #include <type_traits>
@@ -87,6 +88,7 @@ using std::pair;
 using std::nullopt;
 using std::optional;
 using std::set;
+using std::shared_lock;
 using std::shared_ptr;
 using std::sort;
 using std::string;
diff --git a/src/kudu/transactions/txn_status_manager.h 
b/src/kudu/transactions/txn_status_manager.h
index 5b2fc4841..ee6e1f310 100644
--- a/src/kudu/transactions/txn_status_manager.h
+++ b/src/kudu/transactions/txn_status_manager.h
@@ -21,6 +21,7 @@
 #include <memory>
 #include <mutex>
 #include <optional>
+#include <shared_mutex>
 #include <string>
 #include <unordered_map>
 #include <utility>
@@ -324,7 +325,7 @@ class TxnStatusManager final : public 
tablet::TxnCoordinator {
 
    private:
     TxnStatusManager* txn_status_manager_;
-    shared_lock<RWMutex> leader_shared_lock_;
+    std::shared_lock<RWMutex> leader_shared_lock_;
 
     // General status of the transaction status manager. If not OK (e.g. the 
tablet
     // replica is still being initialized), all operations are illegal.
diff --git a/src/kudu/tserver/scanners.cc b/src/kudu/tserver/scanners.cc
index c53b331a1..7bae8cb45 100644
--- a/src/kudu/tserver/scanners.cc
+++ b/src/kudu/tserver/scanners.cc
@@ -23,6 +23,7 @@
 #include <mutex>
 #include <numeric>
 #include <ostream>
+#include <shared_mutex>
 #include <type_traits>
 
 #include <gflags/gflags.h>
@@ -43,7 +44,6 @@
 #include "kudu/tserver/scanner_metrics.h"
 #include "kudu/util/flag_tags.h"
 #include "kudu/util/flag_validators.h"
-#include "kudu/util/locks.h"
 #include "kudu/util/logging.h"
 #include "kudu/util/metrics.h"
 #include "kudu/util/status.h"
@@ -100,6 +100,7 @@ METRIC_DEFINE_gauge_size(server, slow_scans,
 
 using kudu::rpc::RemoteUser;
 using kudu::tablet::TabletReplica;
+using std::shared_lock;
 using std::string;
 using std::unique_ptr;
 using std::unordered_map;
@@ -331,7 +332,7 @@ vector<SharedScanDescriptor> ScannerManager::ListScans() 
const {
   }
 
   {
-    kudu::shared_lock<rw_spinlock> l(completed_scans_lock_.get_lock());
+    shared_lock<rw_spinlock> l(completed_scans_lock_.get_lock());
     // A scanner in 'scans' may have completed between the above loop and here.
     // As we'd rather have the finalized descriptor of the completed scan,
     // update over the old descriptor in this case.
@@ -363,7 +364,7 @@ vector<SharedScanDescriptor> 
ScannerManager::ListSlowScans() const {
   // Get all the scans first.
   unordered_map<string, SharedScanDescriptor> scans;
   {
-    kudu::shared_lock<rw_spinlock> l(slow_scans_lock_.get_lock());
+    shared_lock<rw_spinlock> l(slow_scans_lock_.get_lock());
     for (const auto& scan : slow_scans_) {
       InsertOrUpdate(&scans, scan->scanner_id, scan);
     }
diff --git a/src/kudu/tserver/ts_tablet_manager.cc 
b/src/kudu/tserver/ts_tablet_manager.cc
index 6209ce2a1..8b3ae9a24 100644
--- a/src/kudu/tserver/ts_tablet_manager.cc
+++ b/src/kudu/tserver/ts_tablet_manager.cc
@@ -24,6 +24,7 @@
 #include <optional>
 #include <ostream>
 #include <set>
+#include <shared_mutex>
 #include <string>
 #include <type_traits>
 #include <utility>
@@ -299,6 +300,7 @@ using std::make_shared;
 using std::nullopt;
 using std::optional;
 using std::set;
+using std::shared_lock;
 using std::shared_ptr;
 using std::string;
 using std::vector;
diff --git a/src/kudu/tserver/ts_tablet_manager.h 
b/src/kudu/tserver/ts_tablet_manager.h
index c6222b8ed..d00464816 100644
--- a/src/kudu/tserver/ts_tablet_manager.h
+++ b/src/kudu/tserver/ts_tablet_manager.h
@@ -23,9 +23,11 @@
 #include <map>
 #include <memory>
 #include <optional>
+#include <shared_mutex>
 #include <string>
 #include <unordered_map>
 #include <unordered_set>
+#include <type_traits>
 #include <vector>
 
 #include <gtest/gtest_prod.h>
@@ -386,7 +388,7 @@ class TSTabletManager : public 
tserver::TabletReplicaLookupIf {
                                  int64_t last_logged_term);
 
   TSTabletManagerStatePB state() const {
-    shared_lock<RWMutex> l(lock_);
+    std::shared_lock<RWMutex> l(lock_);
     return state_;
   }
 
diff --git a/src/kudu/util/locks.h b/src/kudu/util/locks.h
index 1ee854493..48d6a73af 100644
--- a/src/kudu/util/locks.h
+++ b/src/kudu/util/locks.h
@@ -147,7 +147,7 @@ class rw_spinlock {
 //
 //   // Lock shared:
 //   {
-//     kudu::shared_lock<rw_spinlock> lock(mylock.get_lock());
+//     std::shared_lock<rw_spinlock> lock(mylock.get_lock());
 //     ...
 //   }
 //
@@ -247,53 +247,6 @@ class percpu_rwlock {
   padded_lock *locks_;
 };
 
-// Simple implementation of the std::shared_lock API, which is not available in
-// the standard library until C++14. Defers error checking to the underlying
-// mutex.
-
-template <typename Mutex>
-class shared_lock {
- public:
-  shared_lock()
-      : m_(nullptr) {
-  }
-
-  explicit shared_lock(Mutex& m)
-      : m_(&m) {
-    m_->lock_shared();
-  }
-
-  shared_lock(Mutex& m, std::try_to_lock_t t)
-      : m_(nullptr) {
-    if (m.try_lock_shared()) {
-      m_ = &m;
-    }
-  }
-
-  bool owns_lock() const {
-    return m_;
-  }
-
-  void swap(shared_lock& other) {
-    std::swap(m_, other.m_);
-  }
-
-  shared_lock& operator=(shared_lock&& other) noexcept {
-    swap(other);
-    return *this;
-  }
-
-  ~shared_lock() {
-    if (m_ != nullptr) {
-      m_->unlock_shared();
-    }
-  }
-
- private:
-  Mutex* m_;
-  DISALLOW_COPY_AND_ASSIGN(shared_lock<Mutex>);
-};
-
 } // namespace kudu
 
 #endif
diff --git a/src/kudu/util/rw_mutex-test.cc b/src/kudu/util/rw_mutex-test.cc
index 34ec8beba..f6a26e2f5 100644
--- a/src/kudu/util/rw_mutex-test.cc
+++ b/src/kudu/util/rw_mutex-test.cc
@@ -18,19 +18,21 @@
 #include <cstdint>
 #include <mutex>
 #include <ostream>
+#include <shared_mutex>
 #include <thread>
+#include <type_traits>
 #include <vector>
 
 #include <glog/logging.h>
 #include <gtest/gtest.h>
 
 #include "kudu/util/atomic.h"
-#include "kudu/util/locks.h"
 #include "kudu/util/monotime.h"
 #include "kudu/util/rw_mutex.h"
 #include "kudu/util/test_util.h"
 
 using std::lock_guard;
+using std::shared_lock;
 using std::thread;
 using std::try_to_lock;
 using std::unique_lock;
diff --git a/src/kudu/util/rw_mutex.h b/src/kudu/util/rw_mutex.h
index bb6168ce2..de65755b6 100644
--- a/src/kudu/util/rw_mutex.h
+++ b/src/kudu/util/rw_mutex.h
@@ -74,7 +74,7 @@ class RWMutex {
   void AssertAcquiredForWriting() const {}
 #endif
 
-  // Aliases for use with std::lock_guard and kudu::shared_lock.
+  // Aliases for use with std::lock_guard and std::shared_lock.
   void lock() { WriteLock(); }
   void unlock() { WriteUnlock(); }
   bool try_lock() { return TryWriteLock(); }
diff --git a/src/kudu/util/rw_semaphore-test.cc 
b/src/kudu/util/rw_semaphore-test.cc
index 771760857..c246d5a8d 100644
--- a/src/kudu/util/rw_semaphore-test.cc
+++ b/src/kudu/util/rw_semaphore-test.cc
@@ -17,16 +17,18 @@
 
 #include <cstdint>
 #include <mutex>
+#include <shared_mutex>
 #include <thread>
+#include <type_traits>
 #include <vector>
 
 #include <glog/logging.h>
 #include <gtest/gtest.h>
 
-#include "kudu/util/locks.h"
 #include "kudu/util/monotime.h"
 #include "kudu/util/rw_semaphore.h"
 
+using std::shared_lock;
 using std::thread;
 using std::vector;
 
diff --git a/src/kudu/util/thread.cc b/src/kudu/util/thread.cc
index 6cfa8916f..220932a29 100644
--- a/src/kudu/util/thread.cc
+++ b/src/kudu/util/thread.cc
@@ -32,7 +32,9 @@
 #include <cstring>
 #include <memory>
 #include <mutex>
+#include <shared_mutex>
 #include <sstream>
+#include <type_traits>
 #include <unordered_map>
 #include <utility>
 #include <vector>
@@ -66,6 +68,7 @@
 using std::atomic;
 using std::ostringstream;
 using std::pair;
+using std::shared_lock;
 using std::shared_ptr;
 using std::string;
 using std::vector;


Reply via email to