frostfs-node/pkg/local_object_storage/shard/put.go
Leonard Lyubich df558cbe6b [#176] shard: Get rid of using the global RW lock
In previous implementation each shard operation locked
RW shard mutex. With this approach RW operations were executed
one-by-one and blocked the execution of RO operations.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-12-11 17:19:37 +03:00

58 lines
1.4 KiB
Go

package shard
import (
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
"github.com/pkg/errors"
)
// PutPrm groups the parameters of Put operation.
type PutPrm struct {
obj *object.Object
}
// PutRes groups resulting values of Put operation.
type PutRes struct{}
// WithObject is a Put option to set object to save.
func (p *PutPrm) WithObject(obj *object.Object) *PutPrm {
if p != nil {
p.obj = obj
}
return p
}
// Put saves the object in shard.
//
// Returns any error encountered that
// did not allow to completely save the object.
func (s *Shard) Put(prm *PutPrm) (*PutRes, error) {
// check object existence
ex, err := s.metaBase.Exists(prm.obj.Address())
if err != nil {
return nil, errors.Wrap(err, "could not check object existence")
} else if ex {
return nil, nil
}
// try to put to WriteCache
// TODO: implement
// put to BlobStor
if _, err := s.blobStor.Put(
new(blobstor.PutPrm).
WithObject(prm.obj),
); err != nil {
return nil, errors.Wrap(err, "could not put object to BLOB storage")
}
// put to metabase
if err := s.metaBase.Put(prm.obj); err != nil {
// may we need to handle this case in a special way
// since the object has been successfully written to BlobStor
return nil, errors.Wrap(err, "could not put object to metabase")
}
return nil, nil
}