Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

octopus: librados/watch_notify: reconnect after socket injection #46500

Open
wants to merge 2 commits into
base: octopus
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 62 additions & 14 deletions src/test/librados/watch_notify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LibRadosWatchNotify : public RadosTest
rados_ioctx_t notify_io;
const char *notify_oid = nullptr;
int notify_err = 0;
rados_completion_t notify_comp;

static void watch_notify2_test_cb(void *arg,
uint64_t notify_id,
Expand All @@ -41,6 +42,8 @@ class LibRadosWatchNotify : public RadosTest
void *data,
size_t data_len);
static void watch_notify2_test_errcb(void *arg, uint64_t cookie, int err);
static void watch_notify2_test_errcb_reconnect(void *arg, uint64_t cookie, int err);
static void watch_notify2_test_errcb_aio_reconnect(void *arg, uint64_t cookie, int err);
};


Expand All @@ -61,6 +64,7 @@ void LibRadosWatchNotify::watch_notify2_test_cb(void *arg,
thiz->notify_bl.append((char*)data, data_len);
if (notify_sleep)
sleep(notify_sleep);
thiz->notify_err = 0;
rados_notify_ack(thiz->notify_io, thiz->notify_oid, notify_id, cookie,
"reply", 5);
}
Expand All @@ -76,6 +80,49 @@ void LibRadosWatchNotify::watch_notify2_test_errcb(void *arg,
thiz->notify_err = err;
}

void LibRadosWatchNotify::watch_notify2_test_errcb_reconnect(void *arg,
uint64_t cookie,
int err)
{
std::cout << __func__ << " cookie " << cookie << " err " << err << std::endl;
ceph_assert(cookie > 1000);
auto thiz = reinterpret_cast<LibRadosWatchNotify*>(arg);
ceph_assert(thiz);
thiz->notify_err = rados_unwatch2(thiz->ioctx, cookie);
thiz->notify_cookies.erase(cookie); //delete old cookie
thiz->notify_err = rados_watch2(thiz->ioctx, thiz->notify_oid, &cookie,
watch_notify2_test_cb, watch_notify2_test_errcb_reconnect, thiz);
if (thiz->notify_err < 0) {
std::cout << __func__ << " reconnect watch failed with error " << thiz->notify_err << std::endl;
return;
}
return;
}


void LibRadosWatchNotify::watch_notify2_test_errcb_aio_reconnect(void *arg,
uint64_t cookie,
int err)
{
std::cout << __func__ << " cookie " << cookie << " err " << err << std::endl;
ceph_assert(cookie > 1000);
auto thiz = reinterpret_cast<LibRadosWatchNotify*>(arg);
ceph_assert(thiz);
thiz->notify_err = rados_aio_unwatch(thiz->ioctx, cookie, thiz->notify_comp);
ASSERT_EQ(0, rados_aio_create_completion2(nullptr, nullptr, &thiz->notify_comp));
thiz->notify_cookies.erase(cookie); //delete old cookie
thiz->notify_err = rados_aio_watch(thiz->ioctx, thiz->notify_oid, thiz->notify_comp, &cookie,
watch_notify2_test_cb, watch_notify2_test_errcb_aio_reconnect, thiz);
ASSERT_EQ(0, rados_aio_wait_for_complete(thiz->notify_comp));
ASSERT_EQ(0, rados_aio_get_return_value(thiz->notify_comp));
rados_aio_release(thiz->notify_comp);
if (thiz->notify_err < 0) {
std::cout << __func__ << " reconnect watch failed with error " << thiz->notify_err << std::endl;
return;
}
return;
}

class WatchNotifyTestCtx2;

// --
Expand Down Expand Up @@ -214,7 +261,7 @@ TEST_F(LibRadosWatchNotify, WatchNotify2) {
ASSERT_EQ(0,
rados_watch2(ioctx, notify_oid, &handle,
watch_notify2_test_cb,
watch_notify2_test_errcb, this));
watch_notify2_test_errcb_reconnect, this));
ASSERT_GT(rados_watch_check(ioctx, handle), 0);
char *reply_buf = 0;
size_t reply_buf_len;
Expand All @@ -231,6 +278,7 @@ TEST_F(LibRadosWatchNotify, WatchNotify2) {
ASSERT_EQ(1u, reply_map.size());
ASSERT_EQ(0u, missed_map.size());
ASSERT_EQ(1u, notify_cookies.size());
handle = *notify_cookies.begin();
ASSERT_EQ(1u, notify_cookies.count(handle));
ASSERT_EQ(5u, reply_map.begin()->second.length());
ASSERT_EQ(0, strncmp("reply", reply_map.begin()->second.c_str(), 5));
Expand All @@ -256,15 +304,14 @@ TEST_F(LibRadosWatchNotify, AioWatchNotify2) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ(0, rados_write(ioctx, notify_oid, buf, sizeof(buf), 0));

rados_completion_t comp;
uint64_t handle;
ASSERT_EQ(0, rados_aio_create_completion2(nullptr, nullptr, &comp));
rados_aio_watch(ioctx, notify_oid, comp, &handle,
watch_notify2_test_cb, watch_notify2_test_errcb, this);
ASSERT_EQ(0, rados_aio_wait_for_complete(comp));
ASSERT_EQ(0, rados_aio_get_return_value(comp));
rados_aio_release(comp);
ASSERT_EQ(0, rados_aio_create_completion2(nullptr, nullptr, &notify_comp));
rados_aio_watch(ioctx, notify_oid, notify_comp, &handle,
watch_notify2_test_cb, watch_notify2_test_errcb_aio_reconnect, this);

ASSERT_EQ(0, rados_aio_wait_for_complete(notify_comp));
ASSERT_EQ(0, rados_aio_get_return_value(notify_comp));
rados_aio_release(notify_comp);

ASSERT_GT(rados_watch_check(ioctx, handle), 0);
char *reply_buf = 0;
Expand All @@ -282,6 +329,7 @@ TEST_F(LibRadosWatchNotify, AioWatchNotify2) {
ASSERT_EQ(1u, reply_map.size());
ASSERT_EQ(0u, missed_map.size());
ASSERT_EQ(1u, notify_cookies.size());
handle = *notify_cookies.begin();
ASSERT_EQ(1u, notify_cookies.count(handle));
ASSERT_EQ(5u, reply_map.begin()->second.length());
ASSERT_EQ(0, strncmp("reply", reply_map.begin()->second.c_str(), 5));
Expand All @@ -296,11 +344,11 @@ TEST_F(LibRadosWatchNotify, AioWatchNotify2) {
ASSERT_EQ((char*)0, reply_buf);
ASSERT_EQ(0u, reply_buf_len);

ASSERT_EQ(0, rados_aio_create_completion2(nullptr, nullptr, &comp));
rados_aio_unwatch(ioctx, handle, comp);
ASSERT_EQ(0, rados_aio_wait_for_complete(comp));
ASSERT_EQ(0, rados_aio_get_return_value(comp));
rados_aio_release(comp);
ASSERT_EQ(0, rados_aio_create_completion2(nullptr, nullptr, &notify_comp));
rados_aio_unwatch(ioctx, handle, notify_comp);
ASSERT_EQ(0, rados_aio_wait_for_complete(notify_comp));
ASSERT_EQ(0, rados_aio_get_return_value(notify_comp));
rados_aio_release(notify_comp);
}

TEST_F(LibRadosWatchNotify, AioNotify) {
Expand Down
40 changes: 38 additions & 2 deletions src/test/librados/watch_notify_cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LibRadosWatchNotifyPP : public RadosTestParamPP
int notify_err = 0;

friend class WatchNotifyTestCtx2;
friend class WatchNotifyTestCtx2TimeOut;
};

IoCtx *notify_ioctx;
Expand All @@ -59,6 +60,41 @@ class WatchNotifyTestCtx2 : public WatchCtx2
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;
Expand Down Expand Up @@ -304,7 +340,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<obj_watch_t> watches;
Expand Down Expand Up @@ -339,7 +375,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<obj_watch_t> watches;
Expand Down