From: Jason Dillaman Date: Mon, 28 Mar 2016 14:40:46 +0000 (-0400) Subject: librbd: track mirror peer replay state X-Git-Tag: v10.1.1~64^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=668b41d1e8f17520c1441b4c73930c04622119ec;p=ceph.git librbd: track mirror peer replay state This new state will protect against the case of an rbd-mirror crash between registering with the remote and starting the image sync. Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/journal/Types.cc b/src/librbd/journal/Types.cc index 494d97311bb..8f9f942733a 100644 --- a/src/librbd/journal/Types.cc +++ b/src/librbd/journal/Types.cc @@ -373,6 +373,7 @@ void MirrorPeerSyncPoint::dump(Formatter *f) const { void MirrorPeerClientMeta::encode(bufferlist& bl) const { ::encode(image_id, bl); + ::encode(static_cast(state), bl); ::encode(sync_object_count, bl); ::encode(static_cast(sync_points.size()), bl); for (auto &sync_point : sync_points) { @@ -383,6 +384,11 @@ void MirrorPeerClientMeta::encode(bufferlist& bl) const { void MirrorPeerClientMeta::decode(__u8 version, bufferlist::iterator& it) { ::decode(image_id, it); + + uint32_t decode_state; + ::decode(decode_state, it); + state = static_cast(decode_state); + ::decode(sync_object_count, it); uint32_t sync_point_count; @@ -397,6 +403,7 @@ void MirrorPeerClientMeta::decode(__u8 version, bufferlist::iterator& it) { void MirrorPeerClientMeta::dump(Formatter *f) const { f->dump_string("image_id", image_id); + f->dump_stream("state") << state; f->dump_unsigned("sync_object_count", sync_object_count); f->open_array_section("sync_points"); for (auto &sync_point : sync_points) { @@ -605,8 +612,24 @@ std::ostream &operator<<(std::ostream &out, const MirrorPeerSyncPoint &sync) { return out; } +std::ostream &operator<<(std::ostream &out, const MirrorPeerState &state) { + switch (state) { + case MIRROR_PEER_STATE_SYNCING: + out << "Syncing"; + break; + case MIRROR_PEER_STATE_REPLAYING: + out << "Replaying"; + break; + default: + out << "Unknown (" << static_cast(state) << ")"; + break; + } + return out; +} + std::ostream &operator<<(std::ostream &out, const MirrorPeerClientMeta &meta) { out << "[image_id=" << meta.image_id << ", " + << "state=" << meta.state << ", " << "sync_object_count=" << meta.sync_object_count << ", " << "sync_points=["; std::string delimiter; diff --git a/src/librbd/journal/Types.h b/src/librbd/journal/Types.h index fe02ffefd82..0f257664792 100644 --- a/src/librbd/journal/Types.h +++ b/src/librbd/journal/Types.h @@ -361,6 +361,11 @@ struct MirrorPeerSyncPoint { void dump(Formatter *f) const; }; +enum MirrorPeerState { + MIRROR_PEER_STATE_SYNCING, + MIRROR_PEER_STATE_REPLAYING +}; + struct MirrorPeerClientMeta { typedef std::list SyncPoints; typedef std::map SnapSeqs; @@ -368,6 +373,7 @@ struct MirrorPeerClientMeta { static const ClientMetaType TYPE = MIRROR_PEER_CLIENT_META_TYPE; std::string image_id; + MirrorPeerState state = MIRROR_PEER_STATE_SYNCING; ///< replay state uint64_t sync_object_count = 0; ///< maximum number of objects ever sync'ed SyncPoints sync_points; ///< max two in-use snapshots for sync SnapSeqs snap_seqs; ///< local to peer snap seq mapping @@ -382,6 +388,7 @@ struct MirrorPeerClientMeta { inline bool operator==(const MirrorPeerClientMeta &meta) const { return (image_id == meta.image_id && + state == meta.state && sync_object_count == meta.sync_object_count && sync_points == meta.sync_points && snap_seqs == meta.snap_seqs); @@ -468,6 +475,7 @@ std::ostream &operator<<(std::ostream &out, const EventType &type); std::ostream &operator<<(std::ostream &out, const ClientMetaType &type); std::ostream &operator<<(std::ostream &out, const ImageClientMeta &meta); std::ostream &operator<<(std::ostream &out, const MirrorPeerSyncPoint &sync); +std::ostream &operator<<(std::ostream &out, const MirrorPeerState &meta); std::ostream &operator<<(std::ostream &out, const MirrorPeerClientMeta &meta); std::ostream &operator<<(std::ostream &out, const TagData &tag_data);