// cons/des
-Client::Client(Messenger *m, MonMap *mm, int in) : timer(client_lock)
+Client::Client(Messenger *m, MonMap *mm) : timer(client_lock)
{
// which client am i?
whoami = m->get_myname().num();
- my_instance = in;
monmap = mm;
mounted = false;
{
dout(10) << "_try_mount" << dendl;
int mon = monmap->pick_mon();
- dout(2) << "sending client_mount to mon" << mon << " as instance " << my_instance << dendl;
+ dout(2) << "sending client_mount to mon" << mon << dendl;
messenger->set_dispatcher(this);
messenger->send_message(new MClientMount, monmap->get_inst(mon));
objecter->init();
_try_mount();
- //messenger->set_dispatcher(this); // FIXME: there is still a race condition here!
while (!mdsmap ||
!osdmap ||
bool mounted;
bool unmounting;
Cond mount_cond;
- int my_instance;
int unsafe_sync_write;
public:
friend class SyntheticClient;
public:
- Client(Messenger *m, MonMap *mm, int i=0);
+ Client(Messenger *m, MonMap *mm);
~Client();
void tear_down_cache();
#define CEPH_MSG_PING_ACK 3
/* client <-> monitor */
+#define CEPH_MSG_MON_MAP 4
#define CEPH_MSG_CLIENT_MOUNT 10
#define CEPH_MSG_CLIENT_UNMOUNT 11
#define CEPH_MSG_STATFS 12
--- /dev/null
+// -*- 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) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * 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 __MMONMAP_H
+#define __MMONMAP_H
+
+#include "msg/Message.h"
+
+class MMonMap : public Message {
+public:
+ bufferlist monmapbl;
+
+ MMonMap() : Message(CEPH_MSG_MON_MAP) { }
+ MMonMap(bufferlist &bl) : Message(CEPH_MSG_MON_MAP) {
+ monmapbl.claim(bl);
+ }
+
+ char *get_type_name() { return "mon_map"; }
+
+ void encode_payload() {
+ payload = monmapbl;
+ }
+ void decode_payload() {
+ monmapbl = payload;
+ }
+};
+
+#endif
acked_me.insert(whoami);
// bcast to everyone else
- for (int i=0; i<mon->monmap->num_mon; ++i) {
- if (i == whoami) continue;
+ for (unsigned i=0; i<mon->monmap->size(); ++i) {
+ if ((int)i == whoami) continue;
mon->messenger->send_message(new MMonElection(MMonElection::OP_PROPOSE, epoch),
mon->monmap->get_inst(i));
}
// did i win?
if (electing_me &&
- acked_me.size() > (unsigned)(mon->monmap->num_mon / 2)) {
+ acked_me.size() > (unsigned)(mon->monmap->size() / 2)) {
// i win
victory();
} else {
dout(5) << " so far i have " << acked_me << dendl;
// is that _everyone_?
- if (acked_me.size() == (unsigned)mon->monmap->num_mon) {
+ if (acked_me.size() == mon->monmap->size()) {
// if yes, shortcut to election finish
victory();
}
public:
epoch_t epoch; // what epoch/version of the monmap
ceph_fsid_t fsid;
- int32_t num_mon;
vector<entity_inst_t> mon_inst;
int last_mon; // last mon i talked to
- MonMap(int s=0) : epoch(0), num_mon(s), mon_inst(s), last_mon(-1) {
+ MonMap(int s=0) : epoch(0), mon_inst(s), last_mon(-1) {
generate_fsid();
}
+ unsigned size() {
+ return mon_inst.size();
+ }
+
void add_mon(entity_inst_t inst) {
mon_inst.push_back(inst);
- num_mon++;
}
// pick a mon.
// choice should be stable, unless we explicitly ask for a new one.
int pick_mon(bool newmon=false) {
if (newmon || (last_mon < 0)) {
- last_mon = rand() % num_mon;
+ last_mon = rand() % mon_inst.size();
}
return last_mon;
}
- const entity_inst_t &get_inst(int m) {
- assert(m < num_mon);
+ const entity_inst_t &get_inst(unsigned m) {
+ assert(m < mon_inst.size());
return mon_inst[m];
}
void encode(bufferlist& blist) {
::_encode(epoch, blist);
::_encode(fsid, blist);
- ::_encode(num_mon, blist);
::_encode(mon_inst, blist);
}
int off = 0;
::_decode(epoch, blist, off);
::_decode(fsid, blist, off);
- ::_decode(num_mon, blist, off);
::_decode(mon_inst, blist, off);
}
reset_tick();
// call election?
- if (monmap->num_mon > 1) {
- assert(monmap->num_mon != 2);
+ if (monmap->size() > 1) {
+ assert(monmap->size() != 2);
call_election();
} else {
// we're standalone.
osdmon->mark_all_down();
// monitors too.
- for (int i=0; i<monmap->num_mon; i++)
- if (i != whoami)
+ for (unsigned i=0; i<monmap->size(); i++)
+ if ((int)i != whoami)
messenger->send_message(new MGenericMessage(CEPH_MSG_SHUTDOWN),
monmap->get_inst(i));
}
void Monitor::call_election()
{
- if (monmap->num_mon == 1) return;
+ if (monmap->size() == 1) return;
dout(10) << "call_election" << dendl;
state = STATE_STARTING;
// we must already have a majority for this to work.
assert(mon->get_quorum().size() == 1 ||
- num_last > (unsigned)mon->monmap->num_mon/2);
+ num_last > (unsigned)mon->monmap->size()/2);
// and no value, yet.
assert(new_value.length() == 0);
dout(10) << " now " << accepted << " have accepted" << dendl;
// new majority?
- if (accepted.size() == (unsigned)mon->monmap->num_mon/2+1) {
+ if (accepted.size() == (unsigned)mon->monmap->size()/2+1) {
// yay, commit!
// note: this may happen before the lease is reextended (below)
dout(10) << " got majority, committing" << dendl;
#include "messages/MPing.h"
#include "messages/MPingAck.h"
-//#include "messages/MFailure.h"
-//#include "messages/MFailureAck.h"
#include "messages/MOSDBoot.h"
#include "messages/MOSDIn.h"
#include "messages/MOSDPGRemove.h"
#include "messages/MOSDPGActivateSet.h"
+#include "messages/MMonMap.h"
+
#include "messages/MClientMount.h"
#include "messages/MClientUnmount.h"
#include "messages/MClientSession.h"
m = new MPingAck();
break;
+ case CEPH_MSG_MON_MAP:
+ m = new MMonMap;
+ break;
+
/*
case MSG_FAILURE:
m = new MFailure();
m = new MOSDPGActivateSet();
break;
+
// clients
case CEPH_MSG_CLIENT_MOUNT:
m = new MClientMount;
map<int,SyntheticClient *> syn;//[start_client];
int nclients = 0;
for (int i=0; i<start_client; i++) {
- //if (mpirank != start_mds + start_osd + i % client_nodes) continue;
- //int node = g_conf.ms_skip_rank0+start_mds + skip_osd + i / clients_per_node;
int node = g_conf.ms_skip_rank0+start_mds + skip_osd + i % client_nodes;
if (mpirank != node) continue;
clientlist.insert(i);
- client[i] = new Client(rank.register_entity(entity_name_t(entity_name_t::TYPE_CLIENT, -1-i)),
- monmap,
- i+1);
+ client[i] = new Client(rank.register_entity(entity_name_t(entity_name_t::TYPE_CLIENT, -1)), monmap);
syn[i] = new SyntheticClient(client[i]);
started++;