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

fs: ListObjects() was reading ETag at wrong offsets #4846

Merged
merged 1 commit into from Aug 24, 2017

Conversation

harshavardhana
Copy link
Member

@harshavardhana harshavardhana commented Aug 22, 2017

Description

Current code was just using io.ReadAll() on an fd()
which might have moved underneath due to a concurrent
read operation. Subsequent read will result in EOF
We should always seek back and read again. pread()
is allowed on all platforms use io.SectionReader to
read from the beginning of the file.

Motivation and Context

Fixes #4842

How Has This Been Tested?

Manually and using the reproducer.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@vadmeste
Copy link
Member

This fixes the issue as I tested it. You mean, in a GNU/Linux, a call to a read() of a moved file returns io.EOF ?

@harshavardhana
Copy link
Member Author

harshavardhana commented Aug 22, 2017

This fixes the issue as I tested it. You mean, in a GNU/Linux, a call to a read() of a moved file returns io.EOF ?

Well the underlying offset would have moved if there is a concurrent read. io.SectionReader helps in seeking back the offsets for the requested Size() and Offset.

cmd/fs-v1.go Outdated
// `fs.json` can be empty due to previously failed
// PutObject() transaction, if we arrive at such
// a situation we just ignore and continue.
if len(fsMetaBuf) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

You could use fi.Size() to validate before ioutil.ReadAll()

cmd/fs-v1.go Outdated
@@ -749,14 +749,21 @@ func (fs fsObjects) getObjectETag(bucket, entry string) (string, error) {
// Read from fs metadata only if it exists.
defer fs.rwPool.Close(fsMetaPath)

fsMetaBuf, err := ioutil.ReadAll(rlk.LockedFile)
fi, err := rlk.LockedFile.Stat()
Copy link
Member

Choose a reason for hiding this comment

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

You could add a comment why Stat() then ioutil.ReadAll() approach is required with ReadAt()

@codecov-io
Copy link

codecov-io commented Aug 23, 2017

Codecov Report

Merging #4846 into master will decrease coverage by <.01%.
The diff coverage is 27.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4846      +/-   ##
==========================================
- Coverage   62.97%   62.97%   -0.01%     
==========================================
  Files         191      191              
  Lines       27444    27449       +5     
==========================================
+ Hits        17283    17285       +2     
- Misses       8991     8992       +1     
- Partials     1170     1172       +2
Impacted Files Coverage Δ
cmd/fs-v1.go 79.27% <27.27%> (-0.33%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b233345...2f15c60. Read the comment docs.

@harshavardhana harshavardhana force-pushed the fs-objectinfo branch 2 times, most recently from 13fa1f7 to bcc3069 Compare August 23, 2017 02:04
@harshavardhana
Copy link
Member Author

@balamurugana can you take a look again?

Copy link
Contributor

@ebozduman ebozduman left a comment

Choose a reason for hiding this comment

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

LGTM

Current code was just using io.ReadAll() on an fd()
which might have moved underneath due to a concurrent
read operation. Subsequent read will result in EOF
We should always seek back and read again. pread()
is allowed on all platforms use io.SectionReader to
read from the beginning of the file.

Fixes minio#4842
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Api and mc return 0 objects / output when downloading from the same dir at the sametime
6 participants