You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by ak...@apache.org on 2017/12/14 07:11:55 UTC

sentry git commit: SENTRY-2078: Have sentry server print an obvious INFO level log message when it becomes the writer (Arjun Mishra, reviewed by Vadim Spector and Alex Kolbasov)

Repository: sentry
Updated Branches:
  refs/heads/master 71283bda2 -> f2e566a05


SENTRY-2078: Have sentry server print an obvious INFO level log message when it becomes the writer (Arjun Mishra, reviewed by Vadim Spector and Alex Kolbasov)


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/f2e566a0
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/f2e566a0
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/f2e566a0

Branch: refs/heads/master
Commit: f2e566a050c700ac3692b30e6c84f5454e24f8d5
Parents: 71283bd
Author: Alexander Kolbasov <ak...@cloudera.com>
Authored: Wed Dec 13 23:11:37 2017 -0800
Committer: Alexander Kolbasov <ak...@cloudera.com>
Committed: Wed Dec 13 23:11:37 2017 -0800

----------------------------------------------------------------------
 .../service/thrift/LeaderStatusMonitor.java     | 27 ++++++++++++--------
 1 file changed, 16 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/f2e566a0/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/LeaderStatusMonitor.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/LeaderStatusMonitor.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/LeaderStatusMonitor.java
index 360c5a5..8e80d55 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/LeaderStatusMonitor.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/LeaderStatusMonitor.java
@@ -17,8 +17,6 @@
 package org.apache.sentry.service.thrift;
 
 import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.recipes.leader.LeaderSelector;
 import org.apache.curator.framework.recipes.leader.LeaderSelectorListener;
@@ -33,6 +31,8 @@ import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.apache.sentry.service.thrift.ServiceConstants.ServerConfig.*;
 
@@ -86,8 +86,7 @@ import static org.apache.sentry.service.thrift.ServiceConstants.ServerConfig.*;
 final class LeaderStatusMonitor
       extends LeaderSelectorListenerAdapter implements AutoCloseable {
 
-  private static final Log LOG =
-          LogFactory.getLog(LeaderStatusMonitor.class);
+  private static final Logger LOGGER = LoggerFactory.getLogger(LeaderStatusMonitor.class);
 
   private static final String LEADER_SELECTOR_SUFFIX = "leader";
 
@@ -138,15 +137,15 @@ final class LeaderStatusMonitor
       haContext = null;
       isLeader = true;
       incarnationId = "";
-      LOG.info("Leader election protocol disabled, assuming single active server");
+      LOGGER.info("Leader election protocol disabled, assuming single active server");
       return;
     }
     isSingleNodeMode = false;
     incarnationId = defaultIncarnationId;
     haContext = HAContext.getHAServerContext(conf);
 
-    LOG.info("Created LeaderStatusMonitor(incarnationId=" + incarnationId +
-        ", zkServers='" + zkServers + "')");
+    LOGGER.info("Created LeaderStatusMonitor(incarnationId={}, "
+        + "zkServers='{}')", incarnationId, zkServers);
   }
 
   /**
@@ -250,8 +249,7 @@ final class LeaderStatusMonitor
   @Override
   public void takeLeadership(CuratorFramework client) throws Exception {
     leaderCount.incrementAndGet();
-    LOG.info("LeaderStatusMonitor: becoming active. " +
-            "leaderCount=" + leaderCount);
+    LOGGER.info("Becoming leader in Sentry HA cluster:{}", this);
     lock.lock();
     try {
       isLeader = true;
@@ -259,11 +257,11 @@ final class LeaderStatusMonitor
       cond.await();
     } catch (InterruptedException ignored) {
       Thread.currentThread().interrupt();
-      LOG.info("LeaderStatusMonitor: interrupted");
+      LOGGER.error("takeLeadership call interrupted:" + this, ignored);
     } finally {
       isLeader = false;
       lock.unlock();
-      LOG.info("LeaderStatusMonitor: becoming standby");
+      LOGGER.info("Resigning from leader status in a Sentry HA cluster:{}", this);
     }
   }
 
@@ -279,4 +277,11 @@ final class LeaderStatusMonitor
     return ManagementFactory.getRuntimeMXBean().getName();
   }
 
+  @Override
+  public String toString() {
+    return isSingleNodeMode?"Leader election disabled":
+        String.format("{isSingleNodeMode=%b, incarnationId=%s, isLeader=%b, leaderCount=%d}",
+        isSingleNodeMode, incarnationId, isLeader, leaderCount);
+  }
+
 }