YARN-2857. ConcurrentModificationException in ContainerLogAppender. Contributed by Mohammad Kamrul Islam

This commit is contained in:
Jason Lowe 2014-11-14 20:47:26 +00:00
parent 1a1dcce827
commit f2fe8a800e
3 changed files with 55 additions and 1 deletions

View File

@ -87,6 +87,9 @@ Release 2.7.0 - UNRELEASED
YARN-2856. Fixed RMAppImpl to handle ATTEMPT_KILLED event at ACCEPTED state
on app recovery. (Rohith Sharmaks via jianhe)
YARN-2857. ConcurrentModificationException in ContainerLogAppender
(Mohammad Kamrul Islam via jlowe)
Release 2.6.0 - 2014-11-18
INCOMPATIBLE CHANGES

View File

@ -41,6 +41,7 @@ public class ContainerLogAppender extends FileAppender
//so that log4j can configure it from the configuration(log4j.properties).
private int maxEvents;
private Queue<LoggingEvent> tail = null;
private boolean closing = false;
@Override
public void activateOptions() {
@ -57,6 +58,9 @@ public class ContainerLogAppender extends FileAppender
@Override
public void append(LoggingEvent event) {
synchronized (this) {
if (closing) { // When closing drop any new/transitive CLA appending
return;
}
if (tail == null) {
super.append(event);
} else {
@ -77,8 +81,9 @@ public class ContainerLogAppender extends FileAppender
@Override
public synchronized void close() {
closing = true;
if (tail != null) {
for(LoggingEvent event: tail) {
for (LoggingEvent event : tail) {
super.append(event);
}
}

View File

@ -0,0 +1,46 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.yarn;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.junit.Test;
public class TestContainerLogAppender {
@Test
public void testAppendInClose() throws Exception {
final ContainerLogAppender claAppender = new ContainerLogAppender();
claAppender.setName("testCLA");
claAppender.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
claAppender.setContainerLogDir("target/testAppendInClose/logDir");
claAppender.setTotalLogFileSize(1000);
claAppender.activateOptions();
final Logger claLog = Logger.getLogger("testAppendInClose-catergory");
claLog.setAdditivity(false);
claLog.addAppender(claAppender);
claLog.info(new Object() {
public String toString() {
claLog.info("message1");
return "return message1";
}
});
claAppender.close();
}
}