mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
31 lines
579 B
Go
31 lines
579 B
Go
package topology
|
|
|
|
import (
|
|
"math/rand"
|
|
"pkg/storage"
|
|
_ "fmt"
|
|
)
|
|
|
|
type Topology struct {
|
|
Node
|
|
}
|
|
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
|
|
r := rand.Intn(slots)
|
|
vid := t.nextVolumeId()
|
|
ret, node := t.Node.ReserveOneVolume(r,vid)
|
|
return ret, node, vid
|
|
}
|
|
|
|
func (t *Topology) nextVolumeId() storage.VolumeId {
|
|
vid := t.Node.GetMaxVolumeId()
|
|
return vid.Next()
|
|
}
|