mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-29 23:05:34 +08:00
5f7b024891
Currently the file size of only one volume location is taken into account in the stats. This commit multiplies the disk usages by the amount of nodes holding a replica of the volume. This will yield the expected amount of disk usage and matches the total size calculations from before.
91 lines
1.9 KiB
Go
91 lines
1.9 KiB
Go
package topology
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
|
)
|
|
|
|
type VolumeLocationList struct {
|
|
list []*DataNode
|
|
}
|
|
|
|
func NewVolumeLocationList() *VolumeLocationList {
|
|
return &VolumeLocationList{}
|
|
}
|
|
|
|
func (dnll *VolumeLocationList) String() string {
|
|
return fmt.Sprintf("%v", dnll.list)
|
|
}
|
|
|
|
func (dnll *VolumeLocationList) Copy() *VolumeLocationList {
|
|
list := make([]*DataNode, len(dnll.list))
|
|
copy(list, dnll.list)
|
|
return &VolumeLocationList{
|
|
list: list,
|
|
}
|
|
}
|
|
|
|
func (dnll *VolumeLocationList) Head() *DataNode {
|
|
//mark first node as master volume
|
|
return dnll.list[0]
|
|
}
|
|
|
|
func (dnll *VolumeLocationList) Length() int {
|
|
if dnll == nil {
|
|
return 0
|
|
}
|
|
return len(dnll.list)
|
|
}
|
|
|
|
func (dnll *VolumeLocationList) Set(loc *DataNode) {
|
|
for i := 0; i < len(dnll.list); i++ {
|
|
if loc.Ip == dnll.list[i].Ip && loc.Port == dnll.list[i].Port {
|
|
dnll.list[i] = loc
|
|
return
|
|
}
|
|
}
|
|
dnll.list = append(dnll.list, loc)
|
|
}
|
|
|
|
func (dnll *VolumeLocationList) Remove(loc *DataNode) bool {
|
|
for i, dnl := range dnll.list {
|
|
if loc.Ip == dnl.Ip && loc.Port == dnl.Port {
|
|
dnll.list = append(dnll.list[:i], dnll.list[i+1:]...)
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (dnll *VolumeLocationList) Refresh(freshThreshHold int64) {
|
|
var changed bool
|
|
for _, dnl := range dnll.list {
|
|
if dnl.LastSeen < freshThreshHold {
|
|
changed = true
|
|
break
|
|
}
|
|
}
|
|
if changed {
|
|
var l []*DataNode
|
|
for _, dnl := range dnll.list {
|
|
if dnl.LastSeen >= freshThreshHold {
|
|
l = append(l, dnl)
|
|
}
|
|
}
|
|
dnll.list = l
|
|
}
|
|
}
|
|
|
|
func (dnll *VolumeLocationList) Stats(vid needle.VolumeId, freshThreshHold int64) (size uint64, fileCount int) {
|
|
for _, dnl := range dnll.list {
|
|
if dnl.LastSeen < freshThreshHold {
|
|
vinfo, err := dnl.GetVolumesById(vid)
|
|
if err == nil {
|
|
return (vinfo.Size - vinfo.DeletedByteCount) * uint64(len(dnll.list)), vinfo.FileCount - vinfo.DeleteCount
|
|
}
|
|
}
|
|
}
|
|
return 0, 0
|
|
}
|