diff --git a/weed/topology/data_center.go b/weed/topology/data_center.go index 250e4bbdd..60d91ba6d 100644 --- a/weed/topology/data_center.go +++ b/weed/topology/data_center.go @@ -44,7 +44,8 @@ func (dc *DataCenter) ToMap() interface{} { func (dc *DataCenter) ToDataCenterInfo() *master_pb.DataCenterInfo { m := &master_pb.DataCenterInfo{ - Id: string(dc.Id()), + Id: string(dc.Id()), + DiskInfos: dc.diskUsages.ToDiskInfo(), } for _, c := range dc.Children() { rack := c.(*Rack) diff --git a/weed/topology/data_node.go b/weed/topology/data_node.go index 038d87043..ae69534da 100644 --- a/weed/topology/data_node.go +++ b/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 { diff --git a/weed/topology/disk.go b/weed/topology/disk.go index 831528949..0e8ce60cd 100644 --- a/weed/topology/disk.go +++ b/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,13 +125,13 @@ 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, + volumeCount: a.volumeCount - b.volumeCount, remoteVolumeCount: a.remoteVolumeCount - b.remoteVolumeCount, activeVolumeCount: a.activeVolumeCount - b.activeVolumeCount, - ecShardCount: a.ecShardCount - b.ecShardCount, - maxVolumeCount: a.maxVolumeCount - b.maxVolumeCount, + ecShardCount: a.ecShardCount - b.ecShardCount, + maxVolumeCount: a.maxVolumeCount - b.maxVolumeCount, } } @@ -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), } diff --git a/weed/topology/node.go b/weed/topology/node.go index 1f5e4194c..25b048452 100644 --- a/weed/topology/node.go +++ b/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) diff --git a/weed/topology/rack.go b/weed/topology/rack.go index 95fd260ad..8eb2a717c 100644 --- a/weed/topology/rack.go +++ b/weed/topology/rack.go @@ -66,7 +66,8 @@ func (r *Rack) ToMap() interface{} { func (r *Rack) ToRackInfo() *master_pb.RackInfo { m := &master_pb.RackInfo{ - Id: string(r.Id()), + Id: string(r.Id()), + DiskInfos: r.diskUsages.ToDiskInfo(), } for _, c := range r.Children() { dn := c.(*DataNode) diff --git a/weed/topology/topology_map.go b/weed/topology/topology_map.go index aa2c9afcd..0fedb6221 100644 --- a/weed/topology/topology_map.go +++ b/weed/topology/topology_map.go @@ -80,7 +80,8 @@ func (t *Topology) ToVolumeLocations() (volumeLocations []*master_pb.VolumeLocat func (t *Topology) ToTopologyInfo() *master_pb.TopologyInfo { m := &master_pb.TopologyInfo{ - Id: string(t.Id()), + Id: string(t.Id()), + DiskInfos: t.diskUsages.ToDiskInfo(), } for _, c := range t.Children() { dc := c.(*DataCenter)