Browse Source

add debug mode to compare data read and write

pull/4089/head
chrislu 2 years ago
parent
commit
3daaefec60
  1. 17
      weed/mount/filehandle.go
  2. 19
      weed/mount/weedfs_file_read.go
  3. 4
      weed/mount/weedfs_file_sync.go
  4. 5
      weed/mount/weedfs_file_write.go

17
weed/mount/filehandle.go

@ -5,14 +5,16 @@ import (
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/util"
"golang.org/x/exp/slices"
"golang.org/x/sync/semaphore"
"math"
"os"
"sync"
)
type FileHandleId uint64
var IsDebug = true
type FileHandle struct {
fh FileHandleId
counter int64
@ -31,6 +33,9 @@ type FileHandle struct {
orderedMutex *semaphore.Weighted
isDeleted bool
// for debugging
mirrorFile *os.File
}
func newFileHandle(wfs *WFS, handleId FileHandleId, inode uint64, entry *filer_pb.Entry) *FileHandle {
@ -50,6 +55,14 @@ func newFileHandle(wfs *WFS, handleId FileHandleId, inode uint64, entry *filer_p
Entry: entry,
}
if IsDebug {
var err error
fh.mirrorFile, err = os.OpenFile("/tmp/sw/"+entry.Name, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
println("failed to create mirror:", err.Error())
}
}
return fh
}
@ -97,5 +110,7 @@ func (fh *FileHandle) Release() {
fh.dirtyPages.Destroy()
fh.CloseReader()
if IsDebug {
fh.mirrorFile.Close()
}
}

19
weed/mount/weedfs_file_read.go

@ -1,7 +1,9 @@
package mount
import (
"bytes"
"context"
"fmt"
"io"
"github.com/hanwen/go-fuse/v2/fuse"
@ -50,6 +52,23 @@ func (wfs *WFS) Read(cancel <-chan struct{}, in *fuse.ReadIn, buff []byte) (fuse
return nil, fuse.EIO
}
if IsDebug {
// print(".")
mirrorData := make([]byte, totalRead)
fh.mirrorFile.ReadAt(mirrorData, offset)
if bytes.Compare(mirrorData, buff[:totalRead]) != 0 {
againBuff := make([]byte, len(buff))
againRead, _ := readDataByFileHandle(buff, fh, offset)
againCorrect := bytes.Compare(mirrorData, againBuff[:againRead]) == 0
againSame := bytes.Compare(buff[:totalRead], againBuff[:againRead]) == 0
fmt.Printf("\ncompare %v [%d,%d) size:%d againSame:%v againCorrect:%v\n", fh.mirrorFile.Name(), offset, offset+totalRead, totalRead, againSame, againCorrect)
//fmt.Printf("read mirrow data: %v\n", mirrorData)
//fmt.Printf("read actual data: %v\n", buff[:totalRead])
}
}
return fuse.ReadResultData(buff[:totalRead]), fuse.OK
}

4
weed/mount/weedfs_file_sync.go

@ -181,5 +181,9 @@ func (wfs *WFS) doFlush(fh *FileHandle, uid, gid uint32) fuse.Status {
return fuse.EIO
}
if IsDebug {
fh.mirrorFile.Sync()
}
return fuse.OK
}

5
weed/mount/weedfs_file_write.go

@ -73,5 +73,10 @@ func (wfs *WFS) Write(cancel <-chan struct{}, in *fuse.WriteIn, data []byte) (wr
fh.dirtyMetadata = true
if IsDebug {
// print("+")
fh.mirrorFile.WriteAt(data, offset)
}
return written, fuse.OK
}
Loading…
Cancel
Save