PG: use a state_name member instead of overriding get_state_name

Also add debugging to each state constructor. Since dout uses
the recovery machine context, anything using it in the constructor
must be a state, not a simple_state.

Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
This commit is contained in:
Josh Durgin 2011-05-04 09:10:00 -07:00
parent 879d6b039f
commit 8d301d299b
2 changed files with 46 additions and 18 deletions

View File

@ -3719,7 +3719,18 @@ std::ostream& operator<<(std::ostream& oss,
#define dout_prefix (*_dout << context< RecoveryMachine >().pg->gen_prefix() \
<< "state<" << get_state_name() << ">: ")
/*------Initial-------*/
PG::RecoveryState::Initial::Initial(my_context ctx) : my_base(ctx) {
state_name = "Initial";
dout(10) << "entered state" << dendl;
}
/*------Started-------*/
PG::RecoveryState::Started::Started(my_context ctx) : my_base(ctx) {
state_name = "Started";
dout(10) << "entered state" << dendl;
}
boost::statechart::result
PG::RecoveryState::Started::react(const AdvMap& advmap) {
dout(10) << "Started advmap" << dendl;
@ -3733,6 +3744,11 @@ PG::RecoveryState::Started::react(const AdvMap& advmap) {
}
/*--------Reset---------*/
PG::RecoveryState::Reset::Reset(my_context ctx) : my_base(ctx) {
state_name = "Reset";
dout(10) << "entered state" << dendl;
}
boost::statechart::result
PG::RecoveryState::Reset::react(const AdvMap& advmap) {
PG *pg = context< RecoveryMachine >().pg;
@ -3756,6 +3772,8 @@ PG::RecoveryState::Reset::react(const ActMap&) {
/*-------Start---------*/
PG::RecoveryState::Start::Start(my_context ctx) : my_base(ctx) {
state_name = "Start";
dout(10) << "entered state" << dendl;
PG *pg = context< RecoveryMachine >().pg;
if (pg->is_primary()) {
dout(1) << "transitioning to Primary" << dendl;
@ -3767,6 +3785,11 @@ PG::RecoveryState::Start::Start(my_context ctx) : my_base(ctx) {
}
/*---------Primary--------*/
PG::RecoveryState::Primary::Primary(my_context ctx) : my_base(ctx) {
state_name = "Primary";
dout(10) << "entered state" << dendl;
}
boost::statechart::result
PG::RecoveryState::Primary::react(const BacklogComplete&) {
PG *pg = context< RecoveryMachine >().pg;
@ -3799,6 +3822,8 @@ PG::RecoveryState::Primary::react(const ActMap&) {
/*---------Peering--------*/
PG::RecoveryState::Peering::Peering(my_context ctx)
: my_base(ctx) {
state_name = "Peering";
dout(10) << "entered state" << dendl;
PG *pg = context< RecoveryMachine >().pg;
assert(!pg->is_active());
assert(!pg->is_peering());
@ -3824,6 +3849,8 @@ void PG::RecoveryState::Peering::exit() {
/*---------Active---------*/
PG::RecoveryState::Active::Active(my_context ctx) : my_base(ctx) {
state_name = "Active";
dout(10) << "entered state" << dendl;
PG *pg = context< RecoveryMachine >().pg;
assert(pg->is_primary());
dout(10) << "In Active, about to call activate" << dendl;
@ -3933,6 +3960,7 @@ PG::RecoveryState::Active::react(const MInfoRec& infoevt) {
/*------ReplicaActive-----*/
PG::RecoveryState::ReplicaActive::ReplicaActive(my_context ctx)
: my_base(ctx) {
state_name = "ReplicaActive";
dout(10) << "In ReplicaActive, about to call activate" << dendl;
PG *pg = context< RecoveryMachine >().pg;
map< int, map< pg_t, Query> > query_map;
@ -3963,6 +3991,8 @@ PG::RecoveryState::ReplicaActive::react(const ActMap&) {
/*-------Stray---*/
PG::RecoveryState::Stray::Stray(my_context ctx)
: my_base(ctx), backlog_requested(false) {
state_name = "Stray";
dout(10) << "entered state" << dendl;
PG *pg = context< RecoveryMachine >().pg;
assert(!pg->is_active());
assert(!pg->is_peering());
@ -4060,6 +4090,8 @@ PG::RecoveryState::Stray::react(const ActMap&) {
/*--------GetInfo---------*/
PG::RecoveryState::GetInfo::GetInfo(my_context ctx) : my_base(ctx) {
state_name = "GetInfo";
dout(10) << "entered state" << dendl;
PG *pg = context< RecoveryMachine >().pg;
pg->generate_past_intervals();
auto_ptr<PgPriorSet> &prior_set = context< Peering >().prior_set;
@ -4110,6 +4142,8 @@ PG::RecoveryState::GetInfo::react(const MNotifyRec& infoevt) {
/*------GetLog------------*/
PG::RecoveryState::GetLog::GetLog(my_context ctx) :
my_base(ctx), newest_update_osd(-1), need_backlog(false), msg(0) {
state_name = "GetLog";
dout(10) << "entered state" << dendl;
PG *pg = context< RecoveryMachine >().pg;
dout(10) << "In GetLog, selecting log location" << dendl;
eversion_t newest_update;
@ -4199,6 +4233,8 @@ PG::RecoveryState::GetLog::~GetLog() {
/*------GetMissing--------*/
PG::RecoveryState::GetMissing::GetMissing(my_context ctx) : my_base(ctx) {
state_name = "GetMissing";
dout(10) << "entered state" << dendl;
PG *pg = context< RecoveryMachine >().pg;
map<int, Missing> &peer_missing = pg->peer_missing;
for (vector<int>::iterator i = pg->acting.begin()++;

View File

@ -894,20 +894,19 @@ public:
/* States */
struct NamedState {
virtual const char *get_state_name() = 0;
string state_name;
virtual string &get_state_name() { return state_name; }
virtual ~NamedState() {}
};
struct Crashed :
boost::statechart::state< Crashed, RecoveryMachine >, NamedState {
const char *get_state_name() { return "Crashed"; }
Crashed(my_context ctx) : my_base(ctx) { assert(0); }
};
struct Started;
struct Initial :
boost::statechart::simple_state< Initial, RecoveryMachine >, NamedState {
const char *get_state_name() { return "Initial"; }
boost::statechart::state< Initial, RecoveryMachine >, NamedState {
typedef boost::mpl::list <
boost::statechart::transition< Initialize, Started >,
boost::statechart::transition< MNotifyRec, Crashed >,
@ -918,11 +917,11 @@ public:
boost::statechart::transition< AdvMap, Crashed >,
boost::statechart::transition< ActMap, Crashed >
> reactions;
Initial(my_context ctx);
};
struct Reset :
boost::statechart::simple_state< Reset, RecoveryMachine >, NamedState {
const char *get_state_name() { return "Reset"; }
boost::statechart::state< Reset, RecoveryMachine >, NamedState {
typedef boost::mpl::list <
boost::statechart::custom_reaction< AdvMap >,
boost::statechart::custom_reaction< ActMap >,
@ -935,12 +934,12 @@ public:
> reactions;
boost::statechart::result react(const AdvMap&);
boost::statechart::result react(const ActMap&);
Reset(my_context ctx);
};
struct Start;
struct Started :
boost::statechart::simple_state< Started, RecoveryMachine, Start >, NamedState {
const char *get_state_name() { return "Started"; }
boost::statechart::state< Started, RecoveryMachine, Start >, NamedState {
typedef boost::mpl::list <
boost::statechart::custom_reaction< AdvMap >,
boost::statechart::transition< ActMap, Crashed >,
@ -952,6 +951,7 @@ public:
boost::statechart::transition< Activate, Crashed >
> reactions;
boost::statechart::result react(const AdvMap&);
Started(my_context ctx);
};
struct MakePrimary : boost::statechart::event< MakePrimary > {};
@ -960,7 +960,6 @@ public:
struct Stray;
struct Start :
boost::statechart::state< Start, Started >, NamedState {
const char *get_state_name() { return "Start"; }
typedef boost::mpl::list <
boost::statechart::transition< MakePrimary, Primary >,
boost::statechart::transition< MakeStray, Stray >
@ -972,8 +971,7 @@ public:
struct Pending;
struct NeedNewMap : boost::statechart::event< NeedNewMap > {};
struct Primary :
boost::statechart::simple_state< Primary, Started, Peering >, NamedState {
const char *get_state_name() { return "Primary"; }
boost::statechart::state< Primary, Started, Peering >, NamedState {
typedef boost::mpl::list <
boost::statechart::custom_reaction< ActMap >,
boost::statechart::custom_reaction< BacklogComplete >,
@ -983,6 +981,7 @@ public:
boost::statechart::result react(const BacklogComplete&);
boost::statechart::result react(const ActMap&);
boost::statechart::result react(const MNotifyRec&);
Primary(my_context ctx);
};
struct Pending :
@ -993,7 +992,6 @@ public:
struct Active;
struct Peering :
boost::statechart::state< Peering, Primary, GetInfo >, NamedState {
const char *get_state_name() { return "Peering"; }
typedef boost::mpl::list <
boost::statechart::transition< Activate, Active >,
boost::statechart::custom_reaction< AdvMap >
@ -1007,7 +1005,6 @@ public:
struct Active :
boost::statechart::state< Active, Primary >, NamedState {
const char *get_state_name() { return "Active"; }
typedef boost::mpl::list <
boost::statechart::custom_reaction< ActMap >,
boost::statechart::custom_reaction< AdvMap >,
@ -1023,7 +1020,6 @@ public:
};
struct ReplicaActive : boost::statechart::state< ReplicaActive, Started >, NamedState {
const char *get_state_name() { return "ReplicaActive"; }
typedef boost::mpl::list <
boost::statechart::transition< MQuery, Crashed >,
boost::statechart::custom_reaction< ActMap >,
@ -1036,7 +1032,6 @@ public:
};
struct Stray : boost::statechart::state< Stray, Started >, NamedState {
const char *get_state_name() { return "Stray"; }
bool backlog_requested;
map<int, Query> pending_queries;
typedef boost::mpl::list <
@ -1061,7 +1056,6 @@ public:
struct GotInfo : boost::statechart::event< GotInfo > {};
struct GetInfo :
boost::statechart::state< GetInfo, Peering >, NamedState {
const char *get_state_name() { return "Peering::GetInfo"; }
set<int> peer_info_requested;
typedef boost::mpl::list <
boost::statechart::transition< GotInfo, GetLog >,
@ -1078,7 +1072,6 @@ public:
struct GotLog : boost::statechart::event< GotLog > {};
struct GetLog :
boost::statechart::state< GetLog, Peering >, NamedState {
const char *get_state_name() { return "Peering::GetLog"; }
int newest_update_osd;
bool need_backlog;
bool wait_on_backlog;
@ -1098,7 +1091,6 @@ public:
struct GetMissing :
boost::statechart::state< GetMissing, Peering >, NamedState {
const char *get_state_name() { return "Peering::GetMissing"; }
set<int> peer_missing_requested;
typedef boost::mpl::list <
boost::statechart::custom_reaction< MLogRec >