ASSERT_EQ(-EREMOTEIO, ctx.wait());
}
+TEST_F(TestMockImageReplayerBootstrapRequest, NonPrimaryRemoteNotTagOwner) {
+ create_local_image();
+
+ InSequence seq;
+
+ // lookup remote image tag class
+ cls::journal::Client client;
+ librbd::journal::ClientData client_data{
+ librbd::journal::ImageClientMeta{123}};
+ encode(client_data, client.data);
+ ::journal::MockJournaler mock_journaler;
+ expect_journaler_get_client(mock_journaler,
+ librbd::Journal<>::IMAGE_CLIENT_ID,
+ client, 0);
+
+ // open the remote image
+ librbd::MockJournal mock_journal;
+ librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
+ MockOpenImageRequest mock_open_image_request;
+ expect_open_image(mock_open_image_request, m_remote_io_ctx,
+ mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
+
+ // test if remote image is primary
+ MockIsPrimaryRequest mock_is_primary_request;
+ expect_is_primary(mock_is_primary_request, false, 0);
+
+ // open the local image
+ librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
+ mock_local_image_ctx.journal = &mock_journal;
+ MockOpenLocalImageRequest mock_open_local_image_request;
+ expect_open_local_image(mock_open_local_image_request, m_local_io_ctx,
+ mock_local_image_ctx.id, &mock_local_image_ctx, 0);
+ expect_is_resync_requested(mock_journal, false, 0);
+
+ expect_journal_get_tag_tid(mock_journal, 345);
+ expect_journal_get_tag_data(mock_journal, {librbd::Journal<>::LOCAL_MIRROR_UUID,
+ librbd::Journal<>::ORPHAN_MIRROR_UUID,
+ true, 344, 0});
+
+ MockCloseImageRequest mock_close_image_request;
+ expect_close_image(mock_close_image_request, mock_local_image_ctx, 0);
+ expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
+
+ C_SaferCond ctx;
+ MockInstanceWatcher mock_instance_watcher;
+ cls::journal::ClientState client_state = cls::journal::CLIENT_STATE_CONNECTED;
+ librbd::journal::MirrorPeerClientMeta mirror_peer_client_meta{
+ mock_local_image_ctx.id};
+ mirror_peer_client_meta.state = librbd::journal::MIRROR_PEER_STATE_REPLAYING;
+ MockBootstrapRequest *request = create_request(
+ &mock_instance_watcher, mock_journaler, mock_local_image_ctx.id,
+ mock_remote_image_ctx.id, "global image id", "local mirror uuid",
+ "remote mirror uuid", &client_state, &mirror_peer_client_meta, &ctx);
+ request->send();
+ ASSERT_EQ(-EREMOTEIO, ctx.wait());
+}
+
TEST_F(TestMockImageReplayerBootstrapRequest, RemoteDemotePromote) {
create_local_image();
// test if remote image is primary
MockIsPrimaryRequest mock_is_primary_request;
- expect_is_primary(mock_is_primary_request, true, 0);
+ expect_is_primary(mock_is_primary_request, false, 0);
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
mock_local_image_ctx.id, &mock_local_image_ctx, 0);
expect_is_resync_requested(mock_journal, false, 0);
+ expect_journal_get_tag_tid(mock_journal, 345);
+ expect_journal_get_tag_data(mock_journal, {"remote mirror uuid"});
+
// remote demotion / promotion event
Tags tags = {
{2, 123, encode_tag_data({librbd::Journal<>::LOCAL_MIRROR_UUID,
true, 4, 369})}
};
expect_journaler_get_tags(mock_journaler, 123, tags, 0);
- expect_journal_get_tag_tid(mock_journal, 345);
- expect_journal_get_tag_data(mock_journal, {"remote mirror uuid"});
MockCloseImageRequest mock_close_image_request;
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
mock_local_image_ctx.id, &mock_local_image_ctx, 0);
expect_is_resync_requested(mock_journal, false, 0);
+ expect_journal_get_tag_tid(mock_journal, 345);
+ expect_journal_get_tag_data(mock_journal, {librbd::Journal<>::ORPHAN_MIRROR_UUID,
+ "remote mirror uuid", true, 4, 1});
+
// remote demotion / promotion event
Tags tags = {
{2, 123, encode_tag_data({librbd::Journal<>::LOCAL_MIRROR_UUID,
true, 7, 1})}
};
expect_journaler_get_tags(mock_journaler, 123, tags, 0);
- expect_journal_get_tag_tid(mock_journal, 345);
- expect_journal_get_tag_data(mock_journal, {librbd::Journal<>::ORPHAN_MIRROR_UUID,
- "remote mirror uuid", true, 4, 1});
MockCloseImageRequest mock_close_image_request;
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
mock_local_image_ctx.id, &mock_local_image_ctx, 0);
expect_is_resync_requested(mock_journal, false, 0);
+ expect_journal_get_tag_tid(mock_journal, 346);
+ expect_journal_get_tag_data(mock_journal,
+ {librbd::Journal<>::ORPHAN_MIRROR_UUID,
+ librbd::Journal<>::LOCAL_MIRROR_UUID,
+ true, 345, 1});
+
// remote demotion / promotion event
Tags tags = {
{2, 123, encode_tag_data({"local mirror uuid", "local mirror uuid",
true, 3, 1})}
};
expect_journaler_get_tags(mock_journaler, 123, tags, 0);
- expect_journal_get_tag_tid(mock_journal, 346);
- expect_journal_get_tag_data(mock_journal,
- {librbd::Journal<>::ORPHAN_MIRROR_UUID,
- librbd::Journal<>::LOCAL_MIRROR_UUID,
- true, 345, 1});
MockCloseImageRequest mock_close_image_request;
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
mock_local_image_ctx.id, &mock_local_image_ctx, 0);
expect_is_resync_requested(mock_journal, false, 0);
+ expect_journal_get_tag_tid(mock_journal, 345);
+ expect_journal_get_tag_data(mock_journal, {librbd::Journal<>::LOCAL_MIRROR_UUID,
+ librbd::Journal<>::ORPHAN_MIRROR_UUID,
+ true, 344, 0});
+
// remote demotion / promotion event
Tags tags = {
{2, 123, encode_tag_data({librbd::Journal<>::LOCAL_MIRROR_UUID,
true, 2, 1})}
};
expect_journaler_get_tags(mock_journaler, 123, tags, 0);
- expect_journal_get_tag_tid(mock_journal, 345);
- expect_journal_get_tag_data(mock_journal, {librbd::Journal<>::LOCAL_MIRROR_UUID,
- librbd::Journal<>::ORPHAN_MIRROR_UUID,
- true, 344, 0});
MockCloseImageRequest mock_close_image_request;
expect_close_image(mock_close_image_request, mock_local_image_ctx, 0);
// resync is requested
expect_is_resync_requested(mock_journal, true, 0);
+ expect_journal_get_tag_tid(mock_journal, 345);
+ expect_journal_get_tag_data(mock_journal, {"remote mirror uuid"});
MockCloseImageRequest mock_close_image_request;
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
mock_local_image_ctx.id, &mock_local_image_ctx, 0);
expect_is_resync_requested(mock_journal, false, 0);
+ expect_journal_get_tag_tid(mock_journal, 345);
+ expect_journal_get_tag_data(mock_journal, {"remote mirror uuid"});
+
// sync the remote image to the local image
MockImageSync mock_image_sync;
expect_image_sync(mock_image_sync, 0);
mock_local_image_ctx.id, &mock_local_image_ctx, 0);
expect_is_resync_requested(mock_journal, false, 0);
+ expect_journal_get_tag_tid(mock_journal, 345);
+ expect_journal_get_tag_data(mock_journal, {"remote mirror uuid"});
+
// sync the remote image to the local image
MockImageSync mock_image_sync;
expect_image_sync(mock_image_sync, 0);
void BootstrapRequest<I>::handle_is_primary(int r) {
dout(20) << ": r=" << r << dendl;
- if (r < 0) {
+ if (r == -ENOENT) {
+ dout(5) << ": remote image is not mirrored" << dendl;
+ m_ret_val = -EREMOTEIO;
+ close_remote_image();
+ return;
+ } else if (r < 0) {
derr << ": error querying remote image primary status: " << cpp_strerror(r)
<< dendl;
m_ret_val = r;
}
if (!m_primary) {
- dout(5) << ": remote image is not primary -- skipping image replay"
- << dendl;
- m_ret_val = -EREMOTEIO;
- update_client_state();
- return;
+ if (m_local_image_id.empty()) {
+ // no local image and remote isn't primary -- don't sync it
+ dout(5) << ": remote image is not primary -- not syncing"
+ << dendl;
+ m_ret_val = -EREMOTEIO;
+ close_remote_image();
+ return;
+ } else if (m_client_meta->state !=
+ librbd::journal::MIRROR_PEER_STATE_REPLAYING) {
+ // ensure we attempt to re-sync to remote if it's re-promoted
+ dout(5) << ": remote image is not primary -- sync interrupted"
+ << dendl;
+ m_ret_val = -EREMOTEIO;
+ update_client_state();
+ return;
+ }
}
if (!m_client_meta->image_id.empty()) {
}
if (m_local_image_id.empty()) {
+ // prepare to create local image
update_client_image();
return;
}
template <typename I>
void BootstrapRequest<I>::update_client_state() {
- if (m_client_meta->state == librbd::journal::MIRROR_PEER_STATE_REPLAYING) {
- // state already set for replaying upon failover
- close_remote_image();
- return;
- }
-
dout(20) << dendl;
update_progress("UPDATE_CLIENT_STATE");
I *local_image_ctx = (*m_local_image_ctx);
{
- RWLock::RLocker snap_locker(local_image_ctx->snap_lock);
+ local_image_ctx->snap_lock.get_read();
if (local_image_ctx->journal == nullptr) {
+ local_image_ctx->snap_lock.put_read();
+
derr << ": local image does not support journaling" << dendl;
m_ret_val = -EINVAL;
close_local_image();
r = (*m_local_image_ctx)->journal->is_resync_requested(m_do_resync);
if (r < 0) {
+ local_image_ctx->snap_lock.put_read();
+
derr << ": failed to check if a resync was requested" << dendl;
m_ret_val = r;
close_local_image();
return;
}
+
+ m_local_tag_tid = local_image_ctx->journal->get_tag_tid();
+ m_local_tag_data = local_image_ctx->journal->get_tag_data();
+ dout(10) << ": local tag=" << m_local_tag_tid << ", "
+ << "local tag data=" << m_local_tag_data << dendl;
+ local_image_ctx->snap_lock.put_read();
+ }
+
+ if (m_local_tag_data.mirror_uuid != m_remote_mirror_uuid && !m_primary) {
+ // if the local mirror is not linked to the (now) non-primary image,
+ // stop the replay. Otherwise, we ignore that the remote is non-primary
+ // so that we can replay the demotion
+ dout(5) << ": remote image is not primary -- skipping image replay"
+ << dendl;
+ m_ret_val = -EREMOTEIO;
+ close_local_image();
+ return;
}
if (*m_do_resync) {
update_progress("REGISTER_CLIENT");
- librbd::journal::MirrorPeerClientMeta mirror_peer_client_meta{
- m_local_image_id};
+ assert(m_local_image_id.empty());
+ librbd::journal::MirrorPeerClientMeta mirror_peer_client_meta;
mirror_peer_client_meta.state = librbd::journal::MIRROR_PEER_STATE_REPLAYING;
librbd::journal::ClientData client_data{mirror_peer_client_meta};
}
*m_client_state = cls::journal::CLIENT_STATE_CONNECTED;
- *m_client_meta = librbd::journal::MirrorPeerClientMeta(m_local_image_id);
+ *m_client_meta = librbd::journal::MirrorPeerClientMeta();
m_client_meta->state = librbd::journal::MIRROR_PEER_STATE_REPLAYING;
is_primary();
// At this point, the local image was existing, non-primary, and replaying;
// and the remote image is primary. Attempt to link the local image's most
// recent tag to the remote image's tag chain.
- uint64_t local_tag_tid;
- librbd::journal::TagData local_tag_data;
- I *local_image_ctx = (*m_local_image_ctx);
- {
- RWLock::RLocker snap_locker(local_image_ctx->snap_lock);
- if (local_image_ctx->journal == nullptr) {
- derr << ": local image does not support journaling" << dendl;
- m_ret_val = -EINVAL;
- close_local_image();
- return;
- }
-
- local_tag_tid = local_image_ctx->journal->get_tag_tid();
- local_tag_data = local_image_ctx->journal->get_tag_data();
- dout(10) << ": local tag " << local_tag_tid << ": "
- << local_tag_data << dendl;
- }
-
bool remote_tag_data_valid = false;
librbd::journal::TagData remote_tag_data;
boost::optional<uint64_t> remote_orphan_tag_tid =
// decode the remote tags
for (auto &remote_tag : m_remote_tags) {
- if (local_tag_data.predecessor.commit_valid &&
- local_tag_data.predecessor.mirror_uuid == m_remote_mirror_uuid &&
- local_tag_data.predecessor.tag_tid > remote_tag.tid) {
+ if (m_local_tag_data.predecessor.commit_valid &&
+ m_local_tag_data.predecessor.mirror_uuid == m_remote_mirror_uuid &&
+ m_local_tag_data.predecessor.tag_tid > remote_tag.tid) {
dout(15) << ": skipping processed predecessor remote tag "
<< remote_tag.tid << dendl;
continue;
dout(10) << ": decoded remote tag " << remote_tag.tid << ": "
<< remote_tag_data << dendl;
- if (!local_tag_data.predecessor.commit_valid) {
+ if (!m_local_tag_data.predecessor.commit_valid) {
// newly synced local image (no predecessor) replays from the first tag
if (remote_tag_data.mirror_uuid != librbd::Journal<>::LOCAL_MIRROR_UUID) {
dout(15) << ": skipping non-primary remote tag" << dendl;
break;
}
- if (local_tag_data.mirror_uuid == librbd::Journal<>::ORPHAN_MIRROR_UUID) {
+ if (m_local_tag_data.mirror_uuid == librbd::Journal<>::ORPHAN_MIRROR_UUID) {
// demotion last available local epoch
- if (remote_tag_data.mirror_uuid == local_tag_data.mirror_uuid &&
+ if (remote_tag_data.mirror_uuid == m_local_tag_data.mirror_uuid &&
remote_tag_data.predecessor.commit_valid &&
remote_tag_data.predecessor.tag_tid ==
- local_tag_data.predecessor.tag_tid) {
+ m_local_tag_data.predecessor.tag_tid) {
// demotion matches remote epoch
if (remote_tag_data.predecessor.mirror_uuid == m_local_mirror_uuid &&
- local_tag_data.predecessor.mirror_uuid ==
+ m_local_tag_data.predecessor.mirror_uuid ==
librbd::Journal<>::LOCAL_MIRROR_UUID) {
// local demoted and remote has matching event
dout(15) << ": found matching local demotion tag" << dendl;
continue;
}
- if (local_tag_data.predecessor.mirror_uuid == m_remote_mirror_uuid &&
+ if (m_local_tag_data.predecessor.mirror_uuid == m_remote_mirror_uuid &&
remote_tag_data.predecessor.mirror_uuid ==
librbd::Journal<>::LOCAL_MIRROR_UUID) {
// remote demoted and local has matching event
}
if (remote_tag_data_valid &&
- local_tag_data.mirror_uuid == m_remote_mirror_uuid) {
+ m_local_tag_data.mirror_uuid == m_remote_mirror_uuid) {
dout(10) << ": local image is in clean replay state" << dendl;
} else if (reconnect_orphan) {
dout(10) << ": remote image was demoted/promoted" << dendl;