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

This commit is contained in:
刘祥超
2023-11-23 17:14:50 +08:00
parent 2633d43897
commit c39b1c794f
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()

View File

@@ -125,6 +125,13 @@ func TestFileListHashMap_Delete(t *testing.T) {
a.IsTrue(m.Len() == 0)
}
func TestFileListHashMap_Clean(t *testing.T) {
var m = caches.NewFileListHashMap()
m.SetIsAvailable(true)
m.Clean()
m.Add("a")
}
func Benchmark_BigInt(b *testing.B) {
var hash = stringutil.Md5("123456")
b.ResetTimer()