SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
correctly runs git clone
Chris Lu6cbd786db9b9
diff --git a/weed/filesys/dir.go b/weed/filesys/dir.goindex b3577dcf0a..3588a5951c 100644--- a/weed/filesys/dir.go+++ b/weed/filesys/dir.go@@ -24,6 +24,7 @@ type Dir struct {wfs *WFSentry *filer_pb.Entryparent *Dir+ id uint64}var _ = fs.Node(&Dir{})@@ -44,7 +45,7 @@ var _ = fs.NodeListxattrer(&Dir{})var _ = fs.NodeForgetter(&Dir{})func (dir *Dir) Id() uint64 {- return util.FullPath(dir.FullPath()).AsInode()+ return dir.id}func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error {@@ -64,7 +65,7 @@ func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error {return err}- attr.Inode = util.FullPath(dir.FullPath()).AsInode()+ attr.Inode = dir.Id()attr.Mode = os.FileMode(entry.Attributes.FileMode) | os.ModeDirattr.Mtime = time.Unix(entry.Attributes.Mtime, 0)attr.Crtime = time.Unix(entry.Attributes.Crtime, 0)@@ -110,16 +111,28 @@ func (dir *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {}func (dir *Dir) newFile(name string) fs.Node {++ fileFullPath := util.NewFullPath(dir.FullPath(), name)+ fileId := fileFullPath.AsInode()+ dir.wfs.handlesLock.Lock()+ existingHandle, found := dir.wfs.handles[fileId]+ dir.wfs.handlesLock.Unlock()++ if found {+ glog.V(4).Infof("newFile found opened file handle: %+v", fileFullPath)+ return existingHandle.f+ }return &File{- Name: name,- dir: dir,- wfs: dir.wfs,+ Name: name,+ dir: dir,+ wfs: dir.wfs,+ id: fileId,}}func (dir *Dir) newDirectory(fullpath util.FullPath) fs.Node {- return &Dir{name: fullpath.Name(), wfs: dir.wfs, parent: dir}+ return &Dir{name: fullpath.Name(), wfs: dir.wfs, parent: dir, id: fullpath.AsInode()}}diff --git a/weed/filesys/dir_rename.go b/weed/filesys/dir_rename.goindex 7bc7051020..b07710d174 100644--- a/weed/filesys/dir_rename.go+++ b/weed/filesys/dir_rename.go@@ -64,11 +64,22 @@ func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirectorreturn fuse.EIO}+ oldFsNode := NodeWithId(oldPath.AsInode())+ newFsNode := NodeWithId(newPath.AsInode())+ dir.wfs.Server.InvalidateInternalNode(oldFsNode, newFsNode, func(internalNode fs.Node) {+ if file, ok := internalNode.(*File); ok {+ glog.V(4).Infof("internal node %s", file.Name)+ file.Name = req.NewName+ file.id = uint64(newFsNode)+ }+ })+// change file handledir.wfs.handlesLock.Lock()defer dir.wfs.handlesLock.Unlock()inodeId := oldPath.AsInode()existingHandle, found := dir.wfs.handles[inodeId]+ glog.V(4).Infof("has open filehandle %s: %v", oldPath, found)if !found || existingHandle == nil {return nil}diff --git a/weed/filesys/file.go b/weed/filesys/file.goindex b3e5cc72de..2e37c6e0ef 100644--- a/weed/filesys/file.go+++ b/weed/filesys/file.go@@ -35,6 +35,7 @@ type File struct {entry *filer_pb.EntryisOpen intdirtyMetadata bool+ id uint64}func (file *File) fullpath() util.FullPath {@@ -42,25 +43,23 @@ func (file *File) fullpath() util.FullPath {}func (file *File) Id() uint64 {- return file.fullpath().AsInode()+ return file.id}func (file *File) Attr(ctx context.Context, attr *fuse.Attr) (err error) {glog.V(4).Infof("file Attr %s, open:%v existing:%v", file.fullpath(), file.isOpen, attr)- entry := file.getEntry()- if file.isOpen <= 0 || entry == nil {- if entry, err = file.maybeLoadEntry(ctx); err != nil {- return err- }+ entry, err := file.maybeLoadEntry(ctx)+ if err != nil {+ return err}if entry == nil {return fuse.ENOENT}- attr.Inode = file.fullpath().AsInode()+ attr.Inode = file.Id()attr.Valid = time.Secondattr.Mode = os.FileMode(entry.Attributes.FileMode)attr.Size = filer.FileSize(entry)@@ -118,7 +117,7 @@ func (file *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *f}if file.isOpen > 0 {file.wfs.handlesLock.Lock()- fileHandle := file.wfs.handles[file.fullpath().AsInode()]+ fileHandle := file.wfs.handles[file.Id()]file.wfs.handlesLock.Unlock()if fileHandle != nil {@@ -262,10 +261,15 @@ func (file *File) Forget() {}func (file *File) maybeLoadEntry(ctx context.Context) (entry *filer_pb.Entry, err error) {- entry = file.getEntry()- if file.isOpen > 0 {- return entry, nil++ file.wfs.handlesLock.Lock()+ handle, found := file.wfs.handles[file.Id()]+ file.wfs.handlesLock.Unlock()+ if found {+ glog.V(4).Infof("maybeLoadEntry found opened file %s/%s: %v %v", file.dir.FullPath(), file.Name, handle.f.entry, entry)+ entry = handle.f.entry}+if entry != nil {if len(entry.HardLinkId) == 0 {// only always reload hard linkdiff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.goindex 5b9a1748af..3f4ee69f45 100644--- a/weed/filesys/filehandle.go+++ b/weed/filesys/filehandle.go@@ -193,20 +193,20 @@ func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *ffunc (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) error {- glog.V(4).Infof("Release %v fh %d", fh.f.fullpath(), fh.handle)+ glog.V(4).Infof("Release %v fh %d open=%d", fh.f.fullpath(), fh.handle, fh.f.isOpen)fh.Lock()defer fh.Unlock()- if fh.f.isOpen <= 0 {+ fh.f.isOpen--++ if fh.f.isOpen < 0 {glog.V(0).Infof("Release reset %s open count %d => %d", fh.f.Name, fh.f.isOpen, 0)fh.f.isOpen = 0return nil}- if fh.f.isOpen == 1 {-- fh.f.isOpen--+ if fh.f.isOpen == 0 {fh.f.entry = nilfh.entryViewCache = nilfh.reader = nildiff --git a/weed/filesys/wfs.go b/weed/filesys/wfs.goindex 7019a464be..42816d23d3 100644--- a/weed/filesys/wfs.go+++ b/weed/filesys/wfs.go@@ -103,6 +103,7 @@ func NewSeaweedFileSystem(option *Option) *WFS {}wfs.metaCache = meta_cache.NewMetaCache(path.Join(cacheDir, "meta"), util.FullPath(option.FilerMountRootPath), option.UidGidMapper, func(filePath util.FullPath) {+fsNode := NodeWithId(filePath.AsInode())if err := wfs.Server.InvalidateNodeData(fsNode); err != nil {glog.V(4).Infof("InvalidateNodeData %s : %v", filePath, err)@@ -139,16 +140,15 @@ func (wfs *WFS) AcquireHandle(file *File, uid, gid uint32) (fileHandle *FileHandfullpath := file.fullpath()glog.V(4).Infof("AcquireHandle %s uid=%d gid=%d", fullpath, uid, gid)- wfs.handlesLock.Lock()- defer wfs.handlesLock.Unlock()+ inodeId := file.Id()- inodeId := file.fullpath().AsInode()- if file.isOpen > 0 {- existingHandle, found := wfs.handles[inodeId]- if found && existingHandle != nil {- file.isOpen++- return existingHandle- }+ wfs.handlesLock.Lock()+ existingHandle, found := wfs.handles[inodeId]+ wfs.handlesLock.Unlock()+ if found && existingHandle != nil {+ existingHandle.f.isOpen+++ glog.V(4).Infof("Acquired Handle %s open %d", fullpath, existingHandle.f.isOpen)+ return existingHandle}entry, _ := file.maybeLoadEntry(context.Background())@@ -156,9 +156,12 @@ func (wfs *WFS) AcquireHandle(file *File, uid, gid uint32) (fileHandle *FileHandfileHandle = newFileHandle(file, uid, gid)file.isOpen+++ wfs.handlesLock.Lock()wfs.handles[inodeId] = fileHandle+ wfs.handlesLock.Unlock()fileHandle.handle = inodeId+ glog.V(4).Infof("Acquired new Handle %s open %d", fullpath, file.isOpen)return}@@ -166,9 +169,9 @@ func (wfs *WFS) ReleaseHandle(fullpath util.FullPath, handleId fuse.HandleID) {wfs.handlesLock.Lock()defer wfs.handlesLock.Unlock()- glog.V(4).Infof("%s ReleaseHandle id %d current handles length %d", fullpath, handleId, len(wfs.handles))+ glog.V(4).Infof("ReleaseHandle %s id %d current handles length %d", fullpath, handleId, len(wfs.handles))- delete(wfs.handles, fullpath.AsInode())+ delete(wfs.handles, uint64(handleId))return}