aboutsummaryrefslogtreecommitdiff
path: root/weed/topology/volume_location.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-02-10 03:25:35 -0800
committerChris Lu <chris.lu@gmail.com>2013-02-10 03:25:35 -0800
commitab6fb13ad795763ba7fc7c91696d2890be6da543 (patch)
tree3d956452bdcef7ea4b50457faff07df06f8d4346 /weed/topology/volume_location.go
parent1b6f53cdac9a44370f67276ede138f5cde8806c2 (diff)
downloadseaweedfs-ab6fb13ad795763ba7fc7c91696d2890be6da543.tar.xz
seaweedfs-ab6fb13ad795763ba7fc7c91696d2890be6da543.zip
avoid the "src" folder
Diffstat (limited to 'weed/topology/volume_location.go')
-rw-r--r--weed/topology/volume_location.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/weed/topology/volume_location.go b/weed/topology/volume_location.go
new file mode 100644
index 000000000..507a240b5
--- /dev/null
+++ b/weed/topology/volume_location.go
@@ -0,0 +1,58 @@
+package topology
+
+import ()
+
+type VolumeLocationList struct {
+ list []*DataNode
+}
+
+func NewVolumeLocationList() *VolumeLocationList {
+ return &VolumeLocationList{}
+}
+
+func (dnll *VolumeLocationList) Head() *DataNode {
+ return dnll.list[0]
+}
+
+func (dnll *VolumeLocationList) Length() int {
+ return len(dnll.list)
+}
+
+func (dnll *VolumeLocationList) Add(loc *DataNode) bool {
+ for _, dnl := range dnll.list {
+ if loc.Ip == dnl.Ip && loc.Port == dnl.Port {
+ return false
+ }
+ }
+ dnll.list = append(dnll.list, loc)
+ return true
+}
+
+func (dnll *VolumeLocationList) Remove(loc *DataNode) bool {
+ 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
+}
+
+func (dnll *VolumeLocationList) 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
+ }
+}