frostfs-node/pkg/local_object_storage/writecache/put.go
Leonard Lyubich 3258d9c616 [#790] writecache: Log each writing operation
Call `storagelog.Write` in all places after the successful writing op.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-09-13 15:02:13 +03:00

48 lines
939 B
Go

package writecache
import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
)
// ErrBigObject is returned when object is too big to be placed in cache.
var ErrBigObject = errors.New("too big object")
// Put puts object to write-cache.
func (c *cache) Put(o *object.Object) error {
sz := uint64(o.ToV2().StableSize())
if sz > c.maxObjectSize {
return ErrBigObject
}
data, err := o.Marshal(nil)
if err != nil {
return err
}
oi := objectInfo{
addr: o.Address().String(),
obj: o,
data: data,
}
c.mtx.Lock()
if sz < c.smallObjectSize && c.curMemSize+sz <= c.maxMemSize {
c.curMemSize += sz
c.mem = append(c.mem, oi)
c.mtx.Unlock()
storagelog.Write(c.log, storagelog.AddressField(oi.addr), storagelog.OpField("in-mem PUT"))
return nil
}
c.mtx.Unlock()
c.persistObjects([]objectInfo{oi})
return nil
}