From 8c1632ba505d496700f7359bda07191ea0aaf9cb Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 31 Jul 2012 15:02:55 -0700 Subject: [PATCH] cephtool: send keepalive to tell target If we 'ceph tell ...' to a non-monitor, we need to send keepalives to ensure we detect a tcp drop. (Not so for monitors; monclient already does its own keepalive thing.) Signed-off-by: Sage Weil --- src/tools/common.cc | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/tools/common.cc b/src/tools/common.cc index 4c671c7cd83ea..e29a674e75ea4 100644 --- a/src/tools/common.cc +++ b/src/tools/common.cc @@ -71,11 +71,12 @@ string reply_rs; int reply_rc; bufferlist reply_bl; entity_inst_t reply_from; -Context *resend_event = 0; OSDMap *osdmap = 0; Connection *command_con = NULL; +Context *tick_event = 0; +float tick_interval = 3.0; // observe (push) #include "mon/PGMap.h" @@ -92,6 +93,19 @@ Connection *command_con = NULL; static set registered, seen; +struct C_Tick : public Context { + CephToolCtx *ctx; + C_Tick(CephToolCtx *c) : ctx(c) {} + void finish(int r) { + if (command_con) + messenger->send_keepalive(command_con); + + assert(tick_event == this); + tick_event = new C_Tick(ctx); + ctx->timer.add_event_after(tick_interval, tick_event); + } +}; + static void send_command(CephToolCtx *ctx) { if (!pending_tell && !pending_tell_pgid) { @@ -162,6 +176,11 @@ static void send_command(CephToolCtx *ctx) command_con = messenger->get_connection(osdmap->get_inst(n)); messenger->send_message(m, command_con); + + if (tick_event) + ctx->timer.cancel_event(tick_event); + tick_event = new C_Tick(ctx); + ctx->timer.add_event_after(tick_interval, tick_event); } return; } @@ -193,10 +212,6 @@ static void handle_ack(CephToolCtx *ctx, MMonCommandAck *ack) reply_rc = ack->r; reply_bl = ack->get_data(); cmd_cond.Signal(); - if (resend_event) { - ctx->timer.cancel_event(resend_event); - resend_event = 0; - } ctx->lock.Unlock(); ack->put(); } @@ -211,9 +226,9 @@ static void handle_ack(CephToolCtx *ctx, MCommandReply *ack) reply_rc = ack->r; reply_bl = ack->get_data(); cmd_cond.Signal(); - if (resend_event) { - ctx->timer.cancel_event(resend_event); - resend_event = 0; + if (tick_event) { + ctx->timer.cancel_event(tick_event); + tick_event = 0; } } ctx->lock.Unlock(); -- 2.39.5