mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/storage: fix HashExplore concurrency bug ethersphere#1211
This commit is contained in:
parent
27e3f96819
commit
70d17edc89
1 changed files with 5 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"sort"
|
"sort"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -104,6 +105,7 @@ func (f *FileStore) GetAllReferences(ctx context.Context, data io.Reader, toEncr
|
||||||
putter := &HashExplorer{
|
putter := &HashExplorer{
|
||||||
hasherStore: NewHasherStore(f.ChunkStore, f.hashFunc, toEncrypt),
|
hasherStore: NewHasherStore(f.ChunkStore, f.hashFunc, toEncrypt),
|
||||||
References: make([]Reference, 0),
|
References: make([]Reference, 0),
|
||||||
|
lock: &sync.RWMutex{},
|
||||||
}
|
}
|
||||||
// do the actual splitting anyway, no way around it
|
// do the actual splitting anyway, no way around it
|
||||||
_, _, err = PyramidSplit(ctx, data, putter, putter)
|
_, _, err = PyramidSplit(ctx, data, putter, putter)
|
||||||
|
|
@ -123,6 +125,7 @@ func (f *FileStore) GetAllReferences(ctx context.Context, data io.Reader, toEncr
|
||||||
type HashExplorer struct {
|
type HashExplorer struct {
|
||||||
*hasherStore
|
*hasherStore
|
||||||
References []Reference
|
References []Reference
|
||||||
|
lock *sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// HashExplorer's Put will add just the chunk hashes to its `References`
|
// HashExplorer's Put will add just the chunk hashes to its `References`
|
||||||
|
|
@ -133,6 +136,8 @@ func (he *HashExplorer) Put(ctx context.Context, chunkData ChunkData) (Reference
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// internally store the reference
|
// internally store the reference
|
||||||
|
he.lock.Lock()
|
||||||
he.References = append(he.References, ref)
|
he.References = append(he.References, ref)
|
||||||
|
he.lock.Unlock()
|
||||||
return ref, nil
|
return ref, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue