Skip to content

Commit

Permalink
[nspcc-dev#1806] writecache: Allow to ignore read errors during flush
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
  • Loading branch information
fyrchik authored and aprasolova committed Oct 19, 2022
1 parent e548d2d commit 1c381a2
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 88 deletions.
13 changes: 11 additions & 2 deletions pkg/local_object_storage/engine/writecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (

// FlushWriteCachePrm groups the parameters of FlushWriteCache operation.
type FlushWriteCachePrm struct {
shardID *shard.ID
shardID *shard.ID
ignoreErrors bool
}

// SetShardID is an option to set shard ID.
Expand All @@ -16,6 +17,11 @@ func (p *FlushWriteCachePrm) SetShardID(id *shard.ID) {
p.shardID = id
}

// SetIgnoreErrors sets errors ignore flag..
func (p *FlushWriteCachePrm) SetIgnoreErrors(ignore bool) {
p.ignoreErrors = ignore
}

// FlushWriteCacheRes groups the resulting values of FlushWriteCache operation.
type FlushWriteCacheRes struct{}

Expand All @@ -29,5 +35,8 @@ func (e *StorageEngine) FlushWriteCache(p FlushWriteCachePrm) (FlushWriteCacheRe
return FlushWriteCacheRes{}, errShardNotFound
}

return FlushWriteCacheRes{}, sh.FlushWriteCache()
var prm shard.FlushWriteCachePrm
prm.SetIgnoreErrors(p.ignoreErrors)

return FlushWriteCacheRes{}, sh.FlushWriteCache(prm)
}
14 changes: 12 additions & 2 deletions pkg/local_object_storage/shard/writecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
)

// FlushWriteCachePrm represents parameters of a `FlushWriteCache` operation.
type FlushWriteCachePrm struct {
ignoreErrors bool
}

// SetIgnoreErrors sets the flag to ignore read-errors during flush.
func (p *FlushWriteCachePrm) SetIgnoreErrors(ignore bool) {
p.ignoreErrors = ignore
}

// errWriteCacheDisabled is returned when an operation on write-cache is performed,
// but write-cache is disabled.
var errWriteCacheDisabled = errors.New("write-cache is disabled")

// FlushWriteCache moves writecache in read-only mode and flushes all data from it.
// After the operation writecache will remain read-only mode.
func (s *Shard) FlushWriteCache() error {
func (s *Shard) FlushWriteCache(p FlushWriteCachePrm) error {
if !s.hasWriteCache() {
return errWriteCacheDisabled
}
Expand All @@ -32,5 +42,5 @@ func (s *Shard) FlushWriteCache() error {
return err
}

return s.writeCache.Flush()
return s.writeCache.Flush(p.ignoreErrors)
}
15 changes: 14 additions & 1 deletion pkg/local_object_storage/writecache/flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (c *cache) flushObject(obj *object.Object) error {
// Flush flushes all objects from the write-cache to the main storage.
// Write-cache must be in readonly mode to ensure correctness of an operation and
// to prevent interference with background flush workers.
func (c *cache) Flush() error {
func (c *cache) Flush(ignoreErrors bool) error {
c.modeMtx.RLock()
defer c.modeMtx.RUnlock()

Expand All @@ -242,6 +242,7 @@ func (c *cache) Flush() error {
}

var prm common.IteratePrm
prm.IgnoreErrors = ignoreErrors
prm.LazyHandler = func(addr oid.Address, f func() ([]byte, error)) error {
_, ok := c.flushed.Peek(addr.EncodeToString())
if ok {
Expand All @@ -250,12 +251,18 @@ func (c *cache) Flush() error {

data, err := f()
if err != nil {
if ignoreErrors {
return nil
}
return err
}

var obj object.Object
err = obj.Unmarshal(data)
if err != nil {
if ignoreErrors {
return nil
}
return err
}

Expand All @@ -279,11 +286,17 @@ func (c *cache) Flush() error {
}

if err := addr.DecodeString(sa); err != nil {
if ignoreErrors {
continue
}
return err
}

var obj object.Object
if err := obj.Unmarshal(data); err != nil {
if ignoreErrors {
continue
}
return err
}

Expand Down
Loading

0 comments on commit 1c381a2

Please sign in to comment.