seaweedfs/weed-fs/src/pkg/topology/volume_location.go

40 lines
717 B
Go
Raw Normal View History

package topology
2012-09-11 08:08:52 +08:00
import ()
type DataNodeLocationList struct {
2012-09-11 08:08:52 +08:00
list []*DataNode
}
func NewDataNodeLocationList() *DataNodeLocationList {
2012-09-11 08:08:52 +08:00
return &DataNodeLocationList{}
}
2012-09-11 08:08:52 +08:00
func (dnll *DataNodeLocationList) Add(loc *DataNode) {
for _, dnl := range dnll.list {
2012-09-12 16:07:23 +08:00
if loc.Ip == dnl.Ip && loc.Port == dnl.Port {
2012-09-11 08:08:52 +08:00
break
}
}
dnll.list = append(dnll.list, loc)
}
func (dnll *DataNodeLocationList) Refresh(freshThreshHold int64) {
var changed bool
for _, dnl := range dnll.list {
if dnl.lastSeen < freshThreshHold {
changed = true
break
}
}
if changed {
var l []*DataNode
for _, dnl := range dnll.list {
if dnl.lastSeen >= freshThreshHold {
l = append(l, dnl)
}
}
dnll.list = l
}
}