├── .dockerignore ├── cmake ├── patches │ ├── zookeeper.3.4.x.buf │ └── wangle.v2020.05.18.00.cmake ├── DownloadProject.CMakeLists.cmake.in ├── DownloadProject.CMakeLists.autogen.in ├── FindGlog.cmake ├── FindGMock.cmake ├── FindGflags.cmake ├── protobuf │ └── local │ │ └── FindProtobuf.cmake ├── FindSasl2.cmake ├── zookeeper │ ├── local │ │ └── FindZookeeper.cmake │ └── system │ │ └── FindZookeeper.cmake ├── FindMaven.cmake ├── wangle │ ├── local │ │ └── FindWangle.cmake │ └── system │ │ └── FindWangle.cmake ├── FindKrb5.cmake ├── ExecuteMaven.cmake ├── boost │ └── local │ │ └── FindBoost.cmake ├── folly │ ├── local │ │ └── FindFolly.cmake │ └── system │ │ └── FindFolly.cmake ├── FindDoubleConversion.cmake ├── DownloadZookeeper.cmake ├── DownloadProtobuf.cmake ├── FindLibEvent.cmake ├── DownloadBoost.cmake ├── DownloadWangle.cmake └── DownloadFolly.cmake ├── NOTICE ├── .gitignore ├── src ├── hbase │ ├── connection │ │ ├── rpc-fault-injector.cc │ │ ├── request.cc │ │ └── pipeline.cc │ ├── client │ │ ├── hbase-rpc-controller.cc │ │ ├── async-rpc-retrying-caller-factory.cc │ │ ├── append.cc │ │ ├── client.cc │ │ ├── increment.cc │ │ ├── region-result.cc │ │ ├── put.cc │ │ ├── mutation.cc │ │ ├── zk-util.cc │ │ ├── time-range.cc │ │ └── keyvalue-codec.cc │ ├── utils │ │ ├── connection-util.cc │ │ ├── bytes-util.cc │ │ └── user-util.cc │ └── serde │ │ └── zk.cc └── test │ ├── user-util-test.cc │ ├── concurrent-map-test.cc │ ├── server-name-test.cc │ ├── time-range-test.cc │ ├── region-info-deserializer-test.cc │ ├── table-name-test.cc │ ├── zk-util-test.cc │ ├── client-deserializer-test.cc │ ├── exception-test.cc │ ├── bytes-util-test.cc │ └── client-serializer-test.cc ├── bin ├── stop-local-hbase.sh ├── format-code.sh ├── start-local-hbase.sh ├── start-docker.sh ├── cpplint.sh └── jenkins │ └── gather_machine_environment.sh ├── include └── hbase │ ├── connection │ ├── service.h │ ├── rpc-fault-injector-inl.h │ ├── rpc-fault-injector.h │ ├── rpc-test-server-handler.h │ ├── sasl-util.h │ ├── pipeline.h │ ├── rpc-test-server.h │ ├── client-dispatcher.h │ ├── client-handler.h │ └── response.h │ ├── utils │ ├── optional.h │ ├── sys-util.h │ ├── user-util.h │ ├── connection-util.h │ ├── bytes-util.h │ └── time-util.h │ ├── test-util │ ├── test-util.h │ └── mini-cluster-util.h │ ├── client │ ├── action.h │ ├── result-scanner.h │ ├── query.h │ ├── region-request.h │ ├── append.h │ ├── region-result.h │ ├── increment.h │ ├── hbase-rpc-controller.h │ ├── zk-util.h │ ├── time-range.h │ ├── row.h │ ├── put.h │ ├── client.h │ ├── server-request.h │ ├── cell.h │ ├── region-location.h │ ├── async-region-locator.h │ ├── meta-utils.h │ ├── response-converter.h │ └── multi-response.h │ ├── serde │ ├── cell-scanner.h │ ├── region-info.h │ ├── server-name.h │ ├── zk.h │ ├── codec.h │ ├── table-name.h │ └── cell-outputstream.h │ └── security │ └── user.h ├── docker-files └── krb5.conf ├── .asf.yaml ├── README.md └── BUILDING.md /.dockerignore: -------------------------------------------------------------------------------- 1 | buck-out 2 | .buckd 3 | -------------------------------------------------------------------------------- /cmake/patches/zookeeper.3.4.x.buf: -------------------------------------------------------------------------------- 1 | 3480c3480 2 | < static char buf[128]; 3 | --- 4 | > static char buf[128+6] = {0}; 5 | -------------------------------------------------------------------------------- /cmake/patches/wangle.v2020.05.18.00.cmake: -------------------------------------------------------------------------------- 1 | 49c49 2 | < find_package(folly CONFIG REQUIRED) 3 | --- 4 | > find_package(Folly REQUIRED) 5 | 51c51 6 | < find_package(fizz CONFIG REQUIRED) 7 | --- 8 | > find_package(Fizz REQUIRED) 9 | 10 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache HBase 2 | Copyright 2020 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | This includes the following derived works from https://github.com/Crascit/DownloadProject , 8 | which is distributed under an MIT license. 9 | DownloadProject.cmake 10 | DownlaodProjects.CmakeLists.autogen.in 11 | DownlaodProjects.CmakeLists.cmake.in 12 | 13 | This includes the following derived works from https://github.com/facebook/folly for details, 14 | which is distributed under an MIT license. 15 | DownloadDoubleConversion.cmake 16 | -------------------------------------------------------------------------------- /cmake/DownloadProject.CMakeLists.cmake.in: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved MIT License. See accompanying 2 | # file LICENSE or https://github.com/Crascit/DownloadProject for details. 3 | 4 | cmake_minimum_required(VERSION 2.8.2) 5 | 6 | project(${DL_ARGS_PROJ}-download NONE) 7 | 8 | include(ExternalProject) 9 | ExternalProject_Add(${DL_ARGS_PROJ}-download 10 | ${DL_ARGS_UNPARSED_ARGUMENTS} 11 | SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" 12 | BINARY_DIR "${DL_ARGS_BINARY_DIR}" 13 | CONFIGURE_COMMAND "" 14 | BUILD_COMMAND "" 15 | INSTALL_COMMAND "" 16 | TEST_COMMAND "" 17 | ) 18 | -------------------------------------------------------------------------------- /cmake/DownloadProject.CMakeLists.autogen.in: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved MIT License. See accompanying 2 | # file LICENSE or https://github.com/Crascit/DownloadProject for details. 3 | 4 | cmake_minimum_required(VERSION 2.8.2) 5 | 6 | project(${DL_ARGS_PROJ}-download NONE) 7 | 8 | include(ExternalProject) 9 | ExternalProject_Add(${DL_ARGS_PROJ}-download 10 | ${DL_ARGS_UNPARSED_ARGUMENTS} 11 | SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" 12 | BUILD_IN_SOURCE true 13 | CONFIGURE_COMMAND "./autogen.sh" 14 | COMMAND ./configure --prefix=${DL_ARGS_BINARY_DIR} 15 | "CFLAGS=-fPIC" 16 | "CXXFLAGS=${CMAKE_CXX_FLAGS} -fPIC" 17 | UPDATE_COMMAND "" 18 | 19 | ) 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | 9 | # Compiled Static libraries 10 | *.lai 11 | *.la 12 | *.a 13 | 14 | #python 15 | *.pyc 16 | 17 | *.swp 18 | 19 | # build directories 20 | build*/* 21 | cmake-build-debug/* 22 | dependencies/* 23 | 24 | # Thirdparty dirs 25 | third-party/* 26 | /gcc-debug/ 27 | 28 | # Generated files 29 | src/hbase/utils/version.h 30 | 31 | # Tests 32 | *-test 33 | src/test/target/* 34 | 35 | # Executables 36 | load-client 37 | simple-client 38 | 39 | # CMake temporary files 40 | CMakeCache.txt 41 | CMakeFiles 42 | Makefile 43 | cmake_install.cmake 44 | CTestTestfile.cmake 45 | 46 | # Copied from hbase-common at build-time 47 | include/hbase/utils/version.h 48 | 49 | .idea/* 50 | -------------------------------------------------------------------------------- /src/hbase/connection/rpc-fault-injector.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #include "hbase/connection/rpc-fault-injector.h" 20 | 21 | namespace hbase {} /* namespace hbase */ 22 | -------------------------------------------------------------------------------- /src/hbase/client/hbase-rpc-controller.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/client/hbase-rpc-controller.h" 21 | 22 | namespace hbase {} /* namespace hbase */ 23 | -------------------------------------------------------------------------------- /src/hbase/client/async-rpc-retrying-caller-factory.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/client/async-rpc-retrying-caller-factory.h" 21 | 22 | namespace hbase {} // namespace hbase 23 | -------------------------------------------------------------------------------- /bin/stop-local-hbase.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ## 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | ps aux | grep proc_master | awk '{print $2}' | xargs kill -9 21 | 22 | while [ $(curl -s -o /dev/null -I -w "%{http_code}" http://localhost:16010) == "200" ] 23 | do 24 | printf "Waiting for local HBase cluster to stop\n" 25 | sleep 1 26 | done 27 | -------------------------------------------------------------------------------- /cmake/FindGlog.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | find_path(GLOG_INCLUDE_DIR glog/logging.h) 18 | # make sure we don't accidentally pick up a different version 19 | find_library(GLOG_SHARED_LIB glog) 20 | find_library(GLOG_STATIC_LIB libglog.a) 21 | include(FindPackageHandleStandardArgs) 22 | find_package_handle_standard_args(GLOG REQUIRED_VARS 23 | GLOG_SHARED_LIB GLOG_STATIC_LIB GLOG_INCLUDE_DIR) 24 | -------------------------------------------------------------------------------- /src/hbase/utils/connection-util.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/utils/connection-util.h" 21 | 22 | namespace hbase { 23 | 24 | const std::vector ConnectionUtils::kRetryBackoff = {1, 2, 3, 5, 10, 20, 40, 25 | 100, 100, 100, 100, 200, 200}; 26 | } /* namespace hbase */ 27 | -------------------------------------------------------------------------------- /cmake/FindGMock.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | find_path(GMOCK_INCLUDE_DIR gmock/gmock.h) 18 | # make sure we don't accidentally pick up a different version 19 | find_library(GMOCK_SHARED_LIB gmock) 20 | find_library(GMOCK_STATIC_LIB libgmock.a) 21 | include(FindPackageHandleStandardArgs) 22 | find_package_handle_standard_args(GMOCK REQUIRED_VARS 23 | GMOCK_SHARED_LIB GMOCK_STATIC_LIB GMOCK_INCLUDE_DIR) 24 | -------------------------------------------------------------------------------- /cmake/FindGflags.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h) 18 | # make sure we don't accidentally pick up a different version 19 | find_library(GFLAGS_SHARED_LIB gflags) 20 | find_library(GFLAGS_STATIC_LIB libgflags.a) 21 | include(FindPackageHandleStandardArgs) 22 | find_package_handle_standard_args(GFLAGS REQUIRED_VARS 23 | GFLAGS_SHARED_LIB GFLAGS_STATIC_LIB GFLAGS_INCLUDE_DIR) 24 | -------------------------------------------------------------------------------- /include/hbase/connection/service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "hbase/connection/request.h" 26 | #include "hbase/connection/response.h" 27 | 28 | namespace hbase { 29 | using HBaseService = wangle::Service, std::unique_ptr>; 30 | } // namespace hbase 31 | -------------------------------------------------------------------------------- /include/hbase/utils/optional.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | namespace hbase { 26 | 27 | /** 28 | * An optional value that may or may not be present. 29 | */ 30 | template 31 | using optional = boost::optional; 32 | 33 | const boost::none_t none = boost::none; 34 | 35 | } /* namespace hbase */ 36 | -------------------------------------------------------------------------------- /cmake/protobuf/local/FindProtobuf.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Stubs to allow us to Protobuf 19 | 20 | 21 | set(PROTOBUF_LIBS "${PROTOBUF_DIR}/lib/libprotobuf.a" "${PROTOBUF_DIR}/lib/libprotoc.a" CACHE STRING "" FORCE) 22 | set(PROTOBUF_LIBRARY "${PROTOBUF_DIR}/lib/libprotobuf.a" CACHE STRING "" FORCE) 23 | set(PROTOBUF_INCLUDE_DIRS "${PROTOBUF_DIR}/include" CACHE STRING "" FORCE) 24 | set(PROTOBUF_FOUND TRUE CACHE STRING "" FORCE) 25 | -------------------------------------------------------------------------------- /cmake/FindSasl2.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | include(CheckSymbolExists) 20 | find_path ( 21 | SASL_INCLUDE_DIRS NAMES sasl/sasl.h 22 | PATHS /include /usr/include /usr/local/include /usr/share/include) 23 | find_library( 24 | SASL_LIBS NAMES sasl2 25 | PATHS /usr/lib /lib /usr/local/lib /usr/lib/x86_64-linux-gnu/) 26 | if (SASL_INCLUDE_DIRS AND SASL_LIBS) 27 | set (SASL_FOUND 1) 28 | message("-- LibSASL found, ${SASL_LIBS}") 29 | endif () 30 | -------------------------------------------------------------------------------- /cmake/zookeeper/local/FindZookeeper.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | set(ZOOKEEPER_INCLUDE_DIRS "${ZOOKEEPER_DIR}/include" CACHE STRING "" FORCE) 18 | set(ZOOKEEPER_LIBRARIES "${ZOOKEEPER_DIR}/lib/libzookeeper_mt.a" CACHE STRING "" FORCE) 19 | include_directories(${ZOOKEEPER_INCLUDE_DIRS}) 20 | set(ZOOKEEPER_FOUND TRUE CACHE STRING "" FORCE) 21 | 22 | mark_as_advanced( 23 | ZOOKEEPER_FOUND 24 | ZOOKEEPER_INCLUDE_DIRS 25 | ZOOKEEPER_LIBRARIES 26 | ) 27 | message("-- Zookeeper found, ${ZOOKEEPER_LIBRARIES}") -------------------------------------------------------------------------------- /bin/format-code.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | set -euo pipefail 19 | IFS=$'\n\t' 20 | 21 | declare -a MODULES=( client connection exceptions security serde utils test-util ) 22 | 23 | for m in ${MODULES[@]}; do 24 | find src/hbase/$m -name "*.h" -or -name "*.cc" | xargs -P8 clang-format -i --style='{BasedOnStyle: Google, ColumnLimit: 100}' 25 | find src/hbase/$m -name "BUCK" | xargs -P8 yapf -i --style=google 26 | done 27 | 28 | find third-party -name "BUCK" | xargs -P8 yapf -i --style=google 29 | -------------------------------------------------------------------------------- /src/test/user-util-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "hbase/utils/user-util.h" 24 | #include "hbase/test-util/test-util.h" 25 | 26 | using namespace std; 27 | using namespace hbase; 28 | 29 | TEST(TestUserUtil, TestGetSomething) { 30 | UserUtil u_util; 31 | string name = u_util.user_name(false); 32 | 33 | // TODO shell out to whoami to check this. 34 | ASSERT_GT(name.length(), 0); 35 | } 36 | 37 | HBASE_TEST_MAIN() 38 | -------------------------------------------------------------------------------- /docker-files/krb5.conf: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | [logging] 20 | default = FILE:/var/log/krb5libs.log 21 | kdc = FILE:/var/log/krb5kdc.log 22 | admin_server = FILE:/var/log/kadmind.log 23 | 24 | [libdefaults] 25 | default_realm = EXAMPLE.COM 26 | dns_lookup_realm = false 27 | dns_lookup_kdc = false 28 | ticket_lifetime = 24h 29 | renew_lifetime = 7d 30 | forwardable = true 31 | rdns = false 32 | 33 | [realms] 34 | EXAMPLE.COM = { 35 | kdc = localhost 36 | admin_server = localhost 37 | } 38 | [domain_realm] 39 | -------------------------------------------------------------------------------- /bin/start-local-hbase.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | 19 | # Clean up from any other tests. 20 | rm -rf /tmp/hbase-* 21 | 22 | # Start the master/regionservers. 23 | T_DIR=${1:-"/tmp/hbase-testing"} 24 | $PWD/../bin/start-hbase.sh -Dhbase.tmp.dir="${T_DIR}" 25 | 26 | until [ $(curl -s -o /dev/null -I -w "%{http_code}" http://localhost:16010/jmx) == "200" ] 27 | do 28 | printf "Waiting for local HBase cluster to start\n" 29 | sleep 1 30 | done 31 | 32 | # This sucks, but master can easily be up and meta not be assigned yet. 33 | sleep 10 34 | -------------------------------------------------------------------------------- /include/hbase/utils/sys-util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace hbase { 25 | 26 | class SysUtil { 27 | public: 28 | template 29 | static constexpr bool InstanceOf(const DERIVED& object) { 30 | return !dynamic_cast(&object); 31 | } 32 | 33 | template 34 | static constexpr bool InstanceOf() { 35 | return std::is_base_of(); 36 | } 37 | }; 38 | 39 | } /* namespace hbase */ 40 | -------------------------------------------------------------------------------- /cmake/FindMaven.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | set (MAVEN_HINT /usr/bin CACHE STRING "Maven installation directory") 19 | 20 | if (WIN32) 21 | ## expect it to be in PATH 22 | find_program(MAVEN_EXECUTABLE NAMES mvn.bat mvn) 23 | else() 24 | find_program(MAVEN_EXECUTABLE NAMES mvn 25 | HINTS ENV${MAVEN_HINT}/mvn ${MAVEN_HINT}/mvn) 26 | endif() 27 | 28 | include(FindPackageHandleStandardArgs) 29 | find_package_handle_standard_args (Maven 30 | FOUND_VAR MAVEN_FOUND 31 | REQUIRED_VARS MAVEN_EXECUTABLE 32 | ) 33 | 34 | mark_as_advanced(MAVEN_FOUND MAVEN_EXECUTABLE) 35 | -------------------------------------------------------------------------------- /cmake/wangle/local/FindWangle.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | # Stubs to allow us to find folly libs 21 | 22 | set(WANGLE_FOUND "true" CACHE STRING "" FORCE) 23 | set(WANGLE_ROOT_DIR "${WANGLE_ROOT_DIR}" CACHE STRING "" FORCE) 24 | set(WANGLE_INCLUDE_DIR "${WANGLE_ROOT_DIR}/include" CACHE STRING "" FORCE) 25 | set(WANGLE_LIBRARIES "${WANGLE_ROOT_DIR}/lib/${BYPRODUCT_PREFIX}wangle${BYPRODUCT_SUFFIX}" CACHE STRING "" FORCE) 26 | 27 | mark_as_advanced( 28 | WANGLE_ROOT_DIR 29 | WANGLE_LIBRARIES 30 | WANGLE_INCLUDE_DIR 31 | ) 32 | message("-- Wangle found, ${WANGLE_LIBRARIES}") -------------------------------------------------------------------------------- /src/test/concurrent-map-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "hbase/test-util/test-util.h" 24 | #include "hbase/utils/concurrent-map.h" 25 | 26 | using hbase::concurrent_map; 27 | 28 | TEST(TestConcurrentMap, TestFindAndErase) { 29 | concurrent_map map{500}; 30 | 31 | map.insert(std::make_pair("foo", "bar")); 32 | auto prev = map.find_and_erase("foo"); 33 | ASSERT_EQ("bar", prev); 34 | 35 | ASSERT_EQ(map.end(), map.find("foo")); 36 | } 37 | 38 | HBASE_TEST_MAIN() 39 | -------------------------------------------------------------------------------- /include/hbase/connection/rpc-fault-injector-inl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | namespace hbase { 22 | 23 | template 24 | std::shared_ptr RpcFaultInjector::instance = std::make_shared(); 25 | 26 | template 27 | RpcFaultInjector::RpcFaultInjector() {} 28 | 29 | template 30 | RpcFaultInjector::~RpcFaultInjector() {} 31 | 32 | template 33 | std::shared_ptr RpcFaultInjector::Get() { 34 | return instance; 35 | } 36 | 37 | template 38 | void RpcFaultInjector::Set(std::shared_ptr injector) { 39 | instance = injector; 40 | } 41 | } /* namespace hbase */ 42 | -------------------------------------------------------------------------------- /include/hbase/test-util/test-util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace hbase { 26 | // main() function intended to be used in tests. This initializes the needed gflags/glog libraries as needed. 27 | #define HBASE_TEST_MAIN() \ 28 | int main(int argc, char** argv) { \ 29 | ::testing::InitGoogleTest(&argc, argv); \ 30 | gflags::ParseCommandLineFlags(&argc, &argv, true);\ 31 | google::InstallFailureSignalHandler();\ 32 | google::InitGoogleLogging(argv[0]);\ 33 | return RUN_ALL_TESTS(); \ 34 | } 35 | } // namespace hbase 36 | -------------------------------------------------------------------------------- /cmake/FindKrb5.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | find_path(KRB5_ROOT_DIR 20 | NAMES include/krb5/krb5.h 21 | ) 22 | find_library(KRB5_LIBRARIES 23 | NAMES krb5 24 | HINTS ${KRB5_ROOT_DIR}/lib 25 | ) 26 | find_path(KRB5_INCLUDE_DIR 27 | NAMES krb5/krb5.h 28 | HINTS ${KRB5_ROOT_DIR}/include 29 | ) 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(krb5 DEFAULT_MSG 32 | KRB5_LIBRARIES 33 | KRB5_INCLUDE_DIR 34 | ) 35 | if (KRB5_LIBRARIES) 36 | set(KRB5_FOUND "true") 37 | message("-- KRB5 Libs Found, ${KRB5_LIBRARIES}") 38 | endif() 39 | mark_as_advanced( 40 | KRB5_ROOT_DIR 41 | KRB5_LIBRARIES 42 | KRB5_INCLUDE_DIR 43 | ) 44 | -------------------------------------------------------------------------------- /cmake/ExecuteMaven.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | ## SOURCE_DIR is typically location of the root pom 19 | ## DEST_OUTPUT is the destination output variable 20 | ## DEST_RESULT is the destination result variable 21 | 22 | function(execute_maven SOURCE_DIR DEST_OUTPUT DEST_RESULT) 23 | 24 | execute_process( 25 | COMMAND "${MAVEN_EXECUTABLE}" "-q" "package" "-DskipTests" "-Denforcer.skip=true" 26 | WORKING_DIRECTORY "${SOURCE_DIR}" 27 | RESULT_VARIABLE result 28 | OUTPUT_VARIABLE output 29 | ERROR_VARIABLE error_variable 30 | ) 31 | 32 | set(${DEST_RESULT} $result PARENT_SCOPE) 33 | set(${DEST_OUTPUT} $output PARENT_SCOPE) 34 | 35 | endfunction(execute_maven) -------------------------------------------------------------------------------- /cmake/boost/local/FindBoost.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Stubs to allow us to find Boost libs 19 | 20 | set(Boost_INCLUDE_DIRS "${BOOST_ROOT}/include" CACHE STRING "" FORCE) 21 | set(Boost_INCLUDE_DIR "${BOOST_ROOT}/include" CACHE STRING "" FORCE) 22 | 23 | set(Boost_LIBRARIES "" CACHE STRING "" FORCE) 24 | foreach(COMPONENT ${Boost_FIND_COMPONENTS}) 25 | list(APPEND Boost_LIBRARIES "${BOOST_ROOT}/lib/${BYPRODUCT_PREFIX}boost_${COMPONENT}${BYPRODUCT_SUFFIX}") 26 | endforeach() 27 | 28 | set(Boost_FOUND "true" CACHE STRING "" FORCE) 29 | 30 | mark_as_advanced( 31 | Boost_FOUND 32 | Boost_INCLUDE_DIR 33 | Boost_INCLUDE_DIRS 34 | Boost_LIBRARIES 35 | ) 36 | message("-- Boost found, ${Boost_LIBRARIES}") 37 | -------------------------------------------------------------------------------- /include/hbase/client/action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include "hbase/client/row.h" 24 | 25 | namespace hbase { 26 | class Action { 27 | public: 28 | Action(std::shared_ptr action, int32_t original_index) 29 | : action_(action), original_index_(original_index) {} 30 | ~Action() {} 31 | 32 | int32_t original_index() const { return original_index_; } 33 | 34 | std::shared_ptr action() const { return action_; } 35 | 36 | private: 37 | std::shared_ptr action_; 38 | int32_t original_index_; 39 | int64_t nonce_ = -1; 40 | int32_t replica_id_ = -1; 41 | }; 42 | 43 | } /* namespace hbase */ 44 | -------------------------------------------------------------------------------- /include/hbase/client/result-scanner.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "hbase/client/cell.h" 30 | #include "hbase/client/result.h" 31 | 32 | namespace hbase { 33 | 34 | /** 35 | * Interface for client-side scanning. Use Table to obtain instances. 36 | */ 37 | class ResultScanner { 38 | // TODO: should we implement forward iterators? 39 | 40 | public: 41 | virtual ~ResultScanner() {} 42 | 43 | virtual void Close() = 0; 44 | 45 | virtual std::shared_ptr Next() = 0; 46 | }; 47 | } /* namespace hbase */ 48 | -------------------------------------------------------------------------------- /include/hbase/serde/cell-scanner.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | #include 22 | #include 23 | 24 | namespace hbase { 25 | 26 | class Cell; 27 | 28 | /** 29 | * @brief Interface for iterating over a sequence of Cells 30 | */ 31 | class CellScanner { 32 | public: 33 | virtual ~CellScanner() {} 34 | 35 | /** 36 | * @brief This method will be used to iterate the cells. 37 | * Typical usage will be :- 38 | * while(cell_scanner.Advance()){ 39 | * auto current_cell = cell_scanner.Current(); 40 | * } 41 | */ 42 | virtual bool Advance() = 0; 43 | 44 | /** 45 | * @brief returns the current cell 46 | */ 47 | virtual const std::shared_ptr Current() const = 0; 48 | }; 49 | 50 | } /* namespace hbase */ 51 | -------------------------------------------------------------------------------- /include/hbase/serde/region-info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "HBase.pb.h" 28 | 29 | namespace hbase { 30 | namespace pb { 31 | template 32 | void parseTo(String in, RegionInfo &out) { 33 | // TODO(eclark): there has to be something better. 34 | std::string s = folly::to(in); 35 | 36 | if (!boost::starts_with(s, "PBUF")) { 37 | throw std::runtime_error("Region Info field doesn't contain preamble"); 38 | } 39 | if (!out.ParseFromArray(s.data() + 4, s.size() - 4)) { 40 | throw std::runtime_error("Bad protobuf for RegionInfo"); 41 | } 42 | } 43 | } // namespace pb 44 | } // namespace hbase 45 | -------------------------------------------------------------------------------- /cmake/wangle/system/FindWangle.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | find_path(WANGLE_ROOT_DIR 20 | NAMES include/wangle/acceptor/Acceptor.h 21 | ) 22 | find_library(WANGLE_LIBRARIES 23 | NAMES wangle 24 | HINTS ${WANGLE_ROOT_DIR}/lib /usr/lib/ /usr/local/lib/ 25 | ) 26 | find_path(WANGLE_INCLUDE_DIR 27 | NAMES wangle/acceptor/Acceptor.h 28 | HINTS ${WANGLE_ROOT_DIR}/include /usr/local/include/ 29 | ) 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(WANGLE DEFAULT_MSG 32 | WANGLE_LIBRARIES 33 | WANGLE_INCLUDE_DIR 34 | ) 35 | mark_as_advanced( 36 | WANGLE_ROOT_DIR 37 | WANGLE_LIBRARIES 38 | WANGLE_INCLUDE_DIR 39 | ) 40 | if (WANGLE_LIBRARIES) 41 | set(WANGLE_FOUND "true") 42 | message("-- Wangle found, ${WANGLE_LIBRARIES}") 43 | endif(WANGLE_LIBRARIES) 44 | -------------------------------------------------------------------------------- /cmake/folly/local/FindFolly.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Stubs to allow us to find folly libs 19 | 20 | set(FOLLY_FOUND "true" CACHE STRING "" FORCE) 21 | set(FOLLY_INCLUDE_DIRS "${FOLLY_ROOT_DIR}/include" CACHE STRING "" FORCE) 22 | set(FOLLY_INCLUDE_DIR "${FOLLY_ROOT_DIR}/include" CACHE STRING "" FORCE) 23 | ## Given that folly is an older dependency, and the way it is built has evolved, newer 24 | ## versions of folly won't require an SO. For now it is far easier to link against the .so (BYPRODUCT_SHARED_SUFFIX) 25 | set(FOLLY_LIBRARIES "${FOLLY_ROOT_DIR}/lib/${BYPRODUCT_PREFIX}folly${BYPRODUCT_SHARED_SUFFIX}" CACHE STRING "" FORCE) 26 | 27 | 28 | 29 | mark_as_advanced( 30 | FOLLY_INCLUDE 31 | FOLLY_INCLUDE_DIRS 32 | FOLLY_INCLUDE_DIR 33 | FOLLY_LIBRARIES 34 | ) 35 | message("-- FOLLY found, ${FOLLY_LIBRARIES}") -------------------------------------------------------------------------------- /include/hbase/serde/server-name.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "HBase.pb.h" 28 | 29 | namespace hbase { 30 | namespace pb { 31 | 32 | template 33 | void parseTo(String in, ServerName &out) { 34 | // TODO see about getting rsplit into folly. 35 | std::string s = folly::to(in); 36 | 37 | auto delim = s.rfind(":"); 38 | if (delim == std::string::npos) { 39 | throw std::runtime_error("Couldn't parse server name"); 40 | } 41 | out.set_host_name(s.substr(0, delim)); 42 | // Now keep everything after the : (delim + 1) to the end. 43 | out.set_port(folly::to(s.substr(delim + 1))); 44 | } 45 | 46 | } // namespace pb 47 | } // namespace hbase 48 | -------------------------------------------------------------------------------- /include/hbase/security/user.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | #include 24 | #include "hbase/client/configuration.h" 25 | 26 | namespace hbase { 27 | namespace security { 28 | static constexpr const char* kKerberos = "kerberos"; 29 | class User { 30 | public: 31 | explicit User(const std::string& user_name) : user_name_(user_name) {} 32 | virtual ~User() = default; 33 | 34 | std::string user_name() { return user_name_; } 35 | 36 | static std::shared_ptr defaultUser() { return std::make_shared("__drwho"); } 37 | 38 | static bool IsSecurityEnabled(const Configuration& conf) { 39 | return conf.Get("hbase.security.authentication", "").compare(kKerberos) == 0; 40 | } 41 | 42 | private: 43 | std::string user_name_; 44 | }; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /cmake/FindDoubleConversion.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Finds libdouble-conversion. 16 | # 17 | # DEFINE DOUBLE_CONVERSION_ROOT_DIR to provide a hint 18 | # This module defines: 19 | # DOUBLE_CONVERSION_INCLUDE_DIR 20 | # DOUBLE_CONVERSION_LIBRARY 21 | # 22 | 23 | find_path(DOUBLE_CONVERSION_INCLUDE_DIR double-conversion/double-conversion.h HINTS ${DOUBLE_CONVERSION_ROOT_DIR}/include) 24 | find_library(DOUBLE_CONVERSION_LIBRARY 25 | NAMES double-conversion 26 | HINTS ${DOUBLE_CONVERSION_ROOT_DIR}/lib /usr/lib/ /usr/local/lib/ /usr/lib/x86_64-linux-gnu/) 27 | 28 | include(FindPackageHandleStandardArgs) 29 | FIND_PACKAGE_HANDLE_STANDARD_ARGS( 30 | DOUBLE_CONVERSION DEFAULT_MSG 31 | DOUBLE_CONVERSION_LIBRARY DOUBLE_CONVERSION_INCLUDE_DIR) 32 | 33 | if (NOT DOUBLE_CONVERSION_FOUND) 34 | message(STATUS "Using third-party bundled double-conversion") 35 | else() 36 | message(STATUS "Found double-conversion: ${DOUBLE_CONVERSION_LIBRARY}") 37 | endif (NOT DOUBLE_CONVERSION_FOUND) 38 | 39 | mark_as_advanced(DOUBLE_CONVERSION_INCLUDE_DIR DOUBLE_CONVERSION_LIBRARY) -------------------------------------------------------------------------------- /include/hbase/client/query.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | #include "hbase/client/filter.h" 25 | 26 | namespace hbase { 27 | 28 | /** 29 | * Base class for read RPC calls (Get / Scan). 30 | */ 31 | class Query { 32 | public: 33 | Query() = default; 34 | Query(const Query &query) { 35 | // filter can be a custom subclass of Filter, so we do not do a deep copy here. 36 | filter_ = query.filter_; 37 | } 38 | 39 | Query &operator=(const Query &query) { 40 | filter_ = query.filter_; 41 | return *this; 42 | } 43 | 44 | virtual ~Query() {} 45 | 46 | void SetFilter(std::shared_ptr filter) { filter_ = filter; } 47 | 48 | const std::shared_ptr filter() const { return filter_; } 49 | 50 | protected: 51 | std::shared_ptr filter_ = nullptr; 52 | }; 53 | 54 | } // namespace hbase 55 | -------------------------------------------------------------------------------- /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # This file controls the integration of HBase project with ASF infrastructure. Refer to 18 | # https://cwiki.apache.org/confluence/display/INFRA/.asf.yaml+features+for+git+repositories for 19 | # details. Be careful when changing the contents of this file since it may affect many developers 20 | # of the project and make sure to discuss the changes with dev@ before committing. 21 | 22 | github: 23 | description: "Apache HBase Native Client" 24 | homepage: https://hbase.apache.org/ 25 | labels: 26 | - database 27 | - java 28 | - hbase 29 | features: 30 | wiki: false 31 | issues: false 32 | projects: false 33 | enabled_merge_buttons: 34 | squash: true 35 | merge: false 36 | rebase: true 37 | notifications: 38 | commits: commits@hbase.apache.org 39 | issues: issues@hbase.apache.org 40 | pullrequests: issues@hbase.apache.org 41 | jira_options: link 42 | -------------------------------------------------------------------------------- /include/hbase/serde/zk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | namespace google { 22 | namespace protobuf { 23 | class Message; 24 | } 25 | } 26 | namespace folly { 27 | class IOBuf; 28 | } 29 | 30 | namespace hbase { 31 | 32 | /** @brief A class to convert data from ZooKeeper to other formats. 33 | * 34 | * This class will convert data to and from Zookeeper into protobuf objects. 35 | * 36 | */ 37 | class ZkDeserializer { 38 | public: 39 | /** 40 | * Merge the data from a buffer into a given message. 41 | * 42 | * @param buf Naked pointer to iobuf containing data read from zookeeper. 43 | * @param out Naked pointer into which the data will be merged. The message 44 | * should be the correct type. 45 | * @return returns true if the parsing was successful. 46 | */ 47 | bool Parse(folly::IOBuf *buf, google::protobuf::Message *out); 48 | }; 49 | } // namespace hbase 50 | -------------------------------------------------------------------------------- /src/test/server-name-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include 21 | 22 | #include "hbase/serde/server-name.h" 23 | #include "hbase/test-util/test-util.h" 24 | 25 | using hbase::pb::ServerName; 26 | 27 | TEST(TestServerName, TestMakeServerName) { 28 | auto sn = folly::to("test:123"); 29 | 30 | ASSERT_EQ("test", sn.host_name()); 31 | ASSERT_EQ(123, sn.port()); 32 | } 33 | 34 | TEST(TestServerName, TestIps) { 35 | auto sn = folly::to("127.0.0.1:999"); 36 | ASSERT_EQ("127.0.0.1", sn.host_name()); 37 | ASSERT_EQ(999, sn.port()); 38 | } 39 | 40 | TEST(TestServerName, TestThrow) { ASSERT_ANY_THROW(folly::to("Ther's no colon here")); } 41 | 42 | TEST(TestServerName, TestIPV6) { 43 | auto sn = folly::to("[::::1]:123"); 44 | 45 | ASSERT_EQ("[::::1]", sn.host_name()); 46 | ASSERT_EQ(123, sn.port()); 47 | } 48 | 49 | HBASE_TEST_MAIN() 50 | -------------------------------------------------------------------------------- /cmake/folly/system/FindFolly.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | find_path(FOLLY_ROOT_DIR 20 | NAMES include/folly/AtomicHashMap.h 21 | ) 22 | find_library(FOLLY_LIBRARIES 23 | NAMES folly 24 | HINTS ${FOLLY_ROOT_DIR}/lib /usr/lib/ /usr/local/lib/ /usr/lib/x86_64-linux-gnu/ 25 | ) 26 | find_library(FOLLY_BENCHMARK_LIBRARIES 27 | NAMES follybenchmark 28 | HINTS ${FOLLY_ROOT_DIR}/lib 29 | ) 30 | find_path(FOLLY_INCLUDE_DIR 31 | NAMES folly/AtomicHashMap.h 32 | HINTS ${FOLLY_ROOT_DIR}/include 33 | ) 34 | include(FindPackageHandleStandardArgs) 35 | find_package_handle_standard_args(Folly DEFAULT_MSG 36 | FOLLY_LIBRARIES 37 | FOLLY_INCLUDE_DIR 38 | ) 39 | mark_as_advanced( 40 | FOLLY_ROOT_DIR 41 | FOLLY_LIBRARIES 42 | FOLLY_BENCHMARK_LIBRARIES 43 | FOLLY_INCLUDE_DIR 44 | ) 45 | if (FOLLY_LIBRARIES) 46 | set(FOLLY_FOUND "true") 47 | message("-- Folly found, ${FOLLY_LIBRARIES}") 48 | endif(FOLLY_LIBRARIES) 49 | -------------------------------------------------------------------------------- /include/hbase/client/region-request.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include "hbase/client/action.h" 26 | #include "hbase/client/region-location.h" 27 | 28 | namespace hbase { 29 | 30 | class RegionRequest { 31 | public: 32 | // Concurrent 33 | using ActionList = std::vector>; 34 | explicit RegionRequest(const std::shared_ptr ®ion_loc) 35 | : region_loc_(region_loc) {} 36 | ~RegionRequest() {} 37 | void AddAction(std::shared_ptr action) { actions_.push_back(action); } 38 | std::shared_ptr region_location() const { return region_loc_; } 39 | const ActionList &actions() const { return actions_; } 40 | 41 | private: 42 | std::shared_ptr region_loc_; 43 | ActionList actions_; 44 | }; 45 | 46 | } /* namespace hbase */ 47 | -------------------------------------------------------------------------------- /include/hbase/utils/user-util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | namespace hbase { 26 | 27 | /** 28 | * @brief Class to help with user/group information. 29 | * 30 | * This class will get the current user, and information about them. It caches 31 | * the user information after the first invocation. 32 | */ 33 | class UserUtil { 34 | public: 35 | /** 36 | * Constructor. 37 | */ 38 | UserUtil(); 39 | 40 | /** 41 | * Get the username of the user owning this process. This is thread safe and 42 | * lockless for every invocation other than the first one. 43 | */ 44 | std::string user_name(bool secure = false); 45 | 46 | private: 47 | /** 48 | * Compute the username. This will block. 49 | */ 50 | void compute_user_name(bool secure); 51 | std::once_flag once_flag_; 52 | std::string user_name_; 53 | }; 54 | } // namespace hbase 55 | -------------------------------------------------------------------------------- /include/hbase/connection/rpc-fault-injector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include "hbase/connection/pipeline.h" 23 | 24 | namespace hbase { 25 | 26 | template 27 | class RpcFaultInjector { 28 | public: 29 | RpcFaultInjector(); 30 | virtual ~RpcFaultInjector(); 31 | 32 | static std::shared_ptr Get(); 33 | static void Set(std::shared_ptr instance); 34 | 35 | private: 36 | static std::shared_ptr instance; 37 | }; 38 | 39 | class RpcClientFaultInjector : public RpcFaultInjector { 40 | public: 41 | RpcClientFaultInjector() {} 42 | virtual ~RpcClientFaultInjector() {} 43 | /** 44 | * Here goes virtual functions for injecting various faults. They should be no-ops by default. 45 | * Sub classes of RpcClientFaultInjector will override by providing concrete faults. 46 | */ 47 | }; 48 | } /* namespace hbase */ 49 | 50 | #include "hbase/connection/rpc-fault-injector-inl.h" 51 | -------------------------------------------------------------------------------- /include/hbase/serde/codec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | #include "hbase/serde/cell-outputstream.h" 26 | #include "hbase/serde/cell-scanner.h" 27 | 28 | namespace hbase { 29 | 30 | /** 31 | * @brief Encoder / Decoder for Cells. 32 | */ 33 | class Codec { 34 | public: 35 | virtual ~Codec() {} 36 | 37 | class Encoder : public CellOutputStream {}; 38 | 39 | class Decoder : public CellScanner {}; 40 | 41 | virtual std::unique_ptr CreateEncoder() = 0; 42 | virtual std::unique_ptr CreateDecoder(std::unique_ptr cell_block, 43 | uint32_t cell_block_start_offset, 44 | uint32_t cell_block_length) = 0; 45 | 46 | /** @brief returns the java class name corresponding to this Codec implementation */ 47 | virtual const char* java_class_name() const = 0; 48 | }; 49 | 50 | } /* namespace hbase */ 51 | -------------------------------------------------------------------------------- /src/test/time-range-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/client/time-range.h" 21 | #include "hbase/test-util/test-util.h" 22 | 23 | #include 24 | 25 | using namespace hbase; 26 | 27 | TEST(TimeRange, DefaultObject) { 28 | TimeRange *timerange_def = nullptr; 29 | ASSERT_NO_THROW(timerange_def = new TimeRange()); 30 | 31 | EXPECT_EQ(0, timerange_def->MinTimeStamp()); 32 | EXPECT_EQ(std::numeric_limits::max(), timerange_def->MaxTimeStamp()); 33 | EXPECT_NE(1000, timerange_def->MinTimeStamp()); 34 | EXPECT_NE(2000, timerange_def->MaxTimeStamp()); 35 | delete timerange_def; 36 | timerange_def = nullptr; 37 | } 38 | 39 | TEST(TimeRange, Exception) { 40 | // Negative Min TS 41 | ASSERT_THROW(TimeRange(-1000, 2000), std::runtime_error); 42 | 43 | // Negative Max TS 44 | ASSERT_THROW(TimeRange(1000, -2000), std::runtime_error); 45 | 46 | // Min TS > Max TS 47 | ASSERT_THROW(TimeRange(10000, 2000), std::runtime_error); 48 | } 49 | 50 | HBASE_TEST_MAIN() 51 | -------------------------------------------------------------------------------- /include/hbase/serde/table-name.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "HBase.pb.h" 29 | 30 | namespace hbase { 31 | namespace pb { 32 | 33 | // Provide folly::to(TableName); 34 | template 35 | void toAppend(const TableName &in, String *result) { 36 | if (!in.has_namespace_() || in.namespace_() == "default") { 37 | folly::toAppend(in.qualifier(), result); 38 | } else { 39 | folly::toAppend(in.namespace_(), ':', in.qualifier(), result); 40 | } 41 | } 42 | 43 | template 44 | void parseTo(String in, TableName &out) { 45 | std::vector v; 46 | folly::split(":", in, v); 47 | 48 | if (v.size() == 1) { 49 | out.set_namespace_("default"); 50 | out.set_qualifier(v[0]); 51 | } else { 52 | out.set_namespace_(v[0]); 53 | out.set_qualifier(v[1]); 54 | } 55 | } 56 | 57 | } // namespace pb 58 | } // namespace hbase 59 | -------------------------------------------------------------------------------- /include/hbase/connection/rpc-test-server-handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | 23 | #include "hbase/connection/request.h" 24 | #include "hbase/connection/response.h" 25 | #include "hbase/serde/rpc-serde.h" 26 | 27 | using namespace hbase; 28 | 29 | namespace hbase { 30 | // A real rpc server would probably use generated client/server stubs 31 | class RpcTestServerSerializeHandler 32 | : public wangle::Handler, std::unique_ptr, 33 | std::unique_ptr, std::unique_ptr> { 34 | public: 35 | RpcTestServerSerializeHandler() : serde_() {} 36 | 37 | void read(Context* ctx, std::unique_ptr buf) override; 38 | 39 | folly::Future write(Context* ctx, std::unique_ptr resp) override; 40 | 41 | private: 42 | std::unique_ptr CreateReceivedRequest(const std::string& method_name); 43 | 44 | private: 45 | hbase::RpcSerde serde_; 46 | }; 47 | } // end of namespace hbase 48 | -------------------------------------------------------------------------------- /src/test/region-info-deserializer-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/serde/region-info.h" 21 | 22 | #include 23 | 24 | #include "hbase/if/HBase.pb.h" 25 | #include "hbase/serde/table-name.h" 26 | #include "hbase/test-util/test-util.h" 27 | 28 | using std::string; 29 | using hbase::pb::RegionInfo; 30 | using hbase::pb::TableName; 31 | 32 | TEST(TestRegionInfoDesializer, TestDeserialize) { 33 | string ns{"test_ns"}; 34 | string tn{"table_name"}; 35 | string start_row{"AAAAAA"}; 36 | string stop_row{"BBBBBBBBBBBB"}; 37 | uint64_t region_id = 2345678; 38 | 39 | RegionInfo ri_out; 40 | ri_out.set_region_id(region_id); 41 | ri_out.mutable_table_name()->set_namespace_(ns); 42 | ri_out.mutable_table_name()->set_qualifier(tn); 43 | ri_out.set_start_key(start_row); 44 | ri_out.set_end_key(stop_row); 45 | 46 | string header{"PBUF"}; 47 | string ser = header + ri_out.SerializeAsString(); 48 | 49 | auto out = folly::to(ser); 50 | 51 | EXPECT_EQ(region_id, out.region_id()); 52 | } 53 | 54 | HBASE_TEST_MAIN() 55 | -------------------------------------------------------------------------------- /include/hbase/client/append.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "hbase/client/cell.h" 28 | #include "hbase/client/mutation.h" 29 | 30 | namespace hbase { 31 | 32 | class Append : public Mutation { 33 | public: 34 | /** 35 | * Constructors 36 | */ 37 | explicit Append(const std::string& row) : Mutation(row) {} 38 | Append(const Append& cappend) : Mutation(cappend) {} 39 | Append& operator=(const Append& cappend) { 40 | Mutation::operator=(cappend); 41 | return *this; 42 | } 43 | 44 | ~Append() = default; 45 | 46 | /** 47 | * @brief Add the specified column and value to this Append operation. 48 | * @param family family name 49 | * @param qualifier column qualifier 50 | * @param value value to append 51 | */ 52 | Append& Add(const std::string& family, const std::string& qualifier, const std::string& value); 53 | Append& Add(std::unique_ptr cell); 54 | }; 55 | 56 | } // namespace hbase 57 | -------------------------------------------------------------------------------- /include/hbase/serde/cell-outputstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace hbase { 25 | 26 | class Cell; 27 | 28 | /** 29 | * @brief Encoder / Decoder for Cells. 30 | */ 31 | class CellOutputStream { 32 | public: 33 | virtual ~CellOutputStream() {} 34 | 35 | /** 36 | * Implementation must copy the entire state of the Cell. If the written Cell is modified 37 | * immediately after the write method returns, the modifications must have absolutely no effect 38 | * on the copy of the Cell that was added in the write. 39 | * @param cell Cell to write out 40 | * @throws IOException 41 | */ 42 | virtual void Write(const Cell& cell) = 0; 43 | 44 | /** 45 | * Let the implementation decide what to do. Usually means writing accumulated data into a 46 | * byte[] that can then be read from the implementation to be sent to disk, put in the block 47 | * cache, or sent over the network. 48 | * @throws IOException 49 | */ 50 | virtual void Flush() = 0; 51 | }; 52 | 53 | } /* namespace hbase */ 54 | -------------------------------------------------------------------------------- /include/hbase/connection/sasl-util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "hbase/client/configuration.h" 26 | 27 | class SaslUtil { 28 | public: 29 | void InitializeSaslLib(void); 30 | static std::string ParseServiceName(std::shared_ptr conf, bool secure); 31 | 32 | private: 33 | static constexpr const char *kDefaultPluginDir = "/usr/lib/sasl2"; 34 | // for now the sasl handler is hardcoded to work against the regionservers only. In the future, if 35 | // we 36 | // need the master rpc to work, we could have a map of service names to principals to use (similar 37 | // to the Java implementation) 38 | static constexpr const char *kServerPrincipalConfKey = "hbase.regionserver.kerberos.principal"; 39 | 40 | static int GetPluginPath(void *context, const char **path); 41 | static void *MutexNew(void); 42 | static int MutexLock(void *m); 43 | static int MutexUnlock(void *m); 44 | static void MutexDispose(void *m); 45 | static std::once_flag library_inited_; 46 | }; 47 | -------------------------------------------------------------------------------- /src/hbase/client/append.cc: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include "hbase/client/append.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace hbase { 30 | 31 | /** 32 | * @brief Append to the column from the specific family with the specified qualifier 33 | * @param family family name 34 | * @param qualifier column qualifier 35 | * @param value value to append 36 | */ 37 | Append& Append::Add(const std::string& family, const std::string& qualifier, 38 | const std::string& value) { 39 | family_map_[family].push_back(std::move( 40 | std::make_unique(row_, family, qualifier, timestamp_, value, hbase::CellType::PUT))); 41 | return *this; 42 | } 43 | Append& Append::Add(std::unique_ptr cell) { 44 | if (cell->Row() != row_) { 45 | throw std::runtime_error("The row in " + cell->DebugString() + 46 | " doesn't match the original one " + row_); 47 | } 48 | 49 | family_map_[cell->Family()].push_back(std::move(cell)); 50 | return *this; 51 | } 52 | 53 | } // namespace hbase 54 | -------------------------------------------------------------------------------- /bin/start-docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | 19 | set -e 20 | set -x 21 | 22 | # Try out some standard docker machine names that could work 23 | eval "$(docker-machine env docker-vm)" 24 | eval "$(docker-machine env dinghy)" 25 | 26 | BIN_DIR=$(pushd `dirname "$0"` 2>&1 > /dev/null && pwd && popd 2>&1 > /dev/null) 27 | BASE_DIR=$(pushd "${BIN_DIR}/../" 2>&1 > /dev/null && pwd && popd 2>&1 > /dev/null) 28 | 29 | 30 | # Go into the base dir. This just makes things cleaner. 31 | pushd ${BASE_DIR} 32 | 33 | # We don't want to have to re-download all the jars in docker if we can help it 34 | if [[ ! -d ~/.m2 ]]; then 35 | echo "~/.m2 directory doesn't exist. Check Apache Maven is installed." 36 | exit 1 37 | fi; 38 | 39 | # Build the image 40 | # 41 | # This shouldn't be needed after the development environment is a little more stable. 42 | docker build -t hbase_native -f docker-files/Dockerfile docker-files 43 | 44 | # After the image is built run the thing 45 | docker run --privileged=true -h="securecluster" -p 16050:16050/tcp \ 46 | -v ${BASE_DIR}/..:/usr/src/hbase \ 47 | -v ~/.m2:/root/.m2 \ 48 | -it hbase_native /bin/bash 49 | popd 50 | -------------------------------------------------------------------------------- /include/hbase/client/region-result.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "hbase/client/result.h" 28 | #include "hbase/if/client/Client.pb.h" 29 | 30 | namespace hbase { 31 | 32 | using ResultOrExceptionTuple = 33 | std::tuple, std::shared_ptr>; 34 | 35 | class RegionResult { 36 | public: 37 | RegionResult(); 38 | void AddResultOrException(int32_t index, std::shared_ptr result, 39 | std::shared_ptr exc); 40 | 41 | void set_stat(std::shared_ptr stat); 42 | 43 | int ResultOrExceptionSize() const; 44 | 45 | std::shared_ptr ResultOrException(int32_t index) const; 46 | 47 | const std::shared_ptr& stat() const; 48 | 49 | ~RegionResult(); 50 | 51 | private: 52 | std::map result_or_excption_; 53 | std::shared_ptr stat_; 54 | }; 55 | } /* namespace hbase */ 56 | -------------------------------------------------------------------------------- /include/hbase/client/increment.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "hbase/client/cell.h" 28 | #include "hbase/client/mutation.h" 29 | 30 | namespace hbase { 31 | 32 | class Increment : public Mutation { 33 | public: 34 | /** 35 | * Constructors 36 | */ 37 | explicit Increment(const std::string& row) : Mutation(row) {} 38 | Increment(const Increment& cincrement) : Mutation(cincrement) {} 39 | Increment& operator=(const Increment& cincrement) { 40 | Mutation::operator=(cincrement); 41 | return *this; 42 | } 43 | 44 | ~Increment() = default; 45 | 46 | /** 47 | * @brief Increment the column from the specific family with the specified qualifier 48 | * by the specified amount. 49 | * @param family family name 50 | * @param qualifier column qualifier 51 | * @param amount amount to increment by 52 | */ 53 | Increment& AddColumn(const std::string& family, const std::string& qualifier, int64_t amount); 54 | Increment& Add(std::unique_ptr cell); 55 | }; 56 | 57 | } // namespace hbase 58 | -------------------------------------------------------------------------------- /src/test/table-name-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include "hbase/serde/table-name.h" 25 | #include "hbase/test-util/test-util.h" 26 | 27 | using namespace hbase; 28 | using hbase::pb::TableName; 29 | 30 | TEST(TestTableName, TestToStringNoDefault) { 31 | TableName tn; 32 | tn.set_qualifier("TestTableName"); 33 | std::string result = folly::to(tn); 34 | ASSERT_EQ(result.find("default"), std::string::npos); 35 | ASSERT_EQ("TestTableName", result); 36 | } 37 | 38 | TEST(TestTableName, TestToStringNoDefaltWhenSet) { 39 | TableName tn; 40 | tn.set_namespace_("default"); 41 | tn.set_qualifier("TestTableName"); 42 | std::string result = folly::to(tn); 43 | ASSERT_EQ(result.find("default"), std::string::npos); 44 | ASSERT_EQ("TestTableName", result); 45 | } 46 | 47 | TEST(TestTableName, TestToStringIncludeNS) { 48 | TableName tn; 49 | tn.set_namespace_("hbase"); 50 | tn.set_qualifier("acl"); 51 | std::string result = folly::to(tn); 52 | ASSERT_EQ(result.find("hbase"), 0); 53 | ASSERT_EQ("hbase:acl", result); 54 | } 55 | 56 | HBASE_TEST_MAIN() 57 | -------------------------------------------------------------------------------- /src/test/zk-util-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #include "hbase/client/zk-util.h" 20 | #include "hbase/test-util/test-util.h" 21 | 22 | using hbase::Configuration; 23 | using hbase::ZKUtil; 24 | 25 | TEST(ZKUtilTest, ParseZooKeeperQuorum) { 26 | Configuration conf{}; 27 | conf.Set(ZKUtil::kHBaseZookeeperQuorum_, "s1"); 28 | conf.SetInt(ZKUtil::kHBaseZookeeperClientPort_, 100); 29 | 30 | ASSERT_EQ("s1:100", ZKUtil::ParseZooKeeperQuorum(conf)); 31 | 32 | conf.Set(ZKUtil::kHBaseZookeeperQuorum_, "s1:42"); 33 | 34 | ASSERT_EQ("s1:42", ZKUtil::ParseZooKeeperQuorum(conf)); 35 | 36 | conf.Set(ZKUtil::kHBaseZookeeperQuorum_, "s1,s2,s3"); 37 | ASSERT_EQ("s1:100,s2:100,s3:100", ZKUtil::ParseZooKeeperQuorum(conf)); 38 | 39 | conf.Set(ZKUtil::kHBaseZookeeperQuorum_, "s1:42,s2:42,s3:42"); 40 | ASSERT_EQ("s1:42,s2:42,s3:42", ZKUtil::ParseZooKeeperQuorum(conf)); 41 | } 42 | 43 | TEST(ZKUtilTest, MetaZNode) { 44 | Configuration conf{}; 45 | ASSERT_EQ("/hbase/meta-region-server", ZKUtil::MetaZNode(conf)); 46 | 47 | conf.Set(ZKUtil::kHBaseZnodeParent_, "/hbase-secure"); 48 | ASSERT_EQ("/hbase-secure/meta-region-server", ZKUtil::MetaZNode(conf)); 49 | } 50 | 51 | HBASE_TEST_MAIN() 52 | -------------------------------------------------------------------------------- /bin/cpplint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | IFS=$'\n\t' 19 | OUTPUT_DIR=$1 20 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 21 | CPPLINT_LOC=https://raw.githubusercontent.com/google/styleguide/gh-pages/cpplint/cpplint.py 22 | OUTPUT=$OUTPUT_DIR/cpplint.py 23 | 24 | declare -a MODULES=( client connection exceptions security serde utils test-util ) 25 | 26 | # Download if not already there 27 | wget -nc $CPPLINT_LOC -O $OUTPUT 28 | 29 | # Execute the script 30 | # Exclude the following rules: build/header_guard (We use #pragma once instead) 31 | # readability/todo (TODOs are generic) 32 | # build/c++11 (We are building with c++14) 33 | for m in ${MODULES[@]}; do 34 | if [ $m != "security" ]; then #These are empty 35 | exec find ${SCRIPT_DIR}/../src/hbase/$m -name "*.h" -or -name "*.cc" | xargs -P8 python $OUTPUT --filter=-build/header_guard,-readability/todo,-build/c++11 --linelength=100 36 | fi 37 | if [ $m != "test-util" ]; then 38 | exec find ${SCRIPT_DIR}/../include/hbase/$m -name "*.h" -or -name "*.cc" | xargs -P8 python $OUTPUT --filter=-build/header_guard,-readability/todo,-build/c++11 --linelength=100 39 | fi 40 | done 41 | -------------------------------------------------------------------------------- /include/hbase/client/hbase-rpc-controller.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace hbase { 27 | 28 | class HBaseRpcController : public google::protobuf::RpcController { 29 | public: 30 | HBaseRpcController() {} 31 | virtual ~HBaseRpcController() = default; 32 | 33 | void set_call_timeout(const std::chrono::milliseconds& call_timeout) { 34 | // TODO: 35 | } 36 | 37 | void Reset() override {} 38 | 39 | bool Failed() const override { return false; } 40 | 41 | folly::exception_wrapper exception() { return exception_; } 42 | 43 | void set_exception(const folly::exception_wrapper& exception) { exception_ = exception; } 44 | 45 | std::string ErrorText() const override { return ""; } 46 | 47 | void StartCancel() override {} 48 | 49 | void SetFailed(const std::string& reason) override {} 50 | 51 | bool IsCanceled() const override { return false; } 52 | 53 | void NotifyOnCancel(google::protobuf::Closure* callback) override {} 54 | 55 | private: 56 | folly::exception_wrapper exception_; 57 | }; 58 | 59 | } /* namespace hbase */ 60 | -------------------------------------------------------------------------------- /src/hbase/client/client.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/client/client.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using hbase::pb::TableName; 29 | 30 | namespace hbase { 31 | 32 | Client::Client() { 33 | HBaseConfigurationLoader loader; 34 | auto conf = loader.LoadDefaultResources(); 35 | if (!conf) { 36 | LOG(ERROR) << "Unable to create default Configuration object. Either hbase-default.xml or " 37 | "hbase-site.xml is absent in the search path or problems in XML parsing"; 38 | throw std::runtime_error("Configuration object not present."); 39 | } 40 | Init(conf.value()); 41 | } 42 | 43 | Client::Client(const Configuration &conf) { Init(conf); } 44 | 45 | void Client::Init(const Configuration &conf) { 46 | auto conf_ = std::make_shared(conf); 47 | async_connection_ = AsyncConnectionImpl::Create(conf_); 48 | } 49 | 50 | std::unique_ptr Client::Table(const TableName &table_name) { 51 | return std::make_unique(table_name, async_connection_); 52 | } 53 | 54 | void Client::Close() { async_connection_->Close(); } 55 | } // namespace hbase 56 | -------------------------------------------------------------------------------- /cmake/DownloadZookeeper.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | ## Download Apache zookeeper 19 | ## SOURCE_DIR is typically the cmake source directory 20 | ## BINARY_DIR is the build directory, typically 'build' 21 | 22 | #################### ZOOKEEPER 23 | 24 | function(download_zookeeper SOURCE_DIR BUILD_DIR) 25 | ExternalProject_Add( 26 | ZooKeeper 27 | URL "https://archive.apache.org/dist/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz" 28 | PREFIX "${BUILD_DIR}/dependencies" 29 | SOURCE_DIR "${BUILD_DIR}/dependencies/zookeeper-src" 30 | BINARY_DIR ${BUILD_DIR}/dependencies/zookeeper-src/src/c/ 31 | CONFIGURE_COMMAND ./configure --without-cppunit --prefix=${BUILD_DIR}/dependencies/zookeeper-install 32 | PATCH_COMMAND patch ${BUILD_DIR}/dependencies/zookeeper-src/src/c/src/zookeeper.c ${CMAKE_CURRENT_SOURCE_DIR}/cmake/patches/zookeeper.3.4.x.buf 33 | UPDATE_COMMAND "" 34 | ) 35 | add_library(zookeeper STATIC IMPORTED) 36 | set_target_properties(zookeeper PROPERTIES IMPORTED_LOCATION "${BUILD_DIR}/dependencies/zookeeper-install/lib/libzookeeper_mt.a") 37 | add_dependencies(zookeeper ZooKeeper) 38 | set(ZOOKEEPER_DIR "${BUILD_DIR}/dependencies/zookeeper-install/" CACHE STRING "" FORCE) 39 | endfunction(download_zookeeper) 40 | -------------------------------------------------------------------------------- /include/hbase/client/zk-util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | #include "hbase/client/configuration.h" 24 | 25 | namespace hbase { 26 | 27 | class ZKUtil { 28 | public: 29 | static constexpr const char* kHBaseZookeeperQuorum_ = "hbase.zookeeper.quorum"; 30 | static constexpr const char* kDefHBaseZookeeperQuorum_ = "localhost:2181"; 31 | static constexpr const char* kHBaseZookeeperClientPort_ = "hbase.zookeeper.property.clientPort"; 32 | static constexpr const int32_t kDefHBaseZookeeperClientPort_ = 2181; 33 | static constexpr const char* kHBaseZnodeParent_ = "zookeeper.znode.parent"; 34 | static constexpr const char* kDefHBaseZnodeParent_ = "/hbase"; 35 | static constexpr const char* kHBaseMetaRegionServer_ = "meta-region-server"; 36 | 37 | static constexpr const char* kHBaseZookeeperSessionTimeout_ = "zookeeper.session.timeout"; 38 | static constexpr const int32_t kDefHBaseZookeeperSessionTimeout_ = 90000; 39 | 40 | static std::string ParseZooKeeperQuorum(const hbase::Configuration& conf); 41 | 42 | static std::string MetaZNode(const hbase::Configuration& conf); 43 | 44 | static int32_t SessionTimeout(const hbase::Configuration& conf); 45 | }; 46 | } // namespace hbase 47 | -------------------------------------------------------------------------------- /include/hbase/client/time-range.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace hbase { 25 | class TimeRange { 26 | public: 27 | /** 28 | * @brief Default constructor. Represents interval [0, 29 | * std::numeric_limits::max()) 30 | * (allTime) 31 | */ 32 | TimeRange(); 33 | TimeRange(const TimeRange &tr); 34 | TimeRange &operator=(const TimeRange &tr); 35 | /** 36 | * @brief Represents interval [minStamp, std::numeric_limits::max()) 37 | * @param minStamp the minimum timestamp value, inclusive 38 | */ 39 | explicit TimeRange(int64_t min_timestamp); 40 | /** 41 | * @brief Represents interval [minStamp, maxStamp) 42 | * @param minStamp the minimum timestamp, inclusive 43 | * @param maxStamp the maximum timestamp, exclusive 44 | * @throws std::runtime_error if min_timestamp < 0 or max_timestamp < 0 or 45 | * max_timestamp < min_timestamp 46 | */ 47 | TimeRange(int64_t min_timestamp, int64_t max_timestamp); 48 | int64_t MinTimeStamp() const; 49 | int64_t MaxTimeStamp() const; 50 | bool IsAllTime() const; 51 | ~TimeRange(); 52 | 53 | private: 54 | int64_t min_timestamp_; 55 | int64_t max_timestamp_; 56 | bool all_time_; 57 | }; 58 | } // namespace hbase 59 | -------------------------------------------------------------------------------- /src/hbase/client/increment.cc: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include "hbase/client/increment.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "hbase/utils/bytes-util.h" 30 | 31 | namespace hbase { 32 | 33 | /** 34 | * @brief Increment the column from the specific family with the specified qualifier 35 | * by the specified amount. 36 | * @param family family name 37 | * @param qualifier column qualifier 38 | * @param amount amount to increment by 39 | */ 40 | Increment& Increment::AddColumn(const std::string& family, const std::string& qualifier, 41 | int64_t amount) { 42 | family_map_[family].push_back(std::move(std::make_unique( 43 | row_, family, qualifier, timestamp_, BytesUtil::ToString(amount), hbase::CellType::PUT))); 44 | return *this; 45 | } 46 | Increment& Increment::Add(std::unique_ptr cell) { 47 | if (cell->Row() != row_) { 48 | throw std::runtime_error("The row in " + cell->DebugString() + 49 | " doesn't match the original one " + row_); 50 | } 51 | 52 | family_map_[cell->Family()].push_back(std::move(cell)); 53 | return *this; 54 | } 55 | 56 | } // namespace hbase 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | # hbase-native-client 21 | 22 | Native client for HBase 23 | 24 | This is a C/C++ library that implements a 25 | HBase client. 26 | 27 | 28 | ## Design Philosphy 29 | 30 | Synchronous and Async versions will both be built 31 | on the same foundation. The core foundation will 32 | be C++. External users wanting a C library will 33 | have to choose either async or sync. These 34 | libraries will be thin veneers ontop of the C++. 35 | 36 | We should try and follow pthreads example as much 37 | as possible: 38 | 39 | * Consistent naming. 40 | * Opaque pointers as types so that binary compat is easy. 41 | * Simple setup when the defaults are good. 42 | * Attr structs when lots of paramters could be needed. 43 | 44 | 45 | ## Naming 46 | All public C files will start with hbase_*.{h, cc}. This 47 | is to keep naming conflicts to a minimum. Anything without 48 | the hbase_ prefix is assumed to be implementation private. 49 | 50 | All C apis and typedefs will be prefixed with hb_. 51 | 52 | All typedefs end with _t. 53 | 54 | 55 | ## Docker 56 | 57 | The build environment is docker. This should keep a consistent 58 | build environment for everyone. Buck the build system works 59 | best with mmap'd files. On OSX this means that vmwarefusion 60 | works the best. However it should work with just the defaults. 61 | -------------------------------------------------------------------------------- /include/hbase/client/row.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #pragma once 25 | 26 | namespace hbase { 27 | 28 | class Row { 29 | public: 30 | Row() {} 31 | explicit Row(const std::string &row) : row_(row) { CheckRow(row_); } 32 | 33 | /** 34 | * @brief Returns the row for the Row interface. 35 | */ 36 | const std::string &row() const { return row_; } 37 | virtual ~Row() {} 38 | 39 | private: 40 | /** 41 | * @brief Checks if the row for this Get operation is proper or not 42 | * @param row Row to check 43 | * @throws std::runtime_error if row is empty or greater than 44 | * MAX_ROW_LENGTH(i.e. std::numeric_limits::max()) 45 | */ 46 | void CheckRow(const std::string &row) { 47 | const int16_t kMaxRowLength = std::numeric_limits::max(); 48 | size_t row_length = row.size(); 49 | if (0 == row_length) { 50 | throw std::runtime_error("Row length can't be 0"); 51 | } 52 | if (row_length > kMaxRowLength) { 53 | throw std::runtime_error("Length of " + row + " is greater than max row size: " + 54 | std::to_string(kMaxRowLength)); 55 | } 56 | } 57 | 58 | protected: 59 | std::string row_ = ""; 60 | }; 61 | 62 | } /* namespace hbase */ 63 | -------------------------------------------------------------------------------- /src/hbase/connection/request.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/connection/request.h" 21 | 22 | #include "hbase/if/client/Client.pb.h" 23 | 24 | namespace hbase { 25 | 26 | Request::Request(std::shared_ptr req, 27 | std::shared_ptr resp, std::string method) 28 | : req_msg_(req), resp_msg_(resp), method_(method), call_id_(0) {} 29 | 30 | std::unique_ptr Request::get() { 31 | return std::make_unique(std::make_shared(), 32 | std::make_shared(), "Get"); 33 | } 34 | std::unique_ptr Request::mutate() { 35 | return std::make_unique(std::make_shared(), 36 | std::make_shared(), "Mutate"); 37 | } 38 | std::unique_ptr Request::scan() { 39 | return std::make_unique(std::make_shared(), 40 | std::make_shared(), "Scan"); 41 | } 42 | std::unique_ptr Request::multi() { 43 | return std::make_unique(std::make_shared(), 44 | std::make_shared(), "Multi"); 45 | } 46 | } // namespace hbase 47 | -------------------------------------------------------------------------------- /src/hbase/client/region-result.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/client/region-result.h" 21 | #include 22 | #include 23 | 24 | using hbase::pb::RegionLoadStats; 25 | 26 | namespace hbase { 27 | 28 | RegionResult::RegionResult() {} 29 | 30 | RegionResult::~RegionResult() {} 31 | 32 | void RegionResult::AddResultOrException(int32_t index, std::shared_ptr result, 33 | std::shared_ptr exc) { 34 | auto index_found = result_or_excption_.find(index); 35 | if (index_found == result_or_excption_.end()) { 36 | result_or_excption_[index] = std::make_tuple(result ? result : nullptr, exc ? exc : nullptr); 37 | } else { 38 | throw std::runtime_error("Index " + std::to_string(index) + 39 | " already set with ResultOrException"); 40 | } 41 | } 42 | 43 | void RegionResult::set_stat(std::shared_ptr stat) { stat_ = stat; } 44 | 45 | int RegionResult::ResultOrExceptionSize() const { return result_or_excption_.size(); } 46 | 47 | std::shared_ptr RegionResult::ResultOrException(int32_t index) const { 48 | return std::make_shared(result_or_excption_.at(index)); 49 | } 50 | 51 | const std::shared_ptr& RegionResult::stat() const { return stat_; } 52 | 53 | } /* namespace hbase */ 54 | -------------------------------------------------------------------------------- /include/hbase/connection/pipeline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include "hbase/connection/request.h" 27 | #include "hbase/connection/response.h" 28 | #include "hbase/client/configuration.h" 29 | #include "hbase/serde/codec.h" 30 | #include "hbase/utils/user-util.h" 31 | 32 | namespace hbase { 33 | 34 | /** Pipeline to turn IOBuf into requests */ 35 | using SerializePipeline = wangle::Pipeline>; 36 | 37 | /** 38 | * Factory to create new pipelines for HBase RPC's. 39 | */ 40 | class RpcPipelineFactory : public wangle::PipelineFactory { 41 | public: 42 | /** 43 | * Constructor. This will create user util. 44 | */ 45 | explicit RpcPipelineFactory(std::shared_ptr codec, std::shared_ptr conf); 46 | 47 | /** 48 | * Create a new pipeline. 49 | * The pipeline will be: 50 | * 51 | * - Async Socke Handler 52 | * - Event Base Handler 53 | * - Length Field Based Frame Decoder 54 | * - Client Handler 55 | */ 56 | SerializePipeline::Ptr newPipeline(std::shared_ptr sock) override; 57 | 58 | private: 59 | UserUtil user_util_; 60 | std::shared_ptr codec_; 61 | std::shared_ptr conf_; 62 | }; 63 | } // namespace hbase 64 | -------------------------------------------------------------------------------- /cmake/DownloadProtobuf.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | ## Download Protobuf 19 | ## SOURCE_DIR is typically the cmake source directory 20 | ## BINARY_DIR is the build directory, typically 'build' 21 | 22 | #################### PROTOBUF 23 | 24 | function(download_protobuf SOURCE_DIR BINARY_DIR) 25 | ExternalProject_Add( 26 | Protobuf 27 | GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git" 28 | GIT_TAG "3.5.1.1" 29 | BUILD_IN_SOURCE true 30 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/dependencies/protobuf-src" 31 | CONFIGURE_COMMAND ./autogen.sh 32 | COMMAND ./configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/dependencies/protobuf 33 | "CFLAGS=-fPIC" 34 | "CXXFLAGS=${CMAKE_CXX_FLAGS} -fPIC" 35 | UPDATE_COMMAND "" 36 | ) 37 | 38 | 39 | set(PROTOBUF_DIR "${CMAKE_CURRENT_BINARY_DIR}/dependencies/protobuf/" CACHE STRING "" FORCE) 40 | 41 | add_library(protobuf STATIC IMPORTED) 42 | set_target_properties(protobuf PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/dependencies/protobuf/lib/libprotobuf.a" ) 43 | set(PROTOBUF_LIBS "${CMAKE_CURRENT_BINARY_DIR}/dependencies/protobuf/lib/libprotobuf.a" "${CMAKE_CURRENT_BINARY_DIR}/dependencies/protobuf/lib/libprotoc.a" CACHE STRING "" FORCE) 44 | set(PROTOBUF_INCLUDE_DIRS "${CMAKE_CURRENT_BINARY_DIR}/dependencies/protobuf/include" CACHE STRING "" FORCE) 45 | add_dependencies(protobuf Protobuf) 46 | set(PROTOBUF_FOUND TRUE CACHE STRING "" FORCE) 47 | endfunction(download_protobuf) 48 | 49 | -------------------------------------------------------------------------------- /cmake/FindLibEvent.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # - Find LibEvent (a cross event library) 18 | # This module defines 19 | # LIB_EVENT_INCLUDE_DIR, where to find LibEvent headers 20 | # LIB_EVENT_LIBRARY, LibEvent libraries 21 | # LibEvent_FOUND, If false, do not try to use libevent 22 | 23 | set(LibEvent_EXTRA_PREFIXES /usr/local /opt/local "$ENV{HOME}") 24 | foreach(prefix ${LibEvent_EXTRA_PREFIXES}) 25 | list(APPEND LibEvent_INCLUDE_PATHS "${prefix}/include") 26 | list(APPEND LIB_EVENT_LIBRARY_PATHS "${prefix}/lib") 27 | endforeach() 28 | 29 | find_path(LIB_EVENT_INCLUDE_DIR event.h PATHS ${LibEvent_INCLUDE_PATHS}) 30 | find_library(LIB_EVENT_LIBRARY NAMES event PATHS ${LIB_EVENT_LIBRARY_PATHS}) 31 | find_library(LIBEVENT_PTHREAD_LIB NAMES event_pthreads PATHS ${LIB_EVENT_LIBRARY_PATHS}) 32 | 33 | if (LIB_EVENT_LIBRARY AND LIB_EVENT_INCLUDE_DIR AND LIBEVENT_PTHREAD_LIB) 34 | set(LibEvent_FOUND TRUE) 35 | set(LIB_EVENT_LIBRARY ${LIB_EVENT_LIBRARY} ${LIBEVENT_PTHREAD_LIB}) 36 | else () 37 | set(LibEvent_FOUND FALSE) 38 | endif () 39 | 40 | if (LibEvent_FOUND) 41 | if (NOT LibEvent_FIND_QUIETLY) 42 | message(STATUS "Found libevent: ${LIB_EVENT_LIBRARY}") 43 | endif () 44 | else () 45 | if (LibEvent_FIND_REQUIRED) 46 | message(FATAL_ERROR "Could NOT find libevent and libevent_pthread.") 47 | endif () 48 | message(STATUS "libevent and libevent_pthread NOT found.") 49 | endif () 50 | 51 | mark_as_advanced( 52 | LIB_EVENT_LIBRARY 53 | LIB_EVENT_INCLUDE_DIR 54 | ) 55 | 56 | -------------------------------------------------------------------------------- /include/hbase/utils/connection-util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "hbase/utils/time-util.h" 28 | 29 | namespace hbase { 30 | class ConnectionUtils { 31 | public: 32 | static int Retries2Attempts(const int& retries) { 33 | return std::max(1, retries == INT_MAX ? INT_MAX : retries + 1); 34 | } 35 | 36 | /* Add a delta to avoid timeout immediately after a retry sleeping. */ 37 | static const uint64_t kSleepDeltaNs = 1000000; 38 | 39 | static const std::vector kRetryBackoff; 40 | /** 41 | * Calculate pause time. Built on {@link kRetryBackoff}. 42 | * @param pause time to pause 43 | * @param tries amount of tries 44 | * @return How long to wait after tries retries 45 | */ 46 | static int64_t GetPauseTime(const int64_t& pause, const int32_t& tries) { 47 | int32_t ntries = tries; 48 | if (static_cast(ntries) >= kRetryBackoff.size()) { 49 | ntries = kRetryBackoff.size() - 1; 50 | } 51 | if (ntries < 0) { 52 | ntries = 0; 53 | } 54 | 55 | int64_t normal_pause = pause * kRetryBackoff[ntries]; 56 | // 1% possible jitter 57 | float r = static_cast(std::rand()) / static_cast(RAND_MAX); 58 | int64_t jitter = (int64_t)(normal_pause * r * 0.01f); 59 | return normal_pause + jitter; 60 | } 61 | }; 62 | } /* namespace hbase */ 63 | -------------------------------------------------------------------------------- /src/test/client-deserializer-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #include 20 | 21 | #include "client/Client.pb.h" 22 | #include "hbase/serde/rpc-serde.h" 23 | #include "hbase/test-util/test-util.h" 24 | 25 | using namespace hbase; 26 | using folly::IOBuf; 27 | using hbase::pb::GetRequest; 28 | using hbase::pb::RegionSpecifier; 29 | using hbase::pb::RegionSpecifier_RegionSpecifierType; 30 | 31 | TEST(TestRpcSerde, TestReturnFalseOnNullPtr) { 32 | RpcSerde deser{nullptr}; 33 | ASSERT_LT(deser.ParseDelimited(nullptr, nullptr), 0); 34 | } 35 | 36 | TEST(TestRpcSerde, TestReturnFalseOnBadInput) { 37 | RpcSerde deser{nullptr}; 38 | auto buf = IOBuf::copyBuffer("test"); 39 | GetRequest gr; 40 | 41 | ASSERT_LT(deser.ParseDelimited(buf.get(), &gr), 0); 42 | } 43 | 44 | TEST(TestRpcSerde, TestGoodGetRequestFullRoundTrip) { 45 | GetRequest in; 46 | RpcSerde ser{nullptr}; 47 | RpcSerde deser{nullptr}; 48 | 49 | // fill up the GetRequest. 50 | in.mutable_region()->set_value("test_region_id"); 51 | in.mutable_region()->set_type( 52 | RegionSpecifier_RegionSpecifierType::RegionSpecifier_RegionSpecifierType_ENCODED_REGION_NAME); 53 | in.mutable_get()->set_row("test_row"); 54 | 55 | // Create the buffer 56 | auto buf = ser.SerializeDelimited(in); 57 | 58 | GetRequest out; 59 | 60 | int used_bytes = deser.ParseDelimited(buf.get(), &out); 61 | 62 | ASSERT_GT(used_bytes, 0); 63 | ASSERT_EQ(used_bytes, buf->length()); 64 | } 65 | 66 | HBASE_TEST_MAIN() 67 | -------------------------------------------------------------------------------- /cmake/DownloadBoost.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | ## Download Boost. 19 | ## SOURCE_DIR is typically the cmake source directory 20 | ## BINARY_DIR is the build directory, typically 'build' 21 | ## Sets BOOST_ROOT, search prefix for FindBoost. 22 | 23 | function(download_boost SOURCE_DIR BUILD_DIR BOOST_LIBS) 24 | set(BOOST_DOWNLOAD_DIR "${BUILD_DIR}/dependencies/boost-download") 25 | set(BOOST_SOURCE_DIR "${BUILD_DIR}/dependencies/boost-src") 26 | set(BOOST_INSTALL_DIR "${BUILD_DIR}/dependencies/boost-install") 27 | 28 | set(CFLAGS "-fPIC") 29 | set(CXXFLAGS "${CMAKE_CXX_FLAGS} -fPIC") 30 | 31 | # Only compile and install the needed libs. 32 | set(LIBS_TO_COMPILE "") 33 | foreach(lib ${BOOST_LIBS}) 34 | string(APPEND LIBS_TO_COMPILE --with-${lib} " ") 35 | endforeach() 36 | 37 | separate_arguments(BUILD_CMD UNIX_COMMAND 38 | "./b2 cflags='${CFLAGS}' cxxflags='${CXXFLAGS}' variant=release link=static threading=multi ${LIBS_TO_COMPILE} install") 39 | 40 | ExternalProject_Add(boost 41 | URL "https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.gz" 42 | PREFIX "${BUILD_DIR}/dependencies" 43 | DOWNLOAD_DIR ${BOOST_DOWNLOAD_DIR} 44 | BUILD_IN_SOURCE true 45 | SOURCE_DIR ${BOOST_SOURCE_DIR} 46 | INSTALL_DIR ${BOOST_INSTALL_DIR} 47 | CONFIGURE_COMMAND ./bootstrap.sh --prefix=${BOOST_INSTALL_DIR} 48 | BUILD_COMMAND ${BUILD_CMD} 49 | INSTALL_COMMAND "" 50 | ) 51 | set(BOOST_ROOT ${BOOST_INSTALL_DIR} PARENT_SCOPE) 52 | endfunction(download_boost) 53 | -------------------------------------------------------------------------------- /include/hbase/utils/bytes-util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | namespace hbase { 26 | 27 | class BytesUtil { 28 | private: 29 | static const constexpr char kHexChars[] = "0123456789ABCDEF"; 30 | 31 | public: 32 | static std::string ToStringBinary(const std::string& b) { return ToStringBinary(b, 0, b.size()); } 33 | /** 34 | * Write a printable representation of a byte array. Non-printable 35 | * characters are hex escaped in the format \\x%02X, eg: 36 | * \x00 \x05 etc 37 | * 38 | * @param b array to write out 39 | * @param off offset to start at 40 | * @param len length to write 41 | * @return string output 42 | */ 43 | static std::string ToStringBinary(const std::string& b, size_t off, size_t len); 44 | 45 | static std::string ToString(int64_t value); 46 | 47 | static int64_t ToInt64(std::string str); 48 | 49 | static bool IsEmptyStartRow(const std::string& row) { return row == ""; } 50 | 51 | static bool IsEmptyStopRow(const std::string& row) { return row == ""; } 52 | 53 | static int32_t CompareTo(const std::string& a, const std::string& b) { 54 | if (a < b) { 55 | return -1; 56 | } 57 | if (a == b) { 58 | return 0; 59 | } 60 | return 1; 61 | } 62 | 63 | /** 64 | * Create the closest row after the specified row 65 | */ 66 | static std::string CreateClosestRowAfter(std::string row) { return row.append(1, '\0'); } 67 | }; 68 | } /* namespace hbase */ 69 | -------------------------------------------------------------------------------- /include/hbase/client/put.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "hbase/client/cell.h" 28 | #include "hbase/client/mutation.h" 29 | 30 | namespace hbase { 31 | 32 | class Put : public Mutation { 33 | public: 34 | /** 35 | * Constructors 36 | */ 37 | explicit Put(const std::string& row) : Mutation(row) {} 38 | Put(const std::string& row, int64_t timestamp) : Mutation(row, timestamp) {} 39 | Put(const Put& cput) : Mutation(cput) {} 40 | Put& operator=(const Put& cput) { 41 | Mutation::operator=(cput); 42 | return *this; 43 | } 44 | 45 | ~Put() = default; 46 | 47 | /** 48 | * @brief Add the specified column and value to this Put operation. 49 | * @param family family name 50 | * @param qualifier column qualifier 51 | * @param value column value 52 | */ 53 | Put& AddColumn(const std::string& family, const std::string& qualifier, const std::string& value); 54 | 55 | /** 56 | * @brief Add the specified column and value to this Put operation. 57 | * @param family family name 58 | * @param qualifier column qualifier 59 | * @param timestamp version timestamp 60 | * @param value column value 61 | */ 62 | Put& AddColumn(const std::string& family, const std::string& qualifier, int64_t timestamp, 63 | const std::string& value); 64 | 65 | Put& Add(std::unique_ptr cell); 66 | }; 67 | 68 | } // namespace hbase 69 | -------------------------------------------------------------------------------- /cmake/DownloadWangle.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | ## Download facebook's wangle library. 19 | ## SOURCE_DIR is typically the cmake source directory 20 | ## BINARY_DIR is the build directory, typically 'build' 21 | 22 | function(download_wangle SOURCE_DIR BUILD_DIR) 23 | set(WANGLE_DOWNLOAD_DIR "${BUILD_DIR}/dependencies/facebook-wangle-proj-download") 24 | set(WANGLE_SOURCE_DIR "${BUILD_DIR}/dependencies/facebook-wangle-proj-src") 25 | set(WANGLE_INSTALL_DIR "${BUILD_DIR}/dependencies/facebook-wangle-proj-install") 26 | if (DOWNLOAD_DEPENDENCIES) 27 | set(PATCH_FOLLY ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/cmake/folly/local/FindFolly.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/boost/local/FindBoost.cmake" "${WANGLE_SOURCE_DIR}/wangle/cmake") 28 | else() 29 | set(PATCH_FOLLY "") 30 | endif() 31 | 32 | ExternalProject_Add( 33 | facebook-wangle-proj 34 | URL "https://github.com/facebook/wangle/archive/v2017.09.04.00.tar.gz" 35 | PREFIX "${BUILD_DIR}/dependencies" 36 | DOWNLOAD_DIR ${WANGLE_DOWNLOAD_DIR} 37 | SOURCE_DIR ${WANGLE_SOURCE_DIR} 38 | PATCH_COMMAND ${PATCH_FOLLY} 39 | INSTALL_DIR ${WANGLE_INSTALL_DIR} 40 | CONFIGURE_COMMAND ${CMAKE_COMMAND} -DBUILD_EXAMPLES=OFF -DCMAKE_CROSSCOMPILING=ON -DBUILD_TESTS=OFF -DFOLLY_ROOT_DIR=${FOLLY_ROOT_DIR} -DBOOST_ROOT=${BOOST_ROOT} -DCMAKE_INSTALL_PREFIX:PATH=${WANGLE_INSTALL_DIR} "${WANGLE_SOURCE_DIR}/wangle" # Tell CMake to use subdirectory as source. 41 | ) 42 | set(WANGLE_ROOT_DIR ${WANGLE_INSTALL_DIR} CACHE STRING "" FORCE) 43 | endfunction(download_wangle) 44 | -------------------------------------------------------------------------------- /bin/jenkins/gather_machine_environment.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | set -e 20 | function usage { 21 | echo "Usage: ${0} /path/for/output/dir" 22 | echo "" 23 | echo " Gather info about a build machine that test harnesses should poll before running." 24 | echo " presumes you'll then archive the passed output dir." 25 | 26 | exit 1 27 | } 28 | 29 | if [ "$#" -lt 1 ]; then 30 | usage 31 | fi 32 | 33 | 34 | declare output=$1 35 | 36 | if [ ! -d "${output}" ] || [ ! -w "${output}" ]; then 37 | echo "Specified output directory must exist and be writable." >&2 38 | exit 1 39 | fi 40 | 41 | echo "getting machine specs, find in ${BUILD_URL}/artifact/${output}/" 42 | echo "JAVA_HOME: ${JAVA_HOME}" >"${output}/java_home" 2>&1 || true 43 | ls -l "${JAVA_HOME}" >"${output}/java_home_ls" 2>&1 || true 44 | echo "MAVEN_HOME: ${MAVEN_HOME}" >"${output}/mvn_home" 2>&1 || true 45 | mvn --offline --version >"${output}/mvn_version" 2>&1 || true 46 | cat /proc/cpuinfo >"${output}/cpuinfo" 2>&1 || true 47 | cat /proc/meminfo >"${output}/meminfo" 2>&1 || true 48 | cat /proc/diskstats >"${output}/diskstats" 2>&1 || true 49 | cat /sys/block/sda/stat >"${output}/sys-block-sda-stat" 2>&1 || true 50 | df -h >"${output}/df-h" 2>&1 || true 51 | ps -Aww >"${output}/ps-Aww" 2>&1 || true 52 | hostname -f >"${output}/fqdn-hostname" 2>&1 || true 53 | ifconfig -a >"${output}/ifconfig-a" 2>&1 || true 54 | lsblk -ta >"${output}/lsblk-ta" 2>&1 || true 55 | lsblk -fa >"${output}/lsblk-fa" 2>&1 || true 56 | ulimit -l >"${output}/ulimit-l" 2>&1 || true 57 | uptime >"${output}/uptime" 2>&1 || true 58 | -------------------------------------------------------------------------------- /include/hbase/client/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | #include "hbase/connection/rpc-client.h" 26 | #include "hbase/client/async-connection.h" 27 | #include "hbase/client/configuration.h" 28 | 29 | #include "hbase/client/table.h" 30 | #include "hbase/serde/table-name.h" 31 | 32 | namespace hbase { 33 | 34 | class Table; 35 | /** 36 | * Client. 37 | * 38 | * This is the class that provides access to an HBase cluster. 39 | * It is thread safe and does connection pooling. Current recommendations are to 40 | * have only one Client per cluster around. 41 | */ 42 | class Client { 43 | public: 44 | /** 45 | * @brief Create a new client. 46 | * @param quorum_spec Where to connect to get Zookeeper bootstrap information. 47 | */ 48 | Client(); 49 | explicit Client(const Configuration& conf); 50 | ~Client() = default; 51 | 52 | /** 53 | * @brief Retrieve a Table implementation for accessing a table. 54 | * @param - table_name 55 | */ 56 | std::unique_ptr<::hbase::Table> Table(const pb::TableName& table_name); 57 | 58 | /** 59 | * @brief Close the Client connection. 60 | */ 61 | void Close(); 62 | 63 | /** 64 | * @brief Internal. DO NOT USE. 65 | */ 66 | std::shared_ptr async_connection() { return async_connection_; } 67 | 68 | private: 69 | /** Data */ 70 | std::shared_ptr async_connection_; 71 | 72 | private: 73 | /** Methods */ 74 | void Init(const Configuration& conf); 75 | }; 76 | 77 | } // namespace hbase 78 | -------------------------------------------------------------------------------- /include/hbase/client/server-request.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "hbase/client/action.h" 27 | #include "hbase/client/region-location.h" 28 | #include "hbase/client/region-request.h" 29 | 30 | namespace hbase { 31 | 32 | class ServerRequest { 33 | public: 34 | // Concurrent 35 | using ActionsByRegion = std::map>; 36 | 37 | explicit ServerRequest(std::shared_ptr region_location) { 38 | auto region_name = region_location->region_name(); 39 | auto region_request = std::make_shared(region_location); 40 | actions_by_region_[region_name] = region_request; 41 | } 42 | ~ServerRequest() {} 43 | 44 | void AddActionsByRegion(std::shared_ptr region_location, 45 | std::shared_ptr action) { 46 | auto region_name = region_location->region_name(); 47 | auto search = actions_by_region_.find(region_name); 48 | if (search == actions_by_region_.end()) { 49 | auto region_request = std::make_shared(region_location); 50 | actions_by_region_[region_name] = region_request; 51 | actions_by_region_[region_name]->AddAction(action); 52 | } else { 53 | search->second->AddAction(action); 54 | } 55 | } 56 | 57 | const ActionsByRegion &actions_by_region() const { return actions_by_region_; } 58 | 59 | private: 60 | ActionsByRegion actions_by_region_; 61 | }; 62 | } /* namespace hbase */ 63 | -------------------------------------------------------------------------------- /src/test/exception-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/exceptions/exception.h" 21 | 22 | #include "folly/ExceptionWrapper.h" 23 | #include "hbase/test-util/test-util.h" 24 | 25 | using hbase::ExceptionUtil; 26 | using hbase::IOException; 27 | using hbase::RemoteException; 28 | 29 | TEST(ExceptionUtilTest, IOExceptionShouldRetry) { 30 | IOException ex{}; 31 | EXPECT_TRUE(ExceptionUtil::ShouldRetry(ex)); 32 | 33 | ex.set_do_not_retry(true); 34 | EXPECT_FALSE(ExceptionUtil::ShouldRetry(ex)); 35 | 36 | ex.set_do_not_retry(false); 37 | EXPECT_TRUE(ExceptionUtil::ShouldRetry(ex)); 38 | 39 | IOException ex2{"description", true}; 40 | EXPECT_FALSE(ExceptionUtil::ShouldRetry(ex2)); 41 | 42 | IOException ex3{"description", std::runtime_error("ex"), true}; 43 | EXPECT_FALSE(ExceptionUtil::ShouldRetry(ex3)); 44 | } 45 | 46 | TEST(ExceptionUtilTest, RemoteExceptionShouldRetry) { 47 | RemoteException ex{}; 48 | EXPECT_TRUE(ExceptionUtil::ShouldRetry(ex)); 49 | 50 | ex.set_do_not_retry(true); 51 | EXPECT_FALSE(ExceptionUtil::ShouldRetry(ex)); 52 | 53 | ex.set_do_not_retry(false); 54 | EXPECT_TRUE(ExceptionUtil::ShouldRetry(ex)); 55 | 56 | ex.set_exception_class_name("org.apache.hadoop.hbase.FooException"); 57 | EXPECT_TRUE(ExceptionUtil::ShouldRetry(ex)); 58 | 59 | ex.set_exception_class_name("org.apache.hadoop.hbase.NotServingRegionException"); 60 | EXPECT_TRUE(ExceptionUtil::ShouldRetry(ex)); 61 | 62 | ex.set_exception_class_name("org.apache.hadoop.hbase.UnknownRegionException"); 63 | EXPECT_FALSE(ExceptionUtil::ShouldRetry(ex)); 64 | } 65 | 66 | HBASE_TEST_MAIN() 67 | -------------------------------------------------------------------------------- /src/hbase/client/put.cc: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include "hbase/client/put.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace hbase { 30 | 31 | /** 32 | * @brief Add the specified column and value to this Put operation. 33 | * @param family family name 34 | * @param qualifier column qualifier 35 | * @param value column value 36 | */ 37 | Put& Put::AddColumn(const std::string& family, const std::string& qualifier, 38 | const std::string& value) { 39 | return AddColumn(family, qualifier, timestamp_, value); 40 | } 41 | 42 | /** 43 | * @brief Add the specified column and value to this Put operation. 44 | * @param family family name 45 | * @param qualifier column qualifier 46 | * @param timestamp version timestamp 47 | * @param value column value 48 | */ 49 | Put& Put::AddColumn(const std::string& family, const std::string& qualifier, int64_t timestamp, 50 | const std::string& value) { 51 | if (timestamp < 0) { 52 | throw std::runtime_error("Timestamp cannot be negative. ts=" + 53 | folly::to(timestamp)); 54 | } 55 | 56 | return Add(CreateCell(family, qualifier, timestamp, value)); 57 | } 58 | 59 | Put& Put::Add(std::unique_ptr cell) { 60 | if (cell->Row() != row_) { 61 | throw std::runtime_error("The row in " + cell->DebugString() + 62 | " doesn't match the original one " + row_); 63 | } 64 | 65 | family_map_[cell->Family()].push_back(std::move(cell)); 66 | return *this; 67 | } 68 | } // namespace hbase 69 | -------------------------------------------------------------------------------- /src/hbase/connection/pipeline.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #include "hbase/connection/pipeline.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "hbase/connection/client-handler.h" 28 | #include "hbase/connection/sasl-handler.h" 29 | 30 | namespace hbase { 31 | 32 | RpcPipelineFactory::RpcPipelineFactory(std::shared_ptr codec, 33 | std::shared_ptr conf) 34 | : user_util_(), codec_(codec), conf_(conf) {} 35 | SerializePipeline::Ptr RpcPipelineFactory::newPipeline( 36 | std::shared_ptr sock) { 37 | folly::SocketAddress addr; // for logging 38 | sock->getPeerAddress(&addr); 39 | 40 | auto pipeline = SerializePipeline::create(); 41 | pipeline->addBack(wangle::AsyncSocketHandler{sock}); 42 | pipeline->addBack(wangle::EventBaseHandler{}); 43 | bool secure = false; 44 | /* for RPC test, there's no need to setup Sasl */ 45 | if (!conf_->GetBool(RpcSerde::HBASE_CLIENT_RPC_TEST_MODE, 46 | RpcSerde::DEFAULT_HBASE_CLIENT_RPC_TEST_MODE)) { 47 | secure = security::User::IsSecurityEnabled(*conf_); 48 | pipeline->addBack(SaslHandler{user_util_.user_name(secure), conf_}); 49 | } 50 | pipeline->addBack(wangle::LengthFieldBasedFrameDecoder{}); 51 | pipeline->addBack(ClientHandler{user_util_.user_name(secure), codec_, conf_, addr.describe()}); 52 | pipeline->finalize(); 53 | return pipeline; 54 | } 55 | } // namespace hbase 56 | -------------------------------------------------------------------------------- /include/hbase/client/cell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | namespace hbase { 26 | 27 | enum class CellType { 28 | MINIMUM = 0, 29 | PUT = 4, 30 | DELETE = 8, 31 | DELETE_FAMILY_VERSION = 10, 32 | DELETE_COLUMN = 12, 33 | DELETE_FAMILY = 14, 34 | MAXIMUM = 255 35 | }; 36 | 37 | class Cell { 38 | public: 39 | Cell(const std::string &row, const std::string &family, const std::string &qualifier, 40 | const int64_t timestamp, const std::string &value, const hbase::CellType &cell_type); 41 | Cell(const Cell &cell); 42 | Cell &operator=(const Cell &cell); 43 | virtual ~Cell(); 44 | const std::string &Row() const; 45 | const std::string &Family() const; 46 | const std::string &Qualifier() const; 47 | int64_t Timestamp() const; 48 | const std::string &Value() const; 49 | CellType Type() const; 50 | int64_t SequenceId() const; 51 | std::string DebugString() const; 52 | /** Returns estimated size of the Cell object including deep heap space usage 53 | * of its data. Notice that this is a very rough estimate. */ 54 | size_t EstimatedSize() const; 55 | 56 | private: 57 | std::string row_; 58 | std::string family_; 59 | std::string qualifier_; 60 | // Since java does not have unsigned, we are also using signed numerics here 61 | // so that we won't have surprises when large uint64's are treated as 62 | // negative values in the java server side 63 | int64_t timestamp_; 64 | hbase::CellType cell_type_; 65 | std::string value_; 66 | int64_t sequence_id_; 67 | 68 | private: 69 | static const char *TypeToString(CellType type); 70 | }; 71 | 72 | } // namespace hbase 73 | -------------------------------------------------------------------------------- /src/hbase/client/mutation.cc: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include "hbase/client/mutation.h" 23 | #include 24 | #include 25 | #include 26 | 27 | namespace hbase { 28 | 29 | Mutation::Mutation(const std::string &row) : Row(row) {} 30 | Mutation::Mutation(const std::string &row, int64_t timestamp) : Row(row), timestamp_(timestamp) {} 31 | 32 | Mutation::Mutation(const Mutation &mutation) { 33 | row_ = mutation.row_; 34 | durability_ = mutation.durability_; 35 | timestamp_ = mutation.timestamp_; 36 | for (auto const &e : mutation.family_map_) { 37 | for (auto const &c : e.second) { 38 | family_map_[e.first].push_back(std::make_unique(*c)); 39 | } 40 | } 41 | } 42 | 43 | Mutation &Mutation::operator=(const Mutation &mutation) { 44 | row_ = mutation.row_; 45 | durability_ = mutation.durability_; 46 | timestamp_ = mutation.timestamp_; 47 | for (auto const &e : mutation.family_map_) { 48 | for (auto const &c : e.second) { 49 | family_map_[e.first].push_back(std::make_unique(*c)); 50 | } 51 | } 52 | return *this; 53 | } 54 | 55 | pb::MutationProto_Durability Mutation::Durability() const { return durability_; } 56 | 57 | Mutation &Mutation::SetDurability(pb::MutationProto_Durability durability) { 58 | durability_ = durability; 59 | return *this; 60 | } 61 | 62 | bool Mutation::HasFamilies() const { return !family_map_.empty(); } 63 | 64 | std::unique_ptr Mutation::CreateCell(const std::string &family, const std::string &qualifier, 65 | int64_t timestamp, const std::string &value) { 66 | return std::make_unique(row_, family, qualifier, timestamp, value, hbase::CellType::PUT); 67 | } 68 | 69 | } // namespace hbase 70 | -------------------------------------------------------------------------------- /src/hbase/client/zk-util.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/client/zk-util.h" 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | namespace hbase { 28 | 29 | /** 30 | * Returns a "proper" zookeeper quorum string, from hbase's broken quorum string formats. In 31 | * hbase.zookeeper.quorum, the ports are not listed explicitly per server (eg. s1,s2,s3), 32 | * however ZooKeeper expects the string of the format s1:2181,s2:2181,s3:2181. This code 33 | * appends the "clientPort" to each node in the quorum string if not there. 34 | */ 35 | std::string ZKUtil::ParseZooKeeperQuorum(const hbase::Configuration& conf) { 36 | auto zk_quorum = conf.Get(kHBaseZookeeperQuorum_, kDefHBaseZookeeperQuorum_); 37 | auto zk_port = conf.GetInt(kHBaseZookeeperClientPort_, kDefHBaseZookeeperClientPort_); 38 | 39 | std::vector zk_quorum_parts; 40 | boost::split(zk_quorum_parts, zk_quorum, boost::is_any_of(","), boost::token_compress_on); 41 | std::vector servers; 42 | for (auto server : zk_quorum_parts) { 43 | if (boost::contains(server, ":")) { 44 | servers.push_back(server); 45 | } else { 46 | servers.push_back(server + ":" + folly::to(zk_port)); 47 | } 48 | } 49 | return boost::join(servers, ","); 50 | } 51 | 52 | std::string ZKUtil::MetaZNode(const hbase::Configuration& conf) { 53 | std::string zk_node = conf.Get(kHBaseZnodeParent_, kDefHBaseZnodeParent_) + "/"; 54 | zk_node += kHBaseMetaRegionServer_; 55 | return zk_node; 56 | } 57 | 58 | int32_t ZKUtil::SessionTimeout(const hbase::Configuration& conf) { 59 | return conf.GetInt(kHBaseZookeeperSessionTimeout_, kDefHBaseZookeeperSessionTimeout_); 60 | } 61 | 62 | } // namespace hbase 63 | -------------------------------------------------------------------------------- /cmake/DownloadFolly.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | ## Download facebook's folly library. 19 | ## SOURCE_DIR is typically the cmake source directory 20 | ## BUILD_DIR is the build directory, typically 'build' 21 | 22 | function(download_folly SOURCE_DIR BUILD_DIR) 23 | 24 | if (DOWNLOAD_DEPENDENCIES) 25 | # Add custom boost include and lib paths. 26 | set(CFLAGS "-fPIC -I${BOOST_ROOT}/include -lboost_context -lboost_coroutine -l${CMAKE_DL_LIBS}") 27 | set(CXXFLAGS "${CMAKE_CXX_FLAGS} -fPIC -I${BOOST_ROOT}/include -lboost_context -lboost_coroutine -l${CMAKE_DL_LIBS}") 28 | set(LDFLAGS "-L${BOOST_ROOT}/lib") 29 | set(CONFIGURE_CMD ./configure --prefix=${BUILD_DIR}/dependencies/facebook-folly-proj-install 30 | --with-boost-libdir=${BOOST_ROOT}/lib CFLAGS=${CFLAGS} CXXFLAGS=${CXXFLAGS} LDFLAGS=${LDFLAGS}) 31 | else() 32 | set(CFLAGS "-fPIC -lboost_context -lboost_coroutine -l${CMAKE_DL_LIBS}") 33 | set(CXXFLAGS "${CMAKE_CXX_FLAGS} -fPIC -lboost_context -lboost_coroutine -l${CMAKE_DL_LIBS}") 34 | set(CONFIGURE_CMD ./configure --prefix=${BUILD_DIR}/dependencies/facebook-folly-proj-install CFLAGS=${CFLAGS} CXXFLAGS=${CXXFLAGS}) 35 | endif() 36 | 37 | ExternalProject_Add( 38 | facebook-folly-proj 39 | # TODO: Source version information from cmake file. 40 | URL "https://github.com/facebook/folly/archive/v2017.09.04.00.tar.gz" 41 | PREFIX "${BUILD_DIR}/dependencies" 42 | SOURCE_DIR "${BUILD_DIR}/dependencies/facebook-folly-proj-src" 43 | BINARY_DIR ${BUILD_DIR}/dependencies/facebook-folly-proj-src/folly 44 | CONFIGURE_COMMAND autoreconf -ivf COMMAND ${CONFIGURE_CMD} 45 | UPDATE_COMMAND "" 46 | ) 47 | set(FOLLY_ROOT_DIR "${BUILD_DIR}/dependencies/facebook-folly-proj-install" CACHE STRING "" FORCE) 48 | endfunction(download_folly) 49 | -------------------------------------------------------------------------------- /include/hbase/client/region-location.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | #include "HBase.pb.h" 25 | 26 | namespace hbase { 27 | 28 | enum class RegionLocateType { kBefore, kCurrent, kAfter }; 29 | 30 | /** 31 | * @brief class to hold where a region is located. 32 | * 33 | * This class holds where a region is located, the information about it, the 34 | * region name. 35 | */ 36 | class RegionLocation { 37 | public: 38 | /** 39 | * Constructor. 40 | * @param region_name The region name of this region. 41 | * @param ri The decoded RegionInfo of this region. 42 | * @param sn The server name of the HBase regionserver thought to be hosting 43 | * this region. 44 | */ 45 | RegionLocation(std::string region_name, hbase::pb::RegionInfo ri, hbase::pb::ServerName sn) 46 | : region_name_(region_name), ri_(ri), sn_(sn) {} 47 | 48 | /** 49 | * Get a reference to the regio info 50 | */ 51 | const hbase::pb::RegionInfo ®ion_info() const { return ri_; } 52 | 53 | /** 54 | * Get a reference to the server name 55 | */ 56 | const hbase::pb::ServerName &server_name() const { return sn_; } 57 | 58 | /** 59 | * Get a reference to the region name. 60 | */ 61 | const std::string ®ion_name() const { return region_name_; } 62 | 63 | /** 64 | * Set the servername if the region has moved. 65 | */ 66 | void set_server_name(hbase::pb::ServerName sn) { sn_ = sn; } 67 | 68 | const std::string DebugString() const { 69 | return "region_info:" + ri_.ShortDebugString() + ", server_name:" + sn_.ShortDebugString(); 70 | } 71 | 72 | private: 73 | std::string region_name_; 74 | hbase::pb::RegionInfo ri_; 75 | hbase::pb::ServerName sn_; 76 | }; 77 | 78 | } // namespace hbase 79 | -------------------------------------------------------------------------------- /src/test/bytes-util-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "hbase/utils/bytes-util.h" 24 | #include "hbase/test-util/test-util.h" 25 | 26 | using hbase::BytesUtil; 27 | 28 | TEST(TestBytesUtil, TestToStringBinary) { 29 | std::string empty{""}; 30 | EXPECT_EQ(empty, BytesUtil::ToStringBinary(empty)); 31 | 32 | std::string foo_bar{"foo bar"}; 33 | EXPECT_EQ(foo_bar, BytesUtil::ToStringBinary(foo_bar)); 34 | 35 | std::string foo_bar2{"foo bar_/!@#$%^&*(){}[]|1234567890"}; 36 | EXPECT_EQ(foo_bar2, BytesUtil::ToStringBinary(foo_bar2)); 37 | 38 | char zero = 0; 39 | EXPECT_EQ("\\x00", BytesUtil::ToStringBinary(std::string{zero})); 40 | 41 | char max = 255; 42 | EXPECT_EQ("\\xFF", BytesUtil::ToStringBinary(std::string{max})); 43 | 44 | EXPECT_EQ("\\x00\\xFF", BytesUtil::ToStringBinary(std::string{zero} + std::string{max})); 45 | 46 | EXPECT_EQ("foo_\\x00\\xFF_bar", 47 | BytesUtil::ToStringBinary("foo_" + std::string{zero} + std::string{max} + "_bar")); 48 | } 49 | 50 | TEST(TestBytesUtil, TestToStringToInt64) { 51 | int64_t num = 761235; 52 | EXPECT_EQ(num, BytesUtil::ToInt64(BytesUtil::ToString(num))); 53 | 54 | num = -56125; 55 | EXPECT_EQ(num, BytesUtil::ToInt64(BytesUtil::ToString(num))); 56 | 57 | num = 0; 58 | EXPECT_EQ(num, BytesUtil::ToInt64(BytesUtil::ToString(num))); 59 | } 60 | 61 | TEST(TestBytesUtil, TestCreateClosestRowAfter) { 62 | std::string empty{""}; 63 | EXPECT_EQ(BytesUtil::CreateClosestRowAfter(empty), std::string{'\0'}); 64 | 65 | std::string foo{"foo"}; 66 | EXPECT_EQ(BytesUtil::CreateClosestRowAfter(foo), std::string{"foo"} + '\0'); 67 | 68 | EXPECT_EQ("f\\x00", BytesUtil::ToStringBinary(BytesUtil::CreateClosestRowAfter("f"))); 69 | } 70 | 71 | HBASE_TEST_MAIN() 72 | -------------------------------------------------------------------------------- /BUILDING.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | # Building HBase native client 21 | 22 | The HBase native client build using cmake and produces a linux library. 23 | 24 | 25 | # Dependencies 26 | 27 | The easiest way to build hbase-native-client is to 28 | use [Docker](https://www.docker.com/). This will mean that any platform 29 | with docker can be used to build the hbase-native-client. It will also 30 | mean that you're building with the same versions of all dependencies that 31 | the client is tested with. 32 | 33 | On OSX the current boot2docker solution will work however it's pretty 34 | slow. If things get too slow using [dinghy](https://github.com/codekitchen/dinghy) 35 | can help speed things up by using nfs. 36 | 37 | If possible pairing virtual box with dinghy will result in the fastest, 38 | most stable docker environment. 39 | 40 | However none of them is a must. 41 | 42 | # Building using docker 43 | 44 | Go into the hbase-native-client directory and run `./bin/start-docker.sh` 45 | that will build the docker development environment and when complete will 46 | drop you into a shell on a linux vm with all the dependencies needed installed. 47 | 48 | To start with make sure that you have built the java project using 49 | `mvn package -DskipTests`. That will allow all tests to spin up a standalone 50 | hbase instance from the jar's created. 51 | 52 | *Note*: you can run the HBase Maven build outside of docker but the cached 53 | classpath used by the unit tests may not reflect the paths from within the 54 | docker container. 55 | 56 | # CMake 57 | 58 | ``` 59 | cmake . 60 | make 61 | make install 62 | ``` 63 | 64 | # Running tests 65 | 66 | To run the tests, you can use `make test` or run each compiled test individually 67 | as they are built in the top level directory of the module. For example from the 68 | hbase-native-client directory you can execute `./client-test`. 69 | -------------------------------------------------------------------------------- /include/hbase/client/async-region-locator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "hbase/client/region-location.h" 28 | #include "hbase/if/client/Client.pb.h" 29 | #include "hbase/serde/region-info.h" 30 | #include "hbase/serde/server-name.h" 31 | #include "hbase/serde/table-name.h" 32 | 33 | namespace hbase { 34 | 35 | class AsyncRegionLocator { 36 | public: 37 | AsyncRegionLocator() {} 38 | virtual ~AsyncRegionLocator() = default; 39 | 40 | /** 41 | * The only method clients should use for meta lookups. If corresponding 42 | * location is cached, it's returned from the cache, otherwise lookup 43 | * in meta table is done, location is cached and then returned. 44 | * It's expected that tiny fraction of invocations incurs meta scan. 45 | * This method is to look up non-meta regions; use LocateMeta() to get the 46 | * location of hbase:meta region. 47 | * 48 | * @param tn Table name of the table to look up. This object must live until 49 | * after the future is returned 50 | * 51 | * @param row of the table to look up. This object must live until after the 52 | * future is returned 53 | */ 54 | virtual folly::Future> LocateRegion( 55 | const hbase::pb::TableName &tn, const std::string &row, 56 | const RegionLocateType locate_type = RegionLocateType::kCurrent, 57 | const int64_t locate_ns = 0) = 0; 58 | /** 59 | * Update cached region location, possibly using the information from exception. 60 | */ 61 | virtual void UpdateCachedLocation(const RegionLocation &loc, 62 | const folly::exception_wrapper &error) = 0; 63 | }; 64 | 65 | } // namespace hbase 66 | -------------------------------------------------------------------------------- /src/test/client-serializer-test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #include 20 | 21 | #include 22 | 23 | #include "HBase.pb.h" 24 | #include "rpc/RPC.pb.h" 25 | #include "hbase/serde/rpc-serde.h" 26 | #include "hbase/test-util/test-util.h" 27 | 28 | using namespace hbase; 29 | using namespace hbase::pb; 30 | using namespace folly; 31 | using namespace folly::io; 32 | 33 | TEST(RpcSerdeTest, PreambleIncludesHBas) { 34 | RpcSerde ser{nullptr}; 35 | auto buf = ser.Preamble(false); 36 | const char *p = reinterpret_cast(buf->data()); 37 | // Take the first for chars and make sure they are the 38 | // magic string 39 | EXPECT_EQ("HBas", std::string(p, 4)); 40 | 41 | EXPECT_EQ(6, buf->computeChainDataLength()); 42 | } 43 | 44 | TEST(RpcSerdeTest, PreambleIncludesVersion) { 45 | RpcSerde ser{nullptr}; 46 | auto buf = ser.Preamble(false); 47 | EXPECT_EQ(0, static_cast(buf->data())[4]); 48 | EXPECT_EQ(80, static_cast(buf->data())[5]); 49 | } 50 | 51 | TEST(RpcSerdeTest, TestHeaderLengthPrefixed) { 52 | RpcSerde ser{nullptr}; 53 | auto header = ser.Header("elliott"); 54 | 55 | // The header should be prefixed by 4 bytes of length. 56 | EXPECT_EQ(4, header->length()); 57 | EXPECT_TRUE(header->length() < header->computeChainDataLength()); 58 | EXPECT_TRUE(header->isChained()); 59 | 60 | // Now make sure the length is correct. 61 | Cursor cursor(header.get()); 62 | auto prefixed_len = cursor.readBE(); 63 | EXPECT_EQ(prefixed_len, header->next()->length()); 64 | } 65 | 66 | TEST(RpcSerdeTest, TestHeaderDecode) { 67 | RpcSerde ser{nullptr}; 68 | auto buf = ser.Header("elliott"); 69 | auto header_buf = buf->next(); 70 | ConnectionHeader h; 71 | 72 | EXPECT_TRUE(h.ParseFromArray(header_buf->data(), header_buf->length())); 73 | EXPECT_EQ("elliott", h.user_info().effective_user()); 74 | } 75 | 76 | HBASE_TEST_MAIN() 77 | -------------------------------------------------------------------------------- /src/hbase/utils/bytes-util.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/utils/bytes-util.h" 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace hbase { 29 | 30 | constexpr char BytesUtil::kHexChars[]; 31 | 32 | std::string BytesUtil::ToString(int64_t val) { 33 | std::string res; 34 | #if BOOST_ENDIAN_BIG_BYTE || BOOST_ENDIAN_BIG_WORD 35 | for (int i = 7; i > 0; i--) { 36 | res += (int8_t)(val & 0xffu); 37 | val = val >> 8; 38 | } 39 | res += (int8_t)val; 40 | #else 41 | int64_t mask = 0xff00000000000000u; 42 | for (int i = 56; i >= 1; i -= 8) { 43 | auto num = ((val & mask) >> i); 44 | res += num; 45 | mask = mask >> 8; 46 | } 47 | res += (val & 0xff); 48 | #endif 49 | return res; 50 | } 51 | 52 | int64_t BytesUtil::ToInt64(std::string str) { 53 | if (str.length() < 8) { 54 | throw std::runtime_error("There are not enough bytes. Expected: 8, actual: " + str.length()); 55 | } 56 | const unsigned char *bytes = reinterpret_cast(const_cast(str.c_str())); 57 | int64_t l = 0; 58 | for (int i = 0; i < 8; i++) { 59 | l <<= 8; 60 | l ^= bytes[i]; 61 | } 62 | return l; 63 | } 64 | 65 | std::string BytesUtil::ToStringBinary(const std::string &b, size_t off, size_t len) { 66 | std::string result; 67 | // Just in case we are passed a 'len' that is > buffer length... 68 | if (off >= b.size()) { 69 | return result; 70 | } 71 | if (off + len > b.size()) { 72 | len = b.size() - off; 73 | } 74 | for (size_t i = off; i < off + len; ++i) { 75 | int32_t ch = b[i] & 0xFF; 76 | if (ch >= ' ' && ch <= '~' && ch != '\\') { 77 | result += ch; 78 | } else { 79 | result += "\\x"; 80 | result += kHexChars[ch / 0x10]; 81 | result += kHexChars[ch % 0x10]; 82 | } 83 | } 84 | return result; 85 | } 86 | 87 | } /* namespace hbase */ 88 | -------------------------------------------------------------------------------- /include/hbase/connection/rpc-test-server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "hbase/connection/request.h" 26 | #include "hbase/connection/response.h" 27 | #include "hbase/exceptions/exception.h" 28 | 29 | using namespace hbase; 30 | using namespace folly; 31 | using namespace wangle; 32 | 33 | namespace hbase { 34 | using RpcTestServerSerializePipeline = wangle::Pipeline>; 35 | 36 | class RpcTestException : public IOException { 37 | public: 38 | RpcTestException() {} 39 | RpcTestException(const std::string& what) : IOException(what) {} 40 | RpcTestException(const std::string& what, const folly::exception_wrapper& cause) 41 | : IOException(what, cause) {} 42 | RpcTestException(const folly::exception_wrapper& cause) : IOException("", cause) {} 43 | }; 44 | 45 | class RpcTestService : public Service, std::unique_ptr> { 46 | public: 47 | RpcTestService(std::shared_ptr socket_address) 48 | : socket_address_(socket_address) {} 49 | virtual ~RpcTestService() = default; 50 | Future> operator()(std::unique_ptr request) override; 51 | 52 | private: 53 | std::shared_ptr socket_address_; 54 | }; 55 | 56 | class RpcTestServerPipelineFactory : public PipelineFactory { 57 | public: 58 | RpcTestServerSerializePipeline::Ptr newPipeline( 59 | std::shared_ptr sock) override; 60 | 61 | private: 62 | void initService(std::shared_ptr sock); 63 | 64 | private: 65 | std::shared_ptr, std::unique_ptr>> service_{ 66 | nullptr}; 67 | }; 68 | } // end of namespace hbase 69 | -------------------------------------------------------------------------------- /include/hbase/test-util/mini-cluster-util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "hbase/client/configuration.h" 29 | #include "hbase/test-util/mini-cluster.h" 30 | 31 | namespace hbase { 32 | /** 33 | * @brief Class to deal with a local instance cluster for testing. 34 | */ 35 | class MiniClusterUtility { 36 | public: 37 | MiniClusterUtility(); 38 | 39 | /** 40 | * Create a random string. This random string is all letters, as such it is 41 | * very good for use as a directory name. 42 | */ 43 | static std::string RandString(int len = 32); 44 | 45 | /** 46 | * Returns the configuration to talk to the local cluster 47 | */ 48 | std::shared_ptr conf() const { return conf_; } 49 | 50 | /** 51 | * Starts mini hbase cluster with specified number of region servers 52 | */ 53 | void StartMiniCluster(int32_t num_region_servers); 54 | 55 | void StopMiniCluster(); 56 | void CreateTable(const std::string &table, const std::string &family); 57 | void CreateTable(const std::string &table, const std::vector &families); 58 | void CreateTable(const std::string &table, const std::string &family, 59 | const std::vector &keys); 60 | void CreateTable(const std::string &table, const std::vector &families, 61 | const std::vector &keys); 62 | 63 | void StartStandAloneInstance(); 64 | void StopStandAloneInstance(); 65 | void RunShellCmd(const std::string &); 66 | void MoveRegion(const std::string ®ion, const std::string &server); 67 | 68 | private: 69 | std::unique_ptr mini_; 70 | folly::test::TemporaryDirectory temp_dir_; 71 | std::shared_ptr conf_ = std::make_shared(); 72 | }; 73 | } // namespace hbase 74 | -------------------------------------------------------------------------------- /cmake/zookeeper/system/FindZookeeper.cmake: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | if (MSVC) 18 | if(${CMAKE_BUILD_TYPE} MATCHES "Debug") 19 | set(ZK_BuildOutputDir "Debug") 20 | else() 21 | set(ZK_BuildOutputDir "Release") 22 | endif() 23 | if("${ZOOKEEPER_HOME}_" MATCHES "^_$") 24 | message(" ") 25 | message("- Please set the cache variable ZOOKEEPER_HOME to point to the directory with the zookeeper source.") 26 | message("- CMAKE will look for zookeeper include files in $ZOOKEEPER_HOME/src/c/include.") 27 | message("- CMAKE will look for zookeeper library files in $ZOOKEEPER_HOME/src/c/Debug or $ZOOKEEPER_HOME/src/c/Release.") 28 | else() 29 | FILE(TO_CMAKE_PATH ${ZOOKEEPER_HOME} Zookeeper_HomePath) 30 | set(Zookeeper_LIB_PATHS ${Zookeeper_HomePath}/src/c/${ZK_BuildOutputDir}) 31 | find_path(ZK_INCLUDE_DIR zookeeper.h ${Zookeeper_HomePath}/src/c/include) 32 | find_path(ZK_INCLUDE_DIR_GEN zookeeper.jute.h ${Zookeeper_HomePath}/src/c/generated) 33 | set(Zookeeper_INCLUDE_DIR zookeeper.h ${ZK_INCLUDE_DIR} ${ZK_INCLUDE_DIR_GEN} ) 34 | find_library(Zookeeper_LIBRARY NAMES zookeeper PATHS ${Zookeeper_LIB_PATHS}) 35 | endif() 36 | else() 37 | set(Zookeeper_LIB_PATHS /usr/local/lib /usr/lib/ /usr/lib/x86_64-linux-gnu/) 38 | find_path(Zookeeper_INCLUDE_DIR zookeeper/zookeeper.h /usr/local/include) 39 | find_library(Zookeeper_LIBRARY NAMES libzookeeper_mt.a PATHS ${Zookeeper_LIB_PATHS}) 40 | endif() 41 | set(Zookeeper_LIBRARIES ${Zookeeper_LIBRARY} ) 42 | set(Zookeeper_INCLUDE_DIRS ${Zookeeper_INCLUDE_DIR} ) 43 | include(FindPackageHandleStandardArgs) 44 | # handle the QUIETLY and REQUIRED arguments and set Zookeeper_FOUND to TRUE 45 | # if all listed variables are TRUE 46 | find_package_handle_standard_args(Zookeeper DEFAULT_MSG 47 | Zookeeper_LIBRARY Zookeeper_INCLUDE_DIR) 48 | if (Zookeeper_LIBRARY) 49 | message("-- Zookeeper found, ${Zookeeper_LIBRARY}") 50 | endif() 51 | mark_as_advanced(Zookeeper_INCLUDE_DIR Zookeeper_LIBRARY ) 52 | -------------------------------------------------------------------------------- /src/hbase/serde/zk.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/serde/zk.h" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | using std::runtime_error; 29 | 30 | namespace hbase { 31 | 32 | static const std::string MAGIC_STRING = "PBUF"; 33 | 34 | bool ZkDeserializer::Parse(folly::IOBuf *buf, google::protobuf::Message *out) { 35 | // The format is like this 36 | // 1 byte of magic number. 255 37 | // 4 bytes of id length. 38 | // id_length number of bytes for the id of who put up the znode 39 | // 4 bytes of a magic string PBUF 40 | // Then the protobuf serialized without a varint header. 41 | 42 | folly::io::Cursor c{buf}; 43 | 44 | // There should be a magic number for recoverable zk 45 | uint8_t magic_num = c.read(); 46 | if (magic_num != 255) { 47 | LOG(ERROR) << "Magic number not in ZK znode data expected 255 got =" << unsigned(magic_num); 48 | throw runtime_error("Magic number not in znode data"); 49 | } 50 | // How long is the id? 51 | uint32_t id_len = c.readBE(); 52 | 53 | if (id_len >= c.length()) { 54 | LOG(ERROR) << "After skiping the if from zookeeper data there's not enough " 55 | "left to read anything else"; 56 | throw runtime_error("Not enough bytes to decode from zookeeper"); 57 | } 58 | 59 | // Skip the id 60 | c.skip(id_len); 61 | 62 | // Make sure that the magic string is there. 63 | if (MAGIC_STRING != c.readFixedString(4)) { 64 | LOG(ERROR) << "There was no PBUF magic string."; 65 | throw runtime_error("No PBUF magic string in the zookpeeper data."); 66 | } 67 | 68 | // Try to decode the protobuf. 69 | // If there's an error bail out. 70 | if (out->ParseFromArray(c.data(), c.length()) == false) { 71 | LOG(ERROR) << "Error parsing Protobuf Message"; 72 | throw runtime_error("Error parsing protobuf"); 73 | } 74 | 75 | return true; 76 | } 77 | } // namespace hbase 78 | -------------------------------------------------------------------------------- /include/hbase/client/meta-utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | #include "hbase/connection/request.h" 25 | #include "hbase/connection/response.h" 26 | #include "hbase/client/region-location.h" 27 | #include "HBase.pb.h" 28 | #include "hbase/serde/table-name.h" 29 | 30 | namespace hbase { 31 | 32 | /** 33 | * @brief Utility for meta operations. 34 | */ 35 | class MetaUtil { 36 | public: 37 | static constexpr const char *kSystemNamespace = "hbase"; 38 | static constexpr const char *kMetaTableQualifier = "meta"; 39 | static constexpr const char *kMetaTableName = "hbase:meta"; 40 | static constexpr const char *kMetaRegion = "1588230740"; 41 | static constexpr const char *kMetaRegionName = "hbase:meta,,1"; 42 | static constexpr const char *kCatalogFamily = "info"; 43 | static constexpr const char *kRegionInfoColumn = "regioninfo"; 44 | static constexpr const char *kServerColumn = "server"; 45 | 46 | MetaUtil(); 47 | 48 | /** 49 | * Given a table and a row give the row key from which to start a scan to find 50 | * region locations. 51 | */ 52 | std::string RegionLookupRowkey(const hbase::pb::TableName &tn, const std::string &row) const; 53 | 54 | /** 55 | * Given a row we're trying to access create a request to look up the 56 | * location. 57 | */ 58 | std::unique_ptr MetaRequest(const hbase::pb::TableName tn, const std::string &row) const; 59 | 60 | /** 61 | * Return a RegionLocation from the parsed Response 62 | */ 63 | std::shared_ptr CreateLocation(const Response &resp, 64 | const hbase::pb::TableName &tn); 65 | 66 | /** 67 | * Return whether the table is the meta table. 68 | */ 69 | static bool IsMeta(const hbase::pb::TableName &tn); 70 | 71 | const pb::RegionInfo &meta_region_info() const { return meta_region_info_; } 72 | 73 | private: 74 | pb::RegionInfo meta_region_info_; 75 | }; 76 | } // namespace hbase 77 | -------------------------------------------------------------------------------- /src/hbase/utils/user-util.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/utils/user-util.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace hbase { 29 | 30 | UserUtil::UserUtil() : once_flag_{} {} 31 | 32 | std::string UserUtil::user_name(bool secure) { 33 | std::call_once(once_flag_, [this, secure]() { compute_user_name(secure); }); 34 | return user_name_; 35 | } 36 | 37 | void UserUtil::compute_user_name(bool secure) { 38 | // According to the man page of getpwuid 39 | // this should never be free'd 40 | // 41 | // So yeah a raw pointer with no ownership.... 42 | struct passwd *passwd = getpwuid(getuid()); 43 | 44 | // make sure that we got something. 45 | if (passwd && passwd->pw_name) { 46 | user_name_ = std::string{passwd->pw_name}; 47 | } 48 | if (!secure) return; 49 | krb5_context ctx; 50 | krb5_error_code ret = krb5_init_context(&ctx); 51 | if (ret != 0) { 52 | throw std::runtime_error("cannot init krb ctx " + std::to_string(ret)); 53 | } 54 | krb5_ccache ccache; 55 | ret = krb5_cc_default(ctx, &ccache); 56 | if (ret != 0) { 57 | throw std::runtime_error("cannot get default cache " + std::to_string(ret)); 58 | } 59 | // Here is sample principal: hbase/23a03935850c@EXAMPLE.COM 60 | // There may be one (user) or two (user/host) components before the @ sign 61 | krb5_principal princ; 62 | ret = krb5_cc_get_principal(ctx, ccache, &princ); 63 | if (ret != 0) { 64 | throw std::runtime_error("cannot get default principal " + std::to_string(ret)); 65 | } 66 | user_name_ = princ->data->data; 67 | if (krb5_princ_size(ctx, princ) >= 2) { 68 | user_name_ += "/"; 69 | user_name_ += static_cast(princ->data[1].data); 70 | } 71 | user_name_ += "@"; 72 | user_name_ += princ->realm.data; 73 | VLOG(1) << "user " << user_name_; 74 | krb5_free_principal(ctx, princ); 75 | krb5_free_context(ctx); 76 | } 77 | } // namespace hbase 78 | -------------------------------------------------------------------------------- /src/hbase/client/time-range.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/client/time-range.h" 21 | #include 22 | #include 23 | #include 24 | 25 | namespace hbase { 26 | 27 | TimeRange::TimeRange() 28 | : min_timestamp_(0L), max_timestamp_(std::numeric_limits::max()), all_time_(true) {} 29 | 30 | TimeRange::TimeRange(const TimeRange &tr) { 31 | this->all_time_ = tr.all_time_; 32 | this->max_timestamp_ = tr.max_timestamp_; 33 | this->min_timestamp_ = tr.min_timestamp_; 34 | } 35 | 36 | TimeRange &TimeRange::operator=(const TimeRange &tr) { 37 | this->all_time_ = tr.all_time_; 38 | this->max_timestamp_ = tr.max_timestamp_; 39 | this->min_timestamp_ = tr.min_timestamp_; 40 | return *this; 41 | } 42 | 43 | TimeRange::~TimeRange() {} 44 | 45 | TimeRange::TimeRange(int64_t min_timestamp) { 46 | this->min_timestamp_ = min_timestamp; 47 | this->max_timestamp_ = std::numeric_limits::max(); 48 | this->all_time_ = false; 49 | } 50 | 51 | TimeRange::TimeRange(int64_t min_timestamp, int64_t max_timestamp) { 52 | if (min_timestamp < 0 || max_timestamp < 0) { 53 | throw std::runtime_error("Timestamp cannot be negative. min_timestamp: " + 54 | std::to_string(min_timestamp) + ", max_timestamp:" + 55 | std::to_string(max_timestamp)); 56 | } 57 | if (max_timestamp < min_timestamp) { 58 | throw std::runtime_error("max_timestamp [" + std::to_string(max_timestamp) + 59 | "] should be greater than min_timestamp [" + 60 | std::to_string(min_timestamp) + "]"); 61 | } 62 | 63 | this->min_timestamp_ = min_timestamp; 64 | this->max_timestamp_ = max_timestamp; 65 | this->all_time_ = false; 66 | } 67 | 68 | int64_t TimeRange::MinTimeStamp() const { return this->min_timestamp_; } 69 | 70 | int64_t TimeRange::MaxTimeStamp() const { return this->max_timestamp_; } 71 | 72 | bool TimeRange::IsAllTime() const { return this->all_time_; } 73 | } // namespace hbase 74 | -------------------------------------------------------------------------------- /include/hbase/client/response-converter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include "hbase/connection/request.h" 25 | #include "hbase/connection/response.h" 26 | #include "hbase/client/multi-response.h" 27 | #include "hbase/client/result.h" 28 | #include "hbase/client/server-request.h" 29 | #include "hbase/if/client/Client.pb.h" 30 | #include "hbase/serde/cell-scanner.h" 31 | 32 | namespace hbase { 33 | 34 | /** 35 | * ResponseConverter class 36 | * This class converts a PB Response to corresponding Result or other objects. 37 | */ 38 | class ResponseConverter { 39 | public: 40 | ~ResponseConverter(); 41 | 42 | static std::shared_ptr ToResult(const hbase::pb::Result& result, 43 | const std::shared_ptr cell_scanner); 44 | 45 | /** 46 | * @brief Returns a Result object created by PB Message in passed Response object. 47 | * @param resp - Response object having the PB message. 48 | */ 49 | static std::shared_ptr FromGetResponse(const Response& resp); 50 | 51 | static std::shared_ptr FromMutateResponse(const Response& resp); 52 | 53 | static bool BoolFromMutateResponse(const Response& resp); 54 | 55 | static std::vector> FromScanResponse(const Response& resp); 56 | 57 | static std::vector> FromScanResponse( 58 | const std::shared_ptr resp, std::shared_ptr cell_scanner); 59 | 60 | static std::unique_ptr GetResults( 61 | std::shared_ptr req, const Response& resp, 62 | const ServerRequest::ActionsByRegion& actions_by_region); 63 | 64 | private: 65 | // Constructor not required. We have all static methods to extract response from PB messages. 66 | ResponseConverter(); 67 | static std::shared_ptr GetRemoteException( 68 | const hbase::pb::NameBytesPair& exc_resp); 69 | }; 70 | 71 | } /* namespace hbase */ 72 | -------------------------------------------------------------------------------- /src/hbase/client/keyvalue-codec.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #include "hbase/client/keyvalue-codec.h" 21 | 22 | #include 23 | 24 | namespace hbase { 25 | 26 | KeyValueCodec::KVDecoder::KVDecoder(std::unique_ptr cell_block, uint32_t offset, 27 | uint32_t length) 28 | : cell_block_(std::move(cell_block)), offset_(offset), length_(length) {} 29 | 30 | KeyValueCodec::KVDecoder::~KVDecoder() {} 31 | 32 | std::shared_ptr KeyValueCodec::KVDecoder::Decode(folly::io::Cursor &cursor) { 33 | uint32_t key_length = cursor.readBE(); 34 | uint32_t value_length = cursor.readBE(); 35 | uint16_t row_length = cursor.readBE(); 36 | std::string row = cursor.readFixedString(row_length); 37 | uint8_t column_family_length = cursor.readBE(); 38 | std::string column_family = cursor.readFixedString(column_family_length); 39 | int qualifier_length = 40 | key_length - (row_length + column_family_length + kHBaseSizeOfKeyInfrastructure_); 41 | std::string column_qualifier = cursor.readFixedString(qualifier_length); 42 | uint64_t timestamp = cursor.readBE(); 43 | uint8_t key_type = cursor.readBE(); 44 | std::string value = cursor.readFixedString(value_length); 45 | 46 | return std::make_shared(row, column_family, column_qualifier, timestamp, value, 47 | static_cast(key_type)); 48 | } 49 | 50 | bool KeyValueCodec::KVDecoder::Advance() { 51 | if (end_of_cell_block_) { 52 | return false; 53 | } 54 | 55 | if (cur_pos_ == length_) { 56 | end_of_cell_block_ = true; 57 | return false; 58 | } 59 | 60 | folly::io::Cursor cursor(cell_block_.get()); 61 | cursor.skip(offset_ + cur_pos_); 62 | uint32_t current_cell_size = cursor.readBE(); 63 | current_cell_ = Decode(cursor); 64 | cur_pos_ += kHBaseSizeOfInt_ + current_cell_size; 65 | return true; 66 | } 67 | 68 | uint32_t KeyValueCodec::KVDecoder::CellBlockLength() const { return length_; } 69 | } /* namespace hbase */ 70 | -------------------------------------------------------------------------------- /include/hbase/utils/time-util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | namespace hbase { 26 | 27 | class TimeUtil { 28 | public: 29 | static inline int64_t ToMillis(const int64_t& nanos) { 30 | return std::chrono::duration_cast(std::chrono::nanoseconds(nanos)) 31 | .count(); 32 | } 33 | 34 | static inline std::chrono::milliseconds ToMillis(const std::chrono::nanoseconds& nanos) { 35 | return std::chrono::duration_cast(std::chrono::nanoseconds(nanos)); 36 | } 37 | 38 | static inline std::chrono::nanoseconds ToNanos(const std::chrono::milliseconds& millis) { 39 | return std::chrono::duration_cast(millis); 40 | } 41 | 42 | static inline std::chrono::nanoseconds MillisToNanos(const int64_t& millis) { 43 | return std::chrono::duration_cast(std::chrono::milliseconds(millis)); 44 | } 45 | 46 | static inline std::chrono::nanoseconds SecondsToNanos(const int64_t& secs) { 47 | return std::chrono::duration_cast(std::chrono::seconds(secs)); 48 | } 49 | 50 | static inline std::string ToMillisStr(const std::chrono::nanoseconds& nanos) { 51 | return std::to_string(std::chrono::duration_cast(nanos).count()); 52 | } 53 | 54 | static inline int64_t GetNowNanos() { 55 | auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); 56 | return std::chrono::duration_cast(duration).count(); 57 | } 58 | 59 | static inline int64_t ElapsedMillis(const int64_t& start_ns) { 60 | return std::chrono::duration_cast( 61 | std::chrono::nanoseconds(GetNowNanos() - start_ns)) 62 | .count(); 63 | } 64 | 65 | static inline std::string ElapsedMillisStr(const int64_t& start_ns) { 66 | return std::to_string(std::chrono::duration_cast( 67 | std::chrono::nanoseconds(GetNowNanos() - start_ns)) 68 | .count()); 69 | } 70 | }; 71 | } /* namespace hbase */ 72 | -------------------------------------------------------------------------------- /include/hbase/client/multi-response.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "hbase/client/region-result.h" 29 | #include "hbase/client/result.h" 30 | #include "client/Client.pb.h" 31 | 32 | namespace hbase { 33 | 34 | class MultiResponse { 35 | public: 36 | MultiResponse(); 37 | /** 38 | * @brief Returns Number of pairs in this container 39 | */ 40 | int Size() const; 41 | 42 | /** 43 | * Add the pair to the container, grouped by the regionName 44 | * 45 | * @param regionName 46 | * @param originalIndex the original index of the Action (request). 47 | * @param resOrEx the result or error; will be empty for successful Put and Delete actions. 48 | */ 49 | void AddRegionResult(const std::string& region_name, int32_t original_index, 50 | std::shared_ptr result, 51 | std::shared_ptr exc); 52 | 53 | void AddRegionException(const std::string& region_name, 54 | std::shared_ptr exception); 55 | 56 | /** 57 | * @return the exception for the region, if any. Null otherwise. 58 | */ 59 | std::shared_ptr RegionException(const std::string& region_name) const; 60 | 61 | const std::map>& RegionExceptions() const; 62 | 63 | void AddStatistic(const std::string& region_name, std::shared_ptr stat); 64 | 65 | const std::map>& RegionResults() const; 66 | 67 | ~MultiResponse(); 68 | 69 | private: 70 | // map of regionName to map of Results by the original index for that Result 71 | std::map> results_; 72 | /** 73 | * The server can send us a failure for the region itself, instead of individual failure. 74 | * It's a part of the protobuf definition. 75 | */ 76 | std::map> exceptions_; 77 | }; 78 | 79 | } /* namespace hbase */ 80 | -------------------------------------------------------------------------------- /include/hbase/connection/client-dispatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "hbase/connection/pipeline.h" 32 | #include "hbase/connection/request.h" 33 | #include "hbase/connection/response.h" 34 | #include "hbase/utils/concurrent-map.h" 35 | 36 | namespace hbase { 37 | 38 | /** 39 | * Dispatcher that assigns a call_id and then routes the response back to the 40 | * future. 41 | */ 42 | class ClientDispatcher 43 | : public wangle::ClientDispatcherBase, 44 | std::unique_ptr> { 45 | public: 46 | /** Create a new ClientDispatcher */ 47 | explicit ClientDispatcher(const std::string &server); 48 | /** Read a response off the pipeline. */ 49 | void read(Context *ctx, std::unique_ptr in) override; 50 | void readException(Context *ctx, folly::exception_wrapper e) override; 51 | void readEOF(Context *ctx) override; 52 | /** Take a request as a call and send it down the pipeline. */ 53 | folly::Future> operator()(std::unique_ptr arg) override; 54 | /** Close the dispatcher and the associated pipeline. */ 55 | folly::Future close(Context *ctx) override; 56 | /** Close the dispatcher and the associated pipeline. */ 57 | folly::Future close() override; 58 | 59 | private: 60 | void CloseAndCleanUpCalls(); 61 | 62 | private: 63 | std::recursive_mutex mutex_; 64 | concurrent_map>> requests_; 65 | // Start at some number way above what could 66 | // be there for un-initialized call id counters. 67 | // 68 | // This makes it easier to make sure that the're are 69 | // no access to un-initialized variables. 70 | // 71 | // uint32_t has a max of 4Billion so 10 more or less is 72 | // not a big deal. 73 | std::atomic current_call_id_; 74 | std::string server_; 75 | bool is_closed_; 76 | }; 77 | } // namespace hbase 78 | -------------------------------------------------------------------------------- /include/hbase/connection/client-handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "hbase/client/configuration.h" 30 | #include "hbase/exceptions/exception.h" 31 | #include "hbase/serde/codec.h" 32 | #include "hbase/serde/rpc-serde.h" 33 | #include "hbase/utils/concurrent-map.h" 34 | 35 | // Forward decs. 36 | namespace hbase { 37 | class Request; 38 | class Response; 39 | class HeaderInfo; 40 | } 41 | namespace google { 42 | namespace protobuf { 43 | class Message; 44 | } 45 | } 46 | 47 | namespace hbase { 48 | 49 | /** 50 | * wangle::Handler implementation to convert hbase::Request to IOBuf and 51 | * convert IOBuf to hbase::Response. 52 | * 53 | * This class deals with sending the connection header and preamble 54 | * on first request. 55 | */ 56 | class ClientHandler 57 | : public wangle::Handler, std::unique_ptr, 58 | std::unique_ptr, std::unique_ptr> { 59 | public: 60 | /** 61 | * Create the handler 62 | * @param user_name the user name of the user running this process. 63 | */ 64 | ClientHandler(std::string user_name, std::shared_ptr codec, 65 | std::shared_ptr conf, const std::string &server); 66 | 67 | /** 68 | * Get bytes from the wire. 69 | * This should be the full message as the length field decoder should be 70 | * in the pipeline before this. 71 | */ 72 | void read(Context *ctx, std::unique_ptr msg) override; 73 | 74 | /** 75 | * Write the data down the wire. 76 | */ 77 | folly::Future write(Context *ctx, std::unique_ptr r) override; 78 | 79 | private: 80 | std::unique_ptr once_flag_; 81 | std::string user_name_; 82 | RpcSerde serde_; 83 | std::string server_; // for logging 84 | std::shared_ptr conf_; 85 | 86 | // in flight requests 87 | std::unique_ptr>> resp_msgs_; 88 | }; 89 | } // namespace hbase 90 | -------------------------------------------------------------------------------- /include/hbase/connection/response.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "hbase/serde/cell-scanner.h" 30 | 31 | // Forward 32 | namespace google { 33 | namespace protobuf { 34 | class Message; 35 | } 36 | } 37 | 38 | namespace hbase { 39 | 40 | /** 41 | * @brief Class representing a rpc response 42 | * 43 | * This is the class sent to a service. 44 | */ 45 | class Response { 46 | public: 47 | /** 48 | * Constructor. 49 | * Initinalizes the call id to 0. 0 should never be a valid call id. 50 | */ 51 | Response() : call_id_(0), resp_msg_(nullptr), cell_scanner_(nullptr), exception_(nullptr) {} 52 | 53 | /** Get the call_id */ 54 | uint32_t call_id() { return call_id_; } 55 | 56 | /** Set the call_id */ 57 | void set_call_id(uint32_t call_id) { call_id_ = call_id; } 58 | 59 | /** 60 | * Get the response message. 61 | * The caller is reponsible for knowing the type. In practice the call id is 62 | * used to figure out the type. 63 | */ 64 | std::shared_ptr resp_msg() const { return resp_msg_; } 65 | 66 | /** Set the response message. */ 67 | void set_resp_msg(std::shared_ptr response) { 68 | resp_msg_ = std::move(response); 69 | } 70 | 71 | void set_cell_scanner(std::shared_ptr cell_scanner) { cell_scanner_ = cell_scanner; } 72 | 73 | const std::shared_ptr cell_scanner() const { return cell_scanner_; } 74 | 75 | folly::exception_wrapper exception() { return exception_; } 76 | 77 | void set_exception(folly::exception_wrapper value) { exception_ = value; } 78 | 79 | std::string DebugString() const { 80 | std::string s{"call_id:"}; 81 | s += folly::to(call_id_); 82 | s += ", resp_msg:"; 83 | s += resp_msg_->ShortDebugString(); 84 | return s; 85 | } 86 | 87 | private: 88 | uint32_t call_id_; 89 | std::shared_ptr resp_msg_; 90 | std::shared_ptr cell_scanner_; 91 | folly::exception_wrapper exception_; 92 | }; 93 | } // namespace hbase 94 | --------------------------------------------------------------------------------