-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HDFS-15042 Add more tests for ByteBufferPositionedReadable. #1747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
HDFS-15042 Add more tests for ByteBufferPositionedReadable. #1747
Conversation
hdfs failures clearly something else
will rebase and fix checkstyles anyway |
@sahilTakiar fyi |
067e0a0
to
79f8583
Compare
Again, hadoop-hdfs test failures must be unrelated: this patch doesn't touch those tests |
|
79f8583
to
44494c7
Compare
44494c7
to
ab7c180
Compare
ab7c180
to
6e050d9
Compare
💔 -1 overall
This message was automatically generated. |
both failures are unrelated...will rebase. test failure is in javadoc failure
|
Changes * Javadocs in ByteBufferPositionedReadable are a bit stricter. * switch to parameterized JUnit test runs for on/off heap buffers * factor put main assertions into higher level asserts New tests * negative offset for reads of actual/empty buffers * read position > EOF. * empty files * verify that interleaving simple reads/seeks work. Change-Id: I27294b15f7cad8e1b87150d9e9fac0623fc44c45
Change-Id: I4c8b17dd897a11d4c8e22b9cbc366455c958242c
6e050d9
to
ac0bcd8
Compare
🎊 +1 overall
This message was automatically generated. |
@mukund-thakur @mehakmeet @virajjasani could i get a quick review of this? i want these tests in before anyone tries to implement it in s3a/abfs/gcs via vectored io |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left minor comments with Javadocs, the core logic and tests look good.
* <p> | ||
* <b>Thread safety</b> | ||
* <p> | ||
* These operations doe not change the current offset of a stream as returned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/doe/does
* The {@code position} offset MUST BE zero or positive; if negative | ||
* an EOFException SHALL BE raised. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If position
is negative, this method seems to be returning -1
instead of throwing EOF with NEGATIVE_POSITION_READ
reason. EOF with NEGATIVE_POSITION_READ
is being thrown with this patch only with void readFully(long position, ByteBuffer buf)
method.
DFSInputStream:
private int pread(long position, ByteBuffer buffer)
throws IOException {
// sanity checks
dfsClient.checkOpen();
if (closed.get()) {
throw new IOException("Stream closed");
}
failures = 0;
long filelen = getFileLength();
if ((position < 0) || (position >= filelen)) {
return -1;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear, we can't change the behaviour of the stream as well, we just need to correct the JavaDoc, changing behaviour to now throw EOF will be incompatible
The below Javadoc also marks -1 as a legitimate return value
* @return the number of bytes read, possibly zero, or -1 if reached
* end-of-stream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, i think that's broken. like you say, can't fix though. or we could, but that complicates code written against the eof raising impl running against older/external stuff
if (position < 0) { | ||
throw new EOFException(NEGATIVE_POSITION_READ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception message will change now, earlier it would be from below
if (nbytes < 0) {
throw new EOFException(FSExceptionMessages.EOF_IN_READ_FULLY);
}
Someone asserting on the exception message will get issues, not sure if it is something to do in scope of adding new tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I would also not want to change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
*/ | ||
private void assertStreamPosition(final Seekable in, long pos) | ||
throws IOException { | ||
assertEquals("Buffer position", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be Stream Position
if (buffer.position() > 0) { | ||
// this implementation does not do a range check before the read; | ||
// it got partway through before failing. | ||
// this is not an error -just inefficient. | ||
LOG.warn("Buffer reads began before range checks with {}", in); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the benefit of having this, is this log gonna help sometime is debugging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i really don't remember. this is a pr from 2019.
🎊 +1 overall
This message was automatically generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like my comment was in pending state.
if (position < 0) { | ||
throw new EOFException(NEGATIVE_POSITION_READ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I would also not want to change this.
Forgotten about this. #6686 would benefit from this |
Changes
New tests
Change-Id: I27294b15f7cad8e1b87150d9e9fac0623fc44c45