mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
fix bug: should use Lock when mutating the flag (#1141)
* should use Lock when mutating the flag * same problem in MVHashMap.Write * hole the rlock while reading WriteCell --------- Co-authored-by: zhiqiangxu <652732310@qq.com>
This commit is contained in:
parent
c629c0fdb6
commit
c559619c80
1 changed files with 14 additions and 23 deletions
|
|
@ -121,34 +121,23 @@ func (mv *MVHashMap) Write(k Key, v Version, data interface{}) {
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
cells.rw.RLock()
|
|
||||||
ci, ok := cells.tm.Get(v.TxnIndex)
|
|
||||||
cells.rw.RUnlock()
|
|
||||||
|
|
||||||
if ok {
|
|
||||||
if ci.(*WriteCell).incarnation > v.Incarnation {
|
|
||||||
panic(fmt.Errorf("existing transaction value does not have lower incarnation: %v, %v",
|
|
||||||
k, v.TxnIndex))
|
|
||||||
}
|
|
||||||
|
|
||||||
ci.(*WriteCell).flag = FlagDone
|
|
||||||
ci.(*WriteCell).incarnation = v.Incarnation
|
|
||||||
ci.(*WriteCell).data = data
|
|
||||||
} else {
|
|
||||||
cells.rw.Lock()
|
cells.rw.Lock()
|
||||||
if ci, ok = cells.tm.Get(v.TxnIndex); !ok {
|
if ci, ok := cells.tm.Get(v.TxnIndex); !ok {
|
||||||
cells.tm.Put(v.TxnIndex, &WriteCell{
|
cells.tm.Put(v.TxnIndex, &WriteCell{
|
||||||
flag: FlagDone,
|
flag: FlagDone,
|
||||||
incarnation: v.Incarnation,
|
incarnation: v.Incarnation,
|
||||||
data: data,
|
data: data,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
if ci.(*WriteCell).incarnation > v.Incarnation {
|
||||||
|
panic(fmt.Errorf("existing transaction value does not have lower incarnation: %v, %v",
|
||||||
|
k, v.TxnIndex))
|
||||||
|
}
|
||||||
ci.(*WriteCell).flag = FlagDone
|
ci.(*WriteCell).flag = FlagDone
|
||||||
ci.(*WriteCell).incarnation = v.Incarnation
|
ci.(*WriteCell).incarnation = v.Incarnation
|
||||||
ci.(*WriteCell).data = data
|
ci.(*WriteCell).data = data
|
||||||
}
|
}
|
||||||
cells.rw.Unlock()
|
cells.rw.Unlock()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mv *MVHashMap) ReadStorage(k Key, fallBack func() any) any {
|
func (mv *MVHashMap) ReadStorage(k Key, fallBack func() any) any {
|
||||||
|
|
@ -166,13 +155,13 @@ func (mv *MVHashMap) MarkEstimate(k Key, txIdx int) {
|
||||||
panic(fmt.Errorf("path must already exist"))
|
panic(fmt.Errorf("path must already exist"))
|
||||||
})
|
})
|
||||||
|
|
||||||
cells.rw.RLock()
|
cells.rw.Lock()
|
||||||
if ci, ok := cells.tm.Get(txIdx); !ok {
|
if ci, ok := cells.tm.Get(txIdx); !ok {
|
||||||
panic(fmt.Sprintf("should not happen - cell should be present for path. TxIdx: %v, path, %x, cells keys: %v", txIdx, k, cells.tm.Keys()))
|
panic(fmt.Sprintf("should not happen - cell should be present for path. TxIdx: %v, path, %x, cells keys: %v", txIdx, k, cells.tm.Keys()))
|
||||||
} else {
|
} else {
|
||||||
ci.(*WriteCell).flag = FlagEstimate
|
ci.(*WriteCell).flag = FlagEstimate
|
||||||
}
|
}
|
||||||
cells.rw.RUnlock()
|
cells.rw.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mv *MVHashMap) Delete(k Key, txIdx int) {
|
func (mv *MVHashMap) Delete(k Key, txIdx int) {
|
||||||
|
|
@ -233,8 +222,8 @@ func (mv *MVHashMap) Read(k Key, txIdx int) (res MVReadResult) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cells.rw.RLock()
|
cells.rw.RLock()
|
||||||
|
|
||||||
fk, fv := cells.tm.Floor(txIdx - 1)
|
fk, fv := cells.tm.Floor(txIdx - 1)
|
||||||
cells.rw.RUnlock()
|
|
||||||
|
|
||||||
if fk != nil && fv != nil {
|
if fk != nil && fv != nil {
|
||||||
c := fv.(*WriteCell)
|
c := fv.(*WriteCell)
|
||||||
|
|
@ -253,6 +242,8 @@ func (mv *MVHashMap) Read(k Key, txIdx int) (res MVReadResult) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cells.rw.RUnlock()
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue