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.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
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.goindex 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.goindex 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.goindex 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 intparent *Nodechildren 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 reservedn.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] = noden.countVolumeCount += node.countVolumeCountdiff --git a/weed-fs/src/pkg/topology/topology.go b/weed-fs/src/pkg/topology/topology.goindex 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()}