master
cheetah 1 year ago
parent e70dbb5a81
commit 159a87faf7

@ -683,6 +683,8 @@ func (p *PoolMaster) AcquireNewOrRecoverPool() (pool *Pool, err error) {
} }
func (p *PoolMaster) Lookup(id string) (exists bool) { func (p *PoolMaster) Lookup(id string) (exists bool) {
p.lock.Lock()
defer p.lock.Unlock()
for _, cp := range p.CurrentPool { for _, cp := range p.CurrentPool {
if cp != nil { // CurrentPool if cp != nil { // CurrentPool
for _, poolItem := range cp.items { for _, poolItem := range cp.items {
@ -692,8 +694,6 @@ func (p *PoolMaster) Lookup(id string) (exists bool) {
} }
} }
} }
p.lock.Lock()
defer p.lock.Unlock()
for _, wormPool := range p.WORMPools { // WORM Pools for _, wormPool := range p.WORMPools { // WORM Pools
for _, poolItem := range wormPool.items { for _, poolItem := range wormPool.items {
if poolItem == id { if poolItem == id {
@ -877,6 +877,9 @@ func (p *PoolMaster) PackFullPools() (err error) {
} }
func (p *PoolMaster) Fetch(id string, writer io.Writer) (err error) { func (p *PoolMaster) Fetch(id string, writer io.Writer) (err error) {
var unlocKOnce sync.Once
p.lock.Lock()
defer unlocKOnce.Do(p.lock.Unlock)
for _, cp := range p.CurrentPool { for _, cp := range p.CurrentPool {
if cp != nil { if cp != nil {
for _, poolItem := range cp.items { for _, poolItem := range cp.items {
@ -900,17 +903,15 @@ func (p *PoolMaster) Fetch(id string, writer io.Writer) (err error) {
} }
} }
} }
p.lock.Lock()
for _, wormPool := range p.WORMPools { for _, wormPool := range p.WORMPools {
for _, poolItem := range wormPool.items { for _, poolItem := range wormPool.items {
if poolItem == id { if poolItem == id {
fmt.Printf("Fetch WORMPool %s file %s\n", wormPool.PoolID, id) fmt.Printf("Fetch WORMPool %s file %s\n", wormPool.PoolID, id)
p.lock.Unlock()
return wormPool.Fetch(id, writer) return wormPool.Fetch(id, writer)
} }
} }
} }
p.lock.Unlock() unlocKOnce.Do(p.lock.Unlock)
for _, fullPool := range p.FullPools { for _, fullPool := range p.FullPools {
for _, poolItem := range fullPool.items { for _, poolItem := range fullPool.items {
if poolItem == id { if poolItem == id {

Loading…
Cancel
Save