From aeadce1e49ed57d3e0d823ec4689bea7ade01a13 Mon Sep 17 00:00:00 2001 From: Elliott Clark Date: Tue, 26 Apr 2016 14:51:06 -0700 Subject: [PATCH] HBASE-15718 Add on TableName implementation and tests Summary: Table name will be needed to look up a row in meta. So this patch adds on the implementation for creating that lookup row. It also adds tests for TableName Test Plan: Added on a unit test Differential Revision: https://reviews.facebook.net/D57285 --- hbase-native-client/Dockerfile | 4 +- hbase-native-client/bin/start-docker.sh | 1 - hbase-native-client/connection/client-handler.cc | 1 - hbase-native-client/core/BUCK | 69 +++++++++++++----------- hbase-native-client/core/meta-utils.cc | 31 +++++++++++ hbase-native-client/core/meta-utils.h | 30 +++++++++++ hbase-native-client/core/simple-client.cc | 4 +- hbase-native-client/core/table-name-test.cc | 50 +++++++++++++++++ hbase-native-client/core/table-name.cc | 15 ++++++ hbase-native-client/core/table-name.h | 25 ++++++++- hbase-native-client/if/Master.proto | 13 +++++ hbase-native-client/if/ZooKeeper.proto | 10 +++- 12 files changed, 214 insertions(+), 39 deletions(-) create mode 100644 hbase-native-client/core/meta-utils.cc create mode 100644 hbase-native-client/core/meta-utils.h create mode 100644 hbase-native-client/core/table-name-test.cc diff --git a/hbase-native-client/Dockerfile b/hbase-native-client/Dockerfile index 1524c56..8e33e74 100644 --- a/hbase-native-client/Dockerfile +++ b/hbase-native-client/Dockerfile @@ -15,13 +15,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM pjameson/buck-folly-watchman +FROM pjameson/buck-folly-watchman:20160425 ARG CC=/usr/bin/gcc-5 ARG CXX=/usr/bin/g++-5 ARG CFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -g -fno-omit-frame-pointer -O2 -pthread" ARG CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -g -fno-omit-frame-pointer -O2 -pthread" +ENV JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/" + RUN apt-get install -y vim maven inetutils-ping python-pip && \ pip install yapf && \ apt-get -qq clean && \ diff --git a/hbase-native-client/bin/start-docker.sh b/hbase-native-client/bin/start-docker.sh index 9cbd8b7..5c03eb9 100755 --- a/hbase-native-client/bin/start-docker.sh +++ b/hbase-native-client/bin/start-docker.sh @@ -53,7 +53,6 @@ docker build -t hbase_native . # After the image is built run the thing docker run -p 16010:16010/tcp \ - -e "JAVA_HOME=/usr/lib/jvm/java-8-oracle" \ -v ${BASE_DIR}/..:/usr/src/hbase \ -v ~/.m2:/root/.m2 \ -it hbase_native /bin/bash diff --git a/hbase-native-client/connection/client-handler.cc b/hbase-native-client/connection/client-handler.cc index 7b7794d..205993a7 100644 --- a/hbase-native-client/connection/client-handler.cc +++ b/hbase-native-client/connection/client-handler.cc @@ -60,7 +60,6 @@ void ClientHandler::read(Context *ctx, std::unique_ptr buf) { } } - // TODO(eclark): Figure out how to handle the // network errors that are going to come. Future ClientHandler::write(Context *ctx, Request r) { diff --git a/hbase-native-client/core/BUCK b/hbase-native-client/core/BUCK index 195fc5c..cf39a0e 100644 --- a/hbase-native-client/core/BUCK +++ b/hbase-native-client/core/BUCK @@ -16,44 +16,49 @@ # limitations under the License. # This is the main library. -cxx_library(name="core", - exported_headers=[ - "client.h", - "connection.h", - "get-request.h", - "get-result.h", - "hbase_macros.h", - "location-cache.h", - "table-name.h", - ], - srcs=[ - "client.cc", - "get-request.cc", - "get-result.cc", - "location-cache.cc", - "table-name.cc", - ], - deps=[ - "//connection:connection", - "//if:if", - "//serde:serde", - "//third-party:folly", - "//third-party:wangle", - "//third-party:zookeeper_mt", - ], - visibility=[ - 'PUBLIC', - ], ) - +cxx_library( + name="core", + exported_headers=[ + "client.h", + "connection.h", + "get-request.h", + "get-result.h", + "hbase_macros.h", + "location-cache.h", + "table-name.h", + # TODO: move this out of exported + # Once meta lookup works + "meta-utils.h", + ], + srcs=[ + "client.cc", + "get-request.cc", + "get-result.cc", + "location-cache.cc", + "meta-utils.cc", + "table-name.cc", + ], + deps=[ + "//connection:connection", + "//if:if", + "//serde:serde", + "//third-party:folly", + "//third-party:wangle", + "//third-party:zookeeper_mt", + ], + visibility=[ + 'PUBLIC', + ], ) cxx_test(name="location-cache-test", srcs=[ "test-env.cc", "location-cache-test.cc", ], - deps=[ - ":core", - ], + deps=[ ":core", ], run_test_separately=True, ) +cxx_test(name="table-name-test", + srcs=[ "table-name-test.cc",], + deps=[":core",], ) cxx_binary(name="simple-client", srcs=["simple-client.cc", ], deps=[":core", "//connection:connection"], ) diff --git a/hbase-native-client/core/meta-utils.cc b/hbase-native-client/core/meta-utils.cc new file mode 100644 index 0000000..7c7d45f --- /dev/null +++ b/hbase-native-client/core/meta-utils.cc @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "core/meta-utils.h" + +#include + +#include "core/table-name.h" + +using namespace hbase; + +std::string MetaUtil::region_lookup_rowkey(const TableName &tn, + const std::string &row) { + return folly::to(tn, ",", row, ",", "999999999999999999"); +} diff --git a/hbase-native-client/core/meta-utils.h b/hbase-native-client/core/meta-utils.h new file mode 100644 index 0000000..391d0ea --- /dev/null +++ b/hbase-native-client/core/meta-utils.h @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include + +namespace hbase { +class TableName; + +class MetaUtil { +public: + std::string region_lookup_rowkey(const TableName &tn, const std::string &row); +}; +} // namespace hbase diff --git a/hbase-native-client/core/simple-client.cc b/hbase-native-client/core/simple-client.cc index 5e6f82e..8b2fae5 100644 --- a/hbase-native-client/core/simple-client.cc +++ b/hbase-native-client/core/simple-client.cc @@ -69,10 +69,12 @@ int main(int argc, char *argv[]) { msg->mutable_region()->set_type( RegionSpecifier_RegionSpecifierType:: RegionSpecifier_RegionSpecifierType_ENCODED_REGION_NAME); + // What row. msg->mutable_get()->set_row(FLAGS_row); + // Send it. - r.set_msg(std::move(msg)); + r.set_msg(msg); auto resp = (*conn)(r).get(milliseconds(5000)); auto get_resp = std::static_pointer_cast(resp.response()); diff --git a/hbase-native-client/core/table-name-test.cc b/hbase-native-client/core/table-name-test.cc new file mode 100644 index 0000000..8aff375 --- /dev/null +++ b/hbase-native-client/core/table-name-test.cc @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include + +#include "core/table-name.h" + +using namespace hbase; + +TEST(TestTableName, TestToStringNoDefault) { + TableName tn{"TestTableName"}; + std::string result = folly::to(tn); + ASSERT_EQ(result.find("default"), std::string::npos); + ASSERT_EQ("TestTableName", result); +} +TEST(TestTableName, TestToStringIncludeNS) { + TableName tn{"hbase", "acl"}; + std::string result = folly::to(tn); + ASSERT_EQ(result.find("hbase"), 0); + ASSERT_EQ("hbase:acl", result); +} +TEST(TestTableName, TestIsDefault) { + TableName default_t1{"in_default"}; + ASSERT_TRUE(default_t1.is_default_name_space()); + + TableName default_t2{"default", "in_also"}; + ASSERT_TRUE(default_t2.is_default_name_space()); + + TableName non_default{"testing", "hmm"}; + ASSERT_FALSE(non_default.is_default_name_space()); +} diff --git a/hbase-native-client/core/table-name.cc b/hbase-native-client/core/table-name.cc index ffaaed0..33087fd 100644 --- a/hbase-native-client/core/table-name.cc +++ b/hbase-native-client/core/table-name.cc @@ -17,3 +17,18 @@ * */ #include "core/table-name.h" + +#include + +using namespace hbase; + +TableName::TableName(std::string table_name) + : name_space_("default"), table_(table_name) {} +TableName::TableName(std::string name_space, std::string table_name) + : name_space_(name_space), table_(table_name) {} +bool TableName::is_default_name_space() const { + return name_space_.length() == 0 || name_space_ == "default"; +} +bool TableName::operator==(const TableName &other) const { + return name_space_ == other.name_space_ && table_ == other.table_; +} diff --git a/hbase-native-client/core/table-name.h b/hbase-native-client/core/table-name.h index 37c3461..816f7da 100644 --- a/hbase-native-client/core/table-name.h +++ b/hbase-native-client/core/table-name.h @@ -21,12 +21,33 @@ #include #include +#include + namespace hbase { // This is the core class of a HBase client. class TableName { public: - explicit TableName(std::string tableName); - explicit TableName(std::string namespaceName, std::string tableName); + explicit TableName(std::string table_name); + explicit TableName(std::string name_space, std::string table_name); + + std::string name_space() const { return name_space_; }; + std::string table() const { return table_; }; + bool is_default_name_space() const; + bool operator==(const TableName &other) const; + +private: + std::string name_space_; + std::string table_; }; + +// Provide folly::to(TableName); +template void toAppend(const TableName &in, String *result) { + if (in.is_default_name_space()) { + folly::toAppend(in.table(), result); + } else { + folly::toAppend(in.name_space(), ':', in.table(), result); + } +} + } // namespace hbase diff --git a/hbase-native-client/if/Master.proto b/hbase-native-client/if/Master.proto index 1f7a3b7..ad8111e 100644 --- a/hbase-native-client/if/Master.proto +++ b/hbase-native-client/if/Master.proto @@ -288,6 +288,7 @@ message SetSplitOrMergeEnabledRequest { required bool enabled = 1; optional bool synchronous = 2; repeated MasterSwitchType switch_types = 3; + optional bool skip_lock = 4; } message SetSplitOrMergeEnabledResponse { @@ -302,6 +303,12 @@ message IsSplitOrMergeEnabledResponse { required bool enabled = 1; } +message ReleaseSplitOrMergeLockAndRollbackRequest { +} + +message ReleaseSplitOrMergeLockAndRollbackResponse { +} + message NormalizeRequest { } @@ -672,6 +679,12 @@ service MasterService { returns(IsSplitOrMergeEnabledResponse); /** + * Release lock and rollback state. + */ + rpc ReleaseSplitOrMergeLockAndRollback(ReleaseSplitOrMergeLockAndRollbackRequest) + returns(ReleaseSplitOrMergeLockAndRollbackResponse); + + /** * Run region normalizer. Can NOT run for various reasons. Check logs. */ rpc Normalize(NormalizeRequest) diff --git a/hbase-native-client/if/ZooKeeper.proto b/hbase-native-client/if/ZooKeeper.proto index 186d183..41c0e0e 100644 --- a/hbase-native-client/if/ZooKeeper.proto +++ b/hbase-native-client/if/ZooKeeper.proto @@ -165,4 +165,12 @@ message TableLock { */ message SwitchState { optional bool enabled = 1; -} \ No newline at end of file +} + +/** + * State for split and merge, used in hbck + */ +message SplitAndMergeState { + optional bool split_enabled = 1; + optional bool merge_enabled = 2; +} -- 2.8.0-rc2