IMPALA-4253: impala-server.backends.client-cache.total-clients shows negative 
value

Fixed double decrement in case a cached connection is broken
and cannot be re-created.

Change-Id: Ic9e28055cb232cdb543c4c9f05a558ab0f73f777
Reviewed-on: http://gerrit.cloudera.org:8080/4668
Reviewed-by: Juan Yu <j...@cloudera.com>
Tested-by: Internal Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/080a6784
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/080a6784
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/080a6784

Branch: refs/heads/master
Commit: 080a67848b3f96eb49cdaab14f32eba8091a4320
Parents: 5a91964
Author: Juan Yu <j...@cloudera.com>
Authored: Fri Oct 7 14:57:24 2016 -0700
Committer: Internal Jenkins <cloudera-hud...@gerrit.cloudera.org>
Committed: Tue Oct 18 09:29:31 2016 +0000

----------------------------------------------------------------------
 be/src/runtime/client-cache.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/080a6784/be/src/runtime/client-cache.cc
----------------------------------------------------------------------
diff --git a/be/src/runtime/client-cache.cc b/be/src/runtime/client-cache.cc
index 155474c..578ef29 100644
--- a/be/src/runtime/client-cache.cc
+++ b/be/src/runtime/client-cache.cc
@@ -86,12 +86,16 @@ Status ClientCacheHelper::ReopenClient(ClientFactory 
factory_method,
   // clean up internal buffers it reopens. To work around this issue, create a 
new client
   // instead.
   ClientKey old_client_key = *client_key;
-  if (metrics_enabled_) total_clients_metric_->Increment(-1);
   Status status = CreateClient(client_impl->address(), factory_method, 
client_key);
   // Only erase the existing client from the map if creation of the new one 
succeeded.
   // This helps to ensure the proper accounting of metrics in the presence of
   // re-connection failures (the original client should be released as usual).
   if (status.ok()) {
+    // CreateClient() will increment total_clients_metric_ if succeed.
+    if (metrics_enabled_) {
+      total_clients_metric_->Increment(-1);
+      DCHECK_GE(total_clients_metric_->value(), 0);
+    }
     lock_guard<mutex> lock(client_map_lock_);
     client_map_.erase(client);
   } else {

Reply via email to