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

HdfsDataInputStream::read(ByteBuffer) method doesn't conform to its API

    XMLWordPrintableJSON

Details

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

    Description

      ByteBufferReadable::read(ByteBuffer) javadoc says:

      After a successful call, buf.position() and buf.limit() should be unchanged, and therefore any data can be immediately read from buf. buf.mark() may be cleared or updated. 
      

      I have the following code:

              ByteBuffer directBuf = ByteBuffer.allocateDirect(len);
              int pos = directBuf.position();
      
                  int count = file.read(directBuf);
                  if (count < 0) throw new EOFException();
                  if (directBuf.position() != pos) {
                    RecordReaderImpl.LOG.info("Warning - position mismatch from " + file.getClass()
                        + ": after reading " + count + ", expected " + pos + " but got " + directBuf.position());
                  }
      

      and I get:

      15/02/23 15:30:56 [pool-4-thread-1] INFO orc.RecordReaderImpl : Warning - position mismatch from class org.apache.hadoop.hdfs.client.HdfsDataInputStream: after reading 6, expected 0 but got 6
      

      So the position is changed, unlike the API doc indicates.

      Also, while I haven't verified yet, it may be that the 0-length read is not handled properly.

      Attachments

        Activity

          People

            Unassigned Unassigned
            sershe Sergey Shelukhin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: