mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-07-16 07:09:15 +08:00
forget() factor in nlookup
This commit is contained in:
parent
f8af0f93d9
commit
6a921e15f3
@ -9,19 +9,23 @@ import (
|
|||||||
type InodeToPath struct {
|
type InodeToPath struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
nextInodeId uint64
|
nextInodeId uint64
|
||||||
inode2path map[uint64]util.FullPath
|
inode2path map[uint64]*InodeEntry
|
||||||
path2inode map[util.FullPath]uint64
|
path2inode map[util.FullPath]uint64
|
||||||
}
|
}
|
||||||
|
type InodeEntry struct {
|
||||||
|
util.FullPath
|
||||||
|
nlookup uint64
|
||||||
|
}
|
||||||
|
|
||||||
func NewInodeToPath() *InodeToPath {
|
func NewInodeToPath() *InodeToPath {
|
||||||
return &InodeToPath{
|
return &InodeToPath{
|
||||||
inode2path: make(map[uint64]util.FullPath),
|
inode2path: make(map[uint64]*InodeEntry),
|
||||||
path2inode: make(map[util.FullPath]uint64),
|
path2inode: make(map[util.FullPath]uint64),
|
||||||
nextInodeId: 2, // the root inode id is 1
|
nextInodeId: 2, // the root inode id is 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *InodeToPath) GetInode(path util.FullPath) uint64 {
|
func (i *InodeToPath) Lookup(path util.FullPath) uint64 {
|
||||||
if path == "/" {
|
if path == "/" {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@ -32,7 +36,22 @@ func (i *InodeToPath) GetInode(path util.FullPath) uint64 {
|
|||||||
inode = i.nextInodeId
|
inode = i.nextInodeId
|
||||||
i.nextInodeId++
|
i.nextInodeId++
|
||||||
i.path2inode[path] = inode
|
i.path2inode[path] = inode
|
||||||
i.inode2path[inode] = path
|
i.inode2path[inode] = &InodeEntry{path, 1}
|
||||||
|
} else {
|
||||||
|
i.inode2path[inode].nlookup++
|
||||||
|
}
|
||||||
|
return inode
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *InodeToPath) GetInode(path util.FullPath) uint64 {
|
||||||
|
if path == "/" {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
i.Lock()
|
||||||
|
defer i.Unlock()
|
||||||
|
inode, found := i.path2inode[path]
|
||||||
|
if !found {
|
||||||
|
glog.Fatalf("GetInode unknown inode %d", inode)
|
||||||
}
|
}
|
||||||
return inode
|
return inode
|
||||||
}
|
}
|
||||||
@ -45,9 +64,9 @@ func (i *InodeToPath) GetPath(inode uint64) util.FullPath {
|
|||||||
defer i.RUnlock()
|
defer i.RUnlock()
|
||||||
path, found := i.inode2path[inode]
|
path, found := i.inode2path[inode]
|
||||||
if !found {
|
if !found {
|
||||||
glog.Fatal("not found inode %d", inode)
|
glog.Fatalf("not found inode %d", inode)
|
||||||
}
|
}
|
||||||
return path
|
return path.FullPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *InodeToPath) HasPath(path util.FullPath) bool {
|
func (i *InodeToPath) HasPath(path util.FullPath) bool {
|
||||||
@ -82,15 +101,19 @@ func (i *InodeToPath) RemovePath(path util.FullPath) {
|
|||||||
delete(i.inode2path, inode)
|
delete(i.inode2path, inode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (i *InodeToPath) RemoveInode(inode uint64) {
|
|
||||||
|
func (i *InodeToPath) Forget(inode, nlookup uint64) {
|
||||||
if inode == 1 {
|
if inode == 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
i.RLock()
|
i.Lock()
|
||||||
defer i.RUnlock()
|
defer i.Unlock()
|
||||||
path, found := i.inode2path[inode]
|
path, found := i.inode2path[inode]
|
||||||
if found {
|
if found {
|
||||||
delete(i.path2inode, path)
|
path.nlookup -= nlookup
|
||||||
|
if path.nlookup <= 0 {
|
||||||
|
delete(i.path2inode, path.FullPath)
|
||||||
delete(i.inode2path, inode)
|
delete(i.inode2path, inode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -50,7 +50,7 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strin
|
|||||||
return fuse.ENOENT
|
return fuse.ENOENT
|
||||||
}
|
}
|
||||||
|
|
||||||
inode := wfs.inodeToPath.GetInode(fullFilePath)
|
inode := wfs.inodeToPath.Lookup(fullFilePath)
|
||||||
|
|
||||||
wfs.outputFilerEntry(out, inode, localEntry)
|
wfs.outputFilerEntry(out, inode, localEntry)
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out
|
|||||||
return fuse.EIO
|
return fuse.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
inode := wfs.inodeToPath.GetInode(entryFullPath)
|
inode := wfs.inodeToPath.Lookup(entryFullPath)
|
||||||
|
|
||||||
wfs.outputPbEntry(out, inode, newEntry)
|
wfs.outputPbEntry(out, inode, newEntry)
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out
|
|||||||
return fuse.EIO
|
return fuse.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
inode := wfs.inodeToPath.GetInode(entryFullPath)
|
inode := wfs.inodeToPath.Lookup(entryFullPath)
|
||||||
|
|
||||||
wfs.outputPbEntry(out, inode, newEntry)
|
wfs.outputPbEntry(out, inode, newEntry)
|
||||||
|
|
||||||
|
@ -43,10 +43,18 @@ package mount
|
|||||||
* @param ino the inode number
|
* @param ino the inode number
|
||||||
* @param nlookup the number of lookups to forget
|
* @param nlookup the number of lookups to forget
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
|
|
||||||
|
int fuse_reply_entry ( fuse_req_t req,
|
||||||
|
const struct fuse_entry_param * e
|
||||||
|
)
|
||||||
|
Reply with a directory entry
|
||||||
|
|
||||||
|
Possible requests: lookup, mknod, mkdir, symlink, link
|
||||||
|
|
||||||
|
Side effects: increments the lookup count on success
|
||||||
|
|
||||||
|
*/
|
||||||
func (wfs *WFS) Forget(nodeid, nlookup uint64) {
|
func (wfs *WFS) Forget(nodeid, nlookup uint64) {
|
||||||
if nlookup == 0 {
|
wfs.inodeToPath.Forget(nodeid, nlookup)
|
||||||
// need to maintain the inode for selective filtering
|
|
||||||
// and caching for metadata updates
|
|
||||||
wfs.inodeToPath.RemoveInode(nodeid)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ func (wfs *WFS) Link(cancel <-chan struct{}, in *fuse.LinkIn, name string, out *
|
|||||||
return fuse.EIO
|
return fuse.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
inode := wfs.inodeToPath.GetInode(newEntryPath)
|
inode := wfs.inodeToPath.Lookup(newEntryPath)
|
||||||
|
|
||||||
wfs.outputPbEntry(out, inode, request.Entry)
|
wfs.outputPbEntry(out, inode, request.Entry)
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ func (wfs *WFS) Symlink(cancel <-chan struct{}, header *fuse.InHeader, target st
|
|||||||
return fuse.EIO
|
return fuse.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
inode := wfs.inodeToPath.GetInode(entryFullPath)
|
inode := wfs.inodeToPath.Lookup(entryFullPath)
|
||||||
|
|
||||||
wfs.outputPbEntry(out, inode, request.Entry)
|
wfs.outputPbEntry(out, inode, request.Entry)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user