deadlock fixed i guess

master
cheetah 2 years ago
parent e19548a0b6
commit ec9bbe8a6c

@ -438,12 +438,13 @@ func (p *PoolMaster) PackPool(poolID string) (packResult PoolPackResult, err err
startTime := time.Now() startTime := time.Now()
packResult.PoolID = poolID packResult.PoolID = poolID
fmt.Printf("Aquiring Lock for PackPool(%s)\n", poolID) /*
p.lock.Lock() fmt.Printf("Aquiring Lock for PackPool(%s)\n", poolID)
defer p.lock.Unlock() p.lock.Lock()
defer fmt.Printf("unlock PackPool\n") defer p.lock.Unlock()
fmt.Printf("Aquired Lock success for PackPool(%s)\n", poolID) defer fmt.Printf("unlock PackPool\n")
fmt.Printf("Aquired Lock success for PackPool(%s)\n", poolID)
*/
packResult.outputFileName = filepath.Join(p.cachePath, "pool", fmt.Sprintf("%s.tar", poolID)) packResult.outputFileName = filepath.Join(p.cachePath, "pool", fmt.Sprintf("%s.tar", poolID))
tarFile, err := os.Create(packResult.outputFileName) tarFile, err := os.Create(packResult.outputFileName)
if err != nil { if err != nil {
@ -804,7 +805,8 @@ func main() {
go func() { go func() {
for { for {
for index, fullPool := range poolMaster.FullPools { var deletedPools []string
for _, fullPool := range poolMaster.FullPools {
poolMaster.lock.Lock() poolMaster.lock.Lock()
packResult, err := poolMaster.PackPool(fullPool.PoolID) packResult, err := poolMaster.PackPool(fullPool.PoolID)
@ -820,10 +822,17 @@ func main() {
panic(err) panic(err)
} }
os.RemoveAll(filepath.Join(poolMaster.cachePath, "pool", fullPool.PoolID)) os.RemoveAll(filepath.Join(poolMaster.cachePath, "pool", fullPool.PoolID))
poolMaster.FullPools = removeFromSlice(poolMaster.FullPools, index) deletedPools = append(deletedPools, fullPool.PoolID)
poolMaster.lock.Unlock() poolMaster.lock.Unlock()
} }
for _, deletedPoolID := range deletedPools {
for index, fullPool := range poolMaster.FullPools {
if fullPool.PoolID == deletedPoolID {
poolMaster.FullPools = removeFromSlice(poolMaster.FullPools, index)
break
}
}
}
time.Sleep(time.Second * 10) time.Sleep(time.Second * 10)
} }
}() }()

Loading…
Cancel
Save