fix: avoid duplicate volume.list parent headers (#10126)

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
7y-9
2026-06-29 11:31:45 -07:00
committed by GitHub
co-authored by Codex
parent c06a2dca87
commit 1e42dd77ca
2 changed files with 38 additions and 0 deletions
+10
View File
@@ -224,12 +224,17 @@ func (c *commandVolumeList) writeDataCenterInfo(writer io.Writer, t *master_pb.D
return strings.Compare(a.Id, b.Id)
})
dataCenterInfoFound := false
dataCenterHeaderPrinted := false
for _, r := range t.RackInfos {
if *c.rack != "" && *c.rack != r.Id {
continue
}
s.add(c.writeRackInfo(writer, r, verbosityLevel, func() {
if dataCenterHeaderPrinted {
return
}
output(verbosityLevel >= 1, writer, " DataCenter %s%s\n", t.Id, diskInfosToString(t.DiskInfos))
dataCenterHeaderPrinted = true
}))
if !dataCenterInfoFound && !s.isEmpty() {
dataCenterInfoFound = true
@@ -245,13 +250,18 @@ func (c *commandVolumeList) writeRackInfo(writer io.Writer, t *master_pb.RackInf
return strings.Compare(a.Id, b.Id)
})
rackInfoFound := false
rackHeaderPrinted := false
for _, dn := range t.DataNodeInfos {
if *c.dataNode != "" && *c.dataNode != dn.Id {
continue
}
s.add(c.writeDataNodeInfo(writer, dn, verbosityLevel, func() {
outCenterInfo()
if rackHeaderPrinted {
return
}
output(verbosityLevel >= 2, writer, " Rack %s%s\n", t.Id, diskInfosToString(t.DiskInfos))
rackHeaderPrinted = true
}))
if !rackInfoFound && !s.isEmpty() {
rackInfoFound = true
+28
View File
@@ -194,6 +194,34 @@ func TestWriteDataNodeInfo_SplitsCollapsedDisksByPhysicalDiskId(t *testing.T) {
}
}
func TestWriteTopologyInfo_PrintsParentHeadersOnce(t *testing.T) {
topo := topoFromNodes(
volNode("node1:8081", &master_pb.VolumeInformationMessage{Id: 1, Collection: "c"}),
volNode("node2:8081", &master_pb.VolumeInformationMessage{Id: 2, Collection: "c"}),
)
topo.DiskInfos = map[string]*master_pb.DiskInfo{"hdd": {Type: "hdd"}}
topo.DataCenterInfos[0].DiskInfos = map[string]*master_pb.DiskInfo{"hdd": {Type: "hdd"}}
topo.DataCenterInfos[0].RackInfos[0].DiskInfos = map[string]*master_pb.DiskInfo{"hdd": {Type: "hdd"}}
c := &commandVolumeList{}
fs := flag.NewFlagSet("volume.list", flag.ContinueOnError)
c.collectionPattern = fs.String("collection", "", "")
c.dataCenter = fs.String("dataCenter", "", "")
c.rack = fs.String("rack", "", "")
c.dataNode = fs.String("dataNode", "", "")
c.readonly = fs.Bool("readonly", false, "")
c.writable = fs.Bool("writable", false, "")
c.volumeId = fs.Uint64("volumeId", 0, "")
var dcBuf bytes.Buffer
c.writeTopologyInfo(&dcBuf, topo, 30000, 1)
assert.Equal(t, 1, strings.Count(dcBuf.String(), " DataCenter dc1 hdd("))
var rackBuf bytes.Buffer
c.writeTopologyInfo(&rackBuf, topo, 30000, 2)
assert.Equal(t, 1, strings.Count(rackBuf.String(), " Rack rack1 hdd("))
}
// volNode builds a single-node topology from (volumeId, collection) pairs so the
// duplicate-detection tests can describe a cluster compactly.
func volNode(nodeId string, volumes ...*master_pb.VolumeInformationMessage) *master_pb.DataNodeInfo {