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