aboutsummaryrefslogtreecommitdiff
path: root/weed
diff options
context:
space:
mode:
authorNyaMisty <gyc990326@gmail.com>2025-06-16 11:27:48 +0800
committerGitHub <noreply@github.com>2025-06-15 20:27:48 -0700
commitcdc543aa9ea012e2e04de04b2433505214694abf (patch)
tree01ac41cc965a650c9a37dcac020192d45d0f2fe2 /weed
parente653de54b4fc00fc6a608266a2ea29b271dc2833 (diff)
downloadseaweedfs-cdc543aa9ea012e2e04de04b2433505214694abf.tar.xz
seaweedfs-cdc543aa9ea012e2e04de04b2433505214694abf.zip
Correctly sort in volume.list to ensure output consistency (#6866)
Diffstat (limited to 'weed')
-rw-r--r--weed/shell/command_volume_list.go31
1 files changed, 29 insertions, 2 deletions
diff --git a/weed/shell/command_volume_list.go b/weed/shell/command_volume_list.go
index 208ef727d..8c556dff4 100644
--- a/weed/shell/command_volume_list.go
+++ b/weed/shell/command_volume_list.go
@@ -9,6 +9,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/storage/types"
"path/filepath"
"slices"
+ "sort"
"strings"
"time"
@@ -73,9 +74,34 @@ func (c *commandVolumeList) Do(args []string, commandEnv *CommandEnv, writer io.
return nil
}
+func sortMapKey[T1 comparable, T2 any](m map[T1]T2) []T1 {
+ keys := make([]T1, 0, len(m))
+ for k, _ := range m {
+ keys = append(keys, k)
+ }
+
+ sort.Slice(keys, func(i, j int) bool {
+ switch v1 := any(keys[i]).(type) {
+ case int:
+ return v1 < any(keys[j]).(int)
+ case string:
+ if strings.Compare(v1, any(keys[j]).(string)) < 0 {
+ return true
+ }
+ return false
+ default:
+ return false
+ }
+ })
+ return keys
+}
+
func diskInfosToString(diskInfos map[string]*master_pb.DiskInfo) string {
var buf bytes.Buffer
- for diskType, diskInfo := range diskInfos {
+
+ for _, diskType := range sortMapKey(diskInfos) {
+ diskInfo := diskInfos[diskType]
+
if diskType == "" {
diskType = types.HddType
}
@@ -152,7 +178,8 @@ func (c *commandVolumeList) writeRackInfo(writer io.Writer, t *master_pb.RackInf
func (c *commandVolumeList) writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo, verbosityLevel int, outRackInfo func()) statistics {
var s statistics
diskInfoFound := false
- for _, diskInfo := range t.DiskInfos {
+ for _, diskType := range sortMapKey(t.DiskInfos) {
+ diskInfo := t.DiskInfos[diskType]
s = s.plus(c.writeDiskInfo(writer, diskInfo, verbosityLevel, func() {
outRackInfo()
output(verbosityLevel >= 3, writer, " DataNode %s%s\n", t.Id, diskInfosToString(t.DiskInfos))