Browse Source

FUSE mount: fix file id written twice?

fix https://github.com/chrislusf/seaweedfs/issues/1373
Chris Lu 4 years ago
parent
commit
3cec4b3c49
3 changed files with 8 additions and 3 deletions
  1. 6 1
      weed/filer2/reader_at.go
  2. 1 1
      weed/filesys/file.go
  3. 1 1
      weed/util/chunk_cache/chunk_cache.go

+ 6 - 1
weed/filer2/reader_at.go

@@ -90,6 +90,9 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, err error) {
 			found = true
 			if c.bufferOffset != chunk.LogicOffset {
 				c.buffer, err = c.fetchChunkData(chunk)
+				if err != nil {
+					glog.Errorf("fetching chunk %+v: %v\n", chunk, err)
+				}
 				c.bufferOffset = chunk.LogicOffset
 			}
 			break
@@ -99,7 +102,9 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, err error) {
 		return 0, io.EOF
 	}
 
-	n = copy(p, c.buffer[offset-c.bufferOffset:])
+	if err == nil {
+		n = copy(p, c.buffer[offset-c.bufferOffset:])
+	}
 
 	// fmt.Printf("> doReadAt [%d,%d), buffer:[%d,%d)\n", offset, offset+int64(n), c.bufferOffset, c.bufferOffset+int64(len(c.buffer)))
 

+ 1 - 1
weed/filesys/file.go

@@ -212,7 +212,7 @@ func (file *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
 
 func (file *File) Forget() {
 	t := util.NewFullPath(file.dir.FullPath(), file.Name)
-	glog.V(3).Infof("Forget file %s", t)
+	glog.V(4).Infof("Forget file %s", t)
 }
 
 func (file *File) maybeLoadEntry(ctx context.Context) error {

+ 1 - 1
weed/util/chunk_cache/chunk_cache.go

@@ -60,7 +60,7 @@ func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) {
 
 	for _, diskCache := range c.diskCaches {
 		data := diskCache.getChunk(fid.Key)
-		if len(data) != 0 {
+		if len(data) != 0 && len(data) >= int(chunkSize) {
 			return data
 		}
 	}