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
filer: set inode
Chris Lu39edcfde4cdd
diff --git a/weed/filer2/abstract_sql/abstract_sql_store.go b/weed/filer2/abstract_sql/abstract_sql_store.goindex d512467c72..47fe507a14 100644--- a/weed/filer2/abstract_sql/abstract_sql_store.go+++ b/weed/filer2/abstract_sql/abstract_sql_store.go@@ -7,6 +7,7 @@ import ("github.com/chrislusf/seaweedfs/weed/filer2""github.com/chrislusf/seaweedfs/weed/glog"+ "github.com/chrislusf/seaweedfs/weed/util")type AbstractSqlStore struct {@@ -65,7 +66,7 @@ func (store *AbstractSqlStore) InsertEntry(ctx context.Context, entry *filer2.Enreturn fmt.Errorf("encode %s: %s", entry.FullPath, err)}- res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlInsert, hashToLong(dir), name, dir, meta)+ res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlInsert, util.HashStringToLong(dir), name, dir, meta)if err != nil {return fmt.Errorf("insert %s: %s", entry.FullPath, err)}@@ -85,7 +86,7 @@ func (store *AbstractSqlStore) UpdateEntry(ctx context.Context, entry *filer2.Enreturn fmt.Errorf("encode %s: %s", entry.FullPath, err)}- res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlUpdate, meta, hashToLong(dir), name, dir)+ res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlUpdate, meta, util.HashStringToLong(dir), name, dir)if err != nil {return fmt.Errorf("update %s: %s", entry.FullPath, err)}@@ -100,7 +101,7 @@ func (store *AbstractSqlStore) UpdateEntry(ctx context.Context, entry *filer2.Enfunc (store *AbstractSqlStore) FindEntry(ctx context.Context, fullpath filer2.FullPath) (*filer2.Entry, error) {dir, name := fullpath.DirAndName()- row := store.getTxOrDB(ctx).QueryRowContext(ctx, store.SqlFind, hashToLong(dir), name, dir)+ row := store.getTxOrDB(ctx).QueryRowContext(ctx, store.SqlFind, util.HashStringToLong(dir), name, dir)var data []byteif err := row.Scan(&data); err != nil {return nil, filer2.ErrNotFound@@ -120,7 +121,7 @@ func (store *AbstractSqlStore) DeleteEntry(ctx context.Context, fullpath filer2.dir, name := fullpath.DirAndName()- res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlDelete, hashToLong(dir), name, dir)+ res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlDelete, util.HashStringToLong(dir), name, dir)if err != nil {return fmt.Errorf("delete %s: %s", fullpath, err)}@@ -135,7 +136,7 @@ func (store *AbstractSqlStore) DeleteEntry(ctx context.Context, fullpath filer2.func (store *AbstractSqlStore) DeleteFolderChildren(ctx context.Context, fullpath filer2.FullPath) error {- res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlDeleteFolderChildren, hashToLong(string(fullpath)), fullpath)+ res, err := store.getTxOrDB(ctx).ExecContext(ctx, store.SqlDeleteFolderChildren, util.HashStringToLong(string(fullpath)), fullpath)if err != nil {return fmt.Errorf("deleteFolderChildren %s: %s", fullpath, err)}@@ -155,7 +156,7 @@ func (store *AbstractSqlStore) ListDirectoryEntries(ctx context.Context, fullpatsqlText = store.SqlListInclusive}- rows, err := store.getTxOrDB(ctx).QueryContext(ctx, sqlText, hashToLong(string(fullpath)), startFileName, string(fullpath), limit)+ rows, err := store.getTxOrDB(ctx).QueryContext(ctx, sqlText, util.HashStringToLong(string(fullpath)), startFileName, string(fullpath), limit)if err != nil {return nil, fmt.Errorf("list %s : %v", fullpath, err)}diff --git a/weed/filer2/abstract_sql/hashing.go b/weed/filer2/abstract_sql/hashing.godeleted file mode 100644index 5c982c5377..0000000000--- a/weed/filer2/abstract_sql/hashing.go+++ /dev/null@@ -1,32 +0,0 @@-package abstract_sql--import (- "crypto/md5"- "io"-)--// returns a 64 bit big int-func hashToLong(dir string) (v int64) {- h := md5.New()- io.WriteString(h, dir)-- b := h.Sum(nil)-- v += int64(b[0])- v <<= 8- v += int64(b[1])- v <<= 8- v += int64(b[2])- v <<= 8- v += int64(b[3])- v <<= 8- v += int64(b[4])- v <<= 8- v += int64(b[5])- v <<= 8- v += int64(b[6])- v <<= 8- v += int64(b[7])-- return-}diff --git a/weed/filesys/dir.go b/weed/filesys/dir.goindex 563581db9e..95b26f4095 100644--- a/weed/filesys/dir.go+++ b/weed/filesys/dir.go@@ -9,6 +9,7 @@ import ("github.com/chrislusf/seaweedfs/weed/filer2""github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/pb/filer_pb"+ "github.com/chrislusf/seaweedfs/weed/util""github.com/seaweedfs/fuse""github.com/seaweedfs/fuse/fs")@@ -34,26 +35,31 @@ var _ = fs.NodeListxattrer(&Dir{})func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error {- glog.V(3).Infof("dir Attr %s", dir.Path)+ glog.V(3).Infof("dir Attr %s, existing attr: %+v", dir.Path, attr)// https://github.com/bazil/fuse/issues/196attr.Valid = time.Secondif dir.Path == dir.wfs.option.FilerMountRootPath {dir.setRootDirAttributes(attr)+ glog.V(3).Infof("root dir Attr %s, attr: %+v", dir.Path, attr)return nil}if err := dir.maybeLoadEntry(ctx); err != nil {+ glog.V(3).Infof("dir Attr %s,err: %+v", dir.Path, err)return err}+ attr.Inode = uint64(util.HashStringToLong(dir.Path))attr.Mode = os.FileMode(dir.entry.Attributes.FileMode) | os.ModeDirattr.Mtime = time.Unix(dir.entry.Attributes.Mtime, 0)attr.Ctime = time.Unix(dir.entry.Attributes.Crtime, 0)attr.Gid = dir.entry.Attributes.Gidattr.Uid = dir.entry.Attributes.Uid+ glog.V(3).Infof("dir Attr %s, attr: %+v", dir.Path, attr)+return nil}@@ -69,7 +75,7 @@ func (dir *Dir) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *f}func (dir *Dir) setRootDirAttributes(attr *fuse.Attr) {- attr.Inode = 1+ attr.Inode = uint64(util.HashStringToLong(dir.Path))attr.Valid = time.Hourattr.Uid = dir.wfs.option.MountUidattr.Gid = dir.wfs.option.MountGid@@ -204,8 +210,9 @@ func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.node = dir.newFile(req.Name, entry)}- resp.EntryValid = time.Duration(0)- resp.Attr.Valid = time.Duration(0)+ resp.EntryValid = time.Second+ resp.Attr.Inode = uint64(util.HashStringToLong(fullFilePath))+ resp.Attr.Valid = time.Secondresp.Attr.Mtime = time.Unix(entry.Attributes.Mtime, 0)resp.Attr.Ctime = time.Unix(entry.Attributes.Crtime, 0)resp.Attr.Mode = os.FileMode(entry.Attributes.FileMode)@@ -226,14 +233,16 @@ func (dir *Dir) ReadDirAll(ctx context.Context) (ret []fuse.Dirent, err error) {cacheTtl := 5 * time.MinutereadErr := filer2.ReadDirAllEntries(ctx, dir.wfs, dir.Path, "", func(entry *filer_pb.Entry, isLast bool) {+ fullpath := path.Join(dir.Path, entry.Name)+ inode := uint64(util.HashStringToLong(fullpath))if entry.IsDirectory {- dirent := fuse.Dirent{Name: entry.Name, Type: fuse.DT_Dir}+ dirent := fuse.Dirent{Inode: inode, Name: entry.Name, Type: fuse.DT_Dir}ret = append(ret, dirent)} else {- dirent := fuse.Dirent{Name: entry.Name, Type: fuse.DT_File}+ dirent := fuse.Dirent{Inode: inode, Name: entry.Name, Type: fuse.DT_File}ret = append(ret, dirent)}- dir.wfs.listDirectoryEntriesCache.Set(path.Join(dir.Path, entry.Name), entry, cacheTtl)+ dir.wfs.listDirectoryEntriesCache.Set(fullpath, entry, cacheTtl)})if readErr != nil {glog.V(0).Infof("list %s: %v", dir.Path, err)diff --git a/weed/filesys/file.go b/weed/filesys/file.goindex afe78ee0f4..b0df344fac 100644--- a/weed/filesys/file.go+++ b/weed/filesys/file.go@@ -10,6 +10,7 @@ import ("github.com/chrislusf/seaweedfs/weed/filer2""github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/pb/filer_pb"+ "github.com/chrislusf/seaweedfs/weed/util""github.com/seaweedfs/fuse""github.com/seaweedfs/fuse/fs")@@ -40,12 +41,13 @@ func (file *File) fullpath() string {func (file *File) Attr(ctx context.Context, attr *fuse.Attr) error {- glog.V(4).Infof("file Attr %s", file.fullpath())+ glog.V(4).Infof("file Attr %s, open:%v, existing attr: %+v", file.fullpath(), file.isOpen, attr)if err := file.maybeLoadEntry(ctx); err != nil {return err}+ attr.Inode = uint64(util.HashStringToLong(file.fullpath()))attr.Mode = os.FileMode(file.entry.Attributes.FileMode)attr.Size = filer2.TotalSize(file.entry.Chunks)attr.Mtime = time.Unix(file.entry.Attributes.Mtime, 0)diff --git a/weed/util/bytes.go b/weed/util/bytes.goindex dfa4ae665a..9c7e5e2cb0 100644--- a/weed/util/bytes.go+++ b/weed/util/bytes.go@@ -1,5 +1,10 @@package util+import (+ "crypto/md5"+ "io"+)+// big endianfunc BytesToUint64(b []byte) (v uint64) {@@ -43,3 +48,29 @@ func Uint16toBytes(b []byte, v uint16) {func Uint8toBytes(b []byte, v uint8) {b[0] = byte(v)}++// returns a 64 bit big int+func HashStringToLong(dir string) (v int64) {+ h := md5.New()+ io.WriteString(h, dir)++ b := h.Sum(nil)++ v += int64(b[0])+ v <<= 8+ v += int64(b[1])+ v <<= 8+ v += int64(b[2])+ v <<= 8+ v += int64(b[3])+ v <<= 8+ v += int64(b[4])+ v <<= 8+ v += int64(b[5])+ v <<= 8+ v += int64(b[6])+ v <<= 8+ v += int64(b[7])++ return+}