diff --git hbase-native-client/core/client.cc hbase-native-client/core/client.cc index dd568ce..c1efd8b 100644 --- hbase-native-client/core/client.cc +++ hbase-native-client/core/client.cc @@ -47,8 +47,8 @@ void Client::init(const hbase::Configuration &conf) { io_executor_ = std::make_shared(sysconf(_SC_NPROCESSORS_ONLN)); rpc_client_ = std::make_shared(io_executor_); - location_cache_ = std::make_shared(zk_quorum, cpu_executor_, - rpc_client_->connection_pool()); + location_cache_ = + std::make_shared(conf_, cpu_executor_, rpc_client_->connection_pool()); } // We can't have the threads continue running after everything is done diff --git hbase-native-client/core/location-cache-test.cc hbase-native-client/core/location-cache-test.cc index 42e7bb3..1ad6c65 100644 --- hbase-native-client/core/location-cache-test.cc +++ 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(4); auto io = std::make_shared(4); auto cp = std::make_shared(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(4); auto io = std::make_shared(4); auto cp = std::make_shared(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("t"); @@ -70,7 +69,7 @@ TEST(LocationCacheTest, TestCaching) { auto cpu = std::make_shared(4); auto io = std::make_shared(4); auto cp = std::make_shared(io); - LocationCache cache{"localhost:2181", cpu, cp}; + LocationCache cache{test_util.conf(), cpu, cp}; auto tn_1 = folly::to("t1"); auto tn_2 = folly::to("t2"); diff --git hbase-native-client/core/location-cache.cc hbase-native-client/core/location-cache.cc index 66f3eb7..dab5deb 100644 --- hbase-native-client/core/location-cache.cc +++ 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 conf, std::shared_ptr cpu_executor, std::shared_ptr 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(buf->writableData()), &len, nullptr); if (zk_result != ZOK || len < 9) { LOG(ERROR) << "Error getting meta location."; diff --git hbase-native-client/core/location-cache.h hbase-native-client/core/location-cache.h index 22a8ad5..4d66e06 100644 --- hbase-native-client/core/location-cache.h +++ hbase-native-client/core/location-cache.h @@ -32,6 +32,7 @@ #include #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 conf, std::shared_ptr cpu_executor, std::shared_ptr cp); /** @@ -179,7 +180,14 @@ class LocationCache { const hbase::pb::TableName &tn); std::shared_ptr 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 conf_; std::string quorum_spec_; std::shared_ptr cpu_executor_; std::unique_ptr> meta_promise_; diff --git hbase-native-client/core/simple-client.cc hbase-native-client/core/simple-client.cc index dac0d10..3cd0a93 100644 --- hbase-native-client/core/simple-client.cc +++ 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(FLAGS_threads); auto io_pool = std::make_shared(5); + auto cp = std::make_shared(io_pool); + + // Configuration + auto conf = std::make_shared(); + 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(FLAGS_table); diff --git hbase-native-client/test-util/BUCK hbase-native-client/test-util/BUCK index e5e6ea2..c6e41f1 100644 --- hbase-native-client/test-util/BUCK +++ 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 hbase-native-client/test-util/test-util.h hbase-native-client/test-util/test-util.h index 2fc9d69..cc35511 100644 --- hbase-native-client/test-util/test-util.h +++ hbase-native-client/test-util/test-util.h @@ -24,6 +24,8 @@ #include #include +#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 conf() const { return conf_; } + private: folly::test::TemporaryDirectory temp_dir_; + std::shared_ptr conf_ = std::make_shared(); }; } // namespace hbase