You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zg...@apache.org on 2019/03/12 12:46:37 UTC

[hbase] 109/133: HBASE-18459 [C++] Fix Segfault in location-cache

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

zghao pushed a commit to branch HBASE-14850
in repository https://gitbox.apache.org/repos/asf/hbase.git

commit b5e5881649855873c3cb1a77d17b849db05e22e6
Author: Enis Soztutar <en...@apache.org>
AuthorDate: Tue Aug 1 16:02:20 2017 -0700

    HBASE-18459 [C++] Fix Segfault in location-cache
---
 hbase-native-client/core/configuration.cc  |  2 +-
 hbase-native-client/core/location-cache.cc | 18 ++++++++++++------
 hbase-native-client/core/location-cache.h  |  4 ++--
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/hbase-native-client/core/configuration.cc b/hbase-native-client/core/configuration.cc
index f4fc46d..1fd2851 100644
--- a/hbase-native-client/core/configuration.cc
+++ b/hbase-native-client/core/configuration.cc
@@ -24,8 +24,8 @@
 #include <utility>
 
 #include <glog/logging.h>
-#include <boost/lexical_cast.hpp>
 #include <boost/format.hpp>
+#include <boost/lexical_cast.hpp>
 
 namespace hbase {
 
diff --git a/hbase-native-client/core/location-cache.cc b/hbase-native-client/core/location-cache.cc
index 5f68420..ed5f5dc 100644
--- a/hbase-native-client/core/location-cache.cc
+++ b/hbase-native-client/core/location-cache.cc
@@ -84,17 +84,20 @@ folly::Future<ServerName> LocationCache::LocateMeta() {
   }
   return meta_promise_->getFuture().onError([&](const folly::exception_wrapper &ew) {
     auto promise = InvalidateMeta();
-    promise->setException(ew);
+    if (promise) {
+      promise->setException(ew);
+    }
+    throw ew;
     return ServerName{};
   });
 }
 
-std::unique_ptr<folly::SharedPromise<hbase::pb::ServerName>> LocationCache::InvalidateMeta() {
+std::shared_ptr<folly::SharedPromise<hbase::pb::ServerName>> LocationCache::InvalidateMeta() {
   VLOG(2) << "Invalidating meta location";
   std::lock_guard<std::recursive_mutex> g(meta_lock_);
   if (meta_promise_ != nullptr) {
     // return the unique_ptr back to the caller.
-    std::unique_ptr<folly::SharedPromise<hbase::pb::ServerName>> ret = nullptr;
+    std::shared_ptr<folly::SharedPromise<hbase::pb::ServerName>> ret = nullptr;
     std::swap(ret, meta_promise_);
     return ret;
   } else {
@@ -102,10 +105,13 @@ std::unique_ptr<folly::SharedPromise<hbase::pb::ServerName>> LocationCache::Inva
   }
 }
 
-/// MUST hold the meta_lock_
 void LocationCache::RefreshMetaLocation() {
-  meta_promise_ = std::make_unique<folly::SharedPromise<ServerName>>();
-  cpu_executor_->add([&] { meta_promise_->setWith([&] { return this->ReadMetaLocation(); }); });
+  meta_promise_ = std::make_shared<folly::SharedPromise<ServerName>>();
+  auto p = meta_promise_;
+  cpu_executor_->add([this, p] {
+    std::lock_guard<std::recursive_mutex> g(meta_lock_);
+    p->setWith([&] { return this->ReadMetaLocation(); });
+  });
 }
 
 // Note: this is a blocking call to zookeeper
diff --git a/hbase-native-client/core/location-cache.h b/hbase-native-client/core/location-cache.h
index a374fb6..932bef7 100644
--- a/hbase-native-client/core/location-cache.h
+++ b/hbase-native-client/core/location-cache.h
@@ -137,7 +137,7 @@ class LocationCache : public AsyncRegionLocator {
   /**
    * Remove the cached location of meta.
    */
-  std::unique_ptr<folly::SharedPromise<hbase::pb::ServerName>> InvalidateMeta();
+  std::shared_ptr<folly::SharedPromise<hbase::pb::ServerName>> InvalidateMeta();
 
   /**
    * Return cached region location corresponding to this row,
@@ -201,7 +201,7 @@ class LocationCache : public AsyncRegionLocator {
   std::shared_ptr<hbase::Configuration> conf_;
   std::string zk_quorum_;
   std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor_;
-  std::unique_ptr<folly::SharedPromise<hbase::pb::ServerName>> meta_promise_;
+  std::shared_ptr<folly::SharedPromise<hbase::pb::ServerName>> meta_promise_;
   std::recursive_mutex meta_lock_;
   MetaUtil meta_util_;
   std::shared_ptr<ConnectionPool> cp_;