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,35 +121,24 @@ func (mv *MVHashMap) Write(k Key, v Version, data interface{}) {
|
|||
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()
|
||||
if ci, ok = cells.tm.Get(v.TxnIndex); !ok {
|
||||
if ci, ok := cells.tm.Get(v.TxnIndex); !ok {
|
||||
cells.tm.Put(v.TxnIndex, &WriteCell{
|
||||
flag: FlagDone,
|
||||
incarnation: v.Incarnation,
|
||||
data: data,
|
||||
})
|
||||
} 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).incarnation = v.Incarnation
|
||||
ci.(*WriteCell).data = data
|
||||
}
|
||||
cells.rw.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (mv *MVHashMap) ReadStorage(k Key, fallBack func() any) any {
|
||||
data, ok := mv.s.Load(string(k[:]))
|
||||
|
|
@ -166,13 +155,13 @@ func (mv *MVHashMap) MarkEstimate(k Key, txIdx int) {
|
|||
panic(fmt.Errorf("path must already exist"))
|
||||
})
|
||||
|
||||
cells.rw.RLock()
|
||||
cells.rw.Lock()
|
||||
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()))
|
||||
} else {
|
||||
ci.(*WriteCell).flag = FlagEstimate
|
||||
}
|
||||
cells.rw.RUnlock()
|
||||
cells.rw.Unlock()
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
fk, fv := cells.tm.Floor(txIdx - 1)
|
||||
cells.rw.RUnlock()
|
||||
|
||||
if fk != nil && fv != nil {
|
||||
c := fv.(*WriteCell)
|
||||
|
|
@ -253,6 +242,8 @@ func (mv *MVHashMap) Read(k Key, txIdx int) (res MVReadResult) {
|
|||
}
|
||||
}
|
||||
|
||||
cells.rw.RUnlock()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue