Skip to content

Conversation

@zsxwing
Copy link

@zsxwing zsxwing commented Sep 13, 2017

This commit includes the following changes:

  • Close the underlying input stream only if it's not being read.
  • Always read to readAheadBuffer.

This commit includes the following changes:
- Close the underlying input stream only if it's not being read.
- Always read to `readAheadBuffer`.
activeBuffer.flip();
readAheadBuffer.position(0);
readAheadBuffer.flip();
long skippedFromInputStream = underlyingInputStream.skip(toSkip);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look right, we should be reading into the activeBuffer instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed your codes to always write to readAheadBuffer so that it's easy to know which one we are writing to. readInternal will handle the case that activeBuffer is empty.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that makes sense.

}
// Flip this so that the close method will not close the underlying input stream when we
// are reading.
isReading = true;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this variable? Can we use readInProgress instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readInProgress == true means the task will be submitted. But it may not run if the executor service is shut down. I changed shutdown to shutdownNow in order to interrupt the blocking read.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Instead of doing that should we just call waitForAsyncReadComplete in close() function call so that we can safely close the input stream? It would clean up the code a lot and make it less complicated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waitForAsyncReadComplete can be interrupted as well.

@sitalkedia sitalkedia merged commit 884c9d7 into sitalkedia:read_ahead_buffer Sep 13, 2017
sitalkedia pushed a commit that referenced this pull request Feb 3, 2018
## What changes were proposed in this pull request?

There were two related fixes regarding `from_json`, `get_json_object` and `json_tuple` ([Fix #1](apache@c8803c0),
 [Fix apache#2](apache@86174ea)), but they weren't comprehensive it seems. I wanted to extend those fixes to all the parsers, and add tests for each case.

## How was this patch tested?

Regression tests

Author: Burak Yavuz <[email protected]>

Closes apache#20302 from brkyvz/json-invfix.
@zsxwing zsxwing deleted the pr18317 branch February 6, 2019 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants