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

45 lines
819 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{}
}
func (dnll *DataNodeLocationList) Head() *DataNode {
return dnll.list[0]
}
func (dnll *DataNodeLocationList) Add(loc *DataNode) bool {
2012-09-11 08:08:52 +08:00
for _, dnl := range dnll.list {
2012-09-12 16:07:23 +08:00
if loc.Ip == dnl.Ip && loc.Port == dnl.Port {
return false
2012-09-11 08:08:52 +08:00
}
}
dnll.list = append(dnll.list, loc)
return true
2012-09-11 08:08:52 +08:00
}
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
}
}