[#472] blobstor: implement write-cache

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-04-06 13:56:06 +03:00 committed by Alex Vanin
parent 96a8ee7c83
commit 59de521fd1
24 changed files with 1011 additions and 116 deletions

View file

@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"path"
"strings"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
)
@ -44,6 +45,52 @@ func stringifyAddress(addr *objectSDK.Address) string {
return hex.EncodeToString(h[:])
}
// Iterate iterates over all stored objects.
func (t *FSTree) Iterate(f func(addr *objectSDK.Address, data []byte) error) error {
return t.iterate(0, []string{t.RootPath}, f)
}
func (t *FSTree) iterate(depth int, curPath []string, f func(*objectSDK.Address, []byte) error) error {
curName := strings.Join(curPath[1:], "")
des, err := ioutil.ReadDir(curName)
if err != nil {
return err
}
isLast := depth >= t.Depth
l := len(curPath)
curPath = append(curPath, "")
for i := range des {
curPath[l] = des[i].Name()
if !isLast && des[i].IsDir() {
err := t.iterate(depth+1, curPath, f)
if err != nil {
return err
}
}
addr := objectSDK.NewAddress()
err := addr.Parse(curName + des[i].Name())
if err != nil {
continue
}
curPath = append(curPath, des[i].Name())
data, err := ioutil.ReadFile(path.Join(curPath...))
if err != nil {
return err
}
if err := f(addr, data); err != nil {
return err
}
}
return nil
}
func (t *FSTree) treePath(addr *objectSDK.Address) string {
sAddr := stringifyAddress(addr)

View file

@ -2,7 +2,7 @@ package blobstor
import "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
// DumpInfo returns information about the BlobStor.
// FSTree returns file-system tree for big object store.
func (b *BlobStor) DumpInfo() fstree.Info {
return b.fsTree.Info
}