From 35ac040c5b906584525312bcd040ef8402b48c2d Mon Sep 17 00:00:00 2001 From: sageweil Date: Tue, 17 Jul 2007 21:38:28 +0000 Subject: [PATCH] cleaned up osdmap sharing code git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1521 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/mds/MDS.cc | 5 +++ trunk/ceph/messages/MOSDGetMap.h | 13 +++--- trunk/ceph/messages/MOSDMap.h | 2 +- trunk/ceph/mon/ClientMonitor.cc | 5 ++- trunk/ceph/mon/MDSMonitor.cc | 6 +-- trunk/ceph/mon/OSDMonitor.cc | 69 ++++++++++---------------------- trunk/ceph/mon/OSDMonitor.h | 4 +- trunk/ceph/osd/OSD.cc | 4 +- trunk/ceph/osdc/Objecter.cc | 2 +- 9 files changed, 45 insertions(+), 65 deletions(-) diff --git a/trunk/ceph/mds/MDS.cc b/trunk/ceph/mds/MDS.cc index 96d6429db30ac..3883e9925a73f 100644 --- a/trunk/ceph/mds/MDS.cc +++ b/trunk/ceph/mds/MDS.cc @@ -501,6 +501,11 @@ void MDS::handle_mds_map(MMDSMap *m) // see who i am whoami = mdsmap->get_addr_rank(messenger->get_myaddr()); + if (whoami < 0) { + dout(1) << "handle_mds_map i'm not in the mdsmap, killing myself" << endl; + shutdown_final(); + return; + } if (oldwhoami != whoami) { // update messenger. messenger->reset_myname(MSG_ADDR_MDS(whoami)); diff --git a/trunk/ceph/messages/MOSDGetMap.h b/trunk/ceph/messages/MOSDGetMap.h index 68e1b7d137dae..3ced814886eaf 100644 --- a/trunk/ceph/messages/MOSDGetMap.h +++ b/trunk/ceph/messages/MOSDGetMap.h @@ -21,27 +21,26 @@ class MOSDGetMap : public Message { public: - epoch_t since; + epoch_t start; MOSDGetMap(epoch_t s=0) : Message(MSG_OSD_GETMAP), - since(s) { + start(s) { } - epoch_t get_since() { return since; } + epoch_t get_start_epoch() { return start; } char *get_type_name() { return "get_osd_map"; } void print(ostream& out) { - out << "get_osd_map(since " << since << ")"; + out << "get_osd_map(" << start << ")"; } void encode_payload() { - payload.append((char*)&since, sizeof(since)); + ::_encode(start, payload); } void decode_payload() { int off = 0; - payload.copy(off, sizeof(since), (char*)&since); - off += sizeof(since); + ::_decode(start, payload, off); } }; diff --git a/trunk/ceph/messages/MOSDMap.h b/trunk/ceph/messages/MOSDMap.h index b6de1b027557c..525ed82ae5c29 100644 --- a/trunk/ceph/messages/MOSDMap.h +++ b/trunk/ceph/messages/MOSDMap.h @@ -64,7 +64,7 @@ class MOSDMap : public Message { virtual char *get_type_name() { return "omap"; } void print(ostream& out) { - out << "osdmap(" << get_first() << "," << get_last() << ")"; + out << "osd_map(" << get_first() << "," << get_last() << ")"; } }; diff --git a/trunk/ceph/mon/ClientMonitor.cc b/trunk/ceph/mon/ClientMonitor.cc index 175f70477f7a5..405759c8b1557 100644 --- a/trunk/ceph/mon/ClientMonitor.cc +++ b/trunk/ceph/mon/ClientMonitor.cc @@ -36,11 +36,12 @@ bool ClientMonitor::update_from_paxos() assert(paxos->is_active()); version_t paxosv = paxos->get_version(); + if (paxosv == client_map.version) return true; + assert(paxosv >= client_map.version); + dout(10) << "update_from_paxos paxosv " << paxosv << ", my v " << client_map.version << endl; - if (paxosv == client_map.version) return true; - assert(paxosv >= client_map.version); if (client_map.version == 0 && paxosv > 1 && mon->store->exists_bl_ss("clientmap","latest")) { diff --git a/trunk/ceph/mon/MDSMonitor.cc b/trunk/ceph/mon/MDSMonitor.cc index 7e3beae7971d1..daebe0ab3f2cb 100644 --- a/trunk/ceph/mon/MDSMonitor.cc +++ b/trunk/ceph/mon/MDSMonitor.cc @@ -74,12 +74,12 @@ bool MDSMonitor::update_from_paxos() assert(paxos->is_active()); version_t paxosv = paxos->get_version(); - dout(10) << "update_from_paxos paxosv " << paxosv - << ", my e " << mdsmap.epoch << endl; - if (paxosv == mdsmap.epoch) return true; assert(paxosv >= mdsmap.epoch); + dout(10) << "update_from_paxos paxosv " << paxosv + << ", my e " << mdsmap.epoch << endl; + // read and decode mdsmap_bl.clear(); bool success = paxos->read(paxosv, mdsmap_bl); diff --git a/trunk/ceph/mon/OSDMonitor.cc b/trunk/ceph/mon/OSDMonitor.cc index 6127297c279c5..659a704b6aaa7 100644 --- a/trunk/ceph/mon/OSDMonitor.cc +++ b/trunk/ceph/mon/OSDMonitor.cc @@ -243,12 +243,12 @@ bool OSDMonitor::update_from_paxos() assert(paxos->is_active()); version_t paxosv = paxos->get_version(); - dout(15) << "update_from_paxos paxos e " << paxosv - << ", my e " << osdmap.epoch << endl; - if (paxosv == osdmap.epoch) return true; assert(paxosv >= osdmap.epoch); + dout(15) << "update_from_paxos paxos e " << paxosv + << ", my e " << osdmap.epoch << endl; + if (osdmap.epoch == 0 && paxosv > 1) { // startup: just load latest full map epoch_t lastfull = mon->store->get_int("osdmap_full","last_epoch"); @@ -368,7 +368,7 @@ bool OSDMonitor::preprocess_query(Message *m) bool OSDMonitor::prepare_update(Message *m) { - dout(10) << "prepare_update " << *m << " from " << m->get_source_inst() << endl; + dout(7) << "prepare_update " << *m << " from " << m->get_source_inst() << endl; switch (m->get_type()) { // damp updates @@ -411,12 +411,12 @@ bool OSDMonitor::should_propose_now() void OSDMonitor::handle_osd_getmap(MOSDGetMap *m) { - dout(7) << "osd_getmap from " << m->get_source() << " since " << m->get_since() << endl; + dout(7) << "handle_osd_getmap from " << m->get_source() << " from " << m->get_start_epoch() << endl; - //if (m->get_since()) - send_incremental(m->get_since(), m->get_source_inst()); - //else - //send_full(m->get_source_inst()); + if (m->get_start_epoch()) + send_incremental(m->get_source_inst(), m->get_start_epoch()); + else + send_full(m->get_source_inst()); delete m; } @@ -435,19 +435,19 @@ bool OSDMonitor::preprocess_failure(MOSDFailure *m) // weird? if (!osdmap.have_inst(badboy)) { dout(5) << "preprocess_failure dne(/dup?): " << m->get_failed() << ", from " << m->get_from() << endl; - send_incremental(m->get_epoch(), m->get_from()); + send_incremental(m->get_from(), m->get_epoch()+1); return true; } if (osdmap.get_inst(badboy) != m->get_failed()) { dout(5) << "preprocess_failure wrong osd: report " << m->get_failed() << " != map's " << osdmap.get_inst(badboy) << ", from " << m->get_from() << endl; - send_incremental(m->get_epoch(), m->get_from()); + send_incremental(m->get_from(), m->get_epoch()+1); return true; } // already reported? if (osdmap.is_down(badboy)) { dout(5) << "preprocess_failure dup: " << m->get_failed() << ", from " << m->get_from() << endl; - send_incremental(m->get_epoch(), m->get_from()); + send_incremental(m->get_from(), m->get_epoch()+1); return true; } @@ -547,31 +547,6 @@ void OSDMonitor::_booted(MOSDBoot *m) } -// in -- - -/* -void OSDMonitor::handle_osd_in(MOSDIn *m) -{ - dout(7) << "osd_in from " << m->get_source() << endl; - int from = m->get_source().num(); - - if (osdmap.is_out(from)) - pending_inc.new_in.push_back(from); - accept_pending(); - send_incremental(m->map_epoch, m->get_source_inst()); -} - -void OSDMonitor::handle_osd_out(MOSDOut *m) -{ - dout(7) << "osd_out from " << m->get_source() << endl; - int from = m->get_source().num(); - if (osdmap.is_in(from)) { - pending_inc.new_out.push_back(from); - accept_pending(); - send_incremental(m->map_epoch, m->get_source_inst()); - } -} -*/ @@ -586,24 +561,24 @@ void OSDMonitor::send_to_waiting() i != awaiting_map.end(); i++) { if (i->second.second) - send_incremental(i->second.second, i->second.first); + send_incremental(i->second.first, i->second.second); else send_full(i->second.first); } } -void OSDMonitor::send_latest(entity_inst_t who, epoch_t since) +void OSDMonitor::send_latest(entity_inst_t who, epoch_t start) { if (paxos->is_readable()) { dout(5) << "send_latest to " << who << " now" << endl; - if (since == (epoch_t)(-1)) + if (start == 0) send_full(who); else - send_incremental(since, who); + send_incremental(who, start); } else { dout(5) << "send_latest to " << who << " later" << endl; awaiting_map[who.name].first = who; - awaiting_map[who.name].second = since; + awaiting_map[who.name].second = start; } } @@ -614,15 +589,15 @@ void OSDMonitor::send_full(entity_inst_t who) mon->messenger->send_message(new MOSDMap(&osdmap), who); } -void OSDMonitor::send_incremental(epoch_t since, entity_inst_t dest) +void OSDMonitor::send_incremental(entity_inst_t dest, epoch_t from) { - dout(5) << "send_incremental " << since << " -> " << osdmap.get_epoch() + dout(5) << "send_incremental from " << from << " -> " << osdmap.get_epoch() << " to " << dest << endl; MOSDMap *m = new MOSDMap; for (epoch_t e = osdmap.get_epoch(); - e > since; + e >= from; e--) { bufferlist bl; if (mon->store->get_bl_sn(bl, "osdmap", e) > 0) { @@ -653,7 +628,7 @@ void OSDMonitor::bcast_latest_mds() for (set::iterator i = up.begin(); i != up.end(); i++) { - send_incremental(osdmap.get_epoch()-1, mon->mdsmon->mdsmap.get_inst(*i)); + send_incremental(mon->mdsmon->mdsmap.get_inst(*i), osdmap.get_epoch()); } } @@ -670,7 +645,7 @@ void OSDMonitor::bcast_latest_osd() it++) { if (osdmap.is_down(*it)) continue; - send_incremental(osdmap.get_epoch()-1, osdmap.get_inst(*it)); + send_incremental(osdmap.get_inst(*it), osdmap.get_epoch()); } } diff --git a/trunk/ceph/mon/OSDMonitor.h b/trunk/ceph/mon/OSDMonitor.h index 59424a6fbe9e8..2ee86c8fe61e8 100644 --- a/trunk/ceph/mon/OSDMonitor.h +++ b/trunk/ceph/mon/OSDMonitor.h @@ -58,7 +58,7 @@ private: void send_to_waiting(); // send current map to waiters. void send_full(entity_inst_t dest); - void send_incremental(epoch_t since, entity_inst_t dest); + void send_incremental(entity_inst_t dest, epoch_t since); void bcast_latest_mds(); void bcast_latest_osd(); void bcast_full_osd(); @@ -114,7 +114,7 @@ private: void mark_all_down(); - void send_latest(entity_inst_t i, epoch_t since=(epoch_t)(-1)); + void send_latest(entity_inst_t i, epoch_t start=0); void fake_osd_failure(int osd, bool down); void fake_osdmap_update(); diff --git a/trunk/ceph/osd/OSD.cc b/trunk/ceph/osd/OSD.cc index 7ce38a8063d0f..12be3519fa276 100644 --- a/trunk/ceph/osd/OSD.cc +++ b/trunk/ceph/osd/OSD.cc @@ -950,7 +950,7 @@ void OSD::wait_for_new_map(Message *m) // ask if (waiting_for_osdmap.empty()) { int mon = monmap->pick_mon(); - messenger->send_message(new MOSDGetMap(osdmap->get_epoch()), + messenger->send_message(new MOSDGetMap(osdmap->get_epoch()+1), monmap->get_inst(mon)); } @@ -1111,7 +1111,7 @@ void OSD::handle_osd_map(MOSDMap *m) else { dout(10) << "handle_osd_map missing epoch " << cur+1 << dendl; int mon = monmap->pick_mon(); - messenger->send_message(new MOSDGetMap(cur), monmap->get_inst(mon)); + messenger->send_message(new MOSDGetMap(cur+1), monmap->get_inst(mon)); break; } diff --git a/trunk/ceph/osdc/Objecter.cc b/trunk/ceph/osdc/Objecter.cc index 64d2374b5bd99..fc7c530824e6d 100644 --- a/trunk/ceph/osdc/Objecter.cc +++ b/trunk/ceph/osdc/Objecter.cc @@ -83,7 +83,7 @@ void Objecter::handle_osd_map(MOSDMap *m) else { dout(3) << "handle_osd_map requesting missing epoch " << osdmap->get_epoch()+1 << endl; int mon = monmap->pick_mon(); - messenger->send_message(new MOSDGetMap(osdmap->get_epoch()), + messenger->send_message(new MOSDGetMap(osdmap->get_epoch()+1), monmap->get_inst(mon)); break; } -- 2.39.5