diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 7e4a6f2cb37..3bee85223f5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -592,6 +592,9 @@ Release 2.8.0 - UNRELEASED HDFS-8214. Secondary NN Web UI shows wrong date for Last Checkpoint. (clamb via wang) + HDFS-8300. Fix unit test failures and findbugs warning caused by HDFS-8283. + (jing9) + Release 2.7.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java index 4646b60bf12..ae5d3eb6a3d 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java @@ -762,7 +762,7 @@ public class DFSOutputStream extends FSOutputSummer protected synchronized void closeImpl() throws IOException { if (isClosed()) { - streamer.getLastException().check(); + streamer.getLastException().check(true); return; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DataStreamer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DataStreamer.java index 3727d20ea91..8e874ebfb7d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DataStreamer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DataStreamer.java @@ -174,13 +174,13 @@ class DataStreamer extends Daemon { packets.clear(); } - static class LastException { - private Throwable thrown; + static class LastExceptionInStreamer { + private IOException thrown; synchronized void set(Throwable t) { - Preconditions.checkNotNull(t); - Preconditions.checkState(thrown == null); - this.thrown = t; + assert t != null; + this.thrown = t instanceof IOException ? + (IOException) t : new IOException(t); } synchronized void clear() { @@ -188,17 +188,23 @@ class DataStreamer extends Daemon { } /** Check if there already is an exception. */ - synchronized void check() throws IOException { + synchronized void check(boolean resetToNull) throws IOException { if (thrown != null) { - throw new IOException(thrown); + if (LOG.isTraceEnabled()) { + // wrap and print the exception to know when the check is called + LOG.trace("Got Exception while checking", new Throwable(thrown)); + } + final IOException e = thrown; + if (resetToNull) { + thrown = null; + } + throw e; } } synchronized void throwException4Close() throws IOException { - check(); - final IOException ioe = new ClosedChannelException(); - thrown = ioe; - throw ioe; + check(false); + throw new ClosedChannelException(); } } @@ -234,7 +240,7 @@ class DataStreamer extends Daemon { private long lastQueuedSeqno = -1; private long lastAckedSeqno = -1; private long bytesCurBlock = 0; // bytes written in current block - private final LastException lastException = new LastException(); + private final LastExceptionInStreamer lastException = new LastExceptionInStreamer(); private Socket s; private final DFSClient dfsClient; @@ -1741,7 +1747,7 @@ class DataStreamer extends Daemon { /** * @return the last exception */ - LastException getLastException(){ + LastExceptionInStreamer getLastException(){ return lastException; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java index eac1fcd289a..e6274556f90 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java @@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hdfs.DataStreamer.LastExceptionInStreamer; import org.apache.hadoop.hdfs.client.impl.DfsClientConf; import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.ExtendedBlock; @@ -65,9 +66,10 @@ public class TestDFSOutputStream { DataStreamer streamer = (DataStreamer) Whitebox .getInternalState(dos, "streamer"); @SuppressWarnings("unchecked") - AtomicReference ex = (AtomicReference) Whitebox + LastExceptionInStreamer ex = (LastExceptionInStreamer) Whitebox .getInternalState(streamer, "lastException"); - Assert.assertEquals(null, ex.get()); + Throwable thrown = (Throwable) Whitebox.getInternalState(ex, "thrown"); + Assert.assertNull(thrown); dos.close(); @@ -78,7 +80,8 @@ public class TestDFSOutputStream { } catch (IOException e) { Assert.assertEquals(e, dummy); } - Assert.assertEquals(null, ex.get()); + thrown = (Throwable) Whitebox.getInternalState(ex, "thrown"); + Assert.assertNull(thrown); dos.close(); }