Repository: sentry Updated Branches: refs/heads/master ef90f311f -> a3a199995
Revert 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) Reverting the patch as it was committed with wrong description. Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/061ef73f Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/061ef73f Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/061ef73f Branch: refs/heads/master Commit: 061ef73fefedf4dc60a6c2ffb2d3973c3dddee33 Parents: ef90f31 Author: Kalyan Kumar Kalvagadda <kkal...@cloudera.com> Authored: Mon Jul 23 10:45:09 2018 -0500 Committer: Kalyan Kumar Kalvagadda <kkal...@cloudera.com> Committed: Mon Jul 23 10:45:09 2018 -0500 ---------------------------------------------------------------------- .../sentry/service/thrift/SentryHMSClient.java | 44 ++++++++------------ 1 file changed, 18 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/061ef73f/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 12266cb..9d1a92f 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,6 +44,7 @@ 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> @@ -54,6 +55,7 @@ import static com.codahale.metrics.MetricRegistry.name; 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; @@ -109,7 +111,7 @@ public class SentryHMSClient implements AutoCloseable { /** * Disconnects the HMS client. */ - public void disconnect() { + public void disconnect() throws Exception { try { if (client != null) { LOGGER.info("Closing the HMS client connection"); @@ -128,7 +130,7 @@ public class SentryHMSClient implements AutoCloseable { * <p>This is similar to disconnect. As this class implements AutoClosable, close should be * implemented. */ - public void close() { + public void close() throws Exception { disconnect(); } @@ -137,15 +139,11 @@ public class SentryHMSClient implements AutoCloseable { * * @return Full path snapshot and the last notification id on success */ - 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); - } + 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); } try { @@ -220,18 +218,12 @@ public class SentryHMSClient implements AutoCloseable { // lastProcessedNotificationID instead of getting it from persistent store. return new PathsImage(pathsFullSnapshot, currentEventId, SentryConstants.EMPTY_PATHS_SNAPSHOT_ID); - } 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(); + } 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)); 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); } } @@ -241,7 +233,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() throws Exception{ + private Map<String, Collection<String>> fetchFullUpdate() { LOGGER.info("Request full HMS snapshot"); try (FullUpdateInitializer updateInitializer = new FullUpdateInitializer(hiveConnectionFactory, conf); @@ -249,10 +241,10 @@ public class SentryHMSClient implements AutoCloseable { Map<String, Collection<String>> pathsUpdate = updateInitializer.getFullHMSSnapshot(); LOGGER.info("Obtained full HMS snapshot"); return pathsUpdate; - } catch (Exception exception) { + } catch (Exception ignored) { failedSnapshotsCount.inc(); - LOGGER.error("Snapshot created failed ", exception); - throw exception; + LOGGER.error("Snapshot created failed ", ignored); + return emptyMap(); } } }