]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
MonClient: add a timeout on commands for librados
authorJosh Durgin <josh.durgin@inktank.com>
Tue, 4 Feb 2014 02:30:00 +0000 (18:30 -0800)
committerJosh Durgin <josh.durgin@inktank.com>
Mon, 10 Feb 2014 20:53:11 +0000 (12:53 -0800)
Just use the conf option directly, since librados is the only caller.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
src/mon/MonClient.cc
src/mon/MonClient.h

index a77a5f899a618ea9f4557c351027707c7fc5877a..3782902cb076b4face0011852f8092e9b89ed5a3 100644 (file)
@@ -882,6 +882,23 @@ void MonClient::handle_mon_command_ack(MMonCommandAck *ack)
   ack->put();
 }
 
+int MonClient::_cancel_mon_command(uint64_t tid, int r)
+{
+  assert(monc_lock.is_locked());
+
+  map<tid_t, MonCommand*>::iterator it = mon_commands.find(tid);
+  if (it == mon_commands.end()) {
+    ldout(cct, 10) << __func__ << " tid " << tid << " dne" << dendl;
+    return -ENOENT;
+  }
+
+  ldout(cct, 10) << __func__ << " tid " << tid << dendl;
+
+  MonCommand *cmd = it->second;
+  _finish_command(cmd, -ETIMEDOUT, "");
+  return 0;
+}
+
 void MonClient::_finish_command(MonCommand *r, int ret, string rs)
 {
   ldout(cct, 10) << "_finish_command " << r->tid << " = " << ret << " " << rs << dendl;
@@ -907,6 +924,10 @@ int MonClient::start_mon_command(const vector<string>& cmd,
   r->poutbl = outbl;
   r->prs = outs;
   r->onfinish = onfinish;
+  if (cct->_conf->rados_mon_op_timeout > 0) {
+    r->ontimeout = new C_CancelMonCommand(r->tid, this);
+    timer.add_event_after(cct->_conf->rados_mon_op_timeout, r->ontimeout);
+  }
   mon_commands[r->tid] = r;
   _send_command(r);
   // can't fail
index 1404f35786d3e23129885a57dab4c38660a31b92..9aea5ad9382ec73f1e241de92b164ebaf02c40f8 100644 (file)
@@ -344,18 +344,30 @@ private:
     bufferlist *poutbl;
     string *prs;
     int *prval;
-    Context *onfinish;
+    Context *onfinish, *ontimeout;
 
     MonCommand(uint64_t t)
       : target_rank(-1),
        tid(t),
-       poutbl(NULL), prs(NULL), prval(NULL), onfinish(NULL)
+       poutbl(NULL), prs(NULL), prval(NULL), onfinish(NULL), ontimeout(NULL)
     {}
   };
   map<uint64_t,MonCommand*> mon_commands;
 
+  class C_CancelMonCommand : public Context
+  {
+    uint64_t tid;
+    MonClient *monc;
+  public:
+    C_CancelMonCommand(uint64_t tid, MonClient *monc) : tid(tid), monc(monc) {}
+    void finish(int r) {
+      monc->_cancel_mon_command(tid, -ETIMEDOUT);
+    }
+  };
+
   void _send_command(MonCommand *r);
   void _resend_mon_commands();
+  int _cancel_mon_command(uint64_t tid, int r);
   void _finish_command(MonCommand *r, int ret, string rs);
   void handle_mon_command_ack(MMonCommandAck *ack);