fix(master): fix some potential deadlock issues.

Signed-off-by: Victor1319 <zengxuewei@oppo.com>
This commit is contained in:
Victor1319 2024-07-08 10:40:26 +08:00 committed by chihe
parent 68d6fd7229
commit 4aa22112e5
4 changed files with 5 additions and 10 deletions

View File

@ -819,8 +819,6 @@ func (c *Cluster) checkDataNodeHeartbeat() {
func (c *Cluster) checkMetaNodeHeartbeat() {
tasks := make([]*proto.AdminTask, 0)
c.volMutex.RLock()
defer c.volMutex.RUnlock()
c.metaNodes.Range(func(addr, metaNode interface{}) bool {
node := metaNode.(*MetaNode)
@ -828,6 +826,9 @@ func (c *Cluster) checkMetaNodeHeartbeat() {
task := node.createHeartbeatTask(c.masterAddr(), c.fileStatsEnable)
hbReq := task.Request.(*proto.HeartBeatRequest)
c.volMutex.RLock()
defer c.volMutex.RUnlock()
for _, vol := range c.vols {
if vol.FollowerRead {
hbReq.FLReadVols = append(hbReq.FLReadVols, vol.Name)

View File

@ -880,8 +880,6 @@ func (partition *DataPartition) getMinus() (minus float64) {
}
func (partition *DataPartition) activeUsedSimilar() bool {
partition.RLock()
defer partition.RUnlock()
liveReplicas := partition.liveReplicas(defaultDataPartitionTimeOutSec)
used := liveReplicas[0].Used
minus := float64(0)

View File

@ -819,9 +819,6 @@ func (mp *MetaPartition) getMinusOfMaxInodeID() (minus float64) {
}
func (mp *MetaPartition) activeMaxInodeSimilar() bool {
mp.RLock()
defer mp.RUnlock()
minus := float64(0)
var sentry float64
replicas := mp.getLiveReplicas()

View File

@ -739,10 +739,9 @@ func (mm *monitorMetrics) setMpInconsistentErrorMetric() {
deleteMps[k] = v
delete(mm.inconsistentMps, k)
}
mm.cluster.volMutex.RLock()
defer mm.cluster.volMutex.RUnlock()
for _, vol := range mm.cluster.vols {
vols := mm.cluster.copyVols()
for _, vol := range vols {
if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && vol.DeleteExecTime.Sub(time.Now()) <= 0) {
continue
}