Skip to content

Commit

Permalink
Merge pull request ceph#14919 from tchaikov/wip-19825
Browse files Browse the repository at this point in the history
mon: check is_shutdown() in timer callbacks

Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas authored May 8, 2017
2 parents fd61780 + 561cbde commit 916c5e3
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 192 deletions.
19 changes: 6 additions & 13 deletions src/mon/Elector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ void Elector::init()

void Elector::shutdown()
{
if (expire_event)
mon->timer.cancel_event(expire_event);
cancel_timer();
}

void Elector::bump_epoch(epoch_t e)
Expand Down Expand Up @@ -127,6 +126,8 @@ void Elector::defer(int who)

void Elector::reset_timer(double plus)
{
// set the timer
cancel_timer();
/**
* This class is used as the callback when the expire_event timer fires up.
*
Expand All @@ -140,17 +141,9 @@ void Elector::reset_timer(double plus)
* as far as we know, we may even be dead); so, just propose ourselves as the
* Leader.
*/
class C_ElectionExpire : public Context {
Elector *elector;
public:
explicit C_ElectionExpire(Elector *e) : elector(e) { }
void finish(int r) override {
elector->expire();
}
};
// set the timer
cancel_timer();
expire_event = new C_ElectionExpire(this);
expire_event = new C_MonContext(mon, [this](int) {
expire();
});
mon->timer.add_event_after(g_conf->mon_election_timeout + plus,
expire_event);
}
Expand Down
3 changes: 1 addition & 2 deletions src/mon/Elector.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Elector {
* Event callback responsible for dealing with an expired election once a
* timer runs out and fires up.
*/
Context *expire_event;
Context *expire_event = nullptr;

/**
* Resets the expire_event timer, by cancelling any existing one and
Expand Down Expand Up @@ -335,7 +335,6 @@ class Elector {
* @param m A Monitor instance
*/
explicit Elector(Monitor *m) : mon(m),
expire_event(0),
epoch(0),
participating(true),
electing_me(false),
Expand Down
2 changes: 1 addition & 1 deletion src/mon/MgrMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void MgrMonitor::send_digests()
sub->session->con->send_message(mdigest);
}

digest_callback = new FunctionContext([this](int r){
digest_callback = new C_MonContext(mon, [this](int){
send_digests();
});
mon->timer.add_event_after(g_conf->mon_mgr_digest_period, digest_callback);
Expand Down
75 changes: 35 additions & 40 deletions src/mon/Monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ long parse_pos_long(const char *s, ostream *pss)
return r;
}

void C_MonContext::finish(int r) {
if (mon->is_shutdown())
return;
FunctionContext::finish(r);
}

Monitor::Monitor(CephContext* cct_, string nm, MonitorDBStore *s,
Messenger *m, Messenger *mgr_m, MonMap *map) :
Dispatcher(cct_),
Expand Down Expand Up @@ -199,12 +205,8 @@ Monitor::Monitor(CephContext* cct_, string nm, MonitorDBStore *s,
timecheck_rounds_since_clean(0),
timecheck_event(NULL),

probe_timeout_event(NULL),

paxos_service(PAXOS_NUM),
admin_hook(NULL),
health_tick_event(NULL),
health_interval_event(NULL),
routed_request_tid(0),
op_tracker(cct, true, 1)
{
Expand Down Expand Up @@ -1260,7 +1262,9 @@ void Monitor::sync_reset_timeout()
dout(10) << __func__ << dendl;
if (sync_timeout_event)
timer.cancel_event(sync_timeout_event);
sync_timeout_event = new C_SyncTimeout(this);
sync_timeout_event = new C_MonContext(this, [this](int) {
sync_timeout();
});
timer.add_event_after(g_conf->mon_sync_timeout, sync_timeout_event);
}

Expand Down Expand Up @@ -1598,7 +1602,9 @@ void Monitor::cancel_probe_timeout()
void Monitor::reset_probe_timeout()
{
cancel_probe_timeout();
probe_timeout_event = new C_ProbeTimeout(this);
probe_timeout_event = new C_MonContext(this, [this](int r) {
probe_timeout(r);
});
double t = g_conf->mon_probe_timeout;
timer.add_event_after(t, probe_timeout_event);
dout(10) << "reset_probe_timeout " << probe_timeout_event << " after " << t << " seconds" << dendl;
Expand Down Expand Up @@ -2257,8 +2263,12 @@ void Monitor::health_tick_start()
dout(15) << __func__ << dendl;

health_tick_stop();
health_tick_event = new C_HealthToClogTick(this);

health_tick_event = new C_MonContext(this, [this](int r) {
if (r < 0)
return;
do_health_to_clog();
health_tick_start();
});
timer.add_event_after(cct->_conf->mon_health_to_clog_tick_interval,
health_tick_event);
}
Expand Down Expand Up @@ -2302,7 +2312,11 @@ void Monitor::health_interval_start()

health_interval_stop();
utime_t next = health_interval_calc_next_update();
health_interval_event = new C_HealthToClogInterval(this);
health_interval_event = new C_MonContext(this, [this](int r) {
if (r < 0)
return;
do_health_to_clog_interval();
});
timer.add_event_at(next, health_interval_event);
}

Expand Down Expand Up @@ -4112,7 +4126,9 @@ void Monitor::timecheck_reset_event()
<< " rounds_since_clean " << timecheck_rounds_since_clean
<< dendl;

timecheck_event = new C_TimeCheck(this);
timecheck_event = new C_MonContext(this, [this](int) {
timecheck_start_round();
});
timer.add_event_after(delay, timecheck_event);
}

Expand Down Expand Up @@ -4952,15 +4968,9 @@ void Monitor::scrub_event_start()
return;
}

struct C_Scrub : public Context {
Monitor *mon;
explicit C_Scrub(Monitor *m) : mon(m) { }
void finish(int r) override {
mon->scrub_start();
}
};

scrub_event = new C_Scrub(this);
scrub_event = new C_MonContext(this, [this](int) {
scrub_start();
});
timer.add_event_after(cct->_conf->mon_scrub_interval, scrub_event);
}

Expand All @@ -4986,33 +4996,18 @@ void Monitor::scrub_reset_timeout()
dout(15) << __func__ << " reset timeout event" << dendl;
scrub_cancel_timeout();

struct C_ScrubTimeout : public Context {
Monitor *mon;
explicit C_ScrubTimeout(Monitor *m) : mon(m) { }
void finish(int r) override {
mon->scrub_timeout();
}
};

scrub_timeout_event = new C_ScrubTimeout(this);
scrub_timeout_event = new C_MonContext(this, [this](int) {
scrub_timeout();
});
timer.add_event_after(g_conf->mon_scrub_timeout, scrub_timeout_event);
}

/************ TICK ***************/

class C_Mon_Tick : public Context {
Monitor *mon;
public:
explicit C_Mon_Tick(Monitor *m) : mon(m) {}
void finish(int r) override {
mon->tick();
}
};

void Monitor::new_tick()
{
C_Mon_Tick *ctx = new C_Mon_Tick(this);
timer.add_event_after(g_conf->mon_tick_interval, ctx);
timer.add_event_after(g_conf->mon_tick_interval, new C_MonContext(this, [this](int) {
tick();
}));
}

void Monitor::tick()
Expand Down
60 changes: 11 additions & 49 deletions src/mon/Monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ struct MonCommand;

#define COMPAT_SET_LOC "feature_set"

class C_MonContext final : public FunctionContext {
const Monitor *mon;
public:
explicit C_MonContext(Monitor *m, boost::function<void(int)>&& callback)
: FunctionContext(std::move(callback)), mon(m) {}
void finish(int r) override;
};

class Monitor : public Dispatcher,
public md_config_obs_t {
public:
Expand Down Expand Up @@ -163,7 +171,6 @@ class Monitor : public Dispatcher,

private:
void new_tick();
friend class C_Mon_Tick;

// -- local storage --
public:
Expand Down Expand Up @@ -336,14 +343,6 @@ class Monitor : public Dispatcher,
*/
version_t sync_last_committed_floor;

struct C_SyncTimeout : public Context {
Monitor *mon;
explicit C_SyncTimeout(Monitor *m) : mon(m) {}
void finish(int r) override {
mon->sync_timeout();
}
};

/**
* Obtain the synchronization target prefixes in set form.
*
Expand Down Expand Up @@ -503,14 +502,6 @@ class Monitor : public Dispatcher,
*/
Context *timecheck_event;

struct C_TimeCheck : public Context {
Monitor *mon;
explicit C_TimeCheck(Monitor *m) : mon(m) { }
void finish(int r) override {
mon->timecheck_start_round();
}
};

void timecheck_start();
void timecheck_finish();
void timecheck_start_round();
Expand Down Expand Up @@ -546,15 +537,7 @@ class Monitor : public Dispatcher,
*/
void handle_ping(MonOpRequestRef op);

Context *probe_timeout_event; // for probing

struct C_ProbeTimeout : public Context {
Monitor *mon;
explicit C_ProbeTimeout(Monitor *m) : mon(m) {}
void finish(int r) override {
mon->probe_timeout(r);
}
};
Context *probe_timeout_event = nullptr; // for probing

void reset_probe_timeout();
void cancel_probe_timeout();
Expand Down Expand Up @@ -713,29 +696,8 @@ class Monitor : public Dispatcher,
}
} health_status_cache;

struct C_HealthToClogTick : public Context {
Monitor *mon;
explicit C_HealthToClogTick(Monitor *m) : mon(m) { }
void finish(int r) override {
if (r < 0)
return;
mon->do_health_to_clog();
mon->health_tick_start();
}
};

struct C_HealthToClogInterval : public Context {
Monitor *mon;
explicit C_HealthToClogInterval(Monitor *m) : mon(m) { }
void finish(int r) override {
if (r < 0)
return;
mon->do_health_to_clog_interval();
}
};

Context *health_tick_event;
Context *health_interval_event;
Context *health_tick_event = nullptr;
Context *health_interval_event = nullptr;

void health_tick_start();
void health_tick_stop();
Expand Down
Loading

0 comments on commit 916c5e3

Please sign in to comment.