frostfs-node/pkg/local_object_storage/metabase/get.go
Leonard Lyubich 85aacbbb10 [#128] localstorage: Implement primary object metabase
Implement bolt-based metabase that is going to be used in local object
storage. Implement Put/Get/Select methods.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-10-29 17:34:41 +03:00

38 lines
732 B
Go

package meta
import (
"errors"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"go.etcd.io/bbolt"
)
var errNotFound = errors.New("object not found")
// Get returns object header for specified address.
func (db *DB) Get(addr *objectSDK.Address) (*object.Object, error) {
var obj *object.Object
if err := db.boltDB.View(func(tx *bbolt.Tx) error {
primaryBucket := tx.Bucket(primaryBucket)
if primaryBucket == nil {
return errNotFound
}
data := primaryBucket.Get(addressKey(addr))
if data == nil {
return errNotFound
}
var err error
obj, err = object.FromBytes(data)
return err
}); err != nil {
return nil, err
}
return obj, nil
}