mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
simplifying dirhash to 64bit integer
This commit is contained in:
parent
955eae3500
commit
87b3b84471
|
@ -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.Entr
|
|||
|
||||
dir, 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 []byte
|
||||
if 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.En
|
|||
dir, 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, st
|
|||
sqlText = "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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 = 2
|
|||
connection_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
|
||||
|
|
Loading…
Reference in a new issue