Browse Source

volume.list display; fix updating maxVolumeCount for disk

pull/1811/head
Chris Lu 4 years ago
parent
commit
cb9cc29518
  1. 1
      weed/topology/data_center.go
  2. 19
      weed/topology/data_node.go
  3. 22
      weed/topology/disk.go
  4. 16
      weed/topology/node.go
  5. 1
      weed/topology/rack.go
  6. 1
      weed/topology/topology_map.go

1
weed/topology/data_center.go

@ -45,6 +45,7 @@ func (dc *DataCenter) ToMap() interface{} {
func (dc *DataCenter) ToDataCenterInfo() *master_pb.DataCenterInfo {
m := &master_pb.DataCenterInfo{
Id: string(dc.Id()),
DiskInfos: dc.diskUsages.ToDiskInfo(),
}
for _, c := range dc.Children() {
rack := c.(*Rack)

19
weed/topology/data_node.go

@ -128,6 +128,25 @@ func (dn *DataNode) DeltaUpdateVolumes(newVolumes, deletedVolumes []storage.Volu
return
}
func (dn *DataNode) AdjustMaxVolumeCounts(maxVolumeCounts map[string]uint32) {
deltaDiskUsages := newDiskUsages()
for diskType, maxVolumeCount := range maxVolumeCounts {
if maxVolumeCount == 0 {
// the volume server may have set the max to zero
continue
}
dt := types.ToDiskType(diskType)
currentDiskUsage := dn.diskUsages.getOrCreateDisk(dt)
if currentDiskUsage.maxVolumeCount == int64(maxVolumeCount) {
continue
}
disk := dn.getOrCreateDisk(dt.String())
deltaDiskUsage := deltaDiskUsages.getOrCreateDisk(dt)
deltaDiskUsage.maxVolumeCount = int64(maxVolumeCount) - currentDiskUsage.maxVolumeCount
disk.UpAdjustDiskUsageDelta(deltaDiskUsages)
}
}
func (dn *DataNode) GetVolumes() (ret []storage.VolumeInfo) {
dn.RLock()
for _, c := range dn.children {

22
weed/topology/disk.go

@ -42,7 +42,7 @@ func newDiskUsages() *DiskUsages {
}
}
func (d *DiskUsages) negative() (*DiskUsages) {
func (d *DiskUsages) negative() *DiskUsages {
d.RLock()
defer d.RUnlock()
t := newDiskUsages()
@ -68,6 +68,21 @@ func (d *DiskUsages) ToMap() interface{} {
return ret
}
func (d *DiskUsages) ToDiskInfo() (map[string]*master_pb.DiskInfo) {
ret := make(map[string]*master_pb.DiskInfo)
for diskType, diskUsageCounts := range d.usages {
m := &master_pb.DiskInfo{
VolumeCount: uint64(diskUsageCounts.volumeCount),
MaxVolumeCount: uint64(diskUsageCounts.maxVolumeCount),
FreeVolumeCount: uint64(diskUsageCounts.maxVolumeCount - diskUsageCounts.volumeCount),
ActiveVolumeCount: uint64(diskUsageCounts.activeVolumeCount),
RemoteVolumeCount: uint64(diskUsageCounts.remoteVolumeCount),
}
ret[string(diskType)] = m
}
return ret
}
func (d *DiskUsages) FreeSpace() (freeSpace int64) {
d.RLock()
defer d.RUnlock()
@ -77,7 +92,6 @@ func (d *DiskUsages) FreeSpace() (freeSpace int64) {
return
}
func (d *DiskUsages) GetMaxVolumeCount() (maxVolumeCount int64) {
d.RLock()
defer d.RUnlock()
@ -111,7 +125,7 @@ func (a *DiskUsageCounts) FreeSpace() int64 {
return freeVolumeSlotCount
}
func (a *DiskUsageCounts) minus(b *DiskUsageCounts) (*DiskUsageCounts) {
func (a *DiskUsageCounts) minus(b *DiskUsageCounts) *DiskUsageCounts {
return &DiskUsageCounts{
volumeCount: a.volumeCount - b.volumeCount,
remoteVolumeCount: a.remoteVolumeCount - b.remoteVolumeCount,
@ -248,7 +262,7 @@ func (d *Disk) ToDiskInfo() *master_pb.DiskInfo {
Type: string(d.Id()),
VolumeCount: uint64(diskUsage.volumeCount),
MaxVolumeCount: uint64(diskUsage.maxVolumeCount),
FreeVolumeCount: uint64(d.FreeSpace()),
FreeVolumeCount: uint64(diskUsage.maxVolumeCount - diskUsage.volumeCount),
ActiveVolumeCount: uint64(diskUsage.activeVolumeCount),
RemoteVolumeCount: uint64(diskUsage.remoteVolumeCount),
}

16
weed/topology/node.go

@ -186,22 +186,6 @@ func (n *NodeImpl) ReserveOneVolume(r int64, option *VolumeGrowOption) (assigned
return nil, errors.New("No free volume slot found!")
}
func (n *NodeImpl) AdjustMaxVolumeCounts(maxVolumeCounts map[string]uint32) {
deltaDiskUsages := newDiskUsages()
for diskType, maxVolumeCount := range maxVolumeCounts {
if maxVolumeCount == 0 {
// the volume server may have set the max to zero
continue
}
dt := types.ToDiskType(diskType)
deltaDiskUsage := deltaDiskUsages.getOrCreateDisk(dt)
currentDiskUsage := n.diskUsages.getOrCreateDisk(dt)
deltaDiskUsage.maxVolumeCount = int64(maxVolumeCount) - currentDiskUsage.maxVolumeCount
deltaDiskUsages.getOrCreateDisk(dt).maxVolumeCount = int64(maxVolumeCount)
}
n.UpAdjustDiskUsageDelta(deltaDiskUsages)
}
func (n *NodeImpl) UpAdjustDiskUsageDelta(deltaDiskUsages *DiskUsages) { //can be negative
for diskType, diskUsage := range deltaDiskUsages.usages {
existingDisk := n.getOrCreateDisk(diskType)

1
weed/topology/rack.go

@ -67,6 +67,7 @@ func (r *Rack) ToMap() interface{} {
func (r *Rack) ToRackInfo() *master_pb.RackInfo {
m := &master_pb.RackInfo{
Id: string(r.Id()),
DiskInfos: r.diskUsages.ToDiskInfo(),
}
for _, c := range r.Children() {
dn := c.(*DataNode)

1
weed/topology/topology_map.go

@ -81,6 +81,7 @@ func (t *Topology) ToVolumeLocations() (volumeLocations []*master_pb.VolumeLocat
func (t *Topology) ToTopologyInfo() *master_pb.TopologyInfo {
m := &master_pb.TopologyInfo{
Id: string(t.Id()),
DiskInfos: t.diskUsages.ToDiskInfo(),
}
for _, c := range t.Children() {
dc := c.(*DataCenter)

Loading…
Cancel
Save