Return complete meta information of HEAD.

Signed-off-by: Tao He <sighingnow@gmail.com>
This commit is contained in:
Tao He 2022-04-06 14:45:33 +08:00
parent 767f0b1c65
commit b5ac4e3e47
5 changed files with 57 additions and 0 deletions

View File

@ -171,6 +171,21 @@ namespace etcd
*/ */
std::chrono::microseconds const & duration() const; 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: protected:
Response(const etcdv3::V3Response& response, std::chrono::microseconds const& duration); Response(const etcdv3::V3Response& response, std::chrono::microseconds const& duration);
Response(int error_code, char const * error_message); 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 // execute duration (in microseconds), during the action created and response parsed
std::chrono::microseconds _duration; std::chrono::microseconds _duration;
uint64_t _cluster_id;
uint64_t _member_id;
uint64_t _raft_term;
friend class Client; friend class Client;
friend class SyncClient; friend class SyncClient;
friend class etcdv3::AsyncWatchAction; friend class etcdv3::AsyncWatchAction;

View File

@ -31,6 +31,9 @@ namespace etcdv3
void set_name(std::string const &name); void set_name(std::string const &name);
std::string const &get_name() const; std::string const &get_name() const;
std::vector<mvccpb::Event> const & get_events() const; std::vector<mvccpb::Event> const & get_events() const;
uint64_t get_cluster_id() const;
uint64_t get_member_id() const;
uint64_t get_raft_term() const;
protected: protected:
int error_code; int error_code;
int64_t index; int64_t index;
@ -44,6 +47,9 @@ namespace etcdv3
std::string lock_key; // for lock std::string lock_key; // for lock
std::string name; // for campaign (in v3election) std::string name; // for campaign (in v3election)
std::vector<mvccpb::Event> events; // for watch std::vector<mvccpb::Event> events; // for watch
uint64_t cluster_id;
uint64_t member_id;
uint64_t raft_term;
}; };
} }
#endif #endif

View File

@ -34,6 +34,11 @@ etcd::Response::Response(const etcdv3::V3Response& reply, std::chrono::microseco
// duration // duration
_duration = 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<etcd::Event> const & etcd::Response::events() const {
std::chrono::microseconds const& etcd::Response::duration() const { std::chrono::microseconds const& etcd::Response::duration() const {
return this->_duration; 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;
}

View File

@ -4,5 +4,8 @@
void etcdv3::AsyncHeadResponse::ParseResponse(RangeResponse& resp) void etcdv3::AsyncHeadResponse::ParseResponse(RangeResponse& resp)
{ {
cluster_id = resp.header().cluster_id();
member_id = resp.header().member_id();
index = resp.header().revision(); index = resp.header().revision();
raft_term = resp.header().raft_term();
} }

View File

@ -85,3 +85,15 @@ std::string const & etcdv3::V3Response::get_name() const {
std::vector<mvccpb::Event> const & etcdv3::V3Response::get_events() const { std::vector<mvccpb::Event> const & etcdv3::V3Response::get_events() const {
return this->events; 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;
}