Skip to content

Commit

Permalink
Merge pull request #9 from abitduck/bug_fix
Browse files Browse the repository at this point in the history
fix segment error when ring expanded
  • Loading branch information
chenyongwang authored Mar 19, 2019
2 parents 7269cec + eaa9763 commit a0bb070
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions common/ring/hash_ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (r *hashRing) LocalDevices(localPort int) ([]*Device, error) {
d := r.getData()
var devs []*Device
for _, dev := range d.Devs {
if localIPs[dev.ReplicationIp] && dev.ReplicationPort == localPort {
if dev != nil && localIPs[dev.ReplicationIp] && dev.ReplicationPort == localPort {
devs = append(devs, dev)
}
}
Expand Down Expand Up @@ -198,9 +198,11 @@ func (r *hashRing) reload() error {
zoneCount := make(map[regionZone]bool)
ipPortCount := make(map[ipPort]bool)
for _, d := range data.Devs {
regionCount[d.Region] = true
zoneCount[regionZone{d.Region, d.Zone}] = true
ipPortCount[ipPort{d.Region, d.Zone, d.Port, d.Ip}] = true
if d != nil {
regionCount[d.Region] = true
zoneCount[regionZone{d.Region, d.Zone}] = true
ipPortCount[ipPort{d.Region, d.Zone, d.Port, d.Ip}] = true
}
}
data.regionCount = len(regionCount)
data.zoneCount = len(zoneCount)
Expand Down

0 comments on commit a0bb070

Please sign in to comment.