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.

perf(weed/topology): preallocate the client-facing topology snapshots (#10615)

Chris Lu228e850da14a
diff --git a/weed/topology/topology_info.go b/weed/topology/topology_info.go
index dd1f59d291..1c9bfa6b99 100644
--- a/weed/topology/topology_info.go
+++ b/weed/topology/topology_info.go
@@ -72,8 +72,9 @@ func (t *Topology) ToVolumeMap() interface{} {
dataNodes := make(map[NodeId]interface{})
for _, d := range rack.Children() {
dn := d.(*DataNode)
- var volumes []interface{}
- for _, v := range dn.GetVolumes() {
+ dnVolumes := dn.GetVolumes()
+ volumes := make([]interface{}, 0, len(dnVolumes))
+ for _, v := range dnVolumes {
volumes = append(volumes, v)
}
dataNodes[d.Id()] = volumes
@@ -99,7 +100,9 @@ func (t *Topology) ToVolumeLocations() (volumeLocations []*master_pb.VolumeLocat
DataCenter: dn.GetDataCenterId(),
GrpcPort: uint32(dn.GrpcPort),
}
- for _, v := range dn.GetVolumes() {
+ dnVolumes := dn.GetVolumes()
+ volumeLocation.NewVids = make([]uint32, 0, len(dnVolumes))
+ for _, v := range dnVolumes {
volumeLocation.NewVids = append(volumeLocation.NewVids, uint32(v.Id))
}
// A single EC volume's shards can live on multiple disks of