forked from TrueCloudLab/frostfs-node
[#176] localstore: Implement primary BlobStor
Implement primary local BLOB storage based on filesystem tree. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
09750484f9
commit
b127607ac6
9 changed files with 467 additions and 0 deletions
49
pkg/local_object_storage/blobstor/fstree.go
Normal file
49
pkg/local_object_storage/blobstor/fstree.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package blobstor
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
)
|
||||
|
||||
type fsTree struct {
|
||||
depth int
|
||||
|
||||
dirNameLen int
|
||||
|
||||
perm os.FileMode
|
||||
|
||||
rootDir string
|
||||
}
|
||||
|
||||
const dirNameLen = 2 // in bytes
|
||||
|
||||
var maxDepth = (hex.EncodedLen(sha256.Size) - 1) / dirNameLen
|
||||
|
||||
var errFileNotFound = errors.New("file not found")
|
||||
|
||||
func stringifyAddress(addr *objectSDK.Address) string {
|
||||
h := sha256.Sum256([]byte(addr.String()))
|
||||
|
||||
return hex.EncodeToString(h[:])
|
||||
}
|
||||
|
||||
func (t *fsTree) treePath(addr *objectSDK.Address) string {
|
||||
sAddr := stringifyAddress(addr)
|
||||
|
||||
dirs := make([]string, 0, t.depth+1+1) // 1 for root, 1 for file
|
||||
dirs = append(dirs, t.rootDir)
|
||||
|
||||
for i := 0; i < t.depth; i++ {
|
||||
dirs = append(dirs, sAddr[:t.dirNameLen])
|
||||
sAddr = sAddr[t.dirNameLen:]
|
||||
}
|
||||
|
||||
dirs = append(dirs, sAddr)
|
||||
|
||||
return path.Join(dirs...)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue