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:45:48 UTC
[hbase] 60/133: HBASE-17485 [C++] Zookeeper quorum and znode lookup
made configurable (Sudeep Sunthankar & enis)
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 eae654abe41882fdde6b8bebc9300d627aa896c3
Author: Enis Soztutar <en...@apache.org>
AuthorDate: Tue Jan 24 15:41:34 2017 -0800
HBASE-17485 [C++] Zookeeper quorum and znode lookup made configurable (Sudeep Sunthankar & enis)
---
hbase-native-client/core/client.cc | 4 ++--
hbase-native-client/core/location-cache-test.cc | 7 +++----
hbase-native-client/core/location-cache.cc | 14 +++++++-------
hbase-native-client/core/location-cache.h | 12 ++++++++++--
hbase-native-client/core/simple-client.cc | 8 +++++++-
hbase-native-client/test-util/BUCK | 3 ++-
hbase-native-client/test-util/test-util.h | 8 ++++++++
7 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/hbase-native-client/core/client.cc b/hbase-native-client/core/client.cc
index dd568ce..c1efd8b 100644
--- a/hbase-native-client/core/client.cc
+++ b/hbase-native-client/core/client.cc
@@ -47,8 +47,8 @@ void Client::init(const hbase::Configuration &conf) {
io_executor_ = std::make_shared<wangle::IOThreadPoolExecutor>(sysconf(_SC_NPROCESSORS_ONLN));
rpc_client_ = std::make_shared<hbase::RpcClient>(io_executor_);
- location_cache_ = std::make_shared<hbase::LocationCache>(zk_quorum, cpu_executor_,
- rpc_client_->connection_pool());
+ location_cache_ =
+ std::make_shared<hbase::LocationCache>(conf_, cpu_executor_, rpc_client_->connection_pool());
}
// We can't have the threads continue running after everything is done
diff --git a/hbase-native-client/core/location-cache-test.cc b/hbase-native-client/core/location-cache-test.cc
index 42e7bb3..1ad6c65 100644
--- a/hbase-native-client/core/location-cache-test.cc
+++ b/hbase-native-client/core/location-cache-test.cc
@@ -31,11 +31,10 @@ using namespace std::chrono;
TEST(LocationCacheTest, TestGetMetaNodeContents) {
TestUtil test_util{};
-
auto cpu = std::make_shared<wangle::CPUThreadPoolExecutor>(4);
auto io = std::make_shared<wangle::IOThreadPoolExecutor>(4);
auto cp = std::make_shared<ConnectionPool>(io);
- LocationCache cache{"localhost:2181", cpu, cp};
+ LocationCache cache{test_util.conf(), cpu, cp};
auto f = cache.LocateMeta();
auto result = f.get();
ASSERT_FALSE(f.hasException());
@@ -51,7 +50,7 @@ TEST(LocationCacheTest, TestGetRegionLocation) {
auto cpu = std::make_shared<wangle::CPUThreadPoolExecutor>(4);
auto io = std::make_shared<wangle::IOThreadPoolExecutor>(4);
auto cp = std::make_shared<ConnectionPool>(io);
- LocationCache cache{"localhost:2181", cpu, cp};
+ LocationCache cache{test_util.conf(), cpu, cp};
// If there is no table this should throw an exception
auto tn = folly::to<hbase::pb::TableName>("t");
@@ -70,7 +69,7 @@ TEST(LocationCacheTest, TestCaching) {
auto cpu = std::make_shared<wangle::CPUThreadPoolExecutor>(4);
auto io = std::make_shared<wangle::IOThreadPoolExecutor>(4);
auto cp = std::make_shared<ConnectionPool>(io);
- LocationCache cache{"localhost:2181", cpu, cp};
+ LocationCache cache{test_util.conf(), cpu, cp};
auto tn_1 = folly::to<hbase::pb::TableName>("t1");
auto tn_2 = folly::to<hbase::pb::TableName>("t2");
diff --git a/hbase-native-client/core/location-cache.cc b/hbase-native-client/core/location-cache.cc
index 66f3eb7..dab5deb 100644
--- a/hbase-native-client/core/location-cache.cc
+++ b/hbase-native-client/core/location-cache.cc
@@ -50,13 +50,10 @@ using hbase::pb::ServerName;
using hbase::pb::MetaRegionServer;
using hbase::pb::RegionInfo;
-// TODO(eclark): make this configurable on client creation
-static const char META_ZNODE_NAME[] = "/hbase/meta-region-server";
-
-LocationCache::LocationCache(std::string quorum_spec,
+LocationCache::LocationCache(std::shared_ptr<hbase::Configuration> conf,
std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor,
std::shared_ptr<ConnectionPool> cp)
- : quorum_spec_(quorum_spec),
+ : conf_(conf),
cpu_executor_(cpu_executor),
meta_promise_(nullptr),
meta_lock_(),
@@ -65,7 +62,8 @@ LocationCache::LocationCache(std::string quorum_spec,
zk_(nullptr),
cached_locations_(),
locations_lock_() {
- zk_ = zookeeper_init(quorum_spec.c_str(), nullptr, 1000, 0, 0, 0);
+ quorum_spec_ = conf_->Get(kHBaseZookeeperQuorum_, kDefHBaseZookeeperQuorum_);
+ zk_ = zookeeper_init(quorum_spec_.c_str(), nullptr, 1000, 0, 0, 0);
}
LocationCache::~LocationCache() {
@@ -101,8 +99,10 @@ ServerName LocationCache::ReadMetaLocation() {
// This needs to be int rather than size_t as that's what ZK expects.
int len = buf->capacity();
+ std::string zk_node = conf_->Get(kHBaseMetaZnodeName_, kDefHBaseMetaZnodeName_);
+ zk_node += "/" + kHBaseMetaRegionServer_;
// TODO(elliott): handle disconnects/reconntion as needed.
- int zk_result = zoo_get(this->zk_, META_ZNODE_NAME, 0,
+ int zk_result = zoo_get(this->zk_, zk_node.c_str(), 0,
reinterpret_cast<char *>(buf->writableData()), &len, nullptr);
if (zk_result != ZOK || len < 9) {
LOG(ERROR) << "Error getting meta location.";
diff --git a/hbase-native-client/core/location-cache.h b/hbase-native-client/core/location-cache.h
index 22a8ad5..4d66e06 100644
--- a/hbase-native-client/core/location-cache.h
+++ b/hbase-native-client/core/location-cache.h
@@ -32,6 +32,7 @@
#include <string>
#include "connection/connection-pool.h"
+#include "core/configuration.h"
#include "core/meta-utils.h"
#include "core/region-location.h"
#include "serde/table-name.h"
@@ -77,12 +78,12 @@ class LocationCache {
public:
/**
* Constructor.
- * @param quorum_spec Where to connect for Zookeeper.
+ * @param conf Configuration instance to fetch Zookeeper Quorum and Zookeeper Znode.
* @param cpu_executor executor used to run non network IO based
* continuations.
* @param io_executor executor used to talk to the network
*/
- LocationCache(std::string quorum_spec,
+ LocationCache(std::shared_ptr<hbase::Configuration> conf,
std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor,
std::shared_ptr<ConnectionPool> cp);
/**
@@ -179,7 +180,14 @@ class LocationCache {
const hbase::pb::TableName &tn);
std::shared_ptr<hbase::PerTableLocationMap> GetNewTableLocations(const hbase::pb::TableName &tn);
+ const std::string kHBaseZookeeperQuorum_ = "hbase.zookeeper.quorum";
+ const std::string kDefHBaseZookeeperQuorum_ = "localhost:2181";
+ const std::string kHBaseMetaZnodeName_ = "zookeeper.znode.parent";
+ const std::string kDefHBaseMetaZnodeName_ = "/hbase";
+ const std::string kHBaseMetaRegionServer_ = "meta-region-server";
+
/* data */
+ std::shared_ptr<hbase::Configuration> conf_;
std::string quorum_spec_;
std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor_;
std::unique_ptr<folly::SharedPromise<hbase::pb::ServerName>> meta_promise_;
diff --git a/hbase-native-client/core/simple-client.cc b/hbase-native-client/core/simple-client.cc
index dac0d10..3cd0a93 100644
--- a/hbase-native-client/core/simple-client.cc
+++ b/hbase-native-client/core/simple-client.cc
@@ -39,6 +39,7 @@
using namespace folly;
using namespace std;
using namespace std::chrono;
+using hbase::Configuration;
using hbase::Response;
using hbase::Request;
using hbase::HBaseService;
@@ -87,9 +88,14 @@ int main(int argc, char *argv[]) {
// Set up thread pools.
auto cpu_pool = std::make_shared<wangle::CPUThreadPoolExecutor>(FLAGS_threads);
auto io_pool = std::make_shared<wangle::IOThreadPoolExecutor>(5);
+ auto cp = std::make_shared<ConnectionPool>(io_pool);
+
+ // Configuration
+ auto conf = std::make_shared<Configuration>();
+ conf->Set("hbase.zookeeper.quorum", FLAGS_zookeeper);
// Create the cache.
- LocationCache cache{FLAGS_zookeeper, cpu_pool, io_pool};
+ LocationCache cache{conf, cpu_pool, cp};
auto row = FLAGS_row;
auto tn = folly::to<TableName>(FLAGS_table);
diff --git a/hbase-native-client/test-util/BUCK b/hbase-native-client/test-util/BUCK
index e5e6ea2..c6e41f1 100644
--- a/hbase-native-client/test-util/BUCK
+++ b/hbase-native-client/test-util/BUCK
@@ -22,8 +22,9 @@ cxx_library(name="test-util",
srcs=["test-util.cc"],
deps=[
"//third-party:folly",
+ "//core:core"
],
visibility=[
'PUBLIC',
],
- )
\ No newline at end of file
+ )
diff --git a/hbase-native-client/test-util/test-util.h b/hbase-native-client/test-util/test-util.h
index 2fc9d69..cc35511 100644
--- a/hbase-native-client/test-util/test-util.h
+++ b/hbase-native-client/test-util/test-util.h
@@ -24,6 +24,8 @@
#include <cstdlib>
#include <string>
+#include "core/configuration.h"
+
namespace hbase {
/**
* @brief Class to deal with a local instance cluster for testing.
@@ -55,7 +57,13 @@ class TestUtil {
*/
static std::string RandString(int len = 32);
+ /**
+ * Returns the configuration to talk to the local cluster
+ */
+ std::shared_ptr<Configuration> conf() const { return conf_; }
+
private:
folly::test::TemporaryDirectory temp_dir_;
+ std::shared_ptr<Configuration> conf_ = std::make_shared<Configuration>();
};
} // namespace hbase