]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monmap: use feature bits and single encode() method
authorSage Weil <sage@inktank.com>
Tue, 15 May 2012 04:01:58 +0000 (21:01 -0700)
committerSage Weil <sage@inktank.com>
Tue, 15 May 2012 04:01:58 +0000 (21:01 -0700)
Instead of selecting an encode method in the caller, use a normal features
argument to encode() and branch there.

Leave behavior of all callers untouched.  We continue to assume, for
example, that all monitors have the same features, and that
'ceph mon getmap' should return the fully-featured encoding.

Signed-off-by: Sage Weil <sage@inktank.com>
src/ceph_mon.cc
src/messages/MMonElection.h
src/mon/MonMap.cc
src/mon/MonMap.h
src/mon/Monitor.cc
src/mon/MonmapMonitor.cc

index 6474685d9d2b8ef831832e2caa65215708ff0d70..e24046c4045cfff266b1378b3d178d5bfde65fa2 100644 (file)
@@ -278,7 +278,7 @@ int main(int argc, const char **argv)
       tmp.set_epoch(v);
     }
     bufferlist mapbl;
-    tmp.encode(mapbl);
+    tmp.encode(mapbl, -1);
     bufferlist final;
     ::encode(v, final);
     ::encode(mapbl, final);
index 7594c49cc1710e18186721f3522898cfaf0f2425..5adf6ff432b57f92ec9222ce78662e9ce6cb55dd 100644 (file)
@@ -48,7 +48,7 @@ public:
   MMonElection(int o, epoch_t e, MonMap *m) : 
     Message(MSG_MON_ELECTION, HEAD_VERSION), 
     fsid(m->fsid), op(o), epoch(e) {
-    m->encode(monmap_bl);
+    m->encode(monmap_bl, -1);
   }
 private:
   ~MMonElection() {}
index 4e90f8c69df50f60cc352311d30f72f42d57c84e..ca5f40ea28b42b66a7bb28deb181aa5de74056a2 100644 (file)
@@ -7,10 +7,26 @@
 
 #include "common/Formatter.h"
 
+#include "include/ceph_features.h"
+
 using ceph::Formatter;
 
-void MonMap::encode(bufferlist& blist) const
+void MonMap::encode(bufferlist& blist, uint64_t features) const
 {
+  if ((features & CEPH_FEATURE_MONNAMES) == 0) {
+    __u16 v = 1;
+    ::encode(v, blist);
+    ::encode_raw(fsid, blist);
+    ::encode(epoch, blist);
+    vector<entity_inst_t> mon_inst(mon_addr.size());
+    for (unsigned n = 0; n < mon_addr.size(); n++)
+      mon_inst[n] = get_inst(n);
+    ::encode(mon_inst, blist);
+    ::encode(last_changed, blist);
+    ::encode(created, blist);
+    return;
+  }
+
   __u16 v = 2;
   ::encode(v, blist);
   ::encode_raw(fsid, blist);
@@ -20,20 +36,6 @@ void MonMap::encode(bufferlist& blist) const
   ::encode(created, blist);
 }
 
-void MonMap::encode_v1(bufferlist& blist) const
-{
-  __u16 v = 1;
-  ::encode(v, blist);
-  ::encode_raw(fsid, blist);
-  ::encode(epoch, blist);
-  vector<entity_inst_t> mon_inst(mon_addr.size());
-  for (unsigned n = 0; n < mon_addr.size(); n++)
-    mon_inst[n] = get_inst(n);
-  ::encode(mon_inst, blist);
-  ::encode(last_changed, blist);
-  ::encode(created, blist);
-}
-
 void MonMap::decode(bufferlist::iterator &p)
 {
   __u16 v;
@@ -72,7 +74,7 @@ int MonMap::write(const char *fn)
 {
   // encode
   bufferlist bl;
-  encode(bl);
+  encode(bl, -1);
   
   return bl.write_file(fn);
 }
index 10c3f137dd9385aa5d5cf98232b05cb0242ceb28..f294b497145e6c665aaf8240e64d6622be366e87 100644 (file)
@@ -171,9 +171,7 @@ class MonMap {
     return i;
   }
 
-  void encode(bufferlist& blist) const;
-  void encode_v1(bufferlist& blist) const;
-
+  void encode(bufferlist& blist, uint64_t features) const;
   void decode(bufferlist& blist) {
     bufferlist::iterator p = blist.begin();
     decode(p);
@@ -194,7 +192,7 @@ class MonMap {
 
   static void generate_test_instances(list<MonMap*>& o);
 };
-WRITE_CLASS_ENCODER(MonMap)
+WRITE_CLASS_ENCODER_FEATURES(MonMap)
 
 inline ostream& operator<<(ostream& out, MonMap& m) {
   m.print_summary(out);
index 91f65dab3968a83749ebad98f7666dd9b63aed36..f376980acf1d4ecec18829f921c69abf908a7fa0 100644 (file)
@@ -524,7 +524,7 @@ void Monitor::handle_probe_probe(MMonProbe *m)
   MMonProbe *r = new MMonProbe(monmap->fsid, MMonProbe::OP_REPLY, name);
   r->name = name;
   r->quorum = quorum;
-  monmap->encode(r->monmap_bl);
+  monmap->encode(r->monmap_bl, -1);
   for (vector<Paxos*>::iterator p = paxos.begin(); p != paxos.end(); ++p)
     r->paxos_versions[(*p)->get_machine_name()] = (*p)->get_version();
   messenger->send_message(r, m->get_connection());
@@ -1722,10 +1722,7 @@ void Monitor::check_sub(Subscription *sub)
 void Monitor::send_latest_monmap(Connection *con)
 {
   bufferlist bl;
-  if (!con->has_feature(CEPH_FEATURE_MONNAMES))
-    monmap->encode_v1(bl);
-  else
-    monmap->encode(bl);
+  monmap->encode(bl, con->get_features());
   messenger->send_message(new MMonMap(bl), con);
 }
 
@@ -1828,7 +1825,7 @@ int Monitor::mkfs(bufferlist& osdmapbl)
 
   // save monmap, osdmap, keyring.
   bufferlist monmapbl;
-  monmap->encode(monmapbl);
+  monmap->encode(monmapbl, -1);
   monmap->set_epoch(0);     // must be 0 to avoid confusing first MonmapMonitor::update_from_paxos()
   store->put_bl_ss(monmapbl, "mkfs", "monmap");
 
index 3d7d775f8601720bdf684f0075312ee7ed026e96..f9e029ffcaa97d722d93bcfb29b7213cb92d5742 100644 (file)
@@ -102,7 +102,7 @@ void MonmapMonitor::encode_pending(bufferlist& bl)
 
   assert(mon->monmap->epoch + 1 == pending_map.epoch ||
         pending_map.epoch == 1);  // special case mkfs!
-  pending_map.encode(bl);
+  pending_map.encode(bl, -1);
 }
 
 bool MonmapMonitor::preprocess_query(PaxosServiceMessage *m)
@@ -137,7 +137,7 @@ bool MonmapMonitor::preprocess_command(MMonCommand *m)
       r = 0;
     }
     else if (m->cmd.size() == 2 && m->cmd[1] == "getmap") {
-      mon->monmap->encode(rdata);
+      mon->monmap->encode(rdata, -1);
       r = 0;
       ss << "got latest monmap";
     }