This is an automated email from the ASF dual-hosted git repository. zghao pushed a commit to branch HBASE-14850 in repository https://gitbox.apache.org/repos/asf/hbase.git
commit 4aa2193b7229a8173ad7bde90b6798850cb34644 Author: Enis Soztutar <[email protected]> AuthorDate: Mon Feb 13 18:52:04 2017 -0800 HBASE-17612 [C++] Set client version info in RPC header --- hbase-common/pom.xml | 6 ++--- hbase-common/src/saveVersion.sh | 24 +++++++++++++++++ hbase-native-client/.gitignore | 3 +++ hbase-native-client/Makefile | 8 +++--- .../{utils/BUCK => bin/copy-version.sh} | 20 ++++++--------- hbase-native-client/bin/start-docker.sh | 3 +++ hbase-native-client/serde/BUCK | 5 +--- hbase-native-client/serde/rpc.cc | 30 +++++++++++++++++++++- hbase-native-client/serde/rpc.h | 2 ++ hbase-native-client/utils/BUCK | 2 +- 10 files changed, 78 insertions(+), 25 deletions(-) diff --git a/hbase-common/pom.xml b/hbase-common/pom.xml index 3e3acf0..e6f371e 100644 --- a/hbase-common/pom.xml +++ b/hbase-common/pom.xml @@ -84,16 +84,14 @@ <goal>run</goal> </goals> </execution> - <!-- Generate web app sources --> <execution> <id>generate-Version-information</id> <phase>generate-sources</phase> <configuration> <target> <property name="generated.sources" location="${project.build.directory}/generated-sources"/> - - <exec executable="bash" failonerror="true"> - <arg line="${basedir}/src/saveVersion.sh ${project.version} ${generated.sources}/java"/> + <exec executable="bash"> + <arg line="${basedir}/src/saveVersion.sh ${project.version} ${generated.sources}/java ${generated.sources}/native"/> </exec> </target> </configuration> diff --git a/hbase-common/src/saveVersion.sh b/hbase-common/src/saveVersion.sh index 507bbb0..013b730 100644 --- a/hbase-common/src/saveVersion.sh +++ b/hbase-common/src/saveVersion.sh @@ -25,6 +25,7 @@ unset LC_CTYPE version=$1 outputDirectory=$2 +cppOutputDirectory=$3 pushd . cd .. @@ -80,3 +81,26 @@ public class Version { } EOF +# Generate C++ code +mkdir -p "$cppOutputDirectory/utils" +cat >"$cppOutputDirectory/utils/version.h" <<EOF +/* + * Generated by src/saveVersion.sh + */ + +#pragma once + +namespace hbase { + +class Version { + public: + static constexpr const char* version = "$version"; + static constexpr const char* revision = "$revision"; + static constexpr const char* user = "$user"; + static constexpr const char* date = "$date"; + static constexpr const char* url = "$url"; + static constexpr const char* src_checksum = "$srcChecksum"; +}; +} // namespace hbase +EOF + diff --git a/hbase-native-client/.gitignore b/hbase-native-client/.gitignore index c0032e4..c99ce59 100644 --- a/hbase-native-client/.gitignore +++ b/hbase-native-client/.gitignore @@ -24,3 +24,6 @@ buck-out # Thirdparty dirs third-party/* /gcc-debug/ + +# Generated files +utils/version.h diff --git a/hbase-native-client/Makefile b/hbase-native-client/Makefile index 99e38ef..84ae556 100644 --- a/hbase-native-client/Makefile +++ b/hbase-native-client/Makefile @@ -57,7 +57,7 @@ ARC_DEBUG=$(DEBUG_PATH)/libHbaseClient_d.a vpath %.cc $(SRC_DIR) -build: checkdirs protos $(LIB_DEBUG) $(LIB_RELEASE) $(ARC_DEBUG) $(ARC_RELEASE) +build: checkdirs copyfiles protos $(LIB_DEBUG) $(LIB_RELEASE) $(ARC_DEBUG) $(ARC_RELEASE) $(LIB_DEBUG): $(DEBUG_BUILD_DIR) define make-goal-dbg $1/%.o: %.cc $(DEPS) $(PROTODEPS) $(PROTOSRC) @@ -72,10 +72,12 @@ endef .PHONY: all clean install - - checkdirs: $(DEBUG_BUILD_DIR) $(RELEASE_BUILD_DIR) $(PROTO_SRC_DIR) +copyfiles: + bin/copy-protobuf.sh + bin/copy-version.sh + protos: createprotosrc @make all -f Makefile.protos diff --git a/hbase-native-client/utils/BUCK b/hbase-native-client/bin/copy-version.sh old mode 100644 new mode 100755 similarity index 69% copy from hbase-native-client/utils/BUCK copy to hbase-native-client/bin/copy-version.sh index 120331a..b33db7a --- a/hbase-native-client/utils/BUCK +++ b/hbase-native-client/bin/copy-version.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash ## # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file @@ -14,16 +15,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +set -euo pipefail +IFS=$'\n\t' -cxx_library( - name="utils", - exported_headers=["user-util.h",], - srcs=["user-util.cc",], - deps=['//third-party:folly',], - tests=[":user-util-test"], - visibility=['PUBLIC',], - compiler_flags=['-Weffc++'],) -cxx_test( - name="user-util-test", - srcs=["user-util-test.cc",], - deps=[":utils",],) +# Copy the version.h generated from hbase-common/src/saveVersion.sh script via the mvn build +BIN_DIR=$(dirname "$0") +VERSION_SOURCE_DIR="${BIN_DIR}/../../hbase-common/target/generated-sources/native/utils/" +VERSION_DEST_DIR="${BIN_DIR}/../utils/" +cp $VERSION_SOURCE_DIR/* $VERSION_DEST_DIR/ diff --git a/hbase-native-client/bin/start-docker.sh b/hbase-native-client/bin/start-docker.sh index 38affa0..1380cdf 100755 --- a/hbase-native-client/bin/start-docker.sh +++ b/hbase-native-client/bin/start-docker.sh @@ -26,7 +26,10 @@ eval "$(docker-machine env dinghy)" BIN_DIR=$(pushd `dirname "$0"` 2>&1 > /dev/null && pwd && popd 2>&1 > /dev/null) BASE_DIR=$(pushd "${BIN_DIR}/../" 2>&1 > /dev/null && pwd && popd 2>&1 > /dev/null) +# TODO: this is wrong. These should be called from BUCK, but I could not find a +# way to execute scripts in BUCK that are in under bin/. ${BIN_DIR}/copy-protobuf.sh +${BIN_DIR}/copy-version.sh # Go into the base dir. This just makes things cleaner. pushd ${BASE_DIR} diff --git a/hbase-native-client/serde/BUCK b/hbase-native-client/serde/BUCK index c6809a8..38e7b4d 100644 --- a/hbase-native-client/serde/BUCK +++ b/hbase-native-client/serde/BUCK @@ -31,10 +31,7 @@ cxx_library( "rpc.cc", "zk.cc", ], - deps=[ - "//if:if", - "//third-party:folly", - ], + deps=["//if:if", "//third-party:folly", "//utils:utils"], tests=[ ":client-deserializer-test", ":client-serializer-test", diff --git a/hbase-native-client/serde/rpc.cc b/hbase-native-client/serde/rpc.cc index d5bca62..e657a64 100644 --- a/hbase-native-client/serde/rpc.cc +++ b/hbase-native-client/serde/rpc.cc @@ -19,16 +19,18 @@ #include "serde/rpc.h" +#include <folly/Conv.h> #include <folly/Logging.h> #include <folly/io/Cursor.h> #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/zero_copy_stream_impl_lite.h> #include <google/protobuf/message.h> +#include <boost/algorithm/string.hpp> #include <utility> -#include "if/HBase.pb.h" #include "if/RPC.pb.h" +#include "utils/version.h" using namespace hbase; @@ -111,12 +113,38 @@ unique_ptr<IOBuf> RpcSerde::Header(const string &user) { // TODO: send the service name and user from the RpcClient h.set_service_name(INTERFACE); + std::unique_ptr<pb::VersionInfo> version_info = CreateVersionInfo(); + + h.set_allocated_version_info(version_info.release()); + if (codec_ != nullptr) { h.set_cell_block_codec_class(codec_->java_class_name()); } return PrependLength(SerializeMessage(h)); } +std::unique_ptr<pb::VersionInfo> RpcSerde::CreateVersionInfo() { + std::unique_ptr<pb::VersionInfo> version_info = std::make_unique<pb::VersionInfo>(); + version_info->set_user(Version::user); + version_info->set_revision(Version::revision); + version_info->set_url(Version::url); + version_info->set_date(Version::date); + version_info->set_src_checksum(Version::src_checksum); + version_info->set_version(Version::version); + + std::string version{Version::version}; + std::vector<std::string> version_parts; + boost::split(version_parts, version, boost::is_any_of("."), boost::token_compress_on); + uint32_t major_version = 0, minor_version = 0; + if (version_parts.size() >= 2) { + version_info->set_version_major(folly::to<uint32_t>(version_parts[0])); + version_info->set_version_minor(folly::to<uint32_t>(version_parts[1])); + } + + VLOG(1) << "Client VersionInfo:" << version_info->ShortDebugString(); + return version_info; +} + unique_ptr<IOBuf> RpcSerde::Request(const uint32_t call_id, const string &method, const Message *msg) { pb::RequestHeader rq; diff --git a/hbase-native-client/serde/rpc.h b/hbase-native-client/serde/rpc.h index c59f903..abebe94 100644 --- a/hbase-native-client/serde/rpc.h +++ b/hbase-native-client/serde/rpc.h @@ -21,6 +21,7 @@ #include <memory> #include <string> +#include "if/HBase.pb.h" #include "serde/cell-scanner.h" #include "serde/codec.h" @@ -120,5 +121,6 @@ class RpcSerde { /* data */ uint8_t auth_type_; std::shared_ptr<Codec> codec_; + std::unique_ptr<pb::VersionInfo> CreateVersionInfo(); }; } // namespace hbase diff --git a/hbase-native-client/utils/BUCK b/hbase-native-client/utils/BUCK index 120331a..796f2f5 100644 --- a/hbase-native-client/utils/BUCK +++ b/hbase-native-client/utils/BUCK @@ -17,7 +17,7 @@ cxx_library( name="utils", - exported_headers=["user-util.h",], + exported_headers=["user-util.h", "version.h"], srcs=["user-util.cc",], deps=['//third-party:folly',], tests=[":user-util-test"],
