enhance(datanode): remove mutex for extent repair read

close:#21999366

Signed-off-by: chihe <chihe@oppo.com>
This commit is contained in:
chihe 2024-03-21 19:43:05 +08:00 committed by leonrayang
parent be9c0c9896
commit 78d380a60a
2 changed files with 6 additions and 27 deletions

View File

@ -88,7 +88,6 @@ type Disk struct {
decommission bool
extentRepairReadLimit chan struct{}
enableExtentRepairReadLimit bool
extentRepairReadMutex sync.RWMutex
extentRepairReadDp uint64
}
@ -757,25 +756,19 @@ func isExpiredPartition(id uint64, partitions []uint64) bool {
}
func (d *Disk) RequireReadExtentToken(id uint64) bool {
d.extentRepairReadMutex.Lock()
defer d.extentRepairReadMutex.Unlock()
if !d.enableExtentRepairReadLimit {
return true
}
hasToken := false
select {
case <-d.extentRepairReadLimit:
hasToken = true
d.extentRepairReadDp = id
return true
default:
hasToken = false
return false
}
return hasToken
}
func (d *Disk) ReleaseReadExtentToken() {
d.extentRepairReadMutex.Lock()
defer d.extentRepairReadMutex.Unlock()
if !d.enableExtentRepairReadLimit {
return
}
@ -789,13 +782,9 @@ func (d *Disk) ReleaseReadExtentToken() {
}
func (d *Disk) SetExtentRepairReadLimitStatus(status bool) {
d.extentRepairReadMutex.Lock()
defer d.extentRepairReadMutex.Unlock()
d.enableExtentRepairReadLimit = status
}
func (d *Disk) QueryExtentRepairReadLimitStatus() (bool, uint64) {
d.extentRepairReadMutex.RLock()
defer d.extentRepairReadMutex.RUnlock()
return d.enableExtentRepairReadLimit, d.extentRepairReadDp
}

View File

@ -944,25 +944,15 @@ func (s *DataNode) handleStreamReadPacket(p *repl.Packet, connect net.Conn, isRe
func (s *DataNode) handleExtentRepairReadPacket(p *repl.Packet, connect net.Conn, isRepairRead bool) {
var (
err error
getExtentReadToken = false
err error
)
defer func() {
if getExtentReadToken {
fininshDoExtentRepair()
}
if err != nil {
p.PackErrorBody(ActionStreamRead, err.Error())
p.WriteToConn(connect)
return
}
}()
err = requestDoExtentRepair()
if err != nil {
p.PackErrorBody(ActionStreamRead, err.Error())
p.WriteToConn(connect)
return
}
getExtentReadToken = true
defer fininshDoExtentRepair()
partition := p.Object.(*DataPartition)
if !partition.disk.RequireReadExtentToken(partition.partitionID) {
err = storage.NoDiskReadRepairExtentTokenError