diff --git a/common/src/java/org/apache/hadoop/hive/common/LogUtils.java b/common/src/java/org/apache/hadoop/hive/common/LogUtils.java index 0a3e0c72011951b6b1543352308bd51233c847fb..56c56062ce59f001bb83fdd9e1cce864f1f9dd8f 100644 --- a/common/src/java/org/apache/hadoop/hive/common/LogUtils.java +++ b/common/src/java/org/apache/hadoop/hive/common/LogUtils.java @@ -256,6 +256,9 @@ public static void stopQueryAppender(String routingAppenderName, String queryId) // this will cause the subordinate appender to close its output stream. subordinateAppender.stop(); } + method = clazz.getDeclaredMethod("deleteAppender", String.class); + method.setAccessible(true); + method.invoke(routingAppender, queryId); } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { l4j.warn("Unable to close the operation log appender for query id " + queryId, e); diff --git a/itests/hive-unit/src/test/java/org/apache/hive/service/cli/operation/TestOperationLoggingLayout.java b/itests/hive-unit/src/test/java/org/apache/hive/service/cli/operation/TestOperationLoggingLayout.java index 8febe3e79ff892c54b696b6c6ef92f7026c46033..60682b6e9430de7ebca38f11f59ff63ec077bd6a 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/service/cli/operation/TestOperationLoggingLayout.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/service/cli/operation/TestOperationLoggingLayout.java @@ -151,19 +151,23 @@ private void checkAppenderState(String msg, String routingAppenderName, String q defaultsField.setAccessible(true); ConcurrentHashMap appenders = (ConcurrentHashMap) defaultsField.get(routingAppender); AppenderControl appenderControl = (AppenderControl) appenders.get(queryId); - Assert.assertNotNull(msg + "could not find AppenderControl for query id " + queryId, appenderControl); - Appender appender = appenderControl.getAppender(); - Assert.assertNotNull(msg + "could not find Appender for query id " + queryId + " from AppenderControl " + appenderControl, appender); - Assert.assertEquals(msg + "Appender for query is in unexpected state", expectedStopped, appender.isStopped()); - Assert.assertTrue("Appender should be a HushableMutableRandomAccessAppender", appender instanceof HushableRandomAccessFileAppender); - HushableRandomAccessFileAppender ra = (HushableRandomAccessFileAppender) appender; - // Even if the appender is stopped it should not throw an exception when we log - try { - ra.append(new LocalLogEvent()); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail("Caught exception while logging to an appender of class " + ra.getClass() - + " with stopped=" + ra.isStopped()); + if (!expectedStopped) { + Assert.assertNotNull(msg + "Could not find AppenderControl for query id " + queryId, appenderControl); + Appender appender = appenderControl.getAppender(); + Assert.assertNotNull(msg + "could not find Appender for query id " + queryId + " from AppenderControl " + appenderControl, appender); + Assert.assertEquals(msg + "Appender for query is in unexpected state", expectedStopped, appender.isStopped()); + Assert.assertTrue("Appender should be a HushableMutableRandomAccessAppender", appender instanceof HushableRandomAccessFileAppender); + HushableRandomAccessFileAppender ra = (HushableRandomAccessFileAppender) appender; + // Even if the appender is stopped it should not throw an exception when we log + try { + ra.append(new LocalLogEvent()); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("Caught exception while logging to an appender of class " + ra.getClass() + + " with stopped=" + ra.isStopped()); + } + } else { + Assert.assertNull(msg + "AppenderControl for query id is not removed" + queryId, appenderControl); } }