Browse Source

Merge branch 'master' into feature/helm-s3-allowEmptyFolder

pull/6206/head
jiawei wei 2 months ago
committed by GitHub
parent
commit
394712d6d4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 14
      weed/filer/reader_at.go
  2. 8
      weed/filer/reader_at_test.go
  3. 2
      weed/mount/filehandle_read.go

14
weed/filer/reader_at.go

@ -173,15 +173,14 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, ts int64, err err
// zero the remaining bytes if a gap exists at the end of the last chunk (or a fully sparse file) // zero the remaining bytes if a gap exists at the end of the last chunk (or a fully sparse file)
if err == nil && remaining > 0 { if err == nil && remaining > 0 {
var delta int64 var delta int64
if c.fileSize > startOffset {
if c.fileSize >= startOffset {
delta = min(remaining, c.fileSize-startOffset) delta = min(remaining, c.fileSize-startOffset)
startOffset -= offset startOffset -= offset
} else {
delta = remaining
startOffset = max(startOffset-offset, startOffset-remaining-offset)
} }
glog.V(4).Infof("zero2 [%d,%d) of file size %d bytes", startOffset, startOffset+delta, c.fileSize)
n += zero(p, startOffset, delta)
if delta > 0 {
glog.V(4).Infof("zero2 [%d,%d) of file size %d bytes", startOffset, startOffset+delta, c.fileSize)
n += zero(p, startOffset, delta)
}
} }
if err == nil && offset+int64(len(p)) >= c.fileSize { if err == nil && offset+int64(len(p)) >= c.fileSize {
@ -220,6 +219,9 @@ func (c *ChunkReadAt) readChunkSliceAt(buffer []byte, chunkView *ChunkView, next
} }
func zero(buffer []byte, start, length int64) int { func zero(buffer []byte, start, length int64) int {
if length <= 0 {
return 0
}
end := min(start+length, int64(len(buffer))) end := min(start+length, int64(len(buffer)))
start = max(start, 0) start = max(start, 0)

8
weed/filer/reader_at_test.go

@ -31,7 +31,7 @@ func (m *mockChunkCache) ReadChunkAt(data []byte, fileId string, offset uint64)
func (m *mockChunkCache) SetChunk(fileId string, data []byte) { func (m *mockChunkCache) SetChunk(fileId string, data []byte) {
} }
func (m *mockChunkCache) GetMaxFilePartSizeInCache() (uint64) {
func (m *mockChunkCache) GetMaxFilePartSizeInCache() uint64 {
return 0 return 0
} }
@ -81,7 +81,7 @@ func TestReaderAt(t *testing.T) {
} }
testReadAt(t, readerAt, 0, 10, 10, io.EOF, nil, nil) testReadAt(t, readerAt, 0, 10, 10, io.EOF, nil, nil)
testReadAt(t, readerAt, 0, 12, 12, io.EOF, nil, nil)
testReadAt(t, readerAt, 0, 12, 10, io.EOF, nil, nil)
testReadAt(t, readerAt, 2, 8, 8, io.EOF, nil, nil) testReadAt(t, readerAt, 2, 8, 8, io.EOF, nil, nil)
testReadAt(t, readerAt, 3, 6, 6, nil, nil, nil) testReadAt(t, readerAt, 3, 6, 6, nil, nil, nil)
@ -131,8 +131,8 @@ func TestReaderAt0(t *testing.T) {
testReadAt(t, readerAt, 3, 16, 7, io.EOF, nil, nil) testReadAt(t, readerAt, 3, 16, 7, io.EOF, nil, nil)
testReadAt(t, readerAt, 3, 5, 5, nil, nil, nil) testReadAt(t, readerAt, 3, 5, 5, nil, nil, nil)
testReadAt(t, readerAt, 11, 5, 5, io.EOF, nil, nil)
testReadAt(t, readerAt, 10, 5, 5, io.EOF, nil, nil)
testReadAt(t, readerAt, 11, 5, 0, io.EOF, nil, nil)
testReadAt(t, readerAt, 10, 5, 0, io.EOF, nil, nil)
} }

2
weed/mount/filehandle_read.go

@ -47,6 +47,8 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, int64, e
if fileSize == 0 { if fileSize == 0 {
glog.V(1).Infof("empty fh %v", fileFullPath) glog.V(1).Infof("empty fh %v", fileFullPath)
return 0, 0, io.EOF return 0, 0, io.EOF
} else if offset == fileSize {
return 0, 0, io.EOF
} else if offset >= fileSize { } else if offset >= fileSize {
glog.V(1).Infof("invalid read, fileSize %d, offset %d for %s", fileSize, offset, fileFullPath) glog.V(1).Infof("invalid read, fileSize %d, offset %d for %s", fileSize, offset, fileFullPath)
return 0, 0, io.EOF return 0, 0, io.EOF

Loading…
Cancel
Save