]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: track mirror peer replay state
authorJason Dillaman <dillaman@redhat.com>
Mon, 28 Mar 2016 14:40:46 +0000 (10:40 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 29 Mar 2016 19:19:25 +0000 (15:19 -0400)
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 <dillaman@redhat.com>
src/librbd/journal/Types.cc
src/librbd/journal/Types.h

index 494d97311bbe7e7d828da718041c894232073ee1..8f9f942733acf10622e8461ff8ea9a8467a35bbd 100644 (file)
@@ -373,6 +373,7 @@ void MirrorPeerSyncPoint::dump(Formatter *f) const {
 
 void MirrorPeerClientMeta::encode(bufferlist& bl) const {
   ::encode(image_id, bl);
+  ::encode(static_cast<uint32_t>(state), bl);
   ::encode(sync_object_count, bl);
   ::encode(static_cast<uint32_t>(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<MirrorPeerState>(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<uint32_t>(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;
index fe02ffefd82e7d9211c47bb17bb4dd32b9067472..0f2576647920b15a659ed13a5f58cb98cbb0e93e 100644 (file)
@@ -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<MirrorPeerSyncPoint> SyncPoints;
   typedef std::map<uint64_t, uint64_t> 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);