mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
this works great and support long file names
This commit is contained in:
parent
2da84ed331
commit
955eae3500
|
@ -20,7 +20,8 @@ func (store *AbstractSqlStore) InsertEntry(entry *filer2.Entry) (err error) {
|
|||
return fmt.Errorf("mysql encode %s: %s", entry.FullPath, err)
|
||||
}
|
||||
|
||||
res, err := store.DB.Exec("INSERT INTO filemeta (directory,name,meta) VALUES(?,?,?)", dir, name, meta)
|
||||
res, err := store.DB.Exec("INSERT INTO filemeta (dirhash,name,directory,meta) VALUES(?,?,?,?)",
|
||||
md5hash(dir), name, dir, meta)
|
||||
if err != nil {
|
||||
return fmt.Errorf("mysql insert %s: %s", entry.FullPath, err)
|
||||
}
|
||||
|
@ -40,7 +41,8 @@ func (store *AbstractSqlStore) UpdateEntry(entry *filer2.Entry) (err error) {
|
|||
return fmt.Errorf("mysql encode %s: %s", entry.FullPath, err)
|
||||
}
|
||||
|
||||
res, err := store.DB.Exec("UPDATE filemeta SET meta=? WHERE directory=? and name=?", dir, name, meta)
|
||||
res, err := store.DB.Exec("UPDATE filemeta SET meta=? WHERE dirhash=? AND name=? AND directory=?",
|
||||
meta, md5hash(dir), name, dir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("mysql update %s: %s", entry.FullPath, err)
|
||||
}
|
||||
|
@ -55,7 +57,8 @@ func (store *AbstractSqlStore) UpdateEntry(entry *filer2.Entry) (err error) {
|
|||
func (store *AbstractSqlStore) FindEntry(fullpath filer2.FullPath) (*filer2.Entry, error) {
|
||||
|
||||
dir, name := fullpath.DirAndName()
|
||||
row := store.DB.QueryRow("SELECT meta FROM filemeta WHERE directory=? and name=?", dir, name)
|
||||
row := store.DB.QueryRow("SELECT meta FROM filemeta WHERE dirhash=? AND name=? AND directory=?",
|
||||
md5hash(dir), name, dir)
|
||||
var data []byte
|
||||
if err := row.Scan(&data); err != nil {
|
||||
return nil, fmt.Errorf("mysql read entry %s: %v", fullpath, err)
|
||||
|
@ -77,7 +80,8 @@ func (store *AbstractSqlStore) DeleteEntry(fullpath filer2.FullPath) (*filer2.En
|
|||
|
||||
dir, name := fullpath.DirAndName()
|
||||
|
||||
res, err := store.DB.Exec("DELETE FROM filemeta WHERE directory=? and name=?", dir, name)
|
||||
res, err := store.DB.Exec("DELETE FROM filemeta WHERE dirhash=? AND name=? AND directory=?",
|
||||
md5hash(dir), name, dir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("mysql delete %s: %s", fullpath, err)
|
||||
}
|
||||
|
@ -92,12 +96,12 @@ func (store *AbstractSqlStore) DeleteEntry(fullpath filer2.FullPath) (*filer2.En
|
|||
|
||||
func (store *AbstractSqlStore) ListDirectoryEntries(fullpath filer2.FullPath, startFileName string, inclusive bool, limit int) (entries []*filer2.Entry, err error) {
|
||||
|
||||
sqlText := "SELECT NAME, meta FROM filemeta WHERE directory=? and name>? LIMIT ?"
|
||||
sqlText := "SELECT NAME, meta FROM filemeta WHERE dirhash=? AND name>? AND directory=? LIMIT ?"
|
||||
if inclusive {
|
||||
sqlText = "SELECT NAME, meta FROM filemeta WHERE directory=? and name>=? LIMIT ?"
|
||||
sqlText = "SELECT NAME, meta FROM filemeta WHERE dirhash=? AND name>=? AND directory=? LIMIT ?"
|
||||
}
|
||||
|
||||
rows, err := store.DB.Query(sqlText, string(fullpath), startFileName, limit)
|
||||
rows, err := store.DB.Query(sqlText, md5hash(string(fullpath)), startFileName, string(fullpath), limit)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("mysql list %s : %v", fullpath, err)
|
||||
}
|
||||
|
|
13
weed/filer2/abstract_sql/hashing.go
Normal file
13
weed/filer2/abstract_sql/hashing.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package abstract_sql
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"io"
|
||||
)
|
||||
|
||||
// returns a 128 bit hash
|
||||
func md5hash(dir string) []byte {
|
||||
h := md5.New()
|
||||
io.WriteString(h, dir)
|
||||
return h.Sum(nil)
|
||||
}
|
|
@ -25,12 +25,15 @@ dir = "." # directory to store level db files
|
|||
#
|
||||
# need to choose or create a database.
|
||||
# need to manually create a table "filemeta".
|
||||
#
|
||||
# CREATE TABLE IF NOT EXISTS filemeta (
|
||||
# directory VARCHAR(512) NOT NULL DEFAULT "" COMMENT 'full path to parent directory',
|
||||
# name VARCHAR(512) NOT NULL DEFAULT "" COMMENT 'directory or file name',
|
||||
# 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',
|
||||
# meta BLOB,
|
||||
# PRIMARY KEY (directory, name)
|
||||
# PRIMARY KEY (dirhash, name)
|
||||
# ) DEFAULT CHARSET=utf8;
|
||||
#
|
||||
enabled = true
|
||||
server = "localhost"
|
||||
port = 3306
|
||||
|
|
Loading…
Reference in a new issue