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

api: getReaderSize() should honor seeked file descriptors. #681

Merged
merged 1 commit into from
May 15, 2017

Conversation

harshavardhana
Copy link
Member

In situations where a file has been Seeked, we need to
start reading from the offset which it indeed happens.
But our reader size calculation needs to honor this to
be accurate.

Fixes #680

@deekoder deekoder requested review from krisis and vadmeste May 14, 2017 16:21
@harshavardhana harshavardhana force-pushed the reader-size branch 2 times, most recently from 26457ec to 8a3d9a1 Compare May 14, 2017 17:17
@harshavardhana
Copy link
Member Author

PR updated, tests fixed ready for review @vadmeste @krisis

vadmeste
vadmeste previously approved these changes May 14, 2017
@harshavardhana
Copy link
Member Author

PR is ready to review @vadmeste @krisis

Copy link
Member

@krisis krisis left a comment

Choose a reason for hiding this comment

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

The changes look good to me, I have a few comments on unit test.

t.Fatal("Error:", err)
}

objectName := fmt.Sprintf("test-file-%v", rand.Uint32())
Copy link
Member

Choose a reason for hiding this comment

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

Why does objectName need a random suffix?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just for uniqueness.. Each test needs to be self contained and not overwrite each other with generic names.

if err != nil {
t.Fatal("Error:", err)
}

Copy link
Member

Choose a reason for hiding this comment

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

Why can't we write data here instead of closing and using io.WriteFile which would do its own Open and Close?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can.. let me add that.


objectName := fmt.Sprintf("test-file-%v", rand.Uint32())

offset := 123
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: we could have offset as length/2 (say). This ensures that offset would be valid independent of the length we choose. Having offset as an independent constant allows for situations in the future where offset may be greater than length etc. We have seen similar cases with our unit tests in the past, e.g index 13 was used to access a variably sized buffer.

Copy link
Member Author

Choose a reason for hiding this comment

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

When would that happen in this case? this is a self contained test. But it is do-able to just do length/2.

Copy link
Member

Choose a reason for hiding this comment

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

There is no issue with this PR. It is possible that constants for length and offset may be changed independently leading to an invalid test case accidentally. So, this is only a suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

In situations where a file has been Seeked, we need to
start reading from the offset which it indeed happens.
But our reader size calculation needs to honor this to
be accurate.

Fixes minio#680
@harshavardhana harshavardhana merged commit 85f15b0 into minio:master May 15, 2017
@harshavardhana harshavardhana deleted the reader-size branch May 15, 2017 18:40
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