From 160a11c9c06f01615768de4cb8990d5d9415a9a5 Mon Sep 17 00:00:00 2001 From: NitzanMordhai Date: Mon, 11 Apr 2022 11:17:54 +0000 Subject: [PATCH] tests: LibRadosWatchNotifyPP.WatchNotify - reconnect on watch terminate When socket failure injection or any delay that time out watch we need reconnect the watch using the error callback to reconnect Fixes: https://tracker.ceph.com/issues/47025 Signed-off-by: Nitzan Mordechai (cherry picked from commit d2c5d7a4bfd58455bf99f2b3506339ce99493ce2) --- src/test/librados/watch_notify_cxx.cc | 40 +++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/test/librados/watch_notify_cxx.cc b/src/test/librados/watch_notify_cxx.cc index 624f417dad194..0a145addd1f42 100644 --- a/src/test/librados/watch_notify_cxx.cc +++ b/src/test/librados/watch_notify_cxx.cc @@ -33,6 +33,7 @@ protected: int notify_err = 0; friend class WatchNotifyTestCtx2; + friend class WatchNotifyTestCtx2TimeOut; }; IoCtx *notify_ioctx; @@ -59,6 +60,41 @@ public: notify_ioctx->notify_ack(notify->notify_oid, notify_id, cookie, reply); } + void handle_error(uint64_t cookie, int err) override { + std::cout << __func__ << " cookie " << cookie + << " err " << err << std::endl; + ceph_assert(cookie > 1000); + notify_ioctx->unwatch2(cookie); + notify->notify_cookies.erase(cookie); + notify->notify_err = notify_ioctx->watch2(notify->notify_oid, &cookie, this); + if (notify->notify_err < err ) { + std::cout << "reconnect notify_err " << notify->notify_err << " err " << err << std::endl; + } + } +}; + +class WatchNotifyTestCtx2TimeOut : public WatchCtx2 +{ + LibRadosWatchNotifyPP *notify; + +public: + WatchNotifyTestCtx2TimeOut(LibRadosWatchNotifyPP *notify) + : notify(notify) + {} + + void handle_notify(uint64_t notify_id, uint64_t cookie, uint64_t notifier_gid, + bufferlist& bl) override { + std::cout << __func__ << " cookie " << cookie << " notify_id " << notify_id + << " notifier_gid " << notifier_gid << std::endl; + notify->notify_bl = bl; + notify->notify_cookies.insert(cookie); + bufferlist reply; + reply.append("reply", 5); + if (notify_sleep) + sleep(notify_sleep); + notify_ioctx->notify_ack(notify->notify_oid, notify_id, cookie, reply); + } + void handle_error(uint64_t cookie, int err) override { std::cout << __func__ << " cookie " << cookie << " err " << err << std::endl; @@ -302,7 +338,7 @@ TEST_P(LibRadosWatchNotifyPP, WatchNotify2Timeout) { bl1.append(buf, sizeof(buf)); ASSERT_EQ(0, ioctx.write(notify_oid, bl1, sizeof(buf), 0)); uint64_t handle; - WatchNotifyTestCtx2 ctx(this); + WatchNotifyTestCtx2TimeOut ctx(this); ASSERT_EQ(0, ioctx.watch2(notify_oid, &handle, &ctx)); ASSERT_GT(ioctx.watch_check(handle), 0); std::list watches; @@ -337,7 +373,7 @@ TEST_P(LibRadosWatchNotifyPP, WatchNotify3) { bl1.append(buf, sizeof(buf)); ASSERT_EQ(0, ioctx.write(notify_oid, bl1, sizeof(buf), 0)); uint64_t handle; - WatchNotifyTestCtx2 ctx(this); + WatchNotifyTestCtx2TimeOut ctx(this); ASSERT_EQ(0, ioctx.watch3(notify_oid, &handle, &ctx, timeout)); ASSERT_GT(ioctx.watch_check(handle), 0); std::list watches; -- 2.39.5