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

* perf(weed/topology): preallocate the /dir/status volume list

ToVolumeMap boxes every volume on a node into an []interface{} grown from nil,
so the slice reallocates its way up alongside the boxing. The count is known.

* perf(weed/topology): preallocate the volume id list sent to clients

Every filer, s3 gateway, and mount that connects to the master gets one
VolumeLocation per data node carrying that node's whole volume id list, grown
from nil. The count is known.

The ec ids are left alone: shards of one volume can span disks, so the shard
count is an upper bound on the deduped vid count, not the count itself.
This commit is contained in:
Chris Lu
2026-08-07 01:14:34 -07:00
committed by GitHub
parent 9f1e21e73f
commit 228e850da1
+6 -3
View File
@@ -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