From: Venky Shankar Date: Thu, 20 Aug 2020 04:35:00 +0000 (-0400) Subject: librados: API to decode notify message (bufferlist) X-Git-Tag: v16.1.0~932^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=310422b34456ab15ea994642f9edc06efb2b59e1;p=ceph.git librados: API to decode notify message (bufferlist) To keep consistency between the C and C++ APIs. Signed-off-by: Venky Shankar --- diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index d4bf6af35623..61569908510c 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -1237,6 +1237,12 @@ inline namespace v14_2_0 { bufferlist& bl, ///< optional broadcast payload uint64_t timeout_ms, ///< timeout (in ms) bufferlist *pbl); ///< reply buffer + /* + * Decode a notify response into acks and timeout vectors. + */ + void decode_notify_response(bufferlist &bl, + std::vector *acks, + std::vector *timeouts); int list_watchers(const std::string& o, std::list *out_watchers); int list_snaps(const std::string& o, snap_set_t *out_snaps); diff --git a/src/include/rados/rados_types.hpp b/src/include/rados/rados_types.hpp index 8c02dd83736a..84023579b3ec 100644 --- a/src/include/rados/rados_types.hpp +++ b/src/include/rados/rados_types.hpp @@ -327,5 +327,15 @@ struct inconsistent_snapset_t { */ const std::string all_nspaces(LIBRADOS_ALL_NSPACES); +struct notify_ack_t { + uint64_t notifier_id; + uint64_t cookie; + ceph::bufferlist payload_bl; +}; + +struct notify_timeout_t { + uint64_t notifier_id; + uint64_t cookie; +}; } #endif diff --git a/src/librados/librados_cxx.cc b/src/librados/librados_cxx.cc index 24810410b64c..1aadae49943c 100644 --- a/src/librados/librados_cxx.cc +++ b/src/librados/librados_cxx.cc @@ -2152,6 +2152,25 @@ int librados::IoCtx::aio_notify(const string& oid, AioCompletion *c, NULL); } +void librados::IoCtx::decode_notify_response(bufferlist &bl, + std::vector *acks, + std::vector *timeouts) +{ + map,bufferlist> acked; + set> missed; + + auto iter = bl.cbegin(); + decode(acked, iter); + decode(missed, iter); + + for (auto &[who, payload] : acked) { + acks->emplace_back(librados::notify_ack_t{who.first, who.second, payload}); + } + for (auto &[notifier_id, cookie] : missed) { + timeouts->emplace_back(librados::notify_timeout_t{notifier_id, cookie}); + } +} + void librados::IoCtx::notify_ack(const std::string& o, uint64_t notify_id, uint64_t handle, bufferlist& bl) diff --git a/src/test/librados/watch_notify_cxx.cc b/src/test/librados/watch_notify_cxx.cc index c74ccbe915aa..e6b1027d4a4b 100644 --- a/src/test/librados/watch_notify_cxx.cc +++ b/src/test/librados/watch_notify_cxx.cc @@ -276,17 +276,15 @@ TEST_P(LibRadosWatchNotifyPP, AioNotify) { ASSERT_EQ(0, comp->wait_for_complete()); ASSERT_EQ(0, comp->get_return_value()); comp->release(); - auto p = bl_reply.cbegin(); - std::map,bufferlist> reply_map; - std::set > missed_map; - decode(reply_map, p); - decode(missed_map, p); + std::vector acks; + std::vector timeouts; + ioctx.decode_notify_response(bl_reply, &acks, &timeouts); ASSERT_EQ(1u, notify_cookies.size()); ASSERT_EQ(1u, notify_cookies.count(handle)); - ASSERT_EQ(1u, reply_map.size()); - ASSERT_EQ(5u, reply_map.begin()->second.length()); - ASSERT_EQ(0, strncmp("reply", reply_map.begin()->second.c_str(), 5)); - ASSERT_EQ(0u, missed_map.size()); + ASSERT_EQ(1u, acks.size()); + ASSERT_EQ(5u, acks[0].payload_bl.length()); + ASSERT_EQ(0, strncmp("reply", acks[0].payload_bl.c_str(), acks[0].payload_bl.length())); + ASSERT_EQ(0u, timeouts.size()); ASSERT_GT(ioctx.watch_check(handle), 0); ioctx.unwatch2(handle); cluster.watch_flush();