-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HADOOP-18631. Migrate Async appenders to log4j properties #5418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
105e51c
HADOOP-18631. Migrate Async appenders to log4j properties
virajjasani 25d04a8
addendum checkstyle
virajjasani bace039
addendum
virajjasani c1aa8d7
addendum
virajjasani 284d6f9
addendum
virajjasani 0fa413b
addendum
virajjasani f9799a9
addendum
virajjasani 6c08b12
appender
virajjasani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
...-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/AsyncRFAAppender.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/** | ||
* 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.hdfs.util; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.log4j.AsyncAppender; | ||
import org.apache.log4j.PatternLayout; | ||
import org.apache.log4j.RollingFileAppender; | ||
import org.apache.log4j.spi.LoggingEvent; | ||
|
||
/** | ||
* Until we migrate to log4j2, use this appender for namenode audit logger as well as | ||
* datanode and namenode metric loggers with log4j1 properties. | ||
* This appender will take parameters necessary to supply RollingFileAppender to AsyncAppender. | ||
* While migrating to log4j2, we can directly specify appender ref to Async appender. | ||
*/ | ||
public class AsyncRFAAppender extends AsyncAppender { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this patch, even though we have new custom appender, it's only temporary here. This solves two purposes:
It's temporary but necessary until going to log4j2, so that we don't loose functionality of wrapping RFA in Async appender. |
||
|
||
/** | ||
* The default maximum file size is 10MB. | ||
*/ | ||
private String maxFileSize = String.valueOf(10*1024*1024); | ||
|
||
/** | ||
* There is one backup file by default. | ||
*/ | ||
private int maxBackupIndex = 1; | ||
|
||
/** | ||
* The name of the log file. | ||
*/ | ||
private String fileName = null; | ||
|
||
private String conversionPattern = null; | ||
|
||
/** | ||
* Does appender block when buffer is full. | ||
*/ | ||
private boolean blocking = true; | ||
|
||
/** | ||
* Buffer size. | ||
*/ | ||
private int bufferSize = DEFAULT_BUFFER_SIZE; | ||
|
||
private RollingFileAppender rollingFileAppender = null; | ||
|
||
private final Object rollingFileAppenderLock = new Object(); | ||
|
||
@Override | ||
public void append(LoggingEvent event) { | ||
if (rollingFileAppender == null) { | ||
synchronized (rollingFileAppenderLock) { | ||
PatternLayout patternLayout; | ||
if (conversionPattern != null) { | ||
patternLayout = new PatternLayout(conversionPattern); | ||
} else { | ||
patternLayout = new PatternLayout(); | ||
} | ||
try { | ||
rollingFileAppender = new RollingFileAppender(patternLayout, fileName, true); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
rollingFileAppender.setMaxBackupIndex(maxBackupIndex); | ||
rollingFileAppender.setMaxFileSize(maxFileSize); | ||
this.addAppender(rollingFileAppender); | ||
super.setBlocking(blocking); | ||
super.setBufferSize(bufferSize); | ||
} | ||
} | ||
super.append(event); | ||
} | ||
|
||
public String getMaxFileSize() { | ||
return maxFileSize; | ||
} | ||
|
||
public void setMaxFileSize(String maxFileSize) { | ||
this.maxFileSize = maxFileSize; | ||
} | ||
|
||
public int getMaxBackupIndex() { | ||
return maxBackupIndex; | ||
} | ||
|
||
public void setMaxBackupIndex(int maxBackupIndex) { | ||
this.maxBackupIndex = maxBackupIndex; | ||
} | ||
|
||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
public void setFileName(String fileName) { | ||
this.fileName = fileName; | ||
} | ||
|
||
public String getConversionPattern() { | ||
return conversionPattern; | ||
} | ||
|
||
public void setConversionPattern(String conversionPattern) { | ||
this.conversionPattern = conversionPattern; | ||
} | ||
|
||
public boolean isBlocking() { | ||
return blocking; | ||
} | ||
|
||
public void setBlocking(boolean blocking) { | ||
this.blocking = blocking; | ||
} | ||
|
||
public int getBufferSize() { | ||
return bufferSize; | ||
} | ||
|
||
public void setBufferSize(int bufferSize) { | ||
this.bufferSize = bufferSize; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.