remove nodemap, fix directory listing cache
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"bazil.org/fuse"
|
"bazil.org/fuse"
|
||||||
"bazil.org/fuse/fs"
|
"bazil.org/fuse/fs"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
@@ -16,10 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Dir struct {
|
type Dir struct {
|
||||||
Path string
|
Path string
|
||||||
NodeMap map[string]fs.Node
|
wfs *WFS
|
||||||
NodeMapLock sync.Mutex
|
|
||||||
wfs *WFS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = fs.Node(&Dir{})
|
var _ = fs.Node(&Dir{})
|
||||||
@@ -38,6 +34,18 @@ func (dir *Dir) Attr(context context.Context, attr *fuse.Attr) error {
|
|||||||
return nil
|
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)
|
parent, name := filepath.Split(dir.Path)
|
||||||
|
|
||||||
var attributes *filer_pb.FuseAttributes
|
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.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.Gid = attributes.Gid
|
||||||
attr.Uid = attributes.Uid
|
attr.Uid = attributes.Uid
|
||||||
|
|
||||||
@@ -121,7 +129,6 @@ func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest,
|
|||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
file := dir.newFile(req.Name, nil)
|
file := dir.newFile(req.Name, nil)
|
||||||
dir.NodeMap[req.Name] = file
|
|
||||||
file.isOpen = true
|
file.isOpen = true
|
||||||
return file, dir.wfs.AcquireHandle(file, req.Uid, req.Gid), nil
|
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) {
|
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 {
|
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 {
|
if err == nil {
|
||||||
node := &Dir{Path: path.Join(dir.Path, req.Name), wfs: dir.wfs}
|
node := &Dir{Path: path.Join(dir.Path, req.Name), wfs: dir.wfs}
|
||||||
dir.NodeMap[req.Name] = node
|
|
||||||
return node, nil
|
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) {
|
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
|
var entry *filer_pb.Entry
|
||||||
err = dir.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
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 {
|
} else {
|
||||||
node = dir.newFile(name, entry.Chunks)
|
node = dir.newFile(name, entry.Chunks)
|
||||||
}
|
}
|
||||||
dir.NodeMap[name] = node
|
|
||||||
return node, nil
|
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 {
|
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 {
|
return dir.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
||||||
request := &filer_pb.DeleteEntryRequest{
|
request := &filer_pb.DeleteEntryRequest{
|
||||||
@@ -264,8 +253,6 @@ func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(dir.NodeMap, req.Name)
|
|
||||||
|
|
||||||
return nil
|
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 {
|
func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirectory fs.Node) error {
|
||||||
|
|
||||||
dir.NodeMapLock.Lock()
|
|
||||||
defer dir.NodeMapLock.Unlock()
|
|
||||||
|
|
||||||
newDir := newDirectory.(*Dir)
|
newDir := newDirectory.(*Dir)
|
||||||
|
|
||||||
var entry *filer_pb.Entry
|
var entry *filer_pb.Entry
|
||||||
@@ -338,8 +322,6 @@ func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirector
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(dir.NodeMap, req.OldName)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (file *File) Attr(ctx context.Context, attr *fuse.Attr) error {
|
|||||||
|
|
||||||
if file.attributes == nil || !file.isOpen {
|
if file.attributes == nil || !file.isOpen {
|
||||||
item := file.wfs.listDirectoryEntriesCache.Get(file.fullpath())
|
item := file.wfs.listDirectoryEntriesCache.Get(file.fullpath())
|
||||||
if item != nil {
|
if item != nil && !item.Expired(){
|
||||||
entry := item.Value().(*filer_pb.Entry)
|
entry := item.Value().(*filer_pb.Entry)
|
||||||
file.Chunks = entry.Chunks
|
file.Chunks = entry.Chunks
|
||||||
file.attributes = entry.Attributes
|
file.attributes = entry.Attributes
|
||||||
|
|||||||
Reference in New Issue
Block a user