Repository: sentry
Updated Branches:
  refs/heads/master 13010b0b6 -> 4a75a3931


SENTRY-2283 Multiple versions of metrics on the classpath causes Sentry to not 
startup (Kalyan Kumar Kalvagadda reviewed by Sergio Pena, Lina li and Arjun 
Mishra)


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

Branch: refs/heads/master
Commit: 4a75a39314ec772d13e56a9b53de5d6603327493
Parents: 13010b0
Author: Kalyan Kumar Kalvagadda <[email protected]>
Authored: Mon Jul 16 16:43:03 2018 -0500
Committer: Kalyan Kumar Kalvagadda <[email protected]>
Committed: Mon Jul 16 16:43:03 2018 -0500

----------------------------------------------------------------------
 .../sentry/service/thrift/SentryHMSClient.java  | 44 ++++++++++++--------
 1 file changed, 26 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/4a75a393/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/service/thrift/SentryHMSClient.java
----------------------------------------------------------------------
diff --git 
a/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/service/thrift/SentryHMSClient.java
 
b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/service/thrift/SentryHMSClient.java
index 9d1a92f..12266cb 100644
--- 
a/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/service/thrift/SentryHMSClient.java
+++ 
b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/service/thrift/SentryHMSClient.java
@@ -44,7 +44,6 @@ import java.util.Collections;
 import java.util.Map;
 
 import static com.codahale.metrics.MetricRegistry.name;
-import static java.util.Collections.emptyMap;
 
 /**
  * Wrapper class for <Code>HiveMetaStoreClient</Code>
@@ -55,7 +54,6 @@ import static java.util.Collections.emptyMap;
 public class SentryHMSClient implements AutoCloseable {
 
   private static final Logger LOGGER = 
LoggerFactory.getLogger(SentryHMSClient.class);
-  private static final String NOT_CONNECTED_MSG = "Client is not connected to 
HMS";
 
   private final Configuration conf;
   private HiveMetaStoreClient client = null;
@@ -111,7 +109,7 @@ public class SentryHMSClient implements AutoCloseable {
   /**
    * Disconnects the HMS client.
    */
-  public void disconnect() throws Exception {
+  public void disconnect() {
     try {
       if (client != null) {
         LOGGER.info("Closing the HMS client connection");
@@ -130,7 +128,7 @@ public class SentryHMSClient implements AutoCloseable {
    * <p>This is similar to disconnect. As this class implements AutoClosable, 
close should be
    * implemented.
    */
-  public void close() throws Exception {
+  public void close() {
     disconnect();
   }
 
@@ -139,11 +137,15 @@ public class SentryHMSClient implements AutoCloseable {
    *
    * @return Full path snapshot and the last notification id on success
    */
-  public PathsImage getFullSnapshot() {
-    if (client == null) {
-      LOGGER.error(NOT_CONNECTED_MSG);
-      return new PathsImage(Collections.<String, Collection<String>>emptyMap(),
-          SentryConstants.EMPTY_NOTIFICATION_ID, 
SentryConstants.EMPTY_PATHS_SNAPSHOT_ID);
+  public PathsImage getFullSnapshot() throws Exception{
+    if(!isConnected()) {
+      try {
+        connect();
+      } catch (Exception e) {
+        LOGGER.warn("Failed to connect to HMS Server. HMS may not be up. Will 
try again ", e);
+        return new PathsImage(Collections.<String, 
Collection<String>>emptyMap(),
+                SentryConstants.EMPTY_NOTIFICATION_ID, 
SentryConstants.EMPTY_PATHS_SNAPSHOT_ID);
+      }
     }
 
     try {
@@ -218,12 +220,18 @@ public class SentryHMSClient implements AutoCloseable {
       // lastProcessedNotificationID instead of getting it from persistent 
store.
       return new PathsImage(pathsFullSnapshot, currentEventId,
         SentryConstants.EMPTY_PATHS_SNAPSHOT_ID);
-    } catch (TException failure) {
-      LOGGER.error("Fetching a new HMS snapshot cannot continue because an 
error occurred during "
-          + "the HMS communication: ", failure);
-      LOGGER.error("Root Exception", ExceptionUtils.getRootCause(failure));
+    } catch (Exception exception) {
+      LOGGER.error("Root Exception", ExceptionUtils.getRootCause(exception));
+      if(exception instanceof TException) {
+        LOGGER.error("Fetching new HMS snapshot failed because of HMS 
communication. HMS seems to be restarted. " +
+                "Will try again.");
+      } else {
+        LOGGER.error("Fetching new HMS snapshot failed. Will try again.");
+      }
+      // Closing the connection towards HMS.
+      close();
       return new PathsImage(Collections.<String, Collection<String>>emptyMap(),
-        SentryConstants.EMPTY_NOTIFICATION_ID, 
SentryConstants.EMPTY_PATHS_SNAPSHOT_ID);
+              SentryConstants.EMPTY_NOTIFICATION_ID, 
SentryConstants.EMPTY_PATHS_SNAPSHOT_ID);
     }
   }
 
@@ -233,7 +241,7 @@ public class SentryHMSClient implements AutoCloseable {
    * @return HMS snapshot. Snapshot consists of a mapping from auth object 
name to the set of paths
    *     corresponding to that name.
    */
-  private Map<String, Collection<String>> fetchFullUpdate() {
+  private Map<String, Collection<String>> fetchFullUpdate() throws Exception{
     LOGGER.info("Request full HMS snapshot");
     try (FullUpdateInitializer updateInitializer =
              new FullUpdateInitializer(hiveConnectionFactory, conf);
@@ -241,10 +249,10 @@ public class SentryHMSClient implements AutoCloseable {
       Map<String, Collection<String>> pathsUpdate = 
updateInitializer.getFullHMSSnapshot();
       LOGGER.info("Obtained full HMS snapshot");
       return pathsUpdate;
-    } catch (Exception ignored) {
+    } catch (Exception exception) {
       failedSnapshotsCount.inc();
-      LOGGER.error("Snapshot created failed ", ignored);
-      return emptyMap();
+      LOGGER.error("Snapshot created failed ", exception);
+      throw exception;
     }
   }
 }

Reply via email to