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

31 lines
579 B
Go
Raw Normal View History

2012-08-24 13:33:37 +08:00
package topology
import (
"math/rand"
"pkg/storage"
2012-09-02 04:17:30 +08:00
_ "fmt"
2012-08-24 13:33:37 +08:00
)
type Topology struct {
Node
2012-08-24 13:33:37 +08:00
}
2012-08-31 16:35:11 +08:00
func NewTopology(id NodeId) *Topology{
t := &Topology{}
t.Node = *NewNode()
t.Node.Id = id
return t
}
func (t *Topology) RandomlyReserveOneVolume() (bool, *Node, storage.VolumeId) {
slots := t.Node.maxVolumeCount-t.Node.activeVolumeCount
2012-09-01 17:20:59 +08:00
r := rand.Intn(slots)
vid := t.nextVolumeId()
ret, node := t.Node.ReserveOneVolume(r,vid)
return ret, node, vid
}
func (t *Topology) nextVolumeId() storage.VolumeId {
2012-08-29 16:37:40 +08:00
vid := t.Node.GetMaxVolumeId()
return vid.Next()
}