lderr(cct) << "group " << group_name
<< " is still primary within a remote cluster" << dendl;
return -EBUSY;
- } else if (force) {
+ }
+
+ std::string group_header_oid = librbd::util::group_header_name(group_id);
+ std::string value;
+ r = librbd::cls_client::metadata_get(&group_ioctx, group_header_oid,
+ RBD_GROUP_RESYNC, &value);
+ if (r < 0 && r != -ENOENT) {
+ lderr(cct) << "failed reading metadata: " << RBD_GROUP_RESYNC << " : "
+ << cpp_strerror(r) << dendl;
+ } else if (r == 0) {
+ ldout(cct, 5) << "found previous resync group request, clearing it"
+ << dendl;
+ r = cls_client::metadata_remove(&group_ioctx, group_header_oid,
+ RBD_GROUP_RESYNC);
+ if (r < 0) {
+ lderr(cct) << "failed removing metadata: " << RBD_GROUP_RESYNC << " : "
+ << cpp_strerror(r) << dendl;
+ }
+ }
+
+ if (force) {
std::vector<cls::rbd::GroupImageStatus> images;
r = Group<I>::group_image_list_by_id(group_ioctx, group_id, &images);
if (r < 0) {
}
}
- std::string group_header_oid = librbd::util::group_header_name(group_id);
if (ret_code < 0) {
// undo
ldout(cct, 20) << "undoing group promote: " << ret_code << dendl;
return r;
}
- std::vector<cls::rbd::GroupImageStatus> images;
- r = Group<I>::group_image_list_by_id(group_ioctx, group_id, &images);
- if (r < 0) {
- lderr(cct) << "listing images in group=" << group_name
- << " failed: " << cpp_strerror(r) << dendl;
- return r;
- }
-
- r = MirroringWatcher<I>::notify_group_updated(
- group_ioctx, cls::rbd::MIRROR_GROUP_STATE_DISABLED, group_id,
- mirror_group.global_group_id, images.size());
- if (r < 0) {
- lderr(cct) << "failed to notify mirroring group=" << group_name
- << " updated: " << cpp_strerror(r) << dendl;
- // not fatal
- }
-
return 0;
}
// If previous entity is not there in current set of entities or if
// their id's don't match then consider its removed
if (it == m_pending_entities.end() || it->second != id ||
- it->first.count < entity.count) {
+ it->first.count != entity.count) {
removed_entities.insert(entity);
}
}
// If current entity is not there in previous set of entities or if
// their id's don't match then consider its added
if (it == m_entities.end() || it->second != id ||
- it->first.count < entity.count) {
+ it->first.count != entity.count) {
added_entities.insert(entity);
}
}
template <typename I>
void BootstrapRequest<I>::send() {
- *m_resync_requested = false;
-
- if (m_local_group_id && !m_local_group_id->empty()) {
- std::string group_header_oid = librbd::util::group_header_name(
- *m_local_group_id);
- std::string value;
- int r = librbd::cls_client::metadata_get(&m_local_io_ctx, group_header_oid,
- RBD_GROUP_RESYNC, &value);
- if (r < 0 && r != -ENOENT) {
- derr << "failed reading metadata: " << cpp_strerror(r) << dendl;
- } else if (r == 0) {
- dout(10) << "local group resync requested" << dendl;
- *m_resync_requested = true;
- }
- }
-
- if (*m_resync_requested) {
- get_local_group_id();
- } else {
- get_remote_group_id();
- }
+ get_remote_group_id();
}
template <typename I>
m_remote_mirror_group_primary = (state == cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY);
}
+ *m_resync_requested = false;
+ if (m_local_group_id && !m_local_group_id->empty()) {
+ std::string group_header_oid = librbd::util::group_header_name(
+ *m_local_group_id);
+ std::string value;
+ int r = librbd::cls_client::metadata_get(&m_local_io_ctx, group_header_oid,
+ RBD_GROUP_RESYNC, &value);
+ if (r < 0 && r != -ENOENT) {
+ derr << "failed reading metadata: " << cpp_strerror(r) << dendl;
+ } else if (r == 0) {
+ dout(10) << "local group resync requested : " << m_local_group_id
+ << dendl;
+ if (m_remote_mirror_group.state == cls::rbd::MIRROR_GROUP_STATE_ENABLED &&
+ m_remote_mirror_group_primary) {
+ *m_resync_requested = true;
+ list_remote_group();
+ return;
+ }
+ dout(10) << "turns out remote is not primary, we cannot resync, will retry later"
+ << dendl;
+ }
+ }
+
if (m_remote_mirror_group.state == cls::rbd::MIRROR_GROUP_STATE_ENABLED &&
m_remote_mirror_group_primary) {
list_remote_group();
m_remote_mirror_group_primary &&
m_local_mirror_group.state == cls::rbd::MIRROR_GROUP_STATE_ENABLED &&
m_local_mirror_group.global_group_id == m_global_group_id &&
- has_remote_image(spec.pool_id, mirror_image.global_image_id)) {
+ has_remote_image(spec.pool_id, mirror_image.global_image_id)
+ && *m_resync_requested == false) {
dout(10) << "add secondary to replayer queue: " << spec.pool_id << " "
<< spec.image_id << " " << mirror_image.global_image_id
<< dendl;
finish(-ERESTART);
return;
}
-
dout(10) << "add to trash queue: " << spec.pool_id << " "
<< spec.image_id << " " << mirror_image.global_image_id
<< dendl;
template <typename I>
void BootstrapRequest<I>::disable_local_mirror_group() {
if (m_local_mirror_group.state == cls::rbd::MIRROR_GROUP_STATE_ENABLED &&
- m_local_mirror_group.global_group_id == m_global_group_id) {
+ m_local_mirror_group.global_group_id == m_global_group_id &&
+ *m_resync_requested == false) {
finish(0);
return;
}
m_local_mirror_group.state = cls::rbd::MIRROR_GROUP_STATE_DISABLED;
if (r != -ENOENT && (m_local_mirror_group.global_group_id == m_global_group_id) &&
(m_remote_mirror_group.state == cls::rbd::MIRROR_GROUP_STATE_ENABLED &&
- m_remote_mirror_group_primary)) {
+ m_remote_mirror_group_primary) && *m_resync_requested == false) {
create_local_mirror_group();
} else {
remove_local_group();