forked from TrueCloudLab/frostfs-node
[#762] storage/shard: Try to read headers from write-cache
Shard should try to read object headers from write-cache if it is enabled. Extend `writecache.Cache` interface with `Head` method. Call the method in `Shard.Head` if `Shard.hasWriteCache` returns true. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
aa2151fbeb
commit
3f293cb55e
2 changed files with 27 additions and 3 deletions
|
@ -1,6 +1,9 @@
|
|||
package shard
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||
|
@ -48,13 +51,33 @@ func (r *HeadRes) Object() *object.Object {
|
|||
//
|
||||
// Returns any error encountered.
|
||||
func (s *Shard) Head(prm *HeadPrm) (*HeadRes, error) {
|
||||
// object can be saved in write-cache (if enabled) or in metabase
|
||||
|
||||
if s.hasWriteCache() {
|
||||
// try to read header from write-cache
|
||||
header, err := s.writeCache.Head(prm.addr)
|
||||
if err == nil {
|
||||
return &HeadRes{
|
||||
obj: header,
|
||||
}, nil
|
||||
} else if !errors.Is(err, object.ErrNotFound) {
|
||||
// in this case we think that object is presented in write-cache, but corrupted
|
||||
return nil, fmt.Errorf("could not read header from write-cache: %w", err)
|
||||
}
|
||||
|
||||
// otherwise object seems to be flushed to metabase
|
||||
}
|
||||
|
||||
headParams := new(meta.GetPrm).
|
||||
WithAddress(prm.addr).
|
||||
WithRaw(prm.raw)
|
||||
|
||||
head, err := s.metaBase.Get(headParams)
|
||||
res, err := s.metaBase.Get(headParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &HeadRes{
|
||||
obj: head.Header(),
|
||||
}, err
|
||||
obj: res.Header(),
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
// Cache represents write-cache for objects.
|
||||
type Cache interface {
|
||||
Get(*objectSDK.Address) (*object.Object, error)
|
||||
Head(*objectSDK.Address) (*object.Object, error)
|
||||
Delete(*objectSDK.Address) error
|
||||
Put(*object.Object) error
|
||||
|
||||
|
|
Loading…
Reference in a new issue