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
simplifying dirhash to 64bit integer
Chris Lu87b3b84471c7
diff --git a/weed/filer2/abstract_sql/abstract_sql_store.go b/weed/filer2/abstract_sql/abstract_sql_store.goindex 3d15c632d9..900056dae3 100644--- a/weed/filer2/abstract_sql/abstract_sql_store.go+++ b/weed/filer2/abstract_sql/abstract_sql_store.go@@ -21,7 +21,7 @@ func (store *AbstractSqlStore) InsertEntry(entry *filer2.Entry) (err error) {}res, err := store.DB.Exec("INSERT INTO filemeta (dirhash,name,directory,meta) VALUES(?,?,?,?)",- md5hash(dir), name, dir, meta)+ hashToLong(dir), name, dir, meta)if err != nil {return fmt.Errorf("mysql insert %s: %s", entry.FullPath, err)}@@ -42,7 +42,7 @@ func (store *AbstractSqlStore) UpdateEntry(entry *filer2.Entry) (err error) {}res, err := store.DB.Exec("UPDATE filemeta SET meta=? WHERE dirhash=? AND name=? AND directory=?",- meta, md5hash(dir), name, dir)+ meta, hashToLong(dir), name, dir)if err != nil {return fmt.Errorf("mysql update %s: %s", entry.FullPath, err)}@@ -58,7 +58,7 @@ func (store *AbstractSqlStore) FindEntry(fullpath filer2.FullPath) (*filer2.Entrdir, name := fullpath.DirAndName()row := store.DB.QueryRow("SELECT meta FROM filemeta WHERE dirhash=? AND name=? AND directory=?",- md5hash(dir), name, dir)+ hashToLong(dir), name, dir)var data []byteif err := row.Scan(&data); err != nil {return nil, fmt.Errorf("mysql read entry %s: %v", fullpath, err)@@ -81,7 +81,7 @@ func (store *AbstractSqlStore) DeleteEntry(fullpath filer2.FullPath) (*filer2.Endir, name := fullpath.DirAndName()res, err := store.DB.Exec("DELETE FROM filemeta WHERE dirhash=? AND name=? AND directory=?",- md5hash(dir), name, dir)+ hashToLong(dir), name, dir)if err != nil {return nil, fmt.Errorf("mysql delete %s: %s", fullpath, err)}@@ -101,7 +101,7 @@ func (store *AbstractSqlStore) ListDirectoryEntries(fullpath filer2.FullPath, stsqlText = "SELECT NAME, meta FROM filemeta WHERE dirhash=? AND name>=? AND directory=? LIMIT ?"}- rows, err := store.DB.Query(sqlText, md5hash(string(fullpath)), startFileName, string(fullpath), limit)+ rows, err := store.DB.Query(sqlText, hashToLong(string(fullpath)), startFileName, string(fullpath), limit)if err != nil {return nil, fmt.Errorf("mysql list %s : %v", fullpath, err)}diff --git a/weed/filer2/abstract_sql/hashing.go b/weed/filer2/abstract_sql/hashing.goindex 5e13902339..5c982c5377 100644--- a/weed/filer2/abstract_sql/hashing.go+++ b/weed/filer2/abstract_sql/hashing.go@@ -5,9 +5,28 @@ import ("io")-// returns a 128 bit hash-func md5hash(dir string) []byte {+// returns a 64 bit big int+func hashToLong(dir string) (v int64) {h := md5.New()io.WriteString(h, dir)- return h.Sum(nil)++ 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/filer2/configuration.go b/weed/filer2/configuration.goindex 910ddcbbc8..14ca61745c 100644--- a/weed/filer2/configuration.go+++ b/weed/filer2/configuration.go@@ -27,9 +27,9 @@ dir = "." # directory to store level db files# need to manually create a table "filemeta".## CREATE TABLE IF NOT EXISTS filemeta (-# dirhash BINARY(16) COMMENT 'MD5 hash value of directory field',-# name VARCHAR(1000) NOT NULL DEFAULT "" COMMENT 'directory or file name',-# directory VARCHAR(4096) NOT NULL DEFAULT "" COMMENT 'full path to parent directory',+# dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',+# name VARCHAR(1000) COMMENT 'directory or file name',+# directory VARCHAR(4096) COMMENT 'full path to parent directory',# meta BLOB,# PRIMARY KEY (dirhash, name)# ) DEFAULT CHARSET=utf8;@@ -44,10 +44,17 @@ connection_max_idle = 2connection_max_open = 100[postgres]+# CREATE TABLE IF NOT EXISTS filemeta (+# dirhash BIGINT,+# name VARCHAR(1000),+# directory VARCHAR(4096),+# meta bytea,+# PRIMARY KEY (dirhash, name)+# );enabled = false-server = "192.168.1.1"-port = 8080-username = ""+server = "localhost"+port = 5432+username = "postgres"password = ""database = ""connection_max_idle = 100