Commit ed0969b7 authored by Esad Akar's avatar Esad Akar Committed by GitHub

fix(pushsync): store chunk only once (#1749)

parent 4a30a526
...@@ -181,10 +181,13 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream) ...@@ -181,10 +181,13 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)
} }
// forwarding replication // forwarding replication
storedChunk := false
if ps.topologyDriver.IsWithinDepth(chunk.Address()) { if ps.topologyDriver.IsWithinDepth(chunk.Address()) {
_, err = ps.storer.Put(ctx, storage.ModePutSync, chunk) _, err = ps.storer.Put(ctx, storage.ModePutSync, chunk)
if err != nil { if err != nil {
ps.logger.Warningf("pushsync: within depth peer's attempt to store chunk failed: %v", err) ps.logger.Warningf("pushsync: within depth peer's attempt to store chunk failed: %v", err)
} else {
storedChunk = true
} }
} }
...@@ -194,9 +197,11 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream) ...@@ -194,9 +197,11 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)
receipt, err := ps.pushToClosest(ctx, chunk, false) receipt, err := ps.pushToClosest(ctx, chunk, false)
if err != nil { if err != nil {
if errors.Is(err, topology.ErrWantSelf) { if errors.Is(err, topology.ErrWantSelf) {
_, err = ps.storer.Put(ctx, storage.ModePutSync, chunk) if !storedChunk {
if err != nil { _, err = ps.storer.Put(ctx, storage.ModePutSync, chunk)
return fmt.Errorf("chunk store: %w", err) if err != nil {
return fmt.Errorf("chunk store: %w", err)
}
} }
count := 0 count := 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment