You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by va...@apache.org on 2017/02/22 00:55:47 UTC

sentry git commit: SENTRY-1635: Limit HMS connections only to the leader of the sentry servers

Repository: sentry
Updated Branches:
  refs/heads/sentry-ha-redesign 33d9f6fe4 -> 21fbb9d43


SENTRY-1635: Limit HMS connections only to the leader of the sentry servers


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

Branch: refs/heads/sentry-ha-redesign
Commit: 21fbb9d43fa850cdac536958732ecd50149701ac
Parents: 33d9f6f
Author: Vamsee Yarlagadda <va...@cloudera.com>
Authored: Fri Feb 17 11:52:13 2017 -0600
Committer: Vamsee Yarlagadda <va...@cloudera.com>
Committed: Tue Feb 21 18:53:30 2017 -0600

----------------------------------------------------------------------
 .../sentry/service/thrift/HMSFollower.java      | 43 ++++++++++++--------
 1 file changed, 26 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/21fbb9d4/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java
index f88f6f1..1a99a04 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java
@@ -184,6 +184,13 @@ public class HMSFollower implements Runnable {
 
   @Override
   public void run() {
+    // Only the leader should listen to HMS updates
+    if ((leaderMonitor != null) && !leaderMonitor.isLeader()) {
+      // Close any outstanding connections to HMS
+      closeHMSConnection();
+      return;
+    }
+
     if (client == null) {
       try {
         client = getMetaStoreClient(authzConf);
@@ -200,11 +207,6 @@ public class HMSFollower implements Runnable {
       }
     }
 
-    // Only the leader should listen to HMS updates
-    if ((leaderMonitor != null) && !leaderMonitor.isLeader()) {
-      return;
-    }
-
     try {
       if (needHiveSnapshot) {
         // TODO: expose time used for full update in the metrics
@@ -255,18 +257,7 @@ public class HMSFollower implements Runnable {
       // If the underlying exception is around socket exception, it is better to retry connection to HMS
       if (e.getCause() instanceof SocketException) {
         LOGGER.error("Encountered Socket Exception during fetching Notification entries, will reconnect to HMS", e);
-        try {
-          if (client != null) {
-            client.close();
-            client = null;
-          }
-          if (kerberosContext != null) {
-            kerberosContext.shutDown();
-            kerberosContext = null;
-          }
-        } catch (LoginException le) {
-          LOGGER.warn("Failed to stop kerberos context (potential to cause thread leak)", le);
-        }
+        closeHMSConnection();
       } else {
         LOGGER.error("ThriftException occured fetching Notification entries, will try", e);
       }
@@ -280,6 +271,24 @@ public class HMSFollower implements Runnable {
   }
 
   /**
+   * Function to close HMS connection and any associated kerberos context (if applicable)
+   */
+  private void closeHMSConnection() {
+    try {
+      if (client != null) {
+        client.close();
+        client = null;
+      }
+      if (kerberosContext != null) {
+        kerberosContext.shutDown();
+        kerberosContext = null;
+      }
+    } catch (LoginException le) {
+      LOGGER.warn("Failed to stop kerberos context (potential to cause thread leak)", le);
+    }
+  }
+
+  /**
    * Retrieve HMS full snapshot.
    */
   private void fetchFullUpdate() throws ExecutionException, InterruptedException, TException {