You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ar...@apache.org on 2022/04/09 17:43:37 UTC

[zookeeper] branch branch-3.6 updated: ZOOKEEPER-4515: ZK Cli quit command always logs error

This is an automated email from the ASF dual-hosted git repository.

arshad pushed a commit to branch branch-3.6
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/branch-3.6 by this push:
     new 430c0276b ZOOKEEPER-4515: ZK Cli quit command always logs error
430c0276b is described below

commit 430c0276ba5ab8012b17dd3a5699b2b642b59af9
Author: Mohammad Arshad <ar...@apache.org>
AuthorDate: Sat Apr 9 23:12:14 2022 +0530

    ZOOKEEPER-4515: ZK Cli quit command always logs error
    
    1. For connection closing state scenario, changed the log level to debug
    2. When JVM exiting with code 0, then logging info instead of error
    
    Author: Mohammad Arshad <ar...@apache.org>
    
    Reviewers: tison <wa...@gmail.com>, Enrico Olivelli <eo...@apache.org>
    
    Closes #1856 from arshadmohammad/ZOOKEEPER-4515-cli and squashes the following commits:
    
    e7e248bd5 [Mohammad Arshad] Logging error only when exit code is non zero
    31e124a2a [Mohammad Arshad] ZOOKEEPER-4515: ZK Cli quit command always logs error 1. For connection closing state scenario, changed the log level to debug 2. When JVM exiting with code 0, then logging info instead of error
    
    (cherry picked from commit e5f84f46283d70b618ce00f2df51f4bfe31d9a44)
    Signed-off-by: Mohammad Arshad <ar...@apache.org>
---
 .../src/main/java/org/apache/zookeeper/ClientCnxn.java    |  9 +++++----
 .../main/java/org/apache/zookeeper/util/ServiceUtils.java | 15 +++++++++++++--
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java
index ed955540e..c3f0079c6 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java
@@ -1294,10 +1294,11 @@ public class ClientCnxn {
                 } catch (Throwable e) {
                     if (closing) {
                         // closing so this is expected
-                        LOG.warn(
-                            "An exception was thrown while closing send thread for session 0x{}.",
-                            Long.toHexString(getSessionId()),
-                            e);
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug(
+                                "An exception was thrown while closing send thread for session 0x{}.",
+                                Long.toHexString(getSessionId()), e);
+                        }
                         break;
                     } else {
                         LOG.warn(
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/util/ServiceUtils.java b/zookeeper-server/src/main/java/org/apache/zookeeper/util/ServiceUtils.java
index 68a25ebb4..99cc685b3 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/util/ServiceUtils.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/util/ServiceUtils.java
@@ -39,7 +39,14 @@ public abstract class ServiceUtils {
      */
     @SuppressFBWarnings("DM_EXIT")
     public static final Consumer<Integer> SYSTEM_EXIT = (code) -> {
-        LOG.error("Exiting JVM with code {}", code);
+        String msg = "Exiting JVM with code {}";
+        if (code == 0) {
+            // JVM exits normally
+            LOG.info(msg, code);
+        } else {
+            // JVM exits with error
+            LOG.error(msg, code);
+        }
         System.exit(code);
     };
 
@@ -47,8 +54,12 @@ public abstract class ServiceUtils {
      * No-op strategy, useful for tests.
      */
     public static final Consumer<Integer> LOG_ONLY = (code) -> {
-        LOG.error("Fatal error, JVM should exit with code {}. "
+        if (code != 0) {
+            LOG.error("Fatal error, JVM should exit with code {}. "
                 + "Actually System.exit is disabled", code);
+        } else {
+            LOG.info("JVM should exit with code {}. Actually System.exit is disabled", code);
+        }
     };
 
     private static Consumer<Integer> systemExitProcedure = SYSTEM_EXIT;