Browse Source

reserve a volume

add VolumeId.Next()
pull/2/head
Chris Lu 12 years ago
parent
commit
317e12644a
  1. 2
      weed-fs/src/pkg/replication/volume_growth.go
  2. 3
      weed-fs/src/pkg/storage/volume_id.go
  3. 9
      weed-fs/src/pkg/topology/node.go
  4. 5
      weed-fs/src/pkg/topology/topology.go

2
weed-fs/src/pkg/replication/volume_growth.go

@ -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()
}
}

3
weed-fs/src/pkg/storage/volume_id.go

@ -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)
}

9
weed-fs/src/pkg/topology/node.go

@ -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

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

@ -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…
Cancel
Save