From d4975f84b3c178ce317297200b889edb2b98c548 Mon Sep 17 00:00:00 2001 From: Tao He Date: Wed, 6 Apr 2022 16:01:49 +0800 Subject: [PATCH] Return complete meta information of HEAD. (#123) * Return complete meta information of HEAD. * Fixes the CI by revisiting the LD_LIBRARY_PATH. Signed-off-by: Tao He --- .github/workflows/build-test.yml | 8 ++++---- CMakeLists.txt | 2 +- etcd/Response.hpp | 19 +++++++++++++++++++ etcd/v3/V3Response.hpp | 6 ++++++ src/Response.cpp | 17 +++++++++++++++++ src/v3/AsyncHeadResponse.cpp | 3 +++ src/v3/V3Response.cpp | 12 ++++++++++++ 7 files changed, 62 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 59a9283..91b45f0 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -129,7 +129,7 @@ jobs: - name: Build run: | - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib/x86_64-linux-gnu mkdir -p build cd build @@ -148,7 +148,7 @@ jobs: - name: Test run: | - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib/x86_64-linux-gnu # use etcd v3 api export ETCDCTL_API="3" @@ -171,7 +171,7 @@ jobs: - name: Authentication Test run: | - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib/x86_64-linux-gnu # use etcd v3 api export ETCDCTL_API="3" @@ -212,7 +212,7 @@ jobs: - name: Transport Security and Authentication Test run: | - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib/x86_64-linux-gnu # use etcd v3 api export ETCDCTL_API="3" diff --git a/CMakeLists.txt b/CMakeLists.txt index 9607774..721f989 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ option(BUILD_ETCD_TESTS "Build test cases" OFF) # reference: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) -set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64") +set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:${CMAKE_INSTALL_PREFIX}/lib/x86_64-linux-gnu") set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) if(MSVC) diff --git a/etcd/Response.hpp b/etcd/Response.hpp index 692444c..435936a 100644 --- a/etcd/Response.hpp +++ b/etcd/Response.hpp @@ -171,6 +171,21 @@ namespace etcd */ std::chrono::microseconds const & duration() const; + /** + * Returns the current cluster id. + */ + uint64_t cluster_id() const; + + /** + * Returns the current member id. + */ + uint64_t member_id() const; + + /** + * Returns ther current raft term. + */ + uint64_t raft_term() const; + protected: Response(const etcdv3::V3Response& response, std::chrono::microseconds const& duration); Response(int error_code, char const * error_message); @@ -190,6 +205,10 @@ namespace etcd // execute duration (in microseconds), during the action created and response parsed std::chrono::microseconds _duration; + uint64_t _cluster_id; + uint64_t _member_id; + uint64_t _raft_term; + friend class Client; friend class SyncClient; friend class etcdv3::AsyncWatchAction; diff --git a/etcd/v3/V3Response.hpp b/etcd/v3/V3Response.hpp index 58d65fa..d96f902 100644 --- a/etcd/v3/V3Response.hpp +++ b/etcd/v3/V3Response.hpp @@ -31,6 +31,9 @@ namespace etcdv3 void set_name(std::string const &name); std::string const &get_name() const; std::vector const & get_events() const; + uint64_t get_cluster_id() const; + uint64_t get_member_id() const; + uint64_t get_raft_term() const; protected: int error_code; int64_t index; @@ -44,6 +47,9 @@ namespace etcdv3 std::string lock_key; // for lock std::string name; // for campaign (in v3election) std::vector events; // for watch + uint64_t cluster_id; + uint64_t member_id; + uint64_t raft_term; }; } #endif diff --git a/src/Response.cpp b/src/Response.cpp index 376d563..b065f8f 100644 --- a/src/Response.cpp +++ b/src/Response.cpp @@ -34,6 +34,11 @@ etcd::Response::Response(const etcdv3::V3Response& reply, std::chrono::microseco // duration _duration = duration; + + // etcd head + _cluster_id = reply.get_cluster_id(); + _member_id = reply.get_member_id(); + _raft_term = reply.get_raft_term(); } @@ -130,3 +135,15 @@ std::vector const & etcd::Response::events() const { std::chrono::microseconds const& etcd::Response::duration() const { return this->_duration; } + +uint64_t etcd::Response::cluster_id() const { + return this->_cluster_id; +} + +uint64_t etcd::Response::member_id() const { + return this->_member_id; +} + +uint64_t etcd::Response::raft_term() const { + return this->_raft_term; +} diff --git a/src/v3/AsyncHeadResponse.cpp b/src/v3/AsyncHeadResponse.cpp index 25fdac6..5169a63 100644 --- a/src/v3/AsyncHeadResponse.cpp +++ b/src/v3/AsyncHeadResponse.cpp @@ -4,5 +4,8 @@ void etcdv3::AsyncHeadResponse::ParseResponse(RangeResponse& resp) { + cluster_id = resp.header().cluster_id(); + member_id = resp.header().member_id(); index = resp.header().revision(); + raft_term = resp.header().raft_term(); } diff --git a/src/v3/V3Response.cpp b/src/v3/V3Response.cpp index 1d9312b..f206fd0 100644 --- a/src/v3/V3Response.cpp +++ b/src/v3/V3Response.cpp @@ -85,3 +85,15 @@ std::string const & etcdv3::V3Response::get_name() const { std::vector const & etcdv3::V3Response::get_events() const { return this->events; } + +uint64_t etcdv3::V3Response::get_cluster_id() const { + return this->cluster_id; +} + +uint64_t etcdv3::V3Response::get_member_id() const { + return this->member_id; +} + +uint64_t etcdv3::V3Response::get_raft_term() const { + return this->raft_term; +}