forked from TrueCloudLab/frostfs-node
[#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
|
@ -53,10 +53,17 @@ func (c *cache) Iterate(prm IterationPrm) error {
|
|||
|
||||
var fsPrm fstree.IterationPrm
|
||||
fsPrm.WithIgnoreErrors(prm.ignoreErrors)
|
||||
fsPrm.WithHandler(func(addr oid.Address, data []byte) error {
|
||||
fsPrm.WithLazyHandler(func(addr oid.Address, f func() ([]byte, error)) error {
|
||||
if _, ok := c.flushed.Peek(addr.EncodeToString()); ok {
|
||||
return nil
|
||||
}
|
||||
data, err := f()
|
||||
if err != nil {
|
||||
if prm.ignoreErrors {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
return prm.handler(data)
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue