From 98b519b113955d1f9f26739707ba6d5ec83352cc Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 5 Nov 2024 08:28:50 -0800 Subject: [PATCH 1/4] fix FUSE mount on mac --- weed/filer/reader_at.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.go index d7617b740..5c52c8a2f 100644 --- a/weed/filer/reader_at.go +++ b/weed/filer/reader_at.go @@ -173,7 +173,7 @@ 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 { @@ -220,6 +220,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) From 6161d0b05db494e2d295487c893ebd432aaa5335 Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 5 Nov 2024 08:41:14 -0800 Subject: [PATCH 2/4] a bit optimization --- weed/mount/filehandle_read.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/weed/mount/filehandle_read.go b/weed/mount/filehandle_read.go index faf99952f..a609c97cc 100644 --- a/weed/mount/filehandle_read.go +++ b/weed/mount/filehandle_read.go @@ -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 From 90acfd939405b8eefcc10f9c4043ea489eba207f Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 5 Nov 2024 08:42:44 -0800 Subject: [PATCH 3/4] remove case when read request is out side of the file size --- weed/filer/reader_at.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.go index 5c52c8a2f..b87fa0411 100644 --- a/weed/filer/reader_at.go +++ b/weed/filer/reader_at.go @@ -176,12 +176,11 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, ts int64, err err 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 { From 706d1a8e22b962f976c0fc2f60966cebbe586b12 Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 5 Nov 2024 08:52:07 -0800 Subject: [PATCH 4/4] fix tests --- weed/filer/reader_at_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/weed/filer/reader_at_test.go b/weed/filer/reader_at_test.go index 0d95d1aad..6d985a397 100644 --- a/weed/filer/reader_at_test.go +++ b/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) 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) }