Skip to content

Commit

Permalink
Revert "[Enhancement]: Support reporting the total size of writable s…
Browse files Browse the repository at this point in the history
…pace in the cluster."

This reverts commit 37bdadf.

Signed-off-by: leonrayang <[email protected]>
  • Loading branch information
leonrayang committed Jan 24, 2024
1 parent 4a7d43e commit 8ee2c10
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 83 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/datanode.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func newDataNodeListCmd(client *master.MasterClient) *cobra.Command {
stdoutln(formatNodeViewTableHeader())
for _, node := range view.DataNodes {
if optFilterStatus != "" &&
!strings.Contains(formatNodeStatus(node.IsActive), optFilterStatus) {
!strings.Contains(formatNodeStatus(node.Status), optFilterStatus) {
continue
}
if optFilterWritable != "" &&
Expand Down
35 changes: 9 additions & 26 deletions cli/cmd/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,12 @@ func formatClusterView(cv *proto.ClusterView, cn *proto.ClusterNodeInfo, cp *pro
sb.WriteString(fmt.Sprintf(" Master-%d : %v\n", master.ID, master.Addr))
}
sb.WriteString(fmt.Sprintf(" Auto allocate : %v\n", formatEnabledDisabled(!cv.DisableAutoAlloc)))

metaNodeActiveCnt := 0
for _, node := range cv.MetaNodes {
if node.IsActive {
metaNodeActiveCnt += 1
}
}
sb.WriteString(fmt.Sprintf(" MetaNode count (active/total) : %v/%v\n", metaNodeActiveCnt, len(cv.MetaNodes)))
sb.WriteString(fmt.Sprintf(" MetaNode used : %v GB\n", cv.MetaNodeStatInfo.UsedGB))
sb.WriteString(fmt.Sprintf(" MetaNode Available : %v GB\n", cv.MetaNodeStatInfo.AvailGB))
sb.WriteString(fmt.Sprintf(" MetaNode total : %v GB\n", cv.MetaNodeStatInfo.TotalGB))

dataNodeActiveCnt := 0
for _, node := range cv.DataNodes {
if node.IsActive {
dataNodeActiveCnt += 1
}
}
sb.WriteString(fmt.Sprintf(" DataNode count (active/total) : %v/%v\n", dataNodeActiveCnt, len(cv.DataNodes)))
sb.WriteString(fmt.Sprintf(" DataNode used : %v GB\n", cv.DataNodeStatInfo.UsedGB))
sb.WriteString(fmt.Sprintf(" DataNode Available : %v GB\n", cv.DataNodeStatInfo.AvailGB))
sb.WriteString(fmt.Sprintf(" DataNode total : %v GB\n", cv.DataNodeStatInfo.TotalGB))

sb.WriteString(fmt.Sprintf(" MetaNode count : %v\n", len(cv.MetaNodes)))
sb.WriteString(fmt.Sprintf(" MetaNode used : %v GB\n", cv.MetaNodeStatInfo.UsedGB))
sb.WriteString(fmt.Sprintf(" MetaNode total : %v GB\n", cv.MetaNodeStatInfo.TotalGB))
sb.WriteString(fmt.Sprintf(" DataNode count : %v\n", len(cv.DataNodes)))
sb.WriteString(fmt.Sprintf(" DataNode used : %v GB\n", cv.DataNodeStatInfo.UsedGB))
sb.WriteString(fmt.Sprintf(" DataNode total : %v GB\n", cv.DataNodeStatInfo.TotalGB))
sb.WriteString(fmt.Sprintf(" Volume count : %v\n", len(cv.VolStatInfo)))
sb.WriteString(fmt.Sprintf(" Allow Mp Decomm : %v\n", formatEnabledDisabled(!cv.ForbidMpDecommission)))
sb.WriteString(fmt.Sprintf(" EbsAddr : %v\n", cp.EbsAddr))
Expand Down Expand Up @@ -103,19 +86,19 @@ func formatClusterStat(cs *proto.ClusterStatInfo) string {
var nodeViewTableRowPattern = "%-6v %-65v %-8v %-8v"

func formatNodeViewTableHeader() string {
return fmt.Sprintf(nodeViewTableRowPattern, "ID", "ADDRESS", "WRITABLE", "ACTIVE")
return fmt.Sprintf(nodeViewTableRowPattern, "ID", "ADDRESS", "WRITABLE", "STATUS")
}

func formatNodeView(view *proto.NodeView, tableRow bool) string {
if tableRow {
return fmt.Sprintf(nodeViewTableRowPattern, view.ID, formatAddr(view.Addr, view.DomainAddr),
formatYesNo(view.IsWritable), formatNodeStatus(view.IsActive))
formatYesNo(view.IsWritable), formatNodeStatus(view.Status))
}
sb := strings.Builder{}
sb.WriteString(fmt.Sprintf(" ID : %v\n", view.ID))
sb.WriteString(fmt.Sprintf(" Address : %v\n", formatAddr(view.Addr, view.DomainAddr)))
sb.WriteString(fmt.Sprintf(" Writable: %v\n", formatYesNo(view.IsWritable)))
sb.WriteString(fmt.Sprintf(" Active : %v", formatNodeStatus(view.IsActive)))
sb.WriteString(fmt.Sprintf(" Status : %v", formatNodeStatus(view.Status)))
return sb.String()
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/metanode.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func newMetaNodeListCmd(client *master.MasterClient) *cobra.Command {
stdout("%v\n", formatNodeViewTableHeader())
for _, node := range view.MetaNodes {
if optFilterStatus != "" &&
!strings.Contains(formatNodeStatus(node.IsActive), optFilterStatus) {
!strings.Contains(formatNodeStatus(node.Status), optFilterStatus) {
continue
}
if optFilterWritable != "" &&
Expand Down
4 changes: 2 additions & 2 deletions master/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ func (m *Server) getTopology(w http.ResponseWriter, r *http.Request) {
dataNode := value.(*DataNode)
nsView.DataNodes = append(nsView.DataNodes, proto.NodeView{
ID: dataNode.ID, Addr: dataNode.Addr,
DomainAddr: dataNode.DomainAddr, IsActive: dataNode.isActive, IsWritable: dataNode.isWriteAble(),
DomainAddr: dataNode.DomainAddr, Status: dataNode.isActive, IsWritable: dataNode.isWriteAble(),
})
return true
})
ns.metaNodes.Range(func(key, value interface{}) bool {
metaNode := value.(*MetaNode)
nsView.MetaNodes = append(nsView.MetaNodes, proto.NodeView{
ID: metaNode.ID, Addr: metaNode.Addr,
DomainAddr: metaNode.DomainAddr, IsActive: metaNode.IsActive, IsWritable: metaNode.isWritable(),
DomainAddr: metaNode.DomainAddr, Status: metaNode.IsActive, IsWritable: metaNode.isWritable(),
})
return true
})
Expand Down
6 changes: 3 additions & 3 deletions master/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3370,7 +3370,7 @@ func (c *Cluster) allMasterNodes() (masterNodes []proto.NodeView) {
for _, addr := range c.cfg.peerAddrs {
split := strings.Split(addr, colonSplit)
id, _ := strconv.ParseUint(split[0], 10, 64)
masterNode := proto.NodeView{ID: id, Addr: split[1] + ":" + split[2], IsActive: true}
masterNode := proto.NodeView{ID: id, Addr: split[1] + ":" + split[2], Status: true}
masterNodes = append(masterNodes, masterNode)
}
return masterNodes
Expand All @@ -3390,7 +3390,7 @@ func (c *Cluster) allDataNodes() (dataNodes []proto.NodeView) {
dataNode := node.(*DataNode)
dataNodes = append(dataNodes, proto.NodeView{
Addr: dataNode.Addr, DomainAddr: dataNode.DomainAddr,
IsActive: dataNode.isActive, ID: dataNode.ID, IsWritable: dataNode.isWriteAble(),
Status: dataNode.isActive, ID: dataNode.ID, IsWritable: dataNode.isWriteAble(),
})
return true
})
Expand All @@ -3403,7 +3403,7 @@ func (c *Cluster) allMetaNodes() (metaNodes []proto.NodeView) {
metaNode := node.(*MetaNode)
metaNodes = append(metaNodes, proto.NodeView{
ID: metaNode.ID, Addr: metaNode.Addr, DomainAddr: metaNode.DomainAddr,
IsActive: metaNode.IsActive, IsWritable: metaNode.isWritable(),
Status: metaNode.IsActive, IsWritable: metaNode.isWritable(),
})
return true
})
Expand Down
31 changes: 8 additions & 23 deletions master/cluster_stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,11 @@ func (c *Cluster) updateDataNodeStatInfo() {
var (
total uint64
used uint64
avail uint64
)
c.dataNodes.Range(func(addr, node interface{}) bool {
dataNode := node.(*DataNode)
total = total + dataNode.Total
used = used + dataNode.Used

if dataNode.isActive {
avail = avail + dataNode.AvailableSpace
}
return true
})
if total <= 0 {
Expand All @@ -136,29 +131,22 @@ func (c *Cluster) updateDataNodeStatInfo() {
Warn(c.Name, fmt.Sprintf("clusterId[%v] space utilization reached [%v],usedSpace[%v],totalSpace[%v] please add dataNode",
c.Name, usedRate, used, total))
}
c.dataNodeStatInfo.TotalGB = strconv.FormatFloat(float64(total)/util.GB, 'f', 3, 32)
c.dataNodeStatInfo.AvailGB = strconv.FormatFloat(float64(avail)/util.GB, 'f', 3, 32)

oldUsedGB, _ := strconv.ParseFloat(c.dataNodeStatInfo.UsedGB, 64)
c.dataNodeStatInfo.IncreasedGB = strconv.FormatFloat(float64(used)/util.GB-oldUsedGB, 'f', 3, 32)

c.dataNodeStatInfo.UsedGB = strconv.FormatFloat(float64(used)/util.GB, 'f', 3, 32)
c.dataNodeStatInfo.TotalGB = total / util.GB
usedGB := used / util.GB
c.dataNodeStatInfo.IncreasedGB = int64(usedGB) - int64(c.dataNodeStatInfo.UsedGB)
c.dataNodeStatInfo.UsedGB = usedGB
c.dataNodeStatInfo.UsedRatio = strconv.FormatFloat(usedRate, 'f', 3, 32)
}

func (c *Cluster) updateMetaNodeStatInfo() {
var (
total uint64
used uint64
avail uint64
)
c.metaNodes.Range(func(addr, node interface{}) bool {
metaNode := node.(*MetaNode)
total = total + metaNode.Total
used = used + metaNode.Used
if metaNode.IsActive {
avail = avail + metaNode.MaxMemAvailWeight
}
return true
})
if total <= 0 {
Expand All @@ -169,13 +157,10 @@ func (c *Cluster) updateMetaNodeStatInfo() {
Warn(c.Name, fmt.Sprintf("clusterId[%v] space utilization reached [%v],usedSpace[%v],totalSpace[%v] please add metaNode",
c.Name, useRate, used, total))
}
c.metaNodeStatInfo.TotalGB = strconv.FormatFloat(float64(total)/util.GB, 'f', 3, 32)
c.metaNodeStatInfo.AvailGB = strconv.FormatFloat(float64(avail)/util.GB, 'f', 3, 32)

oldUsedGB, _ := strconv.ParseFloat(c.metaNodeStatInfo.UsedGB, 64)
c.metaNodeStatInfo.IncreasedGB = strconv.FormatFloat(float64(used)/util.GB-oldUsedGB, 'f', 3, 32)

c.metaNodeStatInfo.UsedGB = strconv.FormatFloat(float64(used)/util.GB, 'f', 3, 32)
c.metaNodeStatInfo.TotalGB = total / util.GB
newUsed := used / util.GB
c.metaNodeStatInfo.IncreasedGB = int64(newUsed) - int64(c.metaNodeStatInfo.UsedGB)
c.metaNodeStatInfo.UsedGB = newUsed
c.metaNodeStatInfo.UsedRatio = strconv.FormatFloat(useRate, 'f', 3, 32)
}

Expand Down
12 changes: 6 additions & 6 deletions master/gapi_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ func (m *ClusterService) getTopology(ctx context.Context, args struct{}) (*proto
cv.NodeSet[ns.ID] = nsView
ns.dataNodes.Range(func(key, value interface{}) bool {
dataNode := value.(*DataNode)
nsView.DataNodes = append(nsView.DataNodes, proto.NodeView{ID: dataNode.ID, Addr: dataNode.Addr, IsActive: dataNode.isActive, IsWritable: dataNode.isWriteAble()})
nsView.DataNodes = append(nsView.DataNodes, proto.NodeView{ID: dataNode.ID, Addr: dataNode.Addr, Status: dataNode.isActive, IsWritable: dataNode.isWriteAble()})
return true
})
ns.metaNodes.Range(func(key, value interface{}) bool {
metaNode := value.(*MetaNode)
nsView.MetaNodes = append(nsView.MetaNodes, proto.NodeView{ID: metaNode.ID, Addr: metaNode.Addr, IsActive: metaNode.IsActive, IsWritable: metaNode.isWritable()})
nsView.MetaNodes = append(nsView.MetaNodes, proto.NodeView{ID: metaNode.ID, Addr: metaNode.Addr, Status: metaNode.IsActive, IsWritable: metaNode.isWritable()})
return true
})
}
Expand Down Expand Up @@ -478,12 +478,12 @@ func (m *ClusterService) addRaftNode(ctx context.Context, args struct {

// Turn on or off the automatic allocation of the data partitions.
// If DisableAutoAllocate == off, then we WILL NOT automatically allocate new data partitions for the volume when:
// 1. the used space is below the max capacity,
// 2. and the number of r&w data partition is less than 20.
// 1. the used space is below the max capacity,
// 2. and the number of r&w data partition is less than 20.
//
// If DisableAutoAllocate == on, then we WILL automatically allocate new data partitions for the volume when:
// 1. the used space is below the max capacity,
// 2. and the number of r&w data partition is less than 20.
// 1. the used space is below the max capacity,
// 2. and the number of r&w data partition is less than 20.
func (m *ClusterService) clusterFreeze(ctx context.Context, args struct {
Status bool
}) (*proto.GeneralResp, error) {
Expand Down
21 changes: 6 additions & 15 deletions master/monitor_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,21 +527,12 @@ func (mm *monitorMetrics) doStat() {
mm.lcNodesCount.Set(float64(lcNodeCount))
volCount := len(mm.cluster.vols)
mm.volCount.Set(float64(volCount))

dataNodesTotal, _ := strconv.ParseFloat(mm.cluster.dataNodeStatInfo.TotalGB, 64)
dataNodesUsed, _ := strconv.ParseFloat(mm.cluster.dataNodeStatInfo.UsedGB, 64)
dataNodeIncreased, _ := strconv.ParseFloat(mm.cluster.dataNodeStatInfo.IncreasedGB, 64)
mm.dataNodesTotal.Set(dataNodesTotal)
mm.dataNodesUsed.Set(dataNodesUsed)
mm.dataNodeIncreased.Set(dataNodeIncreased)

metaNodesTotal, _ := strconv.ParseFloat(mm.cluster.metaNodeStatInfo.TotalGB, 64)
metaNodesUsed, _ := strconv.ParseFloat(mm.cluster.metaNodeStatInfo.UsedGB, 64)
metaNodesIncreased, _ := strconv.ParseFloat(mm.cluster.metaNodeStatInfo.IncreasedGB, 64)
mm.metaNodesTotal.Set(metaNodesTotal)
mm.metaNodesUsed.Set(metaNodesUsed)
mm.metaNodesIncreased.Set(metaNodesIncreased)

mm.dataNodesTotal.Set(float64(mm.cluster.dataNodeStatInfo.TotalGB))
mm.dataNodesUsed.Set(float64(mm.cluster.dataNodeStatInfo.UsedGB))
mm.dataNodeIncreased.Set(float64(mm.cluster.dataNodeStatInfo.IncreasedGB))
mm.metaNodesTotal.Set(float64(mm.cluster.metaNodeStatInfo.TotalGB))
mm.metaNodesUsed.Set(float64(mm.cluster.metaNodeStatInfo.UsedGB))
mm.metaNodesIncreased.Set(float64(mm.cluster.metaNodeStatInfo.IncreasedGB))
mm.setVolMetrics()
mm.setBadPartitionMetrics()
mm.setDiskErrorMetric()
Expand Down
9 changes: 4 additions & 5 deletions proto/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ type ClusterIP struct {
// NodeView provides the view of the data or meta node.
type NodeView struct {
Addr string
IsActive bool
Status bool
DomainAddr string
ID uint64
IsWritable bool
Expand Down Expand Up @@ -225,11 +225,10 @@ type NodeStatView struct {
}

type NodeStatInfo struct {
TotalGB string
UsedGB string
IncreasedGB string
TotalGB uint64
UsedGB uint64
IncreasedGB int64
UsedRatio string
AvailGB string
}

type VolStatInfo struct {
Expand Down
2 changes: 1 addition & 1 deletion sdk/data/wrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func (w *Wrapper) updateDataNodeStatus() (err error) {

newHostsStatus := make(map[string]bool)
for _, node := range cv.DataNodes {
newHostsStatus[node.Addr] = node.IsActive
newHostsStatus[node.Addr] = node.Status
}
log.LogInfof("updateDataNodeStatus: update %d hosts status", len(newHostsStatus))

Expand Down

0 comments on commit 8ee2c10

Please sign in to comment.