2006-10-05 05:39:29 +00:00
|
|
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
|
2007-06-01 19:51:31 +00:00
|
|
|
// vim: ts=8 sw=2 smarttab
|
2006-10-05 05:39:29 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-01-16 14:06:02 +00:00
|
|
|
/* Object Store Device (OSD) Monitor
|
|
|
|
*/
|
2006-10-05 05:39:29 +00:00
|
|
|
|
|
|
|
#ifndef __OSDMONITOR_H
|
|
|
|
#define __OSDMONITOR_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include "include/types.h"
|
|
|
|
#include "msg/Messenger.h"
|
|
|
|
|
|
|
|
#include "osd/OSDMap.h"
|
|
|
|
|
2007-07-01 14:43:27 +00:00
|
|
|
#include "PaxosService.h"
|
2009-09-21 21:30:19 +00:00
|
|
|
#include "Session.h"
|
2006-10-05 05:39:29 +00:00
|
|
|
|
2007-07-01 14:43:27 +00:00
|
|
|
class Monitor;
|
|
|
|
class MOSDBoot;
|
2008-02-28 18:21:48 +00:00
|
|
|
class MMonCommand;
|
2009-06-16 21:25:02 +00:00
|
|
|
class MPoolSnap;
|
2009-10-10 05:27:38 +00:00
|
|
|
class MOSDMap;
|
2006-10-05 05:39:29 +00:00
|
|
|
|
2007-07-01 14:43:27 +00:00
|
|
|
class OSDMonitor : public PaxosService {
|
2006-10-24 16:55:51 +00:00
|
|
|
public:
|
2006-10-11 21:36:16 +00:00
|
|
|
OSDMap osdmap;
|
2006-10-05 05:39:29 +00:00
|
|
|
|
2006-10-24 16:55:51 +00:00
|
|
|
private:
|
2009-10-10 05:27:38 +00:00
|
|
|
map<epoch_t, list<PaxosServiceMessage*> > waiting_for_map;
|
2006-10-09 19:10:44 +00:00
|
|
|
|
|
|
|
// [leader]
|
|
|
|
OSDMap::Incremental pending_inc;
|
|
|
|
map<int,utime_t> down_pending_out; // osd down -> out
|
|
|
|
|
2007-09-28 21:07:08 +00:00
|
|
|
map<int,double> osd_weight;
|
2007-07-01 14:43:27 +00:00
|
|
|
// svc
|
2008-03-10 23:23:41 +00:00
|
|
|
public:
|
2009-01-30 23:47:59 +00:00
|
|
|
void create_initial(bufferlist& bl);
|
2008-03-10 23:23:41 +00:00
|
|
|
private:
|
2007-07-01 14:43:27 +00:00
|
|
|
bool update_from_paxos();
|
|
|
|
void create_pending(); // prepare a new pending
|
|
|
|
void encode_pending(bufferlist &bl);
|
2006-10-09 19:10:44 +00:00
|
|
|
|
2007-09-09 23:47:09 +00:00
|
|
|
void committed();
|
|
|
|
|
2009-06-23 21:03:34 +00:00
|
|
|
void handle_query(PaxosServiceMessage *m);
|
|
|
|
bool preprocess_query(PaxosServiceMessage *m); // true if processed.
|
|
|
|
bool prepare_update(PaxosServiceMessage *m);
|
2007-08-27 02:49:41 +00:00
|
|
|
bool should_propose(double &delay);
|
2006-10-09 19:10:44 +00:00
|
|
|
|
2007-07-01 14:43:27 +00:00
|
|
|
// ...
|
|
|
|
void send_to_waiting(); // send current map to waiters.
|
2009-10-10 05:27:38 +00:00
|
|
|
void send_full(PaxosServiceMessage *m);
|
|
|
|
MOSDMap *build_incremental(epoch_t from);
|
|
|
|
void send_incremental(PaxosServiceMessage *m, epoch_t since);
|
2007-07-01 14:43:27 +00:00
|
|
|
|
|
|
|
bool preprocess_failure(class MOSDFailure *m);
|
|
|
|
bool prepare_failure(class MOSDFailure *m);
|
|
|
|
void _reported_failure(MOSDFailure *m);
|
|
|
|
|
|
|
|
bool preprocess_boot(class MOSDBoot *m);
|
|
|
|
bool prepare_boot(class MOSDBoot *m);
|
2009-04-27 17:50:37 +00:00
|
|
|
void _booted(MOSDBoot *m, bool logit);
|
2007-07-01 14:43:27 +00:00
|
|
|
|
2008-05-13 21:54:29 +00:00
|
|
|
bool preprocess_alive(class MOSDAlive *m);
|
|
|
|
bool prepare_alive(class MOSDAlive *m);
|
2009-10-10 05:27:38 +00:00
|
|
|
void _reply_map(PaxosServiceMessage *m, epoch_t e);
|
2009-08-06 23:15:48 +00:00
|
|
|
|
|
|
|
bool preprocess_pgtemp(class MOSDPGTemp *m);
|
|
|
|
bool prepare_pgtemp(class MOSDPGTemp *m);
|
2008-05-13 19:19:05 +00:00
|
|
|
|
2009-07-07 22:06:33 +00:00
|
|
|
bool preprocess_pool_op ( class MPoolOp *m);
|
2009-07-07 23:04:58 +00:00
|
|
|
bool preprocess_pool_op_create ( class MPoolOp *m);
|
2009-07-07 22:06:33 +00:00
|
|
|
bool prepare_pool_op (MPoolOp *m);
|
2009-07-07 23:04:58 +00:00
|
|
|
bool prepare_pool_op_create (MPoolOp *m);
|
2009-07-07 22:06:33 +00:00
|
|
|
void _pool_op(MPoolOp *m, int replyCode, epoch_t epoch);
|
2009-06-16 21:22:32 +00:00
|
|
|
|
2008-05-13 19:19:05 +00:00
|
|
|
struct C_Booted : public Context {
|
2007-07-01 14:43:27 +00:00
|
|
|
OSDMonitor *cmon;
|
|
|
|
MOSDBoot *m;
|
|
|
|
C_Booted(OSDMonitor *cm, MOSDBoot *m_) :
|
|
|
|
cmon(cm), m(m_) {}
|
|
|
|
void finish(int r) {
|
|
|
|
if (r >= 0)
|
2009-04-27 17:50:37 +00:00
|
|
|
cmon->_booted(m, true);
|
2007-07-01 14:43:27 +00:00
|
|
|
else
|
2009-06-23 21:03:34 +00:00
|
|
|
cmon->dispatch((PaxosServiceMessage*)m);
|
2007-07-01 14:43:27 +00:00
|
|
|
}
|
|
|
|
};
|
2009-06-23 21:03:34 +00:00
|
|
|
|
2009-08-06 23:15:48 +00:00
|
|
|
struct C_ReplyMap : public Context {
|
2008-05-13 19:19:05 +00:00
|
|
|
OSDMonitor *osdmon;
|
2009-10-10 05:27:38 +00:00
|
|
|
PaxosServiceMessage *m;
|
2009-08-06 23:15:48 +00:00
|
|
|
epoch_t e;
|
2009-10-10 05:27:38 +00:00
|
|
|
C_ReplyMap(OSDMonitor *o, PaxosServiceMessage *mm, epoch_t ee) : osdmon(o), m(mm), e(ee) {}
|
2008-05-13 19:19:05 +00:00
|
|
|
void finish(int r) {
|
2009-08-06 23:15:48 +00:00
|
|
|
osdmon->_reply_map(m, e);
|
2008-05-13 19:19:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
struct C_Reported : public Context {
|
2007-07-01 14:43:27 +00:00
|
|
|
OSDMonitor *cmon;
|
|
|
|
MOSDFailure *m;
|
|
|
|
C_Reported(OSDMonitor *cm, MOSDFailure *m_) :
|
|
|
|
cmon(cm), m(m_) {}
|
|
|
|
void finish(int r) {
|
|
|
|
if (r >= 0)
|
|
|
|
cmon->_reported_failure(m);
|
|
|
|
else
|
2009-06-23 21:03:34 +00:00
|
|
|
cmon->dispatch((PaxosServiceMessage*)m);
|
2007-07-01 14:43:27 +00:00
|
|
|
}
|
|
|
|
};
|
2009-07-07 22:06:33 +00:00
|
|
|
struct C_PoolOp : public Context {
|
2009-06-16 21:22:32 +00:00
|
|
|
OSDMonitor *osdmon;
|
2009-07-07 22:06:33 +00:00
|
|
|
MPoolOp *m;
|
2009-06-16 21:22:32 +00:00
|
|
|
int replyCode;
|
|
|
|
int epoch;
|
2009-07-07 22:06:33 +00:00
|
|
|
C_PoolOp(OSDMonitor * osd, MPoolOp *m_, int rc, int e) :
|
2009-06-16 21:22:32 +00:00
|
|
|
osdmon(osd), m(m_), replyCode(rc), epoch(e) {}
|
|
|
|
void finish(int r) {
|
2009-07-07 22:06:33 +00:00
|
|
|
osdmon->_pool_op(m, replyCode, epoch);
|
2009-06-16 21:22:32 +00:00
|
|
|
}
|
|
|
|
};
|
2007-07-01 14:43:27 +00:00
|
|
|
|
|
|
|
bool preprocess_out(class MOSDOut *m);
|
|
|
|
bool prepare_out(class MOSDOut *m);
|
2006-10-09 19:10:44 +00:00
|
|
|
|
2008-08-07 21:21:16 +00:00
|
|
|
bool preprocess_remove_snaps(class MRemoveSnaps *m);
|
|
|
|
bool prepare_remove_snaps(class MRemoveSnaps *m);
|
|
|
|
|
2006-10-05 05:39:29 +00:00
|
|
|
public:
|
2007-07-01 14:43:27 +00:00
|
|
|
OSDMonitor(Monitor *mn, Paxos *p) :
|
|
|
|
PaxosService(mn, p) { }
|
2006-10-05 05:39:29 +00:00
|
|
|
|
|
|
|
void tick(); // check state, take actions
|
|
|
|
|
2008-02-28 18:21:48 +00:00
|
|
|
bool preprocess_command(MMonCommand *m);
|
|
|
|
bool prepare_command(MMonCommand *m);
|
2007-12-19 04:53:48 +00:00
|
|
|
|
2009-07-07 23:04:58 +00:00
|
|
|
int prepare_new_pool(string& name);
|
|
|
|
|
2007-02-26 00:17:32 +00:00
|
|
|
void mark_all_down();
|
|
|
|
|
2009-10-10 05:27:38 +00:00
|
|
|
void send_latest(PaxosServiceMessage *m, epoch_t start=0);
|
2009-11-06 21:54:53 +00:00
|
|
|
void send_latest_now_nodelete(PaxosServiceMessage *m, epoch_t start=0) {
|
|
|
|
send_incremental(m, start);
|
|
|
|
}
|
2007-05-16 21:53:22 +00:00
|
|
|
|
2008-12-16 18:41:55 +00:00
|
|
|
void blacklist(entity_addr_t a, utime_t until);
|
|
|
|
|
2009-08-28 23:48:09 +00:00
|
|
|
void check_subs();
|
2009-09-21 21:30:19 +00:00
|
|
|
void check_sub(Subscription *sub);
|
2009-08-28 23:48:09 +00:00
|
|
|
|
2009-10-22 05:48:12 +00:00
|
|
|
void add_flag(int flag) {
|
2009-10-23 00:15:20 +00:00
|
|
|
if (!(osdmap.flags & flag)) {
|
|
|
|
if (pending_inc.new_flags < 0)
|
|
|
|
pending_inc.new_flags = osdmap.flags;
|
|
|
|
pending_inc.new_flags |= flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove_flag(int flag) {
|
|
|
|
if(osdmap.flags & flag) {
|
|
|
|
if (pending_inc.new_flags < 0)
|
|
|
|
pending_inc.new_flags = osdmap.flags;
|
|
|
|
pending_inc.new_flags &= ~flag;
|
|
|
|
}
|
2009-10-22 05:48:12 +00:00
|
|
|
}
|
2006-10-05 05:39:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|