mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
mount: report filer IO error
related to https://github.com/chrislusf/seaweedfs/issues/1530
This commit is contained in:
parent
3f7d1d1bf1
commit
9b4f7fed14
|
@ -234,7 +234,11 @@ func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.
|
||||||
|
|
||||||
fullFilePath := util.NewFullPath(dir.FullPath(), req.Name)
|
fullFilePath := util.NewFullPath(dir.FullPath(), req.Name)
|
||||||
dirPath := util.FullPath(dir.FullPath())
|
dirPath := util.FullPath(dir.FullPath())
|
||||||
meta_cache.EnsureVisited(dir.wfs.metaCache, dir.wfs, util.FullPath(dirPath))
|
visitErr := meta_cache.EnsureVisited(dir.wfs.metaCache, dir.wfs, dirPath)
|
||||||
|
if visitErr != nil {
|
||||||
|
glog.Errorf("dir Lookup %s: %v", dirPath, visitErr)
|
||||||
|
return nil, fuse.EIO
|
||||||
|
}
|
||||||
cachedEntry, cacheErr := dir.wfs.metaCache.FindEntry(context.Background(), fullFilePath)
|
cachedEntry, cacheErr := dir.wfs.metaCache.FindEntry(context.Background(), fullFilePath)
|
||||||
if cacheErr == filer_pb.ErrNotFound {
|
if cacheErr == filer_pb.ErrNotFound {
|
||||||
return nil, fuse.ENOENT
|
return nil, fuse.ENOENT
|
||||||
|
@ -296,7 +300,10 @@ func (dir *Dir) ReadDirAll(ctx context.Context) (ret []fuse.Dirent, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dirPath := util.FullPath(dir.FullPath())
|
dirPath := util.FullPath(dir.FullPath())
|
||||||
meta_cache.EnsureVisited(dir.wfs.metaCache, dir.wfs, dirPath)
|
if err = meta_cache.EnsureVisited(dir.wfs.metaCache, dir.wfs, dirPath); err != nil {
|
||||||
|
glog.Errorf("dir ReadDirAll %s: %v", dirPath, err)
|
||||||
|
return nil, fuse.EIO
|
||||||
|
}
|
||||||
listedEntries, listErr := dir.wfs.metaCache.ListDirectoryEntries(context.Background(), util.FullPath(dir.FullPath()), "", false, int(math.MaxInt32))
|
listedEntries, listErr := dir.wfs.metaCache.ListDirectoryEntries(context.Background(), util.FullPath(dir.FullPath()), "", false, int(math.MaxInt32))
|
||||||
if listErr != nil {
|
if listErr != nil {
|
||||||
glog.Errorf("list meta cache: %v", listErr)
|
glog.Errorf("list meta cache: %v", listErr)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package meta_cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -116,6 +117,11 @@ func (mc *MetaCache) ListDirectoryEntries(ctx context.Context, dirPath util.Full
|
||||||
mc.RLock()
|
mc.RLock()
|
||||||
defer mc.RUnlock()
|
defer mc.RUnlock()
|
||||||
|
|
||||||
|
|
||||||
|
if !mc.visitedBoundary.HasVisited(dirPath) {
|
||||||
|
return nil, fmt.Errorf("unsynchronized dir: %v", dirPath)
|
||||||
|
}
|
||||||
|
|
||||||
entries, err := mc.localStore.ListDirectoryEntries(ctx, dirPath, startFileName, includeStartFile, limit)
|
entries, err := mc.localStore.ListDirectoryEntries(ctx, dirPath, startFileName, includeStartFile, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func EnsureVisited(mc *MetaCache, client filer_pb.FilerClient, dirPath util.FullPath) {
|
func EnsureVisited(mc *MetaCache, client filer_pb.FilerClient, dirPath util.FullPath) error {
|
||||||
|
|
||||||
mc.visitedBoundary.EnsureVisited(dirPath, func(path util.FullPath) (childDirectories []string, err error) {
|
return mc.visitedBoundary.EnsureVisited(dirPath, func(path util.FullPath) (childDirectories []string, err error) {
|
||||||
|
|
||||||
glog.V(4).Infof("ReadDirAllEntries %s ...", path)
|
glog.V(4).Infof("ReadDirAllEntries %s ...", path)
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ type VisitNodeFunc func(path util.FullPath) (childDirectories []string, err erro
|
||||||
// No action if the directory has been visited before or does not exist.
|
// No action if the directory has been visited before or does not exist.
|
||||||
// A leaf node, which has no children, represents a directory not visited.
|
// A leaf node, which has no children, represents a directory not visited.
|
||||||
// A non-leaf node or a non-existing node represents a directory already visited, or does not need to visit.
|
// A non-leaf node or a non-existing node represents a directory already visited, or does not need to visit.
|
||||||
func (t *BoundedTree) EnsureVisited(p util.FullPath, visitFn VisitNodeFunc) {
|
func (t *BoundedTree) EnsureVisited(p util.FullPath, visitFn VisitNodeFunc) (visitErr error){
|
||||||
t.Lock()
|
t.Lock()
|
||||||
defer t.Unlock()
|
defer t.Unlock()
|
||||||
|
|
||||||
|
@ -46,12 +46,17 @@ func (t *BoundedTree) EnsureVisited(p util.FullPath, visitFn VisitNodeFunc) {
|
||||||
}
|
}
|
||||||
components := p.Split()
|
components := p.Split()
|
||||||
// fmt.Printf("components %v %d\n", components, len(components))
|
// fmt.Printf("components %v %d\n", components, len(components))
|
||||||
if canDelete := t.ensureVisited(t.root, t.baseDir, components, 0, visitFn); canDelete {
|
canDelete, err := t.ensureVisited(t.root, t.baseDir, components, 0, visitFn)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if canDelete {
|
||||||
t.root = nil
|
t.root = nil
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *BoundedTree) ensureVisited(n *Node, currentPath util.FullPath, components []string, i int, visitFn VisitNodeFunc) (canDeleteNode bool) {
|
func (t *BoundedTree) ensureVisited(n *Node, currentPath util.FullPath, components []string, i int, visitFn VisitNodeFunc) (canDeleteNode bool, visitErr error) {
|
||||||
|
|
||||||
// println("ensureVisited", currentPath, i)
|
// println("ensureVisited", currentPath, i)
|
||||||
|
|
||||||
|
@ -73,12 +78,12 @@ func (t *BoundedTree) ensureVisited(n *Node, currentPath util.FullPath, componen
|
||||||
children, err := visitFn(filerPath)
|
children, err := visitFn(filerPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(0).Infof("failed to visit %s: %v", currentPath, err)
|
glog.V(0).Infof("failed to visit %s: %v", currentPath, err)
|
||||||
return
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(children) == 0 {
|
if len(children) == 0 {
|
||||||
// fmt.Printf(" canDelete %v without children\n", currentPath)
|
// fmt.Printf(" canDelete %v without children\n", currentPath)
|
||||||
return true
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
n.Children = make(map[string]*Node)
|
n.Children = make(map[string]*Node)
|
||||||
|
@ -103,19 +108,22 @@ func (t *BoundedTree) ensureVisited(n *Node, currentPath util.FullPath, componen
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Printf(" ensureVisited %v %v\n", currentPath, toVisitNode.Name)
|
// fmt.Printf(" ensureVisited %v %v\n", currentPath, toVisitNode.Name)
|
||||||
|
canDelete, childVisitErr := t.ensureVisited(toVisitNode, currentPath.Child(components[i]), components, i+1, visitFn)
|
||||||
if canDelete := t.ensureVisited(toVisitNode, currentPath.Child(components[i]), components, i+1, visitFn); canDelete {
|
if childVisitErr != nil {
|
||||||
|
return false, childVisitErr
|
||||||
|
}
|
||||||
|
if canDelete {
|
||||||
|
|
||||||
// fmt.Printf(" delete %v %v\n", currentPath, components[i])
|
// fmt.Printf(" delete %v %v\n", currentPath, components[i])
|
||||||
delete(n.Children, components[i])
|
delete(n.Children, components[i])
|
||||||
|
|
||||||
if len(n.Children) == 0 {
|
if len(n.Children) == 0 {
|
||||||
// fmt.Printf(" canDelete %v\n", currentPath)
|
// fmt.Printf(" canDelete %v\n", currentPath)
|
||||||
return true
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue