mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
feat(master): nodeset info return can alloc metanode/datanode cnt
Signed-off-by: NaturalSelect <huangzhibin1@oppo.com>
This commit is contained in:
parent
f665fbbfab
commit
cf772279a7
@ -823,6 +823,8 @@ func formatNodeSetView(ns *proto.NodeSetStatInfo) string {
|
||||
sb.WriteString(fmt.Sprintf("NodeSet ID: %v\n", ns.ID))
|
||||
sb.WriteString(fmt.Sprintf("Capacity: %v\n", ns.Capacity))
|
||||
sb.WriteString(fmt.Sprintf("Zone: %v\n", ns.Zone))
|
||||
sb.WriteString(fmt.Sprintf("CanAllocDataNode: %v\n", ns.CanAllocDataNodeCnt))
|
||||
sb.WriteString(fmt.Sprintf("CanAllocMetaNode: %v\n", ns.CanAllocMetaNodeCnt))
|
||||
sb.WriteString(fmt.Sprintf("DataNodeSelector: %v\n", ns.DataNodeSelector))
|
||||
sb.WriteString(fmt.Sprintf("MetaNodeSelector: %v\n", ns.MetaNodeSelector))
|
||||
var dataTotal, dataUsed, dataAvail, metaTotal, metaUsed, metaAvail uint64
|
||||
|
||||
@ -59,11 +59,11 @@ func newNodeSetListCmd(client *master.MasterClient) *cobra.Command {
|
||||
if nodeSetStats, err = client.AdminAPI().ListNodeSets(zoneName); err != nil {
|
||||
return
|
||||
}
|
||||
zoneTablePattern := "%-6v %-6v %-12v %-10v %-10v\n"
|
||||
stdout(zoneTablePattern, "ID", "Cap", "Zone", "MetaNum", "DataNum")
|
||||
zoneDataPattern := "%-6v %-6v %-12v %-10v %-10v\n"
|
||||
zoneTablePattern := "%-6v %-6v %-12v %-10v %-12v %-10v %-12v\n"
|
||||
stdout(zoneTablePattern, "ID", "Cap", "Zone", "MetaNum", "CanAllocMeta", "DataNum", "CanAllocData")
|
||||
zoneDataPattern := "%-6v %-6v %-12v %-10v %-12v %-10v %-12v\n"
|
||||
for _, nodeSet := range nodeSetStats {
|
||||
stdout(zoneDataPattern, nodeSet.ID, nodeSet.Capacity, nodeSet.Zone, nodeSet.MetaNodeNum, nodeSet.DataNodeNum)
|
||||
stdout(zoneDataPattern, nodeSet.ID, nodeSet.Capacity, nodeSet.Zone, nodeSet.MetaNodeNum, nodeSet.CanAllocMetaNodeCnt, nodeSet.DataNodeNum, nodeSet.CanAllocDataNodeCnt)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@ -477,11 +477,13 @@ func (m *Server) listNodeSets(w http.ResponseWriter, r *http.Request) {
|
||||
nsc := zone.getAllNodeSet()
|
||||
for _, ns := range nsc {
|
||||
nsStat := &proto.NodeSetStat{
|
||||
ID: ns.ID,
|
||||
Capacity: ns.Capacity,
|
||||
Zone: zone.name,
|
||||
DataNodeNum: ns.dataNodeLen(),
|
||||
MetaNodeNum: ns.metaNodeLen(),
|
||||
ID: ns.ID,
|
||||
Capacity: ns.Capacity,
|
||||
Zone: zone.name,
|
||||
CanAllocDataNodeCnt: ns.canAllocDataNodeCnt(),
|
||||
CanAllocMetaNodeCnt: ns.canAllocMetaNodeCnt(),
|
||||
DataNodeNum: ns.dataNodeLen(),
|
||||
MetaNodeNum: ns.metaNodeLen(),
|
||||
}
|
||||
nodeSetStats = append(nodeSetStats, nsStat)
|
||||
}
|
||||
@ -516,11 +518,13 @@ func (m *Server) getNodeSet(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
nsStat := &proto.NodeSetStatInfo{
|
||||
ID: ns.ID,
|
||||
Capacity: ns.Capacity,
|
||||
Zone: ns.zoneName,
|
||||
DataNodeSelector: ns.GetDataNodeSelector(),
|
||||
MetaNodeSelector: ns.GetMetaNodeSelector(),
|
||||
ID: ns.ID,
|
||||
Capacity: ns.Capacity,
|
||||
Zone: ns.zoneName,
|
||||
CanAllocDataNodeCnt: ns.canAllocDataNodeCnt(),
|
||||
CanAllocMetaNodeCnt: ns.canAllocMetaNodeCnt(),
|
||||
DataNodeSelector: ns.GetDataNodeSelector(),
|
||||
MetaNodeSelector: ns.GetMetaNodeSelector(),
|
||||
}
|
||||
ns.dataNodes.Range(func(key, value interface{}) bool {
|
||||
dn := value.(*DataNode)
|
||||
|
||||
@ -1048,6 +1048,17 @@ func (ns *nodeSet) canWriteForDataNode(replicaNum int) bool {
|
||||
return count >= replicaNum
|
||||
}
|
||||
|
||||
func (ns *nodeSet) canAllocDataNodeCnt() (cnt int) {
|
||||
ns.dataNodes.Range(func(key, value interface{}) bool {
|
||||
node := value.(*DataNode)
|
||||
if node.isWriteAble() && node.dpCntInLimit() {
|
||||
cnt++
|
||||
}
|
||||
return true
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (ns *nodeSet) canWriteForMetaNode(replicaNum int) bool {
|
||||
var count int
|
||||
ns.metaNodes.Range(func(key, value interface{}) bool {
|
||||
@ -1065,6 +1076,17 @@ func (ns *nodeSet) canWriteForMetaNode(replicaNum int) bool {
|
||||
return count >= replicaNum
|
||||
}
|
||||
|
||||
func (ns *nodeSet) canAllocMetaNodeCnt() (cnt int) {
|
||||
ns.metaNodes.Range(func(key, value interface{}) bool {
|
||||
node := value.(*MetaNode)
|
||||
if node.isWritable() && node.mpCntInLimit() {
|
||||
cnt++
|
||||
}
|
||||
return true
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (ns *nodeSet) putDataNode(dataNode *DataNode) {
|
||||
ns.dataNodes.Store(dataNode.Addr, dataNode)
|
||||
}
|
||||
|
||||
@ -214,21 +214,25 @@ type ZoneNodesStat struct {
|
||||
}
|
||||
|
||||
type NodeSetStat struct {
|
||||
ID uint64
|
||||
Capacity int
|
||||
Zone string
|
||||
MetaNodeNum int
|
||||
DataNodeNum int
|
||||
ID uint64
|
||||
Capacity int
|
||||
Zone string
|
||||
CanAllocMetaNodeCnt int
|
||||
CanAllocDataNodeCnt int
|
||||
MetaNodeNum int
|
||||
DataNodeNum int
|
||||
}
|
||||
|
||||
type NodeSetStatInfo struct {
|
||||
ID uint64
|
||||
Capacity int
|
||||
Zone string
|
||||
MetaNodes []*NodeStatView
|
||||
DataNodes []*NodeStatView
|
||||
DataNodeSelector string
|
||||
MetaNodeSelector string
|
||||
ID uint64
|
||||
Capacity int
|
||||
Zone string
|
||||
CanAllocMetaNodeCnt int
|
||||
CanAllocDataNodeCnt int
|
||||
MetaNodes []*NodeStatView
|
||||
DataNodes []*NodeStatView
|
||||
DataNodeSelector string
|
||||
MetaNodeSelector string
|
||||
}
|
||||
|
||||
type NodeStatView struct {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user