]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add GetVersion message
authorJosh Durgin <josh.durgin@dreamhost.com>
Tue, 26 Jul 2011 22:59:07 +0000 (15:59 -0700)
committerJosh Durgin <josh.durgin@dreamhost.com>
Fri, 29 Jul 2011 22:38:25 +0000 (15:38 -0700)
This allows clients to determine whether they have the latest
mds, mon, or osd map. This is useful for figuring out if a pool
does not exist, or if the osdmap with it simply hasn't been
received yet.

Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
src/Makefile.am
src/include/ceph_fs.h
src/messages/MMonGetVersion.h [new file with mode: 0644]
src/messages/MMonGetVersionReply.h [new file with mode: 0644]
src/mon/Monitor.cc
src/mon/Monitor.h
src/msg/Message.cc

index 3688f66c5e73505847b262acf05ca3ef194c9147..4e8561cd13caab2a17f23cce088fd20b633f735e 100644 (file)
@@ -1097,6 +1097,8 @@ noinst_HEADERS = \
         messages/MMonCommandAck.h\
         messages/MMonElection.h\
         messages/MMonGetMap.h\
+        messages/MMonGetVersion.h\
+        messages/MMonGetVersionReply.h\
        messages/MMonGlobalID.h\
         messages/MMonMap.h\
         messages/MMonObserve.h\
index 1019f16b80b43985a02c40600b56b8d30ea9e5a1..bfae4c6526f095bf09ad0e693c2e29a114278414 100644 (file)
@@ -116,6 +116,8 @@ struct ceph_dir_layout {
 #define CEPH_MSG_MON_SUBSCRIBE_ACK      16
 #define CEPH_MSG_AUTH                  17
 #define CEPH_MSG_AUTH_REPLY            18
+#define CEPH_MSG_MON_GET_VERSION        19
+#define CEPH_MSG_MON_GET_VERSION_REPLY  20
 
 /* client <-> mds */
 #define CEPH_MSG_MDS_MAP                21
diff --git a/src/messages/MMonGetVersion.h b/src/messages/MMonGetVersion.h
new file mode 100644 (file)
index 0000000..c5e347b
--- /dev/null
@@ -0,0 +1,58 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#ifndef CEPH_MMONGETVERSION_H
+#define CEPH_MMONGETVERSION_H
+
+#include "msg/Message.h"
+
+#include "include/types.h"
+
+/*
+ * This message is sent to the monitors to verify that the client's
+ * version of the map(s) is the latest available. For example, this
+ * can be used to determine whether a pool actually does not exist, or
+ * if it may have been created but the map was not received yet.
+ */
+class MMonGetVersion : public Message {
+public:
+  MMonGetVersion() : Message(CEPH_MSG_MON_GET_VERSION) {}
+
+  const char *get_type_name() {
+    return "mon_get_version";
+  }
+
+  void print(ostream& o) {
+    o << "mon_get_version(what=" << what << " handle=" << handle << ")";
+  }
+
+  void encode_payload(CephContext *cct) {
+    ::encode(handle, payload);
+    ::encode(what, payload);
+  }
+
+  void decode_payload(CephContext *cct) {
+    bufferlist::iterator p = payload.begin();
+    ::decode(handle, p);
+    ::decode(what, p);
+  }
+
+  tid_t handle;
+  string what;
+
+private:
+  ~MMonGetVersion() {}
+};
+
+#endif
diff --git a/src/messages/MMonGetVersionReply.h b/src/messages/MMonGetVersionReply.h
new file mode 100644 (file)
index 0000000..1aa4973
--- /dev/null
@@ -0,0 +1,57 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#ifndef CEPH_MMONGETVERSIONREPLY_H
+#define CEPH_MMONGETVERSIONREPLY_H
+
+#include "msg/Message.h"
+
+#include "include/types.h"
+
+/*
+ * This message is sent from the monitors to clients in response to a
+ * MMonGetVersion. The latest version of the requested thing is sent
+ * back.
+ */
+class MMonGetVersionReply : public Message {
+public:
+  MMonGetVersionReply() : Message(CEPH_MSG_MON_GET_VERSION_REPLY) {}
+
+  const char *get_type_name() {
+    return "mon_check_map_ack";
+  }
+
+  void print(ostream& o) {
+    o << "mon_check_map_ack(handle=" << handle << " version=" << version << ")";
+  }
+
+  void encode_payload(CephContext *cct) {
+    ::encode(handle, payload);
+    ::encode(version, payload);
+  }
+
+  void decode_payload(CephContext *cct) {
+    bufferlist::iterator p = payload.begin();
+    ::decode(handle, p);
+    ::decode(version, p);
+  }
+
+  tid_t handle;
+  version_t version;
+
+private:
+  ~MMonGetVersionReply() {}
+};
+
+#endif
index cafab4240dc418f4cefccfa78fdb54edf384c2ba..142216eed5ce38807f771a095e2193f88c48362e 100644 (file)
@@ -23,6 +23,8 @@
 #include "messages/PaxosServiceMessage.h"
 #include "messages/MMonMap.h"
 #include "messages/MMonGetMap.h"
+#include "messages/MMonGetVersion.h"
+#include "messages/MMonGetVersionReply.h"
 #include "messages/MGenericMessage.h"
 #include "messages/MMonCommand.h"
 #include "messages/MMonCommandAck.h"
@@ -45,6 +47,7 @@
 #include "common/DoutStreambuf.h"
 #include "common/errno.h"
 #include "include/color.h"
+#include "include/ceph_fs.h"
 
 #include "OSDMonitor.h"
 #include "MDSMonitor.h"
@@ -714,6 +717,10 @@ bool Monitor::_ms_dispatch(Message *m)
       handle_mon_get_map((MMonGetMap*)m);
       break;
 
+    case CEPH_MSG_MON_GET_VERSION:
+      handle_get_version((MMonGetVersion*)m);
+      break;
+
     case MSG_MON_COMMAND:
       handle_command((MMonCommand*)m);
       break;
@@ -873,6 +880,36 @@ void Monitor::handle_subscribe(MMonSubscribe *m)
   m->put();
 }
 
+void Monitor::handle_get_version(MMonGetVersion *m)
+{
+  dout(10) << "handle_get_version " << *m << dendl;
+
+  MonSession *s = (MonSession *)m->get_connection()->get_priv();
+  if (!s) {
+    dout(10) << " no session, dropping" << dendl;
+    m->put();
+    return;
+  }
+
+  MMonGetVersionReply *reply = new MMonGetVersionReply();
+  reply->handle = m->handle;
+
+  if (m->what == "mdsmap") {
+    reply->version = mdsmon()->mdsmap.get_epoch();
+  } else if (m->what == "osdmap") {
+    reply->version = osdmon()->osdmap.get_epoch();
+  } else if (m->what == "monmap") {
+    reply->version = monmap->get_epoch();
+  } else {
+    derr << "invalid map type " << m->what << dendl;
+  }
+
+  messenger->send_message(reply, m->get_source_inst());
+
+  s->put();
+  m->put();
+}
+
 bool Monitor::ms_handle_reset(Connection *con)
 {
   dout(10) << "ms_handle_reset " << con << " " << con->get_peer_addr() << dendl;
index 5c95f09d67e6d19c32e23946d8e2464b275f93e2..0bbaf5c816386b30b9a5ab7c8c75fac1614b3d67 100644 (file)
@@ -48,6 +48,7 @@ class MonitorStore;
 class PaxosService;
 
 class MMonGetMap;
+class MMonGetVersion;
 class MMonObserve;
 class MMonSubscribe;
 class MAuthRotating;
@@ -146,6 +147,7 @@ public:
   
 
   // messages
+  void handle_get_version(MMonGetVersion *m);
   void handle_subscribe(MMonSubscribe *m);
   void handle_mon_get_map(MMonGetMap *m);
   void handle_command(class MMonCommand *m);
index f228e2d9904f10936d6aa614d09c25000ac37b87..b75f841eb9a87c676707284ecd7be0eccb355be4 100644 (file)
@@ -64,6 +64,8 @@ using namespace std;
 
 #include "messages/MMonMap.h"
 #include "messages/MMonGetMap.h"
+#include "messages/MMonGetVersion.h"
+#include "messages/MMonGetVersionReply.h"
 
 #include "messages/MAuth.h"
 #include "messages/MAuthReply.h"
@@ -255,6 +257,12 @@ Message *decode_message(CephContext *cct, ceph_msg_header& header, ceph_msg_foot
   case CEPH_MSG_MON_GET_MAP:
     m = new MMonGetMap;
     break;
+  case CEPH_MSG_MON_GET_VERSION:
+    m = new MMonGetVersion();
+    break;
+  case CEPH_MSG_MON_GET_VERSION_REPLY:
+    m = new MMonGetVersionReply();
+    break;
 
   case MSG_OSD_BOOT:
     m = new MOSDBoot();