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

22 lines
436 B
Go
Raw Normal View History

2012-08-24 13:33:37 +08:00
package topology
import (
"math/rand"
"pkg/storage"
2012-08-24 13:33:37 +08:00
)
type Topology struct {
Node
2012-08-24 13:33:37 +08:00
}
2012-08-29 16:37:40 +08:00
func (t *Topology) RandomlyReserveOneVolume() (bool,storage.VolumeId) {
r := rand.Intn(t.Node.maxVolumeCount-t.Node.countVolumeCount-t.Node.reservedVolumeCount)
vid := t.nextVolumeId()
return t.Node.ReserveOneVolume(r,vid), vid
}
func (t *Topology) nextVolumeId() storage.VolumeId {
2012-08-29 16:37:40 +08:00
vid := t.Node.GetMaxVolumeId()
return vid.Next()
}