aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2022-07-22 02:43:07 -0700
committerGitHub <noreply@github.com>2022-07-22 02:43:07 -0700
commit8d97add89cddb316466776d875e9dc1419932ae6 (patch)
treeff08269bbead68cb88f3e98f854cbefa165e4edf
parent7a6c559ab4a6b696bb574454b297ebefabec29ed (diff)
parent58f2dd674061bb48f433abbebd604ba7a8fe1aa7 (diff)
downloadseaweedfs-8d97add89cddb316466776d875e9dc1419932ae6.tar.xz
seaweedfs-8d97add89cddb316466776d875e9dc1419932ae6.zip
Merge pull request #3348 from ningfdx/remote
optimiz: master ui will render data in order
-rw-r--r--weed/server/master_server_handlers_admin.go2
-rw-r--r--weed/server/master_server_handlers_ui.go4
-rw-r--r--weed/topology/data_center.go23
-rw-r--r--weed/topology/data_node.go26
-rw-r--r--weed/topology/rack.go24
-rw-r--r--weed/topology/topology_info.go (renamed from weed/topology/topology_map.go)40
-rw-r--r--weed/topology/volume_layout.go18
7 files changed, 92 insertions, 45 deletions
diff --git a/weed/server/master_server_handlers_admin.go b/weed/server/master_server_handlers_admin.go
index 47abfb892..0c85db791 100644
--- a/weed/server/master_server_handlers_admin.go
+++ b/weed/server/master_server_handlers_admin.go
@@ -48,7 +48,7 @@ func (ms *MasterServer) collectionDeleteHandler(w http.ResponseWriter, r *http.R
func (ms *MasterServer) dirStatusHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{})
m["Version"] = util.Version()
- m["Topology"] = ms.Topo.ToMap()
+ m["Topology"] = ms.Topo.ToInfo()
writeJsonQuiet(w, r, http.StatusOK, m)
}
diff --git a/weed/server/master_server_handlers_ui.go b/weed/server/master_server_handlers_ui.go
index d8260d8d2..f09022399 100644
--- a/weed/server/master_server_handlers_ui.go
+++ b/weed/server/master_server_handlers_ui.go
@@ -26,7 +26,7 @@ func (ms *MasterServer) uiStatusHandler(w http.ResponseWriter, r *http.Request)
VolumeSizeLimitMB uint32
}{
util.Version(),
- ms.Topo.ToMap(),
+ ms.Topo.ToInfo(),
ms.Topo.RaftServer,
infos,
serverStats,
@@ -43,7 +43,7 @@ func (ms *MasterServer) uiStatusHandler(w http.ResponseWriter, r *http.Request)
VolumeSizeLimitMB uint32
}{
util.Version(),
- ms.Topo.ToMap(),
+ ms.Topo.ToInfo(),
ms.Topo.HashicorpRaft,
infos,
serverStats,
diff --git a/weed/topology/data_center.go b/weed/topology/data_center.go
index 60d91ba6d..78c23e748 100644
--- a/weed/topology/data_center.go
+++ b/weed/topology/data_center.go
@@ -2,6 +2,7 @@ package topology
import (
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
+ "golang.org/x/exp/slices"
)
type DataCenter struct {
@@ -30,16 +31,24 @@ func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack {
return rack
}
-func (dc *DataCenter) ToMap() interface{} {
- m := make(map[string]interface{})
- m["Id"] = dc.Id()
- var racks []interface{}
+type DataCenterInfo struct {
+ Id NodeId `json:"Id"`
+ Racks []RackInfo `json:"Racks"`
+}
+
+func (dc *DataCenter) ToInfo() (info DataCenterInfo) {
+ info.Id = dc.Id()
+ var racks []RackInfo
for _, c := range dc.Children() {
rack := c.(*Rack)
- racks = append(racks, rack.ToMap())
+ racks = append(racks, rack.ToInfo())
}
- m["Racks"] = racks
- return m
+
+ slices.SortFunc(racks, func(a, b RackInfo) bool {
+ return a.Id < b.Id
+ })
+ info.Racks = racks
+ return
}
func (dc *DataCenter) ToDataCenterInfo() *master_pb.DataCenterInfo {
diff --git a/weed/topology/data_node.go b/weed/topology/data_node.go
index 6bdbd965f..33bff2d59 100644
--- a/weed/topology/data_node.go
+++ b/weed/topology/data_node.go
@@ -217,10 +217,18 @@ func (dn *DataNode) ServerAddress() pb.ServerAddress {
return pb.NewServerAddress(dn.Ip, dn.Port, dn.GrpcPort)
}
-func (dn *DataNode) ToMap() interface{} {
- ret := make(map[string]interface{})
- ret["Url"] = dn.Url()
- ret["PublicUrl"] = dn.PublicUrl
+type DataNodeInfo struct {
+ Url string `json:"Url"`
+ PublicUrl string `json:"PublicUrl"`
+ Volumes int64 `json:"Volumes"`
+ EcShards int64 `json:"EcShards"`
+ Max int64 `json:"Max"`
+ VolumeIds string `json:"VolumeIds"`
+}
+
+func (dn *DataNode) ToInfo() (info DataNodeInfo) {
+ info.Url = dn.Url()
+ info.PublicUrl = dn.PublicUrl
// aggregated volume info
var volumeCount, ecShardCount, maxVolumeCount int64
@@ -236,12 +244,12 @@ func (dn *DataNode) ToMap() interface{} {
volumeIds += " " + d.GetVolumeIds()
}
- ret["Volumes"] = volumeCount
- ret["EcShards"] = ecShardCount
- ret["Max"] = maxVolumeCount
- ret["VolumeIds"] = volumeIds
+ info.Volumes = volumeCount
+ info.EcShards = ecShardCount
+ info.Max = maxVolumeCount
+ info.VolumeIds = volumeIds
- return ret
+ return
}
func (dn *DataNode) ToDataNodeInfo() *master_pb.DataNodeInfo {
diff --git a/weed/topology/rack.go b/weed/topology/rack.go
index cd09746b2..7b0ed4a54 100644
--- a/weed/topology/rack.go
+++ b/weed/topology/rack.go
@@ -4,6 +4,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
"github.com/chrislusf/seaweedfs/weed/storage/types"
"github.com/chrislusf/seaweedfs/weed/util"
+ "golang.org/x/exp/slices"
"time"
)
@@ -53,16 +54,25 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, grpcPort int, publicUrl
return dn
}
-func (r *Rack) ToMap() interface{} {
- m := make(map[string]interface{})
- m["Id"] = r.Id()
- var dns []interface{}
+type RackInfo struct {
+ Id NodeId `json:"Id"`
+ DataNodes []DataNodeInfo `json:"DataNodes"`
+}
+
+func (r *Rack) ToInfo() (info RackInfo) {
+ info.Id = r.Id()
+ var dns []DataNodeInfo
for _, c := range r.Children() {
dn := c.(*DataNode)
- dns = append(dns, dn.ToMap())
+ dns = append(dns, dn.ToInfo())
}
- m["DataNodes"] = dns
- return m
+
+ slices.SortFunc(dns, func(a, b DataNodeInfo) bool {
+ return a.Url < b.Url
+ })
+
+ info.DataNodes = dns
+ return
}
func (r *Rack) ToRackInfo() *master_pb.RackInfo {
diff --git a/weed/topology/topology_map.go b/weed/topology/topology_info.go
index 0fedb6221..21ce77edf 100644
--- a/weed/topology/topology_map.go
+++ b/weed/topology/topology_info.go
@@ -1,30 +1,44 @@
package topology
-import "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
+import (
+ "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
+ "golang.org/x/exp/slices"
+)
-func (t *Topology) ToMap() interface{} {
- m := make(map[string]interface{})
- m["Max"] = t.diskUsages.GetMaxVolumeCount()
- m["Free"] = t.diskUsages.FreeSpace()
- var dcs []interface{}
+type TopologyInfo struct {
+ Max int64 `json:"Max"`
+ Free int64 `json:"Free"`
+ DataCenters []DataCenterInfo `json:"DataCenters"`
+ Layouts []VolumeLayoutInfo `json:"Layouts"`
+}
+
+func (t *Topology) ToInfo() (info TopologyInfo) {
+ info.Max = t.diskUsages.GetMaxVolumeCount()
+ info.Free = t.diskUsages.FreeSpace()
+ var dcs []DataCenterInfo
for _, c := range t.Children() {
dc := c.(*DataCenter)
- dcs = append(dcs, dc.ToMap())
+ dcs = append(dcs, dc.ToInfo())
}
- m["DataCenters"] = dcs
- var layouts []interface{}
+
+ slices.SortFunc(dcs, func(a, b DataCenterInfo) bool {
+ return a.Id < b.Id
+ })
+
+ info.DataCenters = dcs
+ var layouts []VolumeLayoutInfo
for _, col := range t.collectionMap.Items() {
c := col.(*Collection)
for _, layout := range c.storageType2VolumeLayout.Items() {
if layout != nil {
- tmp := layout.(*VolumeLayout).ToMap()
- tmp["collection"] = c.Name
+ tmp := layout.(*VolumeLayout).ToInfo()
+ tmp.Collection = c.Name
layouts = append(layouts, tmp)
}
}
}
- m["Layouts"] = layouts
- return m
+ info.Layouts = layouts
+ return
}
func (t *Topology) ToVolumeMap() interface{} {
diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go
index dee82762a..03c4c4adf 100644
--- a/weed/topology/volume_layout.go
+++ b/weed/topology/volume_layout.go
@@ -473,13 +473,19 @@ func (vl *VolumeLayout) SetVolumeCrowded(vid needle.VolumeId) {
}
}
-func (vl *VolumeLayout) ToMap() map[string]interface{} {
- m := make(map[string]interface{})
- m["replication"] = vl.rp.String()
- m["ttl"] = vl.ttl.String()
- m["writables"] = vl.writables
+type VolumeLayoutInfo struct {
+ Replication string `json:"replication"`
+ TTL string `json:"ttl"`
+ Writables []needle.VolumeId `json:"writables"`
+ Collection string `json:"collection"`
+}
+
+func (vl *VolumeLayout) ToInfo() (info VolumeLayoutInfo) {
+ info.Replication = vl.rp.String()
+ info.TTL = vl.ttl.String()
+ info.Writables = vl.writables
//m["locations"] = vl.vid2location
- return m
+ return
}
func (vl *VolumeLayout) Stats() *VolumeLayoutStats {