Chris Lu
12 years ago
4 changed files with 112 additions and 75 deletions
-
52weed-fs/src/pkg/topology/topology.go
-
56weed-fs/src/pkg/topology/topology_event_handling.go
-
40weed-fs/src/pkg/topology/volume_layout.go
-
25weed-fs/src/pkg/topology/volume_location.go
@ -0,0 +1,56 @@ |
|||
package topology |
|||
|
|||
import ( |
|||
"fmt" |
|||
"math/rand" |
|||
"pkg/storage" |
|||
"time" |
|||
) |
|||
|
|||
func (t *Topology) StartRefreshWritableVolumes() { |
|||
go func() { |
|||
for { |
|||
freshThreshHold := time.Now().Unix() - 3*t.pulse //5 times of sleep interval
|
|||
t.CollectDeadNodeAndFullVolumes(freshThreshHold, t.volumeSizeLimit) |
|||
time.Sleep(time.Duration(float32(t.pulse*1e3)*(1+rand.Float32())) * time.Millisecond) |
|||
} |
|||
}() |
|||
go func() { |
|||
for { |
|||
select { |
|||
case v := <-t.chanIncomplemteVolumes: |
|||
fmt.Println("Volume", v, "is incomplete!") |
|||
case v := <-t.chanRecoveredVolumes: |
|||
fmt.Println("Volume", v, "is recovered!") |
|||
case v := <-t.chanFullVolumes: |
|||
t.SetVolumeCapacityFull(v) |
|||
fmt.Println("Volume", v, "is full!") |
|||
case dn := <-t.chanRecoveredDataNodes: |
|||
t.RegisterRecoveredDataNode(dn) |
|||
fmt.Println("DataNode", dn, "is back alive!") |
|||
case dn := <-t.chanDeadDataNodes: |
|||
t.UnRegisterDataNode(dn) |
|||
fmt.Println("DataNode", dn, "is dead!") |
|||
} |
|||
} |
|||
}() |
|||
} |
|||
func (t *Topology) SetVolumeCapacityFull(volumeInfo *storage.VolumeInfo) { |
|||
vl := t.GetVolumeLayout(volumeInfo.RepType) |
|||
vl.SetVolumeCapacityFull(volumeInfo.Id) |
|||
} |
|||
func (t *Topology) UnRegisterDataNode(dn *DataNode) { |
|||
for _, v := range dn.volumes { |
|||
fmt.Println("Removing Volume", v.Id, "from the dead volume server", dn) |
|||
vl := t.GetVolumeLayout(v.RepType) |
|||
vl.SetVolumeUnavailable(dn, v.Id) |
|||
} |
|||
} |
|||
func (t *Topology) RegisterRecoveredDataNode(dn *DataNode) { |
|||
for _, v := range dn.volumes { |
|||
if uint64(v.Size) < t.volumeSizeLimit { |
|||
vl := t.GetVolumeLayout(v.RepType) |
|||
vl.SetVolumeAvailable(dn, v.Id) |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue