Skip to content

Commit cd7bdc8

Browse files
author
yxq
committed
fix: chunkStatusCacheMutex unlock bug
1 parent d54b150 commit cd7bdc8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

system/p2p/dht/protocol/p2pstore/refresh.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@ func (p *Protocol) refreshLocalChunk() {
3737
}
3838

3939
// 通过网络从其他节点获取数据
40-
p.chunkStatusCacheMutex.Lock()
41-
chunkHash := hex.EncodeToString(info.ChunkHash)
42-
if _, ok := p.chunkStatusCache[hex.EncodeToString(info.ChunkHash)]; ok {
40+
if exist := p.addChunkStatus(ChunkStatus{info: msg, status: Waiting}); exist {
4341
continue
4442
}
45-
p.chunkStatusCache[chunkHash] = ChunkStatus{info: msg, status: Waiting}
46-
p.chunkStatusCacheMutex.Unlock()
4743
syncNum++
4844
p.chunkToSync <- msg
4945
} else {
@@ -54,6 +50,18 @@ func (p *Protocol) refreshLocalChunk() {
5450
log.Info("refreshLocalChunk", "save num", saveNum, "sync num", syncNum, "delete num", deleteNum, "time cost", time.Since(start), "exRT size", p.getExtendRoutingTable().Size())
5551
}
5652

53+
func (p *Protocol) addChunkStatus(status ChunkStatus) (exist bool) {
54+
p.chunkStatusCacheMutex.Lock()
55+
defer p.chunkStatusCacheMutex.Unlock()
56+
chunkHash := hex.EncodeToString(status.info.ChunkHash)
57+
if _, ok := p.chunkStatusCache[chunkHash]; ok {
58+
exist = true
59+
return
60+
}
61+
p.chunkStatusCache[chunkHash] = status
62+
return
63+
}
64+
5765
func (p *Protocol) shouldSave(chunkHash []byte) bool {
5866
if p.SubConfig.IsFullNode {
5967
return true

0 commit comments

Comments
 (0)