From 1c100fb4b0c3d2b6d73213e20c588b9c8108c018 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 20 May 2022 18:43:05 +0300 Subject: [PATCH] [#1418] writecache: Do not use pointers as parameters Signed-off-by: Pavel Karpy --- pkg/local_object_storage/shard/dump.go | 9 +++++++-- pkg/local_object_storage/writecache/iterate.go | 8 +++----- pkg/local_object_storage/writecache/writecache.go | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/local_object_storage/shard/dump.go b/pkg/local_object_storage/shard/dump.go index 667a72ec2..4f39366e8 100644 --- a/pkg/local_object_storage/shard/dump.go +++ b/pkg/local_object_storage/shard/dump.go @@ -81,7 +81,10 @@ func (s *Shard) Dump(prm *DumpPrm) (*DumpRes, error) { var count int if s.hasWriteCache() { - err := s.writeCache.Iterate(new(writecache.IterationPrm).WithHandler(func(data []byte) error { + var iterPrm writecache.IterationPrm + + iterPrm.WithIgnoreErrors(prm.ignoreErrors) + iterPrm.WithHandler(func(data []byte) error { var size [4]byte binary.LittleEndian.PutUint32(size[:], uint32(len(data))) if _, err := w.Write(size[:]); err != nil { @@ -94,7 +97,9 @@ func (s *Shard) Dump(prm *DumpPrm) (*DumpRes, error) { count++ return nil - }).WithIgnoreErrors(prm.ignoreErrors)) + }) + + err := s.writeCache.Iterate(iterPrm) if err != nil { return nil, err } diff --git a/pkg/local_object_storage/writecache/iterate.go b/pkg/local_object_storage/writecache/iterate.go index a1e598374..9b810b514 100644 --- a/pkg/local_object_storage/writecache/iterate.go +++ b/pkg/local_object_storage/writecache/iterate.go @@ -19,21 +19,19 @@ type IterationPrm struct { } // WithHandler sets a callback to be executed on every object. -func (p *IterationPrm) WithHandler(f func([]byte) error) *IterationPrm { +func (p *IterationPrm) WithHandler(f func([]byte) error) { p.handler = f - return p } // WithIgnoreErrors sets a flag indicating that errors should be ignored. -func (p *IterationPrm) WithIgnoreErrors(ignore bool) *IterationPrm { +func (p *IterationPrm) WithIgnoreErrors(ignore bool) { p.ignoreErrors = ignore - return p } // Iterate iterates over all objects present in write cache. // This is very difficult to do correctly unless write-cache is put in read-only mode. // Thus we silently fail if shard is not in read-only mode to avoid reporting misleading results. -func (c *cache) Iterate(prm *IterationPrm) error { +func (c *cache) Iterate(prm IterationPrm) error { c.modeMtx.RLock() defer c.modeMtx.RUnlock() if !c.readOnly() { diff --git a/pkg/local_object_storage/writecache/writecache.go b/pkg/local_object_storage/writecache/writecache.go index e28b8bf91..59826370c 100644 --- a/pkg/local_object_storage/writecache/writecache.go +++ b/pkg/local_object_storage/writecache/writecache.go @@ -20,7 +20,7 @@ type Cache interface { Get(address oid.Address) (*object.Object, error) Head(oid.Address) (*object.Object, error) Delete(oid.Address) error - Iterate(*IterationPrm) error + Iterate(IterationPrm) error Put(*object.Object) error SetMode(Mode) DumpInfo() Info