From 663cc89296a6edbcebd84db902f0de9cbc3720b8 Mon Sep 17 00:00:00 2001 From: wenjunhuang Date: Fri, 3 Jul 2015 13:10:41 +0800 Subject: [PATCH 2/2] Change cond wait to cond_timeout wait in Client::make_request Signed-off-by: wenjunhuang --- src/client/Client.cc | 22 ++++++++++++++++------ src/common/config_opts.h | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 2bc242c..2fb2f78 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -1544,12 +1544,19 @@ int Client::make_request(MetaRequest *request, request->kick = false; while (!request->reply && // reply request->resend_mds < 0 && // forward - !request->kick) - caller_cond.Wait(client_lock); + !request->kick) { + utime_t w; + w.set_from_double(cct->_conf->client_request_timeout); + int ret_status = caller_cond.WaitInterval(cct, client_lock, w); + if (ret_status == ETIMEDOUT && !request->reply) { + request->aborted = true; + break; + } + } request->caller_cond = NULL; // did we get a reply? - if (request->reply) + if (request->reply) break; } @@ -2106,9 +2113,12 @@ void Client::handle_client_reply(MClientReply *reply) } } - // Only signal the caller once (on the first reply): - // Either its an unsafe reply, or its a safe reply and no unsafe reply was sent. - if (!is_safe || !request->got_unsafe) { + if (request->aborted) { + request->reply->put(); + request->reply = NULL; + } else if (!is_safe || !request->got_unsafe) { + // Only signal the caller once (on the first reply): + // // Either its an unsafe reply, or its a safe reply and no unsafe reply was sent. Cond cond; request->dispatch_cond = &cond; diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 1ea85a6..a7178fd 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -301,6 +301,7 @@ OPTION(mon_pool_quota_crit_threshold, OPT_INT, 0) // percent of quota at which t OPTION(client_cache_size, OPT_INT, 16384) OPTION(client_cache_mid, OPT_FLOAT, .75) OPTION(client_use_random_mds, OPT_BOOL, false) +OPTION(client_request_timeout, OPT_DOUBLE, 120.0) // timeout for a single request to mds in seconds OPTION(client_mount_timeout, OPT_DOUBLE, 300.0) OPTION(client_tick_interval, OPT_DOUBLE, 1.0) OPTION(client_trace, OPT_STR, "") -- 1.9.3