Skip to content
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

Now uses a cursor in the GridFSDownload Stream #109

Closed
wants to merge 5 commits into from
Closed

Conversation

rozza
Copy link
Owner

@rozza rozza commented Aug 27, 2015

The second commit adds batchSize support - so users can control memory consumption v latency.

JAVA-1916

Review on Reviewable

Now uses a cursor rather than fetching each individual chunk

JAVA-1916
@@ -58,6 +62,16 @@ public GridFSFile getGridFSFile() {
}

@Override
public GridFSDownloadStream batchSize(final int batchSize) {
if (batchSize != 0) {

Choose a reason for hiding this comment

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

The if is a bit redundant here

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good catch

@evanchooly
Copy link

lgtm

@@ -33,6 +35,8 @@
private final long length;
private final int chunkSizeInBytes;
private final int numberOfChunks;
private MongoCursor<Document> cursor;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This cursor isn't closed anywhere. It should be closed anywhere that it's set to null (if it's not already null) and in the close method of this stream (which doesn't exist yet as there wasn't a need for it previously)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good catch - done.

@jyemin jyemin mentioned this pull request Aug 31, 2015
Document chunk = null;
if (cursor.hasNext()) {
chunk = cursor.next();
if (batchSize == 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Few questions about this bit of code:

  • Why the check for batch size here? Is that because of the "special" meaning of batchSize of 1? If so, what a PITA. Note that batchSize with the new find command will mean what it should.
  • Should it be responsible for validating that the "n" field equals chunkIndexToFetch? I see that's done in validateData, but that check seems to belong here instead to ensure the method contract is not violated.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Why the check for batch size here?

Yes, it is a PITA - currently as the cursor closes, if I want to minimize memory use I have to get a new cursor each time (essentially its the same as the original way of doing find().first()).

Should it be responsible for validating that the "n" field equals chunkIndexToFetch?

I DRY'd it up but have copied it back.

@rozza
Copy link
Owner Author

rozza commented Sep 1, 2015

Updated.

@rozza
Copy link
Owner Author

rozza commented Sep 1, 2015

Rebased, Squashed and merged

@rozza rozza closed this Sep 1, 2015
@rozza rozza deleted the j1916 branch September 1, 2015 15:48
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.

3 participants