sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kal...@apache.org
Subject [2/2] sentry git commit: SENTRY-2310: Sentry is not be able to fetch full update subsequently, when there is HMS restart in the snapshot process. (Kalyan Kumar Kalvagadda reviewed by Sergio Pena, Lina li and Arjun Mishra)
Date Mon, 23 Jul 2018 17:11:57 GMT
SENTRY-2310: Sentry is not be able to fetch full update subsequently, when there is HMS restart
in the snapshot process. (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/a3a19999
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/a3a19999
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/a3a19999

Branch: refs/heads/master
Commit: a3a1999950d6dc8292651494491302cc808dbba1
Parents: 061ef73
Author: Kalyan Kumar Kalvagadda <kkalyan@cloudera.com>
Authored: Mon Jul 23 10:47:38 2018 -0500
Committer: Kalyan Kumar Kalvagadda <kkalyan@cloudera.com>
Committed: Mon Jul 23 10:47:38 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/a3a19999/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;
     }
   }
 }


Mime
View raw message