Repository: sentry Updated Branches: refs/heads/master 2ef77fc01 -> 1275be7e3
SENTRY-1928: HMSFollower should close HMS connections when an error to HMS occurs (Sergio Pena, reviewed by Alexander Kolbasov, Vamsee Yarlagadda) Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/1275be7e Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/1275be7e Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/1275be7e Branch: refs/heads/master Commit: 1275be7e3ed9cb31959fc5e9424576bb03e2fc02 Parents: 2ef77fc Author: Sergio Pena <[email protected]> Authored: Wed Sep 6 22:38:58 2017 -0500 Committer: Sergio Pena <[email protected]> Committed: Wed Sep 6 22:38:58 2017 -0500 ---------------------------------------------------------------------- .../sentry/service/thrift/HMSFollower.java | 17 +++++------------ .../service/thrift/HiveNotificationFetcher.java | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/1275be7e/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 d4feb38..c234eaf 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 @@ -20,7 +20,6 @@ package org.apache.sentry.service.thrift; import com.google.common.annotations.VisibleForTesting; -import java.net.SocketException; import java.util.Collection; import java.util.List; import javax.jdo.JDODataStoreException; @@ -186,19 +185,13 @@ public class HMSFollower implements Runnable, AutoCloseable { // Continue with processing new notifications if no snapshots are done. processNotifications(notifications); } catch (TException e) { - // 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 attempt to reconnect to HMS after configured interval", e); - close(); - } else { - LOGGER.error("ThriftException occurred communicating with HMS", e); - } + LOGGER.error("An error occurred while fetching HMS notifications: {}", e.getMessage()); + close(); } catch (Throwable t) { // catching errors to prevent the executor to halt. - LOGGER.error("Exception in HMSFollower! Caused by: " + t.getMessage(), - t); + LOGGER.error("Exception in HMSFollower! Caused by: " + t.getMessage(), t); + + close(); } } http://git-wip-us.apache.org/repos/asf/sentry/blob/1275be7e/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HiveNotificationFetcher.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HiveNotificationFetcher.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HiveNotificationFetcher.java index 4d32992..097aa62 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HiveNotificationFetcher.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HiveNotificationFetcher.java @@ -90,8 +90,14 @@ public final class HiveNotificationFetcher implements AutoCloseable { } LOGGER.debug("Requesting HMS notifications since ID = {}", lastEventId); - NotificationEventResponse response = - getHmsClient().getNextNotification(lastEventId, maxEvents, filter); + + NotificationEventResponse response; + try { + response = getHmsClient().getNextNotification(lastEventId, maxEvents, filter); + } catch (Exception e) { + close(); + throw e; + } if (response != null && response.isSetEvents()) { LOGGER.debug("Fetched {} new HMS notification(s)", response.getEventsSize()); @@ -173,7 +179,14 @@ public final class HiveNotificationFetcher implements AutoCloseable { * @throws Exception when an error occurs when talking to the HMS client */ long getCurrentNotificationId() throws Exception { - CurrentNotificationEventId eventId = getHmsClient().getCurrentNotificationEventId(); + CurrentNotificationEventId eventId; + try { + eventId = getHmsClient().getCurrentNotificationEventId(); + } catch (Exception e) { + close(); + throw e; + } + if (eventId != null && eventId.isSetEventId()) { return eventId.getEventId(); }
