HDFS-5249. Fix dumper thread which may die silently. Contributed by Brandon Li

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1525770 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brandon Li 2013-09-24 04:11:15 +00:00
parent 28e3d09230
commit e3088e4aef
2 changed files with 31 additions and 11 deletions

View File

@ -199,9 +199,9 @@ private void dump() {
try { try {
synchronized (this) { synchronized (this) {
// check if alive again // check if alive again
Preconditions.checkState(dumpFile.createNewFile(), Preconditions.checkState(dumpFile.createNewFile(),
"The dump file should not exist: %s", dumpFilePath); "The dump file should not exist: %s", dumpFilePath);
dumpOut = new FileOutputStream(dumpFile); dumpOut = new FileOutputStream(dumpFile);
} }
} catch (IOException e) { } catch (IOException e) {
LOG.error("Got failure when creating dump stream " + dumpFilePath, e); LOG.error("Got failure when creating dump stream " + dumpFilePath, e);
@ -239,6 +239,10 @@ private void dump() {
&& nonSequentialWriteInMemory.get() > 0) { && nonSequentialWriteInMemory.get() > 0) {
OffsetRange key = it.next(); OffsetRange key = it.next();
WriteCtx writeCtx = pendingWrites.get(key); WriteCtx writeCtx = pendingWrites.get(key);
if (writeCtx == null) {
// This write was just deleted
continue;
}
try { try {
long dumpedDataSize = writeCtx.dumpData(dumpOut, raf); long dumpedDataSize = writeCtx.dumpData(dumpOut, raf);
if (dumpedDataSize > 0) { if (dumpedDataSize > 0) {
@ -262,16 +266,30 @@ private void dump() {
@Override @Override
public void run() { public void run() {
while (activeState && enabledDump) { while (activeState && enabledDump) {
if (nonSequentialWriteInMemory.get() >= DUMP_WRITE_WATER_MARK) { try {
dump(); if (nonSequentialWriteInMemory.get() >= DUMP_WRITE_WATER_MARK) {
} dump();
synchronized (OpenFileCtx.this) { }
if (nonSequentialWriteInMemory.get() < DUMP_WRITE_WATER_MARK) { synchronized (OpenFileCtx.this) {
try { if (nonSequentialWriteInMemory.get() < DUMP_WRITE_WATER_MARK) {
OpenFileCtx.this.wait(); try {
} catch (InterruptedException e) { OpenFileCtx.this.wait();
if (LOG.isDebugEnabled()) {
LOG.debug("Dumper woke up");
}
} catch (InterruptedException e) {
LOG.info("Dumper is interrupted, dumpFilePath= "
+ OpenFileCtx.this.dumpFilePath);
}
} }
} }
if (LOG.isDebugEnabled()) {
LOG.debug("Dumper checking OpenFileCtx activeState: " + activeState
+ " enabledDump: " + enabledDump);
}
} catch (Throwable t) {
LOG.info("Dumper get Throwable: " + t + ". dumpFilePath: "
+ OpenFileCtx.this.dumpFilePath);
} }
} }
} }

View File

@ -494,6 +494,8 @@ Release 2.1.1-beta - 2013-09-23
HDFS-5231. Fix broken links in the document of HDFS Federation. (Haohui Mai HDFS-5231. Fix broken links in the document of HDFS Federation. (Haohui Mai
via jing9) via jing9)
HDFS-5249. Fix dumper thread which may die silently. (brandonli)
Release 2.1.0-beta - 2013-08-22 Release 2.1.0-beta - 2013-08-22
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES