SENTRY-1716: HMSFollower doesn't need to save path info when HDFS sync is disabled (Sergio Pena, reviewed by: Na Li and Alex Kolbasov)
Change-Id: I175fe7919c32d78f37a9ade3a2ff058f92f45df3 Reviewed-on: http://gerrit.sjc.cloudera.com:8080/22714 Tested-by: Jenkins User Reviewed-by: Alexander Kolbasov <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/e4f6f22f Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/e4f6f22f Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/e4f6f22f Branch: refs/for/cdh5-1.5.1_ha Commit: e4f6f22f501176df62518c2419e5135bedc6a8c2 Parents: f0faf2f Author: Alexander Kolbasov <[email protected]> Authored: Tue May 16 08:22:15 2017 -0700 Committer: Alexander Kolbasov <[email protected]> Committed: Tue May 16 12:05:54 2017 -0700 ---------------------------------------------------------------------- .../sentry/service/thrift/SentryService.java | 10 +++++++++- .../service/thrift/SentryServiceUtil.java | 21 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/e4f6f22f/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java index 3543ace..3afc06f 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java @@ -106,6 +106,7 @@ public class SentryService implements Callable, SigUtils.SigListener { private ScheduledExecutorService sentryStoreCleanService; private final LeaderStatusMonitor leaderMonitor; private final boolean notificationLogEnabled; + private final boolean hdfsSyncEnabled; public SentryService(Configuration conf) throws Exception { this.conf = conf; @@ -165,6 +166,8 @@ public class SentryService implements Callable, SigUtils.SigListener { notificationLogEnabled = conf.getBoolean(ServerConfig.SENTRY_NOTIFICATION_LOG_ENABLED, ServerConfig.SENTRY_NOTIFICATION_LOG_ENABLED_DEFAULT); + hdfsSyncEnabled = SentryServiceUtil.isHDFSSyncEnabled(conf); + status = Status.NOT_STARTED; // Enable signal handler for HA leader/follower status if configured @@ -273,6 +276,11 @@ public class SentryService implements Callable, SigUtils.SigListener { } private void startHMSFollower(Configuration conf) throws Exception{ + if (!hdfsSyncEnabled) { + LOGGER.info("HMS follower is not started because HDFS sync is disabled."); + return; + } + if (!notificationLogEnabled) { return; } @@ -302,7 +310,7 @@ public class SentryService implements Callable, SigUtils.SigListener { } private void stopHMSFollower(Configuration conf) { - if (!notificationLogEnabled) { + if (!notificationLogEnabled || !hdfsSyncEnabled) { return; } http://git-wip-us.apache.org/repos/asf/sentry/blob/e4f6f22f/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java index d58ee95..50e413c 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java @@ -18,11 +18,14 @@ package org.apache.sentry.service.thrift; +import java.util.Arrays; +import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import com.google.common.base.Preconditions; import org.apache.commons.lang.StringUtils; +import org.apache.hadoop.conf.Configuration; import org.slf4j.Logger; public final class SentryServiceUtil { @@ -63,6 +66,24 @@ public final class SentryServiceUtil { } } + /** + * Checks if Sentry is configured with HDFS sync enabled. + * + * @param conf The Configuration object where HDFS sync configurations are set. + * @return True if enabled; False otherwise. + */ + static boolean isHDFSSyncEnabled(Configuration conf) { + List<String> processorFactories = + Arrays.asList(conf.get(ServiceConstants.ServerConfig.PROCESSOR_FACTORIES, "").split(",")); + + List<String> policyStorePlugins = + Arrays.asList(conf.get(ServiceConstants.ServerConfig.SENTRY_POLICY_STORE_PLUGINS, "").split(",")); + + + return processorFactories.contains("org.apache.sentry.hdfs.SentryHDFSServiceProcessorFactory") + && policyStorePlugins.contains("org.apache.sentry.hdfs.SentryPlugin"); + } + private SentryServiceUtil() { // Make constructor private to avoid instantiation }
