修复清空文件索引Map时产生并发异常

This commit is contained in:
GoEdgeLab
2023-11-23 17:14:50 +08:00
parent d42ccfcafb
commit d11f6574a3
2 changed files with 11 additions and 1 deletions

View File

@@ -133,7 +133,10 @@ func (this *FileListHashMap) Clean() {
this.lockers[i].Lock()
}
this.m = make([]map[uint64]zero.Zero, HashMapSharding)
// 这里不能简单清空 this.m ,避免导致别的数据无法写入 map 而产生 panic
for i := 0; i < HashMapSharding; i++ {
this.m[i] = map[uint64]zero.Zero{}
}
for i := HashMapSharding - 1; i >= 0; i-- {
this.lockers[i].Unlock()