2012-09-10 15:18:07 +08:00
|
|
|
package topology
|
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
type VolumeLocationList struct {
|
2012-09-11 08:08:52 +08:00
|
|
|
list []*DataNode
|
2012-09-10 15:18:07 +08:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
func NewVolumeLocationList() *VolumeLocationList {
|
|
|
|
return &VolumeLocationList{}
|
2012-09-10 15:18:07 +08:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
func (dnll *VolumeLocationList) Head() *DataNode {
|
2012-09-17 08:31:15 +08:00
|
|
|
return dnll.list[0]
|
|
|
|
}
|
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
func (dnll *VolumeLocationList) Length() int {
|
2013-01-17 16:56:56 +08:00
|
|
|
return len(dnll.list)
|
2012-09-20 07:48:04 +08:00
|
|
|
}
|
|
|
|
|
2014-03-19 19:48:13 +08:00
|
|
|
func (dnll *VolumeLocationList) Set(loc *DataNode) {
|
|
|
|
for i := 0; i < len(dnll.list); i++ {
|
|
|
|
if loc.Ip == dnll.list[i].Ip && loc.Port == dnll.list[i].Port {
|
|
|
|
dnll.list[i] = loc
|
|
|
|
return
|
2012-09-11 08:08:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dnll.list = append(dnll.list, loc)
|
|
|
|
}
|
2012-11-07 17:51:43 +08:00
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
func (dnll *VolumeLocationList) Remove(loc *DataNode) bool {
|
2013-01-17 16:56:56 +08:00
|
|
|
for i, dnl := range dnll.list {
|
|
|
|
if loc.Ip == dnl.Ip && loc.Port == dnl.Port {
|
|
|
|
dnll.list = append(dnll.list[:i], dnll.list[i+1:]...)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2012-09-20 07:48:04 +08:00
|
|
|
}
|
2012-09-11 08:08:52 +08:00
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
func (dnll *VolumeLocationList) Refresh(freshThreshHold int64) {
|
2012-09-11 08:08:52 +08:00
|
|
|
var changed bool
|
|
|
|
for _, dnl := range dnll.list {
|
2012-09-17 16:48:09 +08:00
|
|
|
if dnl.LastSeen < freshThreshHold {
|
2012-09-11 08:08:52 +08:00
|
|
|
changed = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if changed {
|
|
|
|
var l []*DataNode
|
|
|
|
for _, dnl := range dnll.list {
|
2012-09-17 16:48:09 +08:00
|
|
|
if dnl.LastSeen >= freshThreshHold {
|
2012-09-11 08:08:52 +08:00
|
|
|
l = append(l, dnl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dnll.list = l
|
|
|
|
}
|
2012-09-10 15:18:07 +08:00
|
|
|
}
|