Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8F39C200828 for ; Fri, 13 May 2016 23:37:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8E141160A22; Fri, 13 May 2016 21:37:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 90E6B160A1E for ; Fri, 13 May 2016 23:37:05 +0200 (CEST) Received: (qmail 55999 invoked by uid 500); 13 May 2016 21:36:57 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 54571 invoked by uid 99); 13 May 2016 21:36:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 May 2016 21:36:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 32740EAB44; Fri, 13 May 2016 21:36:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: eclark@apache.org To: commits@hbase.apache.org Date: Fri, 13 May 2016 21:37:24 -0000 Message-Id: <8d01996a51c74e03823733563ae74571@git.apache.org> In-Reply-To: <80b9b2e3d844456dab1a41ae325c5104@git.apache.org> References: <80b9b2e3d844456dab1a41ae325c5104@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [30/50] [abbrv] hbase git commit: HBASE-15718 Add on TableName implementation and tests archived-at: Fri, 13 May 2016 21:37:06 -0000 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 Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1cde692c Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1cde692c Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1cde692c Branch: refs/heads/HBASE-14850 Commit: 1cde692c5fc477f8d5b8b3295ba1568b1e9cb65a Parents: de5b5a2 Author: Elliott Clark Authored: Tue Apr 26 14:51:06 2016 -0700 Committer: Elliott Clark Committed: Fri May 13 14:36:28 2016 -0700 ---------------------------------------------------------------------- .../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 ++- 10 files changed, 211 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/1cde692c/hbase-native-client/connection/client-handler.cc ---------------------------------------------------------------------- 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) { http://git-wip-us.apache.org/repos/asf/hbase/blob/1cde692c/hbase-native-client/core/BUCK ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/BUCK b/hbase-native-client/core/BUCK index 195fc5c..9db6fda 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"], ) http://git-wip-us.apache.org/repos/asf/hbase/blob/1cde692c/hbase-native-client/core/meta-utils.cc ---------------------------------------------------------------------- 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"); +} http://git-wip-us.apache.org/repos/asf/hbase/blob/1cde692c/hbase-native-client/core/meta-utils.h ---------------------------------------------------------------------- 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/1cde692c/hbase-native-client/core/simple-client.cc ---------------------------------------------------------------------- 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()); http://git-wip-us.apache.org/repos/asf/hbase/blob/1cde692c/hbase-native-client/core/table-name-test.cc ---------------------------------------------------------------------- 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()); +} http://git-wip-us.apache.org/repos/asf/hbase/blob/1cde692c/hbase-native-client/core/table-name.cc ---------------------------------------------------------------------- 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_; +} http://git-wip-us.apache.org/repos/asf/hbase/blob/1cde692c/hbase-native-client/core/table-name.h ---------------------------------------------------------------------- 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/1cde692c/hbase-native-client/if/Master.proto ---------------------------------------------------------------------- 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) http://git-wip-us.apache.org/repos/asf/hbase/blob/1cde692c/hbase-native-client/if/ZooKeeper.proto ---------------------------------------------------------------------- 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; +}