[#1462] fstree: Allow to fetch file content lazily
If we should process address based on some condition, there is no need to read file content in memory. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
54d4503701
commit
f2a7503964
3 changed files with 37 additions and 9 deletions
|
@ -138,13 +138,19 @@ func (c *cache) flushBigObjects() {
|
|||
evictNum := 0
|
||||
|
||||
var prm fstree.IterationPrm
|
||||
prm.WithHandler(func(addr oid.Address, data []byte) error {
|
||||
prm.WithLazyHandler(func(addr oid.Address, f func() ([]byte, error)) error {
|
||||
sAddr := addr.EncodeToString()
|
||||
|
||||
if _, ok := c.store.flushed.Peek(sAddr); ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
data, err := f()
|
||||
if err != nil {
|
||||
c.log.Error("can't read a file", zap.Stringer("address", addr))
|
||||
return nil
|
||||
}
|
||||
|
||||
c.mtx.Lock()
|
||||
_, compress := c.compressFlags[sAddr]
|
||||
c.mtx.Unlock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue