add debug mode to compare data read and write

This commit is contained in:
chrislu
2022-12-25 12:12:22 -08:00
parent a8a9589f80
commit 3daaefec60
4 changed files with 44 additions and 1 deletions
+16 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
}