#include "msg/Messenger.h"
#include "msg/Message.h"
+#include "mon/MonClient.h"
+
#include "messages/MLog.h"
#include "messages/MGenericMessage.h"
// cons/des
-OSD::OSD(int id, Messenger *m, Messenger *hbm, MonMap *mm, const char *dev, const char *jdev) :
+OSD::OSD(int id, Messenger *m, Messenger *hbm, MonClient *mc, const char *dev, const char *jdev) :
osd_lock("OSD::osd_lock"),
timer(osd_lock),
messenger(m),
+ monc(mc),
logger(NULL),
store(NULL),
- monmap(mm),
- logclient(messenger, monmap),
+ logclient(messenger, &mc->monmap),
whoami(id),
dev_path(dev), journal_path(jdev),
state(STATE_BOOTING), boot_epoch(0), up_epoch(0),
snap_trim_wq(this, &disk_tp),
scrub_wq(this, &disk_tp)
{
+ monc->set_messenger(messenger);
+
osdmap = 0;
memset(&my_stat, 0, sizeof(my_stat));
dout(10) << "read_superblock " << superblock << dendl;
- if (ceph_fsid_compare(&superblock.fsid, &monmap->fsid)) {
- derr(0) << "read_superblock fsid " << superblock.fsid << " != monmap " << monmap->fsid << dendl;
+ if (ceph_fsid_compare(&superblock.fsid, &monc->get_fsid())) {
+ derr(0) << "read_superblock fsid " << superblock.fsid << " != monmap " << monc->get_fsid() << dendl;
return -1;
}
if (now - last_mon_heartbeat > g_conf.osd_mon_heartbeat_interval) {
last_mon_heartbeat = now;
dout(10) << "i have no heartbeat peers; checking mon for new map" << dendl;
- int mon = monmap->pick_mon();
- messenger->send_message(new MOSDGetMap(monmap->fsid, osdmap->get_epoch()+1),
- monmap->get_inst(mon));
+ monc->send_mon_message(new MOSDGetMap(monc->get_fsid(), osdmap->get_epoch()+1));
}
}
pg_stat_queue_lock.Unlock();
if (retry) {
- int oldmon = monmap->pick_mon();
- messenger->mark_down(monmap->get_inst(oldmon).addr);
- int mon = monmap->pick_mon(true);
- dout(10) << "marked down old mon" << oldmon << ", chose new mon" << mon << dendl;
+ monc->pick_new_mon();
+ dout(10) << "picked a new mon" << dendl;
}
// do any pending reports
void OSD::send_boot()
{
- int mon = monmap->pick_mon(true);
- dout(10) << "send_boot to mon" << mon << dendl;
- messenger->send_message(new MOSDBoot(superblock),
- monmap->get_inst(mon));
+ dout(10) << "send_boot" << dendl;
+ monc->send_mon_message(new MOSDBoot(superblock));
}
void OSD::queue_want_up_thru(epoch_t want)
dout(10) << "send_alive up_thru currently " << up_thru << " want " << up_thru_wanted << dendl;
if (up_thru_wanted > up_thru) {
up_thru_pending = up_thru_wanted;
- int mon = monmap->pick_mon();
- dout(10) << "send_alive to mon" << mon << " (want " << up_thru_wanted << ")" << dendl;
- messenger->send_message(new MOSDAlive(osdmap->get_epoch()),
- monmap->get_inst(mon));
+ dout(10) << "send_alive want " << up_thru_wanted << dendl;
+ monc->send_mon_message(new MOSDAlive(osdmap->get_epoch()));
}
}
void OSD::send_failures()
{
- int mon = monmap->pick_mon();
while (!failure_queue.empty()) {
int osd = *failure_queue.begin();
- messenger->send_message(new MOSDFailure(monmap->fsid, osdmap->get_inst(osd), osdmap->get_epoch()),
- monmap->get_inst(mon));
+ monc->send_mon_message(new MOSDFailure(monc->get_fsid(), osdmap->get_inst(osd), osdmap->get_epoch()));
failure_queue.erase(osd);
}
}
m->osd_stat.hb_out.push_back(p->first);
dout(20) << " osd_stat " << m->osd_stat << dendl;
- int mon = monmap->pick_mon();
- messenger->send_message(m, monmap->get_inst(mon));
+ monc->send_mon_message(m);
}
pg_stat_queue_lock.Unlock();
{
dout(10) << "handle_scrub " << *m << dendl;
- if (ceph_fsid_compare(&m->fsid, &monmap->fsid)) {
- dout(0) << "handle_scrub fsid " << m->fsid << " != " << monmap->fsid << dendl;
+ if (ceph_fsid_compare(&m->fsid, &monc->get_fsid())) {
+ dout(0) << "handle_scrub fsid " << m->fsid << " != " << monc->get_fsid() << dendl;
delete m;
return;
}
{
// ask
if (waiting_for_osdmap.empty()) {
- int mon = monmap->pick_mon();
- messenger->send_message(new MOSDGetMap(monmap->fsid, osdmap->get_epoch()+1),
- monmap->get_inst(mon));
+ monc->send_mon_message(new MOSDGetMap(monc->get_fsid(), osdmap->get_epoch()+1));
}
waiting_for_osdmap.push_back(m);
void OSD::handle_osd_map(MOSDMap *m)
{
assert(osd_lock.is_locked());
- if (ceph_fsid_compare(&m->fsid, &monmap->fsid)) {
- dout(0) << "handle_osd_map fsid " << m->fsid << " != " << monmap->fsid << dendl;
+ if (ceph_fsid_compare(&m->fsid, &monc->get_fsid())) {
+ dout(0) << "handle_osd_map fsid " << m->fsid << " != " << monc->get_fsid() << dendl;
delete m;
return;
}
}
else {
dout(10) << "handle_osd_map missing epoch " << cur+1 << dendl;
- int mon = monmap->pick_mon();
- messenger->send_message(new MOSDGetMap(monmap->fsid, cur+1), monmap->get_inst(mon));
+ monc->send_mon_message(new MOSDGetMap(monc->get_fsid(), cur+1));
break;
}
dout(10) << "send_incremental_map " << since << " -> " << osdmap->get_epoch()
<< " to " << inst << dendl;
- MOSDMap *m = new MOSDMap(monmap->fsid);
+ MOSDMap *m = new MOSDMap(monc->get_fsid());
for (epoch_t e = osdmap->get_epoch();
e > since;
void OSD::send_class_request(const char *cname, ClassVersion& version)
{
dout(10) << "send_class_request class=" << cname << " version=" << version << dendl;
- MClass *m = new MClass(monmap->get_fsid(), 0);
+ MClass *m = new MClass(monc->get_fsid(), 0);
ClassInfo info;
info.name = cname;
info.version = version;
m->info.push_back(info);
m->action = CLASS_GET;
- int mon = monmap->pick_mon();
- messenger->send_message(m, monmap->get_inst(mon));
+ monc->send_mon_message(m);
}