mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
reserve a volume
add VolumeId.Next()
This commit is contained in:
parent
f7adf1687f
commit
317e12644a
|
@ -22,7 +22,7 @@ type VolumeGrowth struct {
|
|||
func (vg *VolumeGrowth) GrowVolumeCopy(copyLevel int, topo topology.Topology) {
|
||||
if copyLevel == 1 {
|
||||
for i := 0; i <vg.copy1factor; i++ {
|
||||
topo.RandomlyCreateOneVolume()
|
||||
topo.RandomlyReserveOneVolume()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,3 +12,6 @@ func NewVolumeId(vid string) (VolumeId,error) {
|
|||
func (vid *VolumeId) String() string{
|
||||
return strconv.FormatUint(uint64(*vid), 10)
|
||||
}
|
||||
func (vid *VolumeId) Next() VolumeId{
|
||||
return VolumeId(uint32(*vid)+1)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ type Node struct {
|
|||
maxVolumeCount int
|
||||
parent *Node
|
||||
children map[NodeId]*Node
|
||||
isLeaf bool
|
||||
maxVolumeId storage.VolumeId
|
||||
}
|
||||
|
||||
func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) bool {
|
||||
|
@ -33,6 +33,9 @@ func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) bool {
|
|||
}
|
||||
|
||||
func (n *Node) AddVolume(v *storage.VolumeInfo) {
|
||||
if n.maxVolumeId < v.Id {
|
||||
n.maxVolumeId = v.Id
|
||||
}
|
||||
n.countVolumeCount++
|
||||
if n.reservedVolumeCount > 0 { //if reserved
|
||||
n.reservedVolumeCount--
|
||||
|
@ -42,6 +45,10 @@ func (n *Node) AddVolume(v *storage.VolumeInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
func (n *Node) GetMaxVolumeId() storage.VolumeId {
|
||||
return n.maxVolumeId
|
||||
}
|
||||
|
||||
func (n *Node) AddNode(node *Node) {
|
||||
n.children[node.id] = node
|
||||
n.countVolumeCount += node.countVolumeCount
|
||||
|
|
|
@ -9,12 +9,13 @@ type Topology struct {
|
|||
Node
|
||||
}
|
||||
|
||||
func (t *Topology) RandomlyCreateOneVolume() (bool,storage.VolumeId) {
|
||||
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 {
|
||||
return storage.VolumeId(0)
|
||||
vid := t.Node.GetMaxVolumeId()
|
||||
return vid.Next()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue