diff --git a/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java b/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java index 172f58d..0b3d891 100644 --- a/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java +++ b/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java @@ -265,7 +265,7 @@ private void enqueue(NotificationEvent event) { private static class CleanerThread extends Thread { private RawStore rs; private int ttl; - + static private long sleepTime = 60000; CleanerThread(HiveConf conf, RawStore rs) { super("CleanerThread"); @@ -281,8 +281,9 @@ public void run() { synchronized(NOTIFICATION_TBL_LOCK) { rs.cleanNotificationEvents(ttl); } + LOG.debug("Cleaner thread done"); try { - Thread.sleep(60000); + Thread.sleep(sleepTime); } catch (InterruptedException e) { LOG.info("Cleaner thread sleep interupted", e); } diff --git a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java index d0802d6..81ce67b 100644 --- a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java +++ b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java @@ -48,6 +48,7 @@ import org.junit.BeforeClass; import org.junit.Test; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -58,12 +59,14 @@ private static final Logger LOG = LoggerFactory.getLogger(TestDbNotificationListener.class.getName()); private static final int EVENTS_TTL = 30; + private static final int CLEANUP_SLEEP_TIME = 10; private static Map emptyParameters = new HashMap(); private static IMetaStoreClient msClient; private static Driver driver; private int startTime; private long firstEventId; + @SuppressWarnings("rawtypes") @BeforeClass public static void connectToMetastore() throws Exception { HiveConf conf = new HiveConf(); @@ -73,6 +76,16 @@ public static void connectToMetastore() throws Exception { conf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false); conf.setBoolVar(HiveConf.ConfVars.FIRE_EVENTS_FOR_DML, true); conf.setVar(HiveConf.ConfVars.DYNAMICPARTITIONINGMODE, "nonstrict"); + Class dbNotificationListener = + Class.forName("org.apache.hive.hcatalog.listener.DbNotificationListener"); + Class[] classes = dbNotificationListener.getDeclaredClasses(); + for (Class c : classes) { + if (c.getName().endsWith("CleanerThread")) { + Field sleepTimeField = c.getDeclaredField("sleepTime"); + sleepTimeField.setAccessible(true); + sleepTimeField.set(null, CLEANUP_SLEEP_TIME * 1000); + } + } conf .setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory"); @@ -602,13 +615,16 @@ public void cleanupNotifs() throws Exception { msClient.createDatabase(db); msClient.dropDatabase("cleanup1"); + LOG.info("Pulling events immediately after createDatabase/dropDatabase"); NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null); assertEquals(2, rsp.getEventsSize()); // sleep for expiry time, and then fetch again Thread.sleep(EVENTS_TTL * 2 * 1000); // sleep twice the TTL interval - things should have been cleaned by then. + LOG.info("Pulling events again after cleanup"); NotificationEventResponse rsp2 = msClient.getNextNotification(firstEventId, 0, null); + LOG.info("second trigger done"); assertEquals(0, rsp2.getEventsSize()); } }