fix: fs verify error counter (#5261)
This commit is contained in:
committed by
GitHub
parent
3b5d8ffb70
commit
6181aa7594
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/storage"
|
"github.com/seaweedfs/seaweedfs/weed/storage"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||||
|
"go.uber.org/atomic"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
@@ -137,7 +138,7 @@ type ItemEntry struct {
|
|||||||
path util.FullPath
|
path util.FullPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandFsVerify) verifyTraverseBfs(path string) (fileCount int64, errCount int64, err error) {
|
func (c *commandFsVerify) verifyTraverseBfs(path string) (fileCount uint64, errCount uint64, err error) {
|
||||||
timeNowAtSec := time.Now().Unix()
|
timeNowAtSec := time.Now().Unix()
|
||||||
return fileCount, errCount, doTraverseBfsAndSaving(c.env, c.writer, path, false,
|
return fileCount, errCount, doTraverseBfsAndSaving(c.env, c.writer, path, false,
|
||||||
func(entry *filer_pb.FullEntry, outputChan chan interface{}) (err error) {
|
func(entry *filer_pb.FullEntry, outputChan chan interface{}) (err error) {
|
||||||
@@ -160,19 +161,24 @@ func (c *commandFsVerify) verifyTraverseBfs(path string) (fileCount int64, errCo
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(outputChan chan interface{}) {
|
func(outputChan chan interface{}) {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
itemErrCount := atomic.NewUint64(0)
|
||||||
for itemEntry := range outputChan {
|
for itemEntry := range outputChan {
|
||||||
i := itemEntry.(*ItemEntry)
|
i := itemEntry.(*ItemEntry)
|
||||||
itemPath := string(i.path)
|
itemPath := string(i.path)
|
||||||
fileMsg := fmt.Sprintf("file:%s", itemPath)
|
fileMsg := fmt.Sprintf("file:%s", itemPath)
|
||||||
errItem := make(map[string]error)
|
itemIsVerifed := atomic.NewBool(true)
|
||||||
errItemLock := sync.RWMutex{}
|
|
||||||
for _, chunk := range i.chunks {
|
for _, chunk := range i.chunks {
|
||||||
if volumeIds, ok := c.volumeIds[chunk.Fid.VolumeId]; ok {
|
if volumeIds, ok := c.volumeIds[chunk.Fid.VolumeId]; ok {
|
||||||
for _, volumeServer := range volumeIds {
|
for _, volumeServer := range volumeIds {
|
||||||
if *c.concurrency == 0 {
|
if *c.concurrency == 0 {
|
||||||
if err = c.verifyEntry(volumeServer, chunk.Fid); err != nil {
|
if err = c.verifyEntry(volumeServer, chunk.Fid); err != nil {
|
||||||
fmt.Fprintf(c.writer, "%s failed verify needle %d:%d: %+v\n",
|
fmt.Fprintf(c.writer, "%s failed verify fileId %s: %+v\n",
|
||||||
fileMsg, chunk.Fid.VolumeId, chunk.Fid.FileKey, err)
|
fileMsg, chunk.GetFileIdString(), err)
|
||||||
|
if itemIsVerifed.Load() {
|
||||||
|
itemIsVerifed.Store(false)
|
||||||
|
itemErrCount.Add(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -180,43 +186,48 @@ func (c *commandFsVerify) verifyTraverseBfs(path string) (fileCount int64, errCo
|
|||||||
waitChan, ok := c.waitChan[string(volumeServer)]
|
waitChan, ok := c.waitChan[string(volumeServer)]
|
||||||
c.waitChanLock.RUnlock()
|
c.waitChanLock.RUnlock()
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Fprintf(c.writer, "%s failed to get channel for %s chunk: %d:%d: %+v\n",
|
fmt.Fprintf(c.writer, "%s failed to get channel for %s fileId: %s: %+v\n",
|
||||||
string(volumeServer), fileMsg, chunk.Fid.VolumeId, chunk.Fid.FileKey, err)
|
string(volumeServer), fileMsg, chunk.GetFileIdString(), err)
|
||||||
|
if itemIsVerifed.Load() {
|
||||||
|
itemIsVerifed.Store(false)
|
||||||
|
itemErrCount.Add(1)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
wg.Add(1)
|
||||||
waitChan <- struct{}{}
|
waitChan <- struct{}{}
|
||||||
go func(fId *filer_pb.FileId, path string, volumeServer pb.ServerAddress, msg string) {
|
go func(fChunk *filer_pb.FileChunk, path string, volumeServer pb.ServerAddress, msg string) {
|
||||||
if err = c.verifyEntry(volumeServer, fId); err != nil {
|
defer wg.Done()
|
||||||
errItemLock.Lock()
|
if err = c.verifyEntry(volumeServer, fChunk.Fid); err != nil {
|
||||||
errItem[path] = err
|
fmt.Fprintf(c.writer, "%s failed verify fileId %s: %+v\n",
|
||||||
fmt.Fprintf(c.writer, "%s failed verify needle %d:%d: %+v\n",
|
msg, fChunk.GetFileIdString(), err)
|
||||||
msg, fId.VolumeId, fId.FileKey, err)
|
if itemIsVerifed.Load() {
|
||||||
errItemLock.Unlock()
|
itemIsVerifed.Store(false)
|
||||||
|
itemErrCount.Add(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
<-waitChan
|
<-waitChan
|
||||||
}(chunk.Fid, itemPath, volumeServer, fileMsg)
|
}(chunk, itemPath, volumeServer, fileMsg)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("volumeId %d not found", chunk.Fid.VolumeId)
|
err = fmt.Errorf("volumeId %d not found", chunk.Fid.VolumeId)
|
||||||
fmt.Fprintf(c.writer, "%s %d:%d: %+v\n",
|
fmt.Fprintf(c.writer, "%s failed verify fileId %s: %+v\n",
|
||||||
fileMsg, chunk.Fid.VolumeId, chunk.Fid.FileKey, err)
|
fileMsg, chunk.GetFileIdString(), err)
|
||||||
|
if itemIsVerifed.Load() {
|
||||||
|
itemIsVerifed.Store(false)
|
||||||
|
itemErrCount.Add(1)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errItemLock.RLock()
|
if itemIsVerifed.Load() {
|
||||||
err, _ = errItem[itemPath]
|
if *c.verbose {
|
||||||
errItemLock.RUnlock()
|
fmt.Fprintf(c.writer, "%s needles:%d verifed\n", fileMsg, len(i.chunks))
|
||||||
|
}
|
||||||
if err != nil {
|
fileCount++
|
||||||
errCount++
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if *c.verbose {
|
|
||||||
fmt.Fprintf(c.writer, "%s needles:%d verifed\n", fileMsg, len(i.chunks))
|
|
||||||
}
|
|
||||||
fileCount++
|
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
|
errCount = itemErrCount.Load()
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user