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

22 lines
436 B
Go
Raw Normal View History

2012-08-24 05:33:37 +00:00
package topology
import (
"math/rand"
"pkg/storage"
2012-08-24 05:33:37 +00:00
)
type Topology struct {
Node
2012-08-24 05:33:37 +00:00
}
2012-08-29 08:37:40 +00: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 08:37:40 +00:00
vid := t.Node.GetMaxVolumeId()
return vid.Next()
}