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; +}