Uploaded image for project: 'Hadoop HDFS'
  1. Hadoop HDFS
  2. HDFS-15679

DFSOutputStream close should be a no-op when called multiple times

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Later
    • None
    • None
    • None

    Description

      While I was looking into the incorrect implementation of HDFS-15678, I found that once I implement the correct logic, the Junit test fails.
      It turns out that there is inconsistency in DFSOutputStream.closeImpl() introduced by HDFS-13164.

      The change in that line makes the close() throws exception multiple times which contradicts with HDFS-5335.

      That change breaks the semantic of close(). For convenience, this is a test code that fails because of the change in HDFS-13164.

        public void testCloseTwice() throws IOException {
          DistributedFileSystem fs = cluster.getFileSystem();
          FSDataOutputStream os = fs.create(new Path("/test"));
          DFSOutputStream dos = (DFSOutputStream) Whitebox.getInternalState(os,
              "wrappedStream");
          DataStreamer streamer = (DataStreamer) Whitebox
              .getInternalState(dos, "streamer");
          @SuppressWarnings("unchecked")
          LastExceptionInStreamer ex = (LastExceptionInStreamer) Whitebox
              .getInternalState(streamer, "lastException");
          Throwable thrown = (Throwable) Whitebox.getInternalState(ex, "thrown");
          Assert.assertNull(thrown);
          // force stream to break. output stream needs to encounter a real
          // error to properly mark it closed with an exception
          cluster.shutdown(true, false);
          try {
            dos.close();
            Assert.fail("should have thrown");
          } catch (IOException e) {
            Assert.assertEquals(e.toString(), EOFException.class, e.getClass());
          }
          thrown = (Throwable) Whitebox.getInternalState(ex, "thrown");
          Assert.assertNull(thrown);
          dos.close();
          // even if the exception is set again, close should not throw it
          ex.set(new IOException("dummy"));
          dos.close();
        }
      

      Attachments

        Issue Links

          Activity

            People

              ahussein Ahmed Hussein
              ahussein Ahmed Hussein
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 40m
                  1h 40m