Skip to content

Commit

Permalink
Fix: refresh leader status, prevent master from getting an `Unavailab…
Browse files Browse the repository at this point in the history
…le` leader for data partition

Signed-off-by: xuxihao <[email protected]>
  • Loading branch information
xuxihao1 committed Jun 18, 2020
1 parent d2eee4e commit d1aed97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions master/data_partition_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,24 @@ func (partition *DataPartition) checkReplicaStatusOnLiveNode(liveReplicas []*Dat
}

func (partition *DataPartition) checkReplicaStatus(timeOutSec int64) {
partition.RLock()
defer partition.RUnlock()
partition.Lock()
defer partition.Unlock()
for _, replica := range partition.Replicas {
replica.isLive(timeOutSec)
if !replica.isLive(timeOutSec) {
replica.Status = proto.Unavailable
}
}
}

func (partition *DataPartition) checkLeader(timeOut int64) {
partition.Lock()
defer partition.Unlock()
for _, dr := range partition.Replicas {
if !dr.isLive(timeOut) {
dr.IsLeader = false
}
}
return
}

// Check if there is any missing replica for a data partition.
Expand Down
2 changes: 1 addition & 1 deletion master/vol.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (vol *Vol) checkDataPartitions(c *Cluster) (cnt int) {
for _, dp := range vol.dataPartitions.partitionMap {
dp.checkReplicaStatus(c.cfg.DataPartitionTimeOutSec)
dp.checkStatus(c.Name, true, c.cfg.DataPartitionTimeOutSec)

dp.checkLeader(c.cfg.DataPartitionTimeOutSec)
dp.checkMissingReplicas(c.Name, c.leaderInfo.addr, c.cfg.MissingDataPartitionInterval, c.cfg.IntervalToAlarmMissingDataPartition)
dp.checkReplicaNum(c, vol)
if dp.Status == proto.ReadWrite {
Expand Down

0 comments on commit d1aed97

Please sign in to comment.