HDFS-9294. DFSClient deadlock when close file and failed to renew lease. Contributed by Brahma Reddy Battula

This commit is contained in:
Tsz-Wo Nicholas Sze 2015-12-02 17:39:28 -08:00
parent 6b9a5beb2b
commit e8bd1ba74b
3 changed files with 32 additions and 21 deletions

View File

@ -708,13 +708,17 @@ public class DFSOutputStream extends FSOutputSummer
* Aborts this output stream and releases any system
* resources associated with this stream.
*/
synchronized void abort() throws IOException {
if (isClosed()) {
return;
void abort() throws IOException {
synchronized (this) {
if (isClosed()) {
return;
}
getStreamer().getLastException().set(
new IOException("Lease timeout of "
+ (dfsClient.getConf().getHdfsTimeout() / 1000)
+ " seconds expired."));
closeThreads(true);
}
getStreamer().getLastException().set(new IOException("Lease timeout of "
+ (dfsClient.getConf().getHdfsTimeout() / 1000) + " seconds expired."));
closeThreads(true);
dfsClient.endFileLease(fileId);
}
@ -747,11 +751,14 @@ public class DFSOutputStream extends FSOutputSummer
* resources associated with this stream.
*/
@Override
public synchronized void close() throws IOException {
try (TraceScope ignored =
dfsClient.newPathTraceScope("DFSOutputStream#close", src)) {
closeImpl();
public void close() throws IOException {
synchronized (this) {
try (TraceScope ignored = dfsClient.newPathTraceScope(
"DFSOutputStream#close", src)) {
closeImpl();
}
}
dfsClient.endFileLease(fileId);
}
protected synchronized void closeImpl() throws IOException {
@ -779,7 +786,6 @@ public class DFSOutputStream extends FSOutputSummer
dfsClient.getTracer().newScope("completeFile")) {
completeFile(lastBlock);
}
dfsClient.endFileLease(fileId);
} catch (ClosedChannelException ignored) {
} finally {
setClosed();

View File

@ -757,16 +757,19 @@ public class DFSStripedOutputStream extends DFSOutputStream {
}
@Override
synchronized void abort() throws IOException {
if (isClosed()) {
return;
void abort() throws IOException {
synchronized (this) {
if (isClosed()) {
return;
}
for (StripedDataStreamer streamer : streamers) {
streamer.getLastException().set(
new IOException("Lease timeout of "
+ (dfsClient.getConf().getHdfsTimeout() / 1000)
+ " seconds expired."));
}
closeThreads(true);
}
for (StripedDataStreamer streamer : streamers) {
streamer.getLastException().set(new IOException("Lease timeout of "
+ (dfsClient.getConf().getHdfsTimeout()/1000) +
" seconds expired."));
}
closeThreads(true);
dfsClient.endFileLease(fileId);
}
@ -954,7 +957,6 @@ public class DFSStripedOutputStream extends DFSOutputStream {
dfsClient.getTracer().newScope("completeFile")) {
completeFile(currentBlockGroup);
}
dfsClient.endFileLease(fileId);
} catch (ClosedChannelException ignored) {
} finally {
setClosed();

View File

@ -2535,6 +2535,9 @@ Release 2.7.2 - UNRELEASED
HDFS-9426. Rollingupgrade finalization is not backward compatible
(Kihwal Lee via vinayakumarb)
HDFS-9294. DFSClient deadlock when close file and failed to renew lease.
(Brahma Reddy Battula via szetszwo)
Release 2.7.1 - 2015-07-06
INCOMPATIBLE CHANGES