|
@ -19,17 +19,21 @@ type Node interface { |
|
|
FreeSpace() int64 |
|
|
FreeSpace() int64 |
|
|
ReserveOneVolume(r int64) (*DataNode, error) |
|
|
ReserveOneVolume(r int64) (*DataNode, error) |
|
|
UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int64) |
|
|
UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int64) |
|
|
|
|
|
UpAdjustMaxSsdVolumeCountDelta(maxSsdVolumeCountDelta int64) |
|
|
UpAdjustVolumeCountDelta(volumeCountDelta int64) |
|
|
UpAdjustVolumeCountDelta(volumeCountDelta int64) |
|
|
|
|
|
UpAdjustSsdVolumeCountDelta(ssdVolumeCountDelta int64) |
|
|
UpAdjustRemoteVolumeCountDelta(remoteVolumeCountDelta int64) |
|
|
UpAdjustRemoteVolumeCountDelta(remoteVolumeCountDelta int64) |
|
|
UpAdjustEcShardCountDelta(ecShardCountDelta int64) |
|
|
UpAdjustEcShardCountDelta(ecShardCountDelta int64) |
|
|
UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int64) |
|
|
UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int64) |
|
|
UpAdjustMaxVolumeId(vid needle.VolumeId) |
|
|
UpAdjustMaxVolumeId(vid needle.VolumeId) |
|
|
|
|
|
|
|
|
GetVolumeCount() int64 |
|
|
GetVolumeCount() int64 |
|
|
|
|
|
GetSsdVolumeCount() int64 |
|
|
GetEcShardCount() int64 |
|
|
GetEcShardCount() int64 |
|
|
GetActiveVolumeCount() int64 |
|
|
GetActiveVolumeCount() int64 |
|
|
GetRemoteVolumeCount() int64 |
|
|
GetRemoteVolumeCount() int64 |
|
|
GetMaxVolumeCount() int64 |
|
|
GetMaxVolumeCount() int64 |
|
|
|
|
|
GetMaxSsdVolumeCount() int64 |
|
|
GetMaxVolumeId() needle.VolumeId |
|
|
GetMaxVolumeId() needle.VolumeId |
|
|
SetParent(Node) |
|
|
SetParent(Node) |
|
|
LinkChildNode(node Node) |
|
|
LinkChildNode(node Node) |
|
@ -47,9 +51,11 @@ type Node interface { |
|
|
type NodeImpl struct { |
|
|
type NodeImpl struct { |
|
|
volumeCount int64 |
|
|
volumeCount int64 |
|
|
remoteVolumeCount int64 |
|
|
remoteVolumeCount int64 |
|
|
|
|
|
ssdVolumeCount int64 |
|
|
activeVolumeCount int64 |
|
|
activeVolumeCount int64 |
|
|
ecShardCount int64 |
|
|
ecShardCount int64 |
|
|
maxVolumeCount int64 |
|
|
maxVolumeCount int64 |
|
|
|
|
|
maxSsdVolumeCount int64 |
|
|
id NodeId |
|
|
id NodeId |
|
|
parent Node |
|
|
parent Node |
|
|
sync.RWMutex // lock children
|
|
|
sync.RWMutex // lock children
|
|
@ -143,7 +149,7 @@ func (n *NodeImpl) Id() NodeId { |
|
|
return n.id |
|
|
return n.id |
|
|
} |
|
|
} |
|
|
func (n *NodeImpl) FreeSpace() int64 { |
|
|
func (n *NodeImpl) FreeSpace() int64 { |
|
|
freeVolumeSlotCount := n.maxVolumeCount + n.remoteVolumeCount - n.volumeCount |
|
|
|
|
|
|
|
|
freeVolumeSlotCount := n.maxVolumeCount + n.maxSsdVolumeCount + n.remoteVolumeCount - n.volumeCount - n.ssdVolumeCount |
|
|
if n.ecShardCount > 0 { |
|
|
if n.ecShardCount > 0 { |
|
|
freeVolumeSlotCount = freeVolumeSlotCount - n.ecShardCount/erasure_coding.DataShardsCount - 1 |
|
|
freeVolumeSlotCount = freeVolumeSlotCount - n.ecShardCount/erasure_coding.DataShardsCount - 1 |
|
|
} |
|
|
} |
|
@ -200,6 +206,15 @@ func (n *NodeImpl) UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int64) { //ca |
|
|
n.parent.UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta) |
|
|
n.parent.UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
func (n *NodeImpl) UpAdjustMaxSsdVolumeCountDelta(maxSsdVolumeCountDelta int64) { //can be negative
|
|
|
|
|
|
if maxSsdVolumeCountDelta == 0 { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
atomic.AddInt64(&n.maxSsdVolumeCount, maxSsdVolumeCountDelta) |
|
|
|
|
|
if n.parent != nil { |
|
|
|
|
|
n.parent.UpAdjustMaxSsdVolumeCountDelta(maxSsdVolumeCountDelta) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
func (n *NodeImpl) UpAdjustVolumeCountDelta(volumeCountDelta int64) { //can be negative
|
|
|
func (n *NodeImpl) UpAdjustVolumeCountDelta(volumeCountDelta int64) { //can be negative
|
|
|
if volumeCountDelta == 0 { |
|
|
if volumeCountDelta == 0 { |
|
|
return |
|
|
return |
|
@ -218,6 +233,15 @@ func (n *NodeImpl) UpAdjustRemoteVolumeCountDelta(remoteVolumeCountDelta int64) |
|
|
n.parent.UpAdjustRemoteVolumeCountDelta(remoteVolumeCountDelta) |
|
|
n.parent.UpAdjustRemoteVolumeCountDelta(remoteVolumeCountDelta) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
func (n *NodeImpl) UpAdjustSsdVolumeCountDelta(ssdVolumeCountDelta int64) { //can be negative
|
|
|
|
|
|
if ssdVolumeCountDelta == 0 { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
atomic.AddInt64(&n.ssdVolumeCount, ssdVolumeCountDelta) |
|
|
|
|
|
if n.parent != nil { |
|
|
|
|
|
n.parent.UpAdjustSsdVolumeCountDelta(ssdVolumeCountDelta) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
func (n *NodeImpl) UpAdjustEcShardCountDelta(ecShardCountDelta int64) { //can be negative
|
|
|
func (n *NodeImpl) UpAdjustEcShardCountDelta(ecShardCountDelta int64) { //can be negative
|
|
|
if ecShardCountDelta == 0 { |
|
|
if ecShardCountDelta == 0 { |
|
|
return |
|
|
return |
|
@ -250,6 +274,9 @@ func (n *NodeImpl) GetMaxVolumeId() needle.VolumeId { |
|
|
func (n *NodeImpl) GetVolumeCount() int64 { |
|
|
func (n *NodeImpl) GetVolumeCount() int64 { |
|
|
return n.volumeCount |
|
|
return n.volumeCount |
|
|
} |
|
|
} |
|
|
|
|
|
func (n *NodeImpl) GetSsdVolumeCount() int64 { |
|
|
|
|
|
return n.ssdVolumeCount |
|
|
|
|
|
} |
|
|
func (n *NodeImpl) GetEcShardCount() int64 { |
|
|
func (n *NodeImpl) GetEcShardCount() int64 { |
|
|
return n.ecShardCount |
|
|
return n.ecShardCount |
|
|
} |
|
|
} |
|
@ -262,6 +289,9 @@ func (n *NodeImpl) GetActiveVolumeCount() int64 { |
|
|
func (n *NodeImpl) GetMaxVolumeCount() int64 { |
|
|
func (n *NodeImpl) GetMaxVolumeCount() int64 { |
|
|
return n.maxVolumeCount |
|
|
return n.maxVolumeCount |
|
|
} |
|
|
} |
|
|
|
|
|
func (n *NodeImpl) GetMaxSsdVolumeCount() int64 { |
|
|
|
|
|
return n.maxSsdVolumeCount |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (n *NodeImpl) LinkChildNode(node Node) { |
|
|
func (n *NodeImpl) LinkChildNode(node Node) { |
|
|
n.Lock() |
|
|
n.Lock() |
|
@ -269,8 +299,10 @@ func (n *NodeImpl) LinkChildNode(node Node) { |
|
|
if n.children[node.Id()] == nil { |
|
|
if n.children[node.Id()] == nil { |
|
|
n.children[node.Id()] = node |
|
|
n.children[node.Id()] = node |
|
|
n.UpAdjustMaxVolumeCountDelta(node.GetMaxVolumeCount()) |
|
|
n.UpAdjustMaxVolumeCountDelta(node.GetMaxVolumeCount()) |
|
|
|
|
|
n.UpAdjustMaxSsdVolumeCountDelta(node.GetMaxSsdVolumeCount()) |
|
|
n.UpAdjustMaxVolumeId(node.GetMaxVolumeId()) |
|
|
n.UpAdjustMaxVolumeId(node.GetMaxVolumeId()) |
|
|
n.UpAdjustVolumeCountDelta(node.GetVolumeCount()) |
|
|
n.UpAdjustVolumeCountDelta(node.GetVolumeCount()) |
|
|
|
|
|
n.UpAdjustSsdVolumeCountDelta(node.GetSsdVolumeCount()) |
|
|
n.UpAdjustRemoteVolumeCountDelta(node.GetRemoteVolumeCount()) |
|
|
n.UpAdjustRemoteVolumeCountDelta(node.GetRemoteVolumeCount()) |
|
|
n.UpAdjustEcShardCountDelta(node.GetEcShardCount()) |
|
|
n.UpAdjustEcShardCountDelta(node.GetEcShardCount()) |
|
|
n.UpAdjustActiveVolumeCountDelta(node.GetActiveVolumeCount()) |
|
|
n.UpAdjustActiveVolumeCountDelta(node.GetActiveVolumeCount()) |
|
@ -287,10 +319,12 @@ func (n *NodeImpl) UnlinkChildNode(nodeId NodeId) { |
|
|
node.SetParent(nil) |
|
|
node.SetParent(nil) |
|
|
delete(n.children, node.Id()) |
|
|
delete(n.children, node.Id()) |
|
|
n.UpAdjustVolumeCountDelta(-node.GetVolumeCount()) |
|
|
n.UpAdjustVolumeCountDelta(-node.GetVolumeCount()) |
|
|
|
|
|
n.UpAdjustSsdVolumeCountDelta(-node.GetSsdVolumeCount()) |
|
|
n.UpAdjustRemoteVolumeCountDelta(-node.GetRemoteVolumeCount()) |
|
|
n.UpAdjustRemoteVolumeCountDelta(-node.GetRemoteVolumeCount()) |
|
|
n.UpAdjustEcShardCountDelta(-node.GetEcShardCount()) |
|
|
n.UpAdjustEcShardCountDelta(-node.GetEcShardCount()) |
|
|
n.UpAdjustActiveVolumeCountDelta(-node.GetActiveVolumeCount()) |
|
|
n.UpAdjustActiveVolumeCountDelta(-node.GetActiveVolumeCount()) |
|
|
n.UpAdjustMaxVolumeCountDelta(-node.GetMaxVolumeCount()) |
|
|
n.UpAdjustMaxVolumeCountDelta(-node.GetMaxVolumeCount()) |
|
|
|
|
|
n.UpAdjustMaxSsdVolumeCountDelta(-node.GetMaxSsdVolumeCount()) |
|
|
glog.V(0).Infoln(n, "removes", node.Id()) |
|
|
glog.V(0).Infoln(n, "removes", node.Id()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|