summaryrefslogtreecommitdiffstats
path: root/src/mon/Paxos.cc
diff options
context:
space:
mode:
authorKefu Chai <kchai@redhat.com>2017-05-05 06:02:05 +0200
committerKefu Chai <kchai@redhat.com>2017-05-05 07:54:45 +0200
commit561cbded0c7e28231b1c7ce18663b8d7d40aad6d (patch)
tree274f5e4e505cc70c3bcc2f0ca587fa946163b6e3 /src/mon/Paxos.cc
parentmon/Elector: call cancel_timer() in shutdown() (diff)
downloadceph-561cbded0c7e28231b1c7ce18663b8d7d40aad6d.tar.xz
ceph-561cbded0c7e28231b1c7ce18663b8d7d40aad6d.zip
mon: check is_shutdown() in timer callbacks
introduce a helper class: C_MonContext, and initialize all timer events using it, to ensure that they do check is_shutdown() before doing their work. Fixes: http://tracker.ceph.com/issues/19825 Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to 'src/mon/Paxos.cc')
-rw-r--r--src/mon/Paxos.cc85
1 files changed, 25 insertions, 60 deletions
diff --git a/src/mon/Paxos.cc b/src/mon/Paxos.cc
index 2e905ac8fb7..8ba73118e0f 100644
--- a/src/mon/Paxos.cc
+++ b/src/mon/Paxos.cc
@@ -37,61 +37,6 @@ static ostream& _prefix(std::ostream *_dout, Monitor *mon, const string& name,
<< ") ";
}
-class Paxos::C_CollectTimeout : public Context {
- Paxos *paxos;
-public:
- explicit C_CollectTimeout(Paxos *p) : paxos(p) {}
- void finish(int r) override {
- if (r == -ECANCELED)
- return;
- paxos->collect_timeout();
- }
-};
-
-class Paxos::C_AcceptTimeout : public Context {
- Paxos *paxos;
-public:
- explicit C_AcceptTimeout(Paxos *p) : paxos(p) {}
- void finish(int r) override {
- if (r == -ECANCELED)
- return;
- paxos->accept_timeout();
- }
-};
-
-class Paxos::C_LeaseAckTimeout : public Context {
- Paxos *paxos;
-public:
- explicit C_LeaseAckTimeout(Paxos *p) : paxos(p) {}
- void finish(int r) override {
- if (r == -ECANCELED)
- return;
- paxos->lease_ack_timeout();
- }
-};
-
-class Paxos::C_LeaseTimeout : public Context {
- Paxos *paxos;
-public:
- explicit C_LeaseTimeout(Paxos *p) : paxos(p) {}
- void finish(int r) override {
- if (r == -ECANCELED)
- return;
- paxos->lease_timeout();
- }
-};
-
-class Paxos::C_LeaseRenew : public Context {
- Paxos *paxos;
-public:
- explicit C_LeaseRenew(Paxos *p) : paxos(p) {}
- void finish(int r) override {
- if (r == -ECANCELED)
- return;
- paxos->lease_renew_timeout();
- }
-};
-
class Paxos::C_Trimmed : public Context {
Paxos *paxos;
public:
@@ -249,7 +194,11 @@ void Paxos::collect(version_t oldpn)
}
// set timeout event
- collect_timeout_event = new C_CollectTimeout(this);
+ collect_timeout_event = new C_MonContext(mon, [this](int r) {
+ if (r == -ECANCELED)
+ return;
+ collect_timeout();
+ });
mon->timer.add_event_after(g_conf->mon_accept_timeout_factor *
g_conf->mon_lease,
collect_timeout_event);
@@ -737,7 +686,11 @@ void Paxos::begin(bufferlist& v)
}
// set timeout event
- accept_timeout_event = new C_AcceptTimeout(this);
+ accept_timeout_event = new C_MonContext(mon, [this](int r) {
+ if (r == -ECANCELED)
+ return;
+ accept_timeout();
+ });
mon->timer.add_event_after(g_conf->mon_accept_timeout_factor *
g_conf->mon_lease,
accept_timeout_event);
@@ -1023,14 +976,22 @@ void Paxos::extend_lease()
// set timeout event.
// if old timeout is still in place, leave it.
if (!lease_ack_timeout_event) {
- lease_ack_timeout_event = new C_LeaseAckTimeout(this);
+ lease_ack_timeout_event = new C_MonContext(mon, [this](int r) {
+ if (r == -ECANCELED)
+ return;
+ lease_ack_timeout();
+ });
mon->timer.add_event_after(g_conf->mon_lease_ack_timeout_factor *
g_conf->mon_lease,
lease_ack_timeout_event);
}
// set renew event
- lease_renew_event = new C_LeaseRenew(this);
+ lease_renew_event = new C_MonContext(mon, [this](int r) {
+ if (r == -ECANCELED)
+ return;
+ lease_renew_timeout();
+ });
utime_t at = lease_expire;
at -= g_conf->mon_lease;
at += g_conf->mon_lease_renew_interval_factor * g_conf->mon_lease;
@@ -1213,7 +1174,11 @@ void Paxos::reset_lease_timeout()
dout(20) << "reset_lease_timeout - setting timeout event" << dendl;
if (lease_timeout_event)
mon->timer.cancel_event(lease_timeout_event);
- lease_timeout_event = new C_LeaseTimeout(this);
+ lease_timeout_event = new C_MonContext(mon, [this](int r) {
+ if (r == -ECANCELED)
+ return;
+ lease_timeout();
+ });
mon->timer.add_event_after(g_conf->mon_lease_ack_timeout_factor *
g_conf->mon_lease,
lease_timeout_event);