mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-25 11:39:12 +08:00
remove nodemap, fix directory listing cache
This commit is contained in:
parent
5c25d29272
commit
daabdfe357
@ -5,8 +5,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
|
||||
"bazil.org/fuse"
|
||||
"bazil.org/fuse/fs"
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
@ -16,10 +14,8 @@ import (
|
||||
)
|
||||
|
||||
type Dir struct {
|
||||
Path string
|
||||
NodeMap map[string]fs.Node
|
||||
NodeMapLock sync.Mutex
|
||||
wfs *WFS
|
||||
Path string
|
||||
wfs *WFS
|
||||
}
|
||||
|
||||
var _ = fs.Node(&Dir{})
|
||||
@ -38,6 +34,18 @@ func (dir *Dir) Attr(context context.Context, attr *fuse.Attr) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
item := dir.wfs.listDirectoryEntriesCache.Get(dir.Path)
|
||||
if item != nil && !item.Expired() {
|
||||
entry := item.Value().(*filer_pb.Entry)
|
||||
|
||||
attr.Mtime = time.Unix(entry.Attributes.Mtime, 0)
|
||||
attr.Ctime = time.Unix(entry.Attributes.Crtime, 0)
|
||||
attr.Gid = entry.Attributes.Gid
|
||||
attr.Uid = entry.Attributes.Uid
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
parent, name := filepath.Split(dir.Path)
|
||||
|
||||
var attributes *filer_pb.FuseAttributes
|
||||
@ -74,7 +82,7 @@ func (dir *Dir) Attr(context context.Context, attr *fuse.Attr) error {
|
||||
}
|
||||
|
||||
attr.Mtime = time.Unix(attributes.Mtime, 0)
|
||||
attr.Ctime = time.Unix(attributes.Mtime, 0)
|
||||
attr.Ctime = time.Unix(attributes.Crtime, 0)
|
||||
attr.Gid = attributes.Gid
|
||||
attr.Uid = attributes.Uid
|
||||
|
||||
@ -121,7 +129,6 @@ func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest,
|
||||
|
||||
if err == nil {
|
||||
file := dir.newFile(req.Name, nil)
|
||||
dir.NodeMap[req.Name] = file
|
||||
file.isOpen = true
|
||||
return file, dir.wfs.AcquireHandle(file, req.Uid, req.Gid), nil
|
||||
}
|
||||
@ -130,8 +137,6 @@ func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest,
|
||||
}
|
||||
|
||||
func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) {
|
||||
dir.NodeMapLock.Lock()
|
||||
defer dir.NodeMapLock.Unlock()
|
||||
|
||||
err := dir.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
@ -161,7 +166,6 @@ func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, err
|
||||
|
||||
if err == nil {
|
||||
node := &Dir{Path: path.Join(dir.Path, req.Name), wfs: dir.wfs}
|
||||
dir.NodeMap[req.Name] = node
|
||||
return node, nil
|
||||
}
|
||||
|
||||
@ -170,17 +174,6 @@ func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, err
|
||||
|
||||
func (dir *Dir) Lookup(ctx context.Context, name string) (node fs.Node, err error) {
|
||||
|
||||
dir.NodeMapLock.Lock()
|
||||
defer dir.NodeMapLock.Unlock()
|
||||
|
||||
if dir.NodeMap == nil {
|
||||
dir.NodeMap = make(map[string]fs.Node)
|
||||
}
|
||||
|
||||
if node, ok := dir.NodeMap[name]; ok {
|
||||
return node, nil
|
||||
}
|
||||
|
||||
var entry *filer_pb.Entry
|
||||
err = dir.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
@ -206,7 +199,6 @@ func (dir *Dir) Lookup(ctx context.Context, name string) (node fs.Node, err erro
|
||||
} else {
|
||||
node = dir.newFile(name, entry.Chunks)
|
||||
}
|
||||
dir.NodeMap[name] = node
|
||||
return node, nil
|
||||
}
|
||||
|
||||
@ -246,9 +238,6 @@ func (dir *Dir) ReadDirAll(ctx context.Context) (ret []fuse.Dirent, err error) {
|
||||
|
||||
func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
|
||||
|
||||
dir.NodeMapLock.Lock()
|
||||
defer dir.NodeMapLock.Unlock()
|
||||
|
||||
return dir.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
request := &filer_pb.DeleteEntryRequest{
|
||||
@ -264,8 +253,6 @@ func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
|
||||
return err
|
||||
}
|
||||
|
||||
delete(dir.NodeMap, req.Name)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -273,9 +260,6 @@ func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
|
||||
|
||||
func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirectory fs.Node) error {
|
||||
|
||||
dir.NodeMapLock.Lock()
|
||||
defer dir.NodeMapLock.Unlock()
|
||||
|
||||
newDir := newDirectory.(*Dir)
|
||||
|
||||
var entry *filer_pb.Entry
|
||||
@ -338,8 +322,6 @@ func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirector
|
||||
return err
|
||||
}
|
||||
|
||||
delete(dir.NodeMap, req.OldName)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -34,7 +34,7 @@ func (file *File) Attr(ctx context.Context, attr *fuse.Attr) error {
|
||||
|
||||
if file.attributes == nil || !file.isOpen {
|
||||
item := file.wfs.listDirectoryEntriesCache.Get(file.fullpath())
|
||||
if item != nil {
|
||||
if item != nil && !item.Expired(){
|
||||
entry := item.Value().(*filer_pb.Entry)
|
||||
file.Chunks = entry.Chunks
|
||||
file.attributes = entry.Attributes
|
||||
|
Loading…
Reference in New Issue
Block a user