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

This commit is contained in:
jiawei wei 2024-11-06 09:30:27 +08:00 committed by GitHub
commit 394712d6d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 10 deletions

View File

@ -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)
if err == nil && remaining > 0 {
var delta int64
if c.fileSize > startOffset {
if c.fileSize >= startOffset {
delta = min(remaining, c.fileSize-startOffset)
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 {
@ -220,6 +219,9 @@ func (c *ChunkReadAt) readChunkSliceAt(buffer []byte, chunkView *ChunkView, next
}
func zero(buffer []byte, start, length int64) int {
if length <= 0 {
return 0
}
end := min(start+length, int64(len(buffer)))
start = max(start, 0)

View File

@ -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) GetMaxFilePartSizeInCache() (uint64) {
func (m *mockChunkCache) GetMaxFilePartSizeInCache() uint64 {
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, 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, 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, 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)
}

View File

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