YARN-1670. aggregated log writer can write more log data then it says is the log length (Mit Desai via jeagles)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1580963 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5f0f16c0f6
commit
c2d8ab6085
|
@ -182,28 +182,36 @@ public class AggregatedLogFormat {
|
||||||
Arrays.sort(logFiles);
|
Arrays.sort(logFiles);
|
||||||
for (File logFile : logFiles) {
|
for (File logFile : logFiles) {
|
||||||
|
|
||||||
long fileLength = 0;
|
final long fileLength = logFile.length();
|
||||||
|
|
||||||
// Write the logFile Type
|
// Write the logFile Type
|
||||||
out.writeUTF(logFile.getName());
|
out.writeUTF(logFile.getName());
|
||||||
|
|
||||||
// Write the log length as UTF so that it is printable
|
// Write the log length as UTF so that it is printable
|
||||||
out.writeUTF(String.valueOf(fileLength = logFile.length()));
|
out.writeUTF(String.valueOf(fileLength));
|
||||||
|
|
||||||
// Write the log itself
|
// Write the log itself
|
||||||
FileInputStream in = null;
|
FileInputStream in = null;
|
||||||
try {
|
try {
|
||||||
in = SecureIOUtils.openForRead(logFile, getUser(), null);
|
in = SecureIOUtils.openForRead(logFile, getUser(), null);
|
||||||
byte[] buf = new byte[65535];
|
byte[] buf = new byte[65535];
|
||||||
long curRead = 0;
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while ( ((len = in.read(buf)) != -1) && (curRead < fileLength) ) {
|
long bytesLeft = fileLength;
|
||||||
|
while ((len = in.read(buf)) != -1) {
|
||||||
|
//If buffer contents within fileLength, write
|
||||||
|
if (len < bytesLeft) {
|
||||||
out.write(buf, 0, len);
|
out.write(buf, 0, len);
|
||||||
curRead += len;
|
bytesLeft-=len;
|
||||||
|
}
|
||||||
|
//else only write contents within fileLength, then exit early
|
||||||
|
else {
|
||||||
|
out.write(buf, 0, (int)bytesLeft);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
long newLength = logFile.length();
|
long newLength = logFile.length();
|
||||||
if(fileLength < newLength) {
|
if(fileLength < newLength) {
|
||||||
LOG.warn("Aggregated Logs Truncated by "+
|
LOG.warn("Aggregated logs truncated by approximately "+
|
||||||
(newLength-fileLength) +" bytes.");
|
(newLength-fileLength) +" bytes.");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Reference in New Issue