Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

reserve a volume add VolumeId.Next()

Chris Lu317e12644a81
diff --git a/weed-fs/src/pkg/replication/volume_growth.go b/weed-fs/src/pkg/replication/volume_growth.go
index 49afc741c8..5747330ea6 100644
--- a/weed-fs/src/pkg/replication/volume_growth.go
+++ b/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()
}
}
diff --git a/weed-fs/src/pkg/storage/volume_id.go b/weed-fs/src/pkg/storage/volume_id.go
index 952663a815..bf73966731 100644
--- a/weed-fs/src/pkg/storage/volume_id.go
+++ b/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)
+}
diff --git a/weed-fs/src/pkg/topology/node.go b/weed-fs/src/pkg/topology/node.go
index 15075e0ca2..401826e045 100644
--- a/weed-fs/src/pkg/topology/node.go
+++ b/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
diff --git a/weed-fs/src/pkg/topology/topology.go b/weed-fs/src/pkg/topology/topology.go
index 05f603af36..7afa198034 100644
--- a/weed-fs/src/pkg/topology/topology.go
+++ b/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()
}