From 6b13dfbcc14913d27d26db7ad39899271c8911fc Mon Sep 17 00:00:00 2001 From: Tao He Date: Tue, 16 May 2023 09:24:16 +0800 Subject: [PATCH] Include watch_id in the response Signed-off-by: Tao He --- etcd/Response.hpp | 6 ++++++ etcd/v3/V3Response.hpp | 4 ++++ src/Response.cpp | 6 ++++++ src/v3/AsyncGRPC.cpp | 2 +- src/v3/V3Response.cpp | 15 +++++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/etcd/Response.hpp b/etcd/Response.hpp index 5a62322..d37a6d9 100644 --- a/etcd/Response.hpp +++ b/etcd/Response.hpp @@ -161,6 +161,11 @@ namespace etcd */ int64_t compact_revision() const; + /** + * Returns the watcher id for client.watch() requests. `-1` means uninitialized (the response is not for watch). + */ + int64_t watch_id() const; + /** * Returns the lock key. */ @@ -215,6 +220,7 @@ namespace etcd Values _values; Keys _keys; int64_t _compact_revision = -1; // for watch + int64_t _watch_id = -1; // for watch std::string _lock_key; // for lock std::string _name; // for campaign (in v3election) std::vector _events; // for watch diff --git a/etcd/v3/V3Response.hpp b/etcd/v3/V3Response.hpp index abe4614..2fa6eb0 100644 --- a/etcd/v3/V3Response.hpp +++ b/etcd/v3/V3Response.hpp @@ -26,6 +26,9 @@ namespace etcdv3 etcdv3::KeyValue const & get_prev_value() const; bool has_values() const; int64_t get_compact_revision() const; + void set_compact_revision(const int64_t compact_revision); + int64_t get_watch_id() const; + void set_watch_id(const int64_t watch_id); void set_lock_key(std::string const &key); std::string const &get_lock_key() const; void set_name(std::string const &name); @@ -45,6 +48,7 @@ namespace etcdv3 std::vector values; std::vector prev_values; int64_t compact_revision = -1; + int64_t watch_id = -1; std::string lock_key; // for lock std::string name; // for campaign (in v3election) std::vector events; // for watch diff --git a/src/Response.cpp b/src/Response.cpp index 759a4b5..85624a3 100644 --- a/src/Response.cpp +++ b/src/Response.cpp @@ -53,6 +53,7 @@ etcd::Response::Response(const etcdv3::V3Response& reply, std::chrono::microseco _prev_value = Value(reply.get_prev_value()); _compact_revision = reply.get_compact_revision(); + _watch_id = reply.get_watch_id(); _lock_key = reply.get_lock_key(); _name = reply.get_name(); @@ -156,6 +157,11 @@ int64_t etcd::Response::compact_revision() const return _compact_revision; } +int64_t etcd::Response::watch_id() const +{ + return _watch_id; +} + std::string const & etcd::Response::lock_key() const { return _lock_key; } diff --git a/src/v3/AsyncGRPC.cpp b/src/v3/AsyncGRPC.cpp index f8d0461..d31e321 100644 --- a/src/v3/AsyncGRPC.cpp +++ b/src/v3/AsyncGRPC.cpp @@ -261,7 +261,6 @@ void etcdv3::AsyncWatchResponse::ParseResponse(WatchResponse& reply) action = etcdv3::SET_ACTION; } value.kvs = event.kv(); - } else if(mvccpb::Event::EventType::Event_EventType_DELETE_ == event.type()) { @@ -1355,6 +1354,7 @@ etcdv3::AsyncWatchResponse etcdv3::AsyncWatchAction::ParseResponse() { AsyncWatchResponse watch_resp; watch_resp.set_action(etcdv3::WATCH_ACTION); + watch_resp.set_watch_id(reply.watch_id()); if(!status.ok()) { diff --git a/src/v3/V3Response.cpp b/src/v3/V3Response.cpp index 661e045..c35108e 100644 --- a/src/v3/V3Response.cpp +++ b/src/v3/V3Response.cpp @@ -66,6 +66,21 @@ int64_t etcdv3::V3Response::get_compact_revision() const return compact_revision; } +void etcdv3::V3Response::set_compact_revision(const int64_t compact_revision) +{ + this->compact_revision = compact_revision; +} + +int64_t etcdv3::V3Response::get_watch_id() const +{ + return watch_id; +} + +void etcdv3::V3Response::set_watch_id(const int64_t watch_id) +{ + this->watch_id = watch_id; +} + void etcdv3::V3Response::set_lock_key(std::string const &key) { this->lock_key = key; }