diff --git hbase-native-client/core/location-cache.cc hbase-native-client/core/location-cache.cc index e377266..fdf9d0e 100644 --- hbase-native-client/core/location-cache.cc +++ hbase-native-client/core/location-cache.cc @@ -87,17 +87,20 @@ folly::Future 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> LocationCache::InvalidateMeta() { +std::shared_ptr> LocationCache::InvalidateMeta() { VLOG(2) << "Invalidating meta location"; std::lock_guard g(meta_lock_); if (meta_promise_ != nullptr) { // return the unique_ptr back to the caller. - std::unique_ptr> ret = nullptr; + std::shared_ptr> ret = nullptr; std::swap(ret, meta_promise_); return ret; } else { @@ -105,10 +108,14 @@ std::unique_ptr> LocationCache::Inva } } -/// MUST hold the meta_lock_ void LocationCache::RefreshMetaLocation() { - meta_promise_ = std::make_unique>(); - cpu_executor_->add([&] { meta_promise_->setWith([&] { return this->ReadMetaLocation(); }); }); + meta_promise_ = std::make_shared>(); + auto p = meta_promise_; + cpu_executor_->add([this, p] { + std::lock_guard g(meta_lock_); + p->setWith([&] { + return this->ReadMetaLocation(); }); + }); } // Note: this is a blocking call to zookeeper diff --git hbase-native-client/core/location-cache.h hbase-native-client/core/location-cache.h index 084c2d8..838e100 100644 --- hbase-native-client/core/location-cache.h +++ hbase-native-client/core/location-cache.h @@ -139,7 +139,7 @@ class LocationCache : public AsyncRegionLocator { /** * Remove the cached location of meta. */ - std::unique_ptr> InvalidateMeta(); + std::shared_ptr> InvalidateMeta(); /** * Return cached region location corresponding to this row, @@ -204,7 +204,7 @@ class LocationCache : public AsyncRegionLocator { std::string zk_quorum_; std::shared_ptr io_executor_; std::shared_ptr cpu_executor_; - std::unique_ptr> meta_promise_; + std::shared_ptr> meta_promise_; std::recursive_mutex meta_lock_; MetaUtil meta_util_; std::shared_ptr cp_;