]> git-server-git.apps.pok.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 23:45:36 +0000 (15:45 -0800)
Just use the conf option directly, since librados is the only caller.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
(cherry picked from commit 671a76d64bc50e4f15f4c2804d99887e22dcdb69)

src/mon/MonClient.cc
src/mon/MonClient.h

index 38bead8f29fb8c3f591881dd3fab7718a4d99402..5c8ad4ee788b0b6cdf812a13bc7f1bae9a725286 100644 (file)
@@ -810,6 +810,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;
@@ -834,6 +851,10 @@ int MonClient::start_mon_command(const vector<string>& cmd, bufferlist& inbl,
   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 f82714ecf3774407cd9cb29100cf8cf1a3823877..dcd39775a8571d84a959a29c03d16a06d7c6324f 100644 (file)
@@ -280,18 +280,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);