Skip to content

Commit

Permalink
feat: erasuredata mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Nov 21, 2023
1 parent 16f7480 commit c85a884
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/file/redundancy/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type inflightChunk struct {
// it caches sibling chunks if erasure decoding was called on the level already
type getter struct {
storage.Getter
mu sync.Mutex
sAddresses []swarm.Address // shard addresses
pAddresses []swarm.Address // parity addresses
cache map[string]inflightChunk // map from chunk address to cached shard chunk data
Expand Down Expand Up @@ -75,8 +76,15 @@ func (g *getter) Get(ctx context.Context, addr swarm.Address) (swarm.Chunk, erro
return g.executeStrategies(ctx, addr)
}

// Inc increments the counter for the given key.
func (g *getter) setErasureData(index int, data []byte) {
g.mu.Lock()
g.erasureData[index] = data
g.mu.Unlock()
}

// processing returns whether the recovery workflow has been started
func (g getter) processing(addr swarm.Address) bool {
func (g *getter) processing(addr swarm.Address) bool {
_, ok := g.cache[addr.String()]
return ok
}
Expand Down Expand Up @@ -147,7 +155,7 @@ func (g *getter) cautiousStrategy(ctx context.Context) error {
if err != nil {
return
}
g.erasureData[c.pos] = ch.Data()
g.setErasureData(c.pos, ch.Data())
close(c.wait)
retrievedCh <- struct{}{}
}(a, c)
Expand All @@ -161,7 +169,7 @@ func (g *getter) cautiousStrategy(ctx context.Context) error {
if err != nil {
return
}
g.erasureData[c.pos] = ch.Data()
g.setErasureData(c.pos, ch.Data())
retrievedCh <- struct{}{}
}(a, c)
}
Expand Down

0 comments on commit c85a884

Please sign in to comment.