2012-08-24 03:56:09 +00:00
|
|
|
package topology
|
|
|
|
|
2012-08-24 05:56:14 +00:00
|
|
|
import (
|
2014-03-03 06:16:54 +00:00
|
|
|
"errors"
|
2020-12-14 03:44:57 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage"
|
2014-03-03 06:16:54 +00:00
|
|
|
"math/rand"
|
2014-03-13 19:13:39 +00:00
|
|
|
"strings"
|
2016-05-20 06:57:31 +00:00
|
|
|
"sync"
|
2019-04-05 02:27:00 +00:00
|
|
|
"sync/atomic"
|
2014-10-26 18:34:55 +00:00
|
|
|
|
2016-06-03 01:09:14 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2019-06-05 06:41:56 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
|
2019-04-19 04:43:36 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
2012-08-24 05:56:14 +00:00
|
|
|
)
|
2012-08-24 03:56:09 +00:00
|
|
|
|
2012-08-28 08:04:39 +00:00
|
|
|
type NodeId string
|
2012-09-02 21:33:48 +00:00
|
|
|
type Node interface {
|
|
|
|
Id() NodeId
|
|
|
|
String() string
|
2019-04-05 02:27:00 +00:00
|
|
|
FreeSpace() int64
|
2020-12-17 21:25:05 +00:00
|
|
|
AvailableSpaceFor(option *VolumeGrowOption) int64
|
|
|
|
ReserveOneVolume(r int64, option *VolumeGrowOption) (*DataNode, error)
|
2019-04-05 02:27:00 +00:00
|
|
|
UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int64)
|
2020-12-13 11:11:24 +00:00
|
|
|
UpAdjustMaxSsdVolumeCountDelta(maxSsdVolumeCountDelta int64)
|
2019-04-05 02:27:00 +00:00
|
|
|
UpAdjustVolumeCountDelta(volumeCountDelta int64)
|
2020-12-13 11:11:24 +00:00
|
|
|
UpAdjustSsdVolumeCountDelta(ssdVolumeCountDelta int64)
|
2019-12-04 05:36:42 +00:00
|
|
|
UpAdjustRemoteVolumeCountDelta(remoteVolumeCountDelta int64)
|
2019-06-05 06:41:56 +00:00
|
|
|
UpAdjustEcShardCountDelta(ecShardCountDelta int64)
|
2019-04-05 02:27:00 +00:00
|
|
|
UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int64)
|
2019-04-19 04:43:36 +00:00
|
|
|
UpAdjustMaxVolumeId(vid needle.VolumeId)
|
2012-10-10 03:53:31 +00:00
|
|
|
|
2019-04-05 02:27:00 +00:00
|
|
|
GetVolumeCount() int64
|
2020-12-13 11:11:24 +00:00
|
|
|
GetSsdVolumeCount() int64
|
2019-06-05 06:41:56 +00:00
|
|
|
GetEcShardCount() int64
|
2019-04-05 02:27:00 +00:00
|
|
|
GetActiveVolumeCount() int64
|
2019-12-04 05:36:42 +00:00
|
|
|
GetRemoteVolumeCount() int64
|
2019-04-05 02:27:00 +00:00
|
|
|
GetMaxVolumeCount() int64
|
2020-12-13 11:11:24 +00:00
|
|
|
GetMaxSsdVolumeCount() int64
|
2019-04-19 04:43:36 +00:00
|
|
|
GetMaxVolumeId() needle.VolumeId
|
2012-09-19 08:45:30 +00:00
|
|
|
SetParent(Node)
|
2012-09-02 21:33:48 +00:00
|
|
|
LinkChildNode(node Node)
|
|
|
|
UnlinkChildNode(nodeId NodeId)
|
2012-09-18 21:05:12 +00:00
|
|
|
CollectDeadNodeAndFullVolumes(freshThreshHold int64, volumeSizeLimit uint64)
|
2012-09-03 08:50:04 +00:00
|
|
|
|
2012-09-08 23:25:44 +00:00
|
|
|
IsDataNode() bool
|
2013-06-20 01:10:38 +00:00
|
|
|
IsRack() bool
|
|
|
|
IsDataCenter() bool
|
2016-05-20 06:57:31 +00:00
|
|
|
Children() []Node
|
2012-09-10 07:18:07 +00:00
|
|
|
Parent() Node
|
2012-10-10 03:53:31 +00:00
|
|
|
|
|
|
|
GetValue() interface{} //get reference to the topology,dc,rack,datanode
|
2012-08-24 03:56:09 +00:00
|
|
|
}
|
2012-09-02 21:33:48 +00:00
|
|
|
type NodeImpl struct {
|
2019-04-05 02:27:00 +00:00
|
|
|
volumeCount int64
|
2019-12-04 05:36:42 +00:00
|
|
|
remoteVolumeCount int64
|
2020-12-13 11:11:24 +00:00
|
|
|
ssdVolumeCount int64
|
2019-04-05 02:27:00 +00:00
|
|
|
activeVolumeCount int64
|
2019-06-05 06:41:56 +00:00
|
|
|
ecShardCount int64
|
2019-04-05 02:27:00 +00:00
|
|
|
maxVolumeCount int64
|
2020-12-13 11:11:24 +00:00
|
|
|
maxSsdVolumeCount int64
|
2019-06-05 06:41:56 +00:00
|
|
|
id NodeId
|
2012-09-02 21:33:48 +00:00
|
|
|
parent Node
|
2019-06-11 04:33:32 +00:00
|
|
|
sync.RWMutex // lock children
|
|
|
|
children map[NodeId]Node
|
|
|
|
maxVolumeId needle.VolumeId
|
2012-08-29 07:58:03 +00:00
|
|
|
|
2012-09-02 21:33:48 +00:00
|
|
|
//for rack, data center, topology
|
|
|
|
nodeType string
|
2012-10-10 03:53:31 +00:00
|
|
|
value interface{}
|
2012-09-01 09:20:59 +00:00
|
|
|
}
|
2012-08-31 08:35:11 +00:00
|
|
|
|
2014-03-03 06:16:54 +00:00
|
|
|
// the first node must satisfy filterFirstNodeFn(), the rest nodes must have one free slot
|
2020-12-17 21:25:05 +00:00
|
|
|
func (n *NodeImpl) PickNodesByWeight(numberOfNodes int, option *VolumeGrowOption, filterFirstNodeFn func(dn Node) error) (firstNode Node, restNodes []Node, err error) {
|
2020-03-05 05:41:52 +00:00
|
|
|
var totalWeights int64
|
2015-03-10 07:20:31 +00:00
|
|
|
var errs []string
|
2016-05-20 06:57:31 +00:00
|
|
|
n.RLock()
|
2020-03-05 05:41:52 +00:00
|
|
|
candidates := make([]Node, 0, len(n.children))
|
|
|
|
candidatesWeights := make([]int64, 0, len(n.children))
|
|
|
|
//pick nodes which has enough free volumes as candidates, and use free volumes number as node weight.
|
2014-03-03 06:16:54 +00:00
|
|
|
for _, node := range n.children {
|
2020-12-17 21:25:05 +00:00
|
|
|
if node.AvailableSpaceFor(option) <= 0 {
|
2020-03-05 05:41:52 +00:00
|
|
|
continue
|
2014-03-03 06:16:54 +00:00
|
|
|
}
|
2020-12-17 21:25:05 +00:00
|
|
|
totalWeights += node.AvailableSpaceFor(option)
|
2020-03-05 05:41:52 +00:00
|
|
|
candidates = append(candidates, node)
|
2020-12-17 21:25:05 +00:00
|
|
|
candidatesWeights = append(candidatesWeights, node.AvailableSpaceFor(option))
|
2014-03-03 06:16:54 +00:00
|
|
|
}
|
2016-05-20 06:57:31 +00:00
|
|
|
n.RUnlock()
|
2020-03-05 05:41:52 +00:00
|
|
|
if len(candidates) < numberOfNodes {
|
2020-03-23 01:32:49 +00:00
|
|
|
glog.V(0).Infoln(n.Id(), "failed to pick", numberOfNodes, "from ", len(candidates), "node candidates")
|
2020-03-05 05:41:52 +00:00
|
|
|
return nil, nil, errors.New("No enough data node found!")
|
2014-03-03 06:16:54 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 05:41:52 +00:00
|
|
|
//pick nodes randomly by weights, the node picked earlier has higher final weights
|
|
|
|
sortedCandidates := make([]Node, 0, len(candidates))
|
2020-03-07 14:12:57 +00:00
|
|
|
for i := 0; i < len(candidates); i++ {
|
2020-03-05 05:41:52 +00:00
|
|
|
weightsInterval := rand.Int63n(totalWeights)
|
|
|
|
lastWeights := int64(0)
|
|
|
|
for k, weights := range candidatesWeights {
|
2020-03-07 14:12:57 +00:00
|
|
|
if (weightsInterval >= lastWeights) && (weightsInterval < lastWeights+weights) {
|
2020-03-05 05:41:52 +00:00
|
|
|
sortedCandidates = append(sortedCandidates, candidates[k])
|
|
|
|
candidatesWeights[k] = 0
|
|
|
|
totalWeights -= weights
|
|
|
|
break
|
|
|
|
}
|
|
|
|
lastWeights += weights
|
2014-03-03 06:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-05 05:41:52 +00:00
|
|
|
|
|
|
|
restNodes = make([]Node, 0, numberOfNodes-1)
|
|
|
|
ret := false
|
|
|
|
n.RLock()
|
|
|
|
for k, node := range sortedCandidates {
|
|
|
|
if err := filterFirstNodeFn(node); err == nil {
|
|
|
|
firstNode = node
|
|
|
|
if k >= numberOfNodes-1 {
|
|
|
|
restNodes = sortedCandidates[:numberOfNodes-1]
|
|
|
|
} else {
|
|
|
|
restNodes = append(restNodes, sortedCandidates[:k]...)
|
|
|
|
restNodes = append(restNodes, sortedCandidates[k+1:numberOfNodes]...)
|
2014-03-03 06:16:54 +00:00
|
|
|
}
|
2020-03-05 05:41:52 +00:00
|
|
|
ret = true
|
|
|
|
break
|
2014-03-03 06:16:54 +00:00
|
|
|
} else {
|
2020-03-05 05:41:52 +00:00
|
|
|
errs = append(errs, string(node.Id())+":"+err.Error())
|
2014-03-03 06:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-05 05:41:52 +00:00
|
|
|
n.RUnlock()
|
2014-03-03 06:16:54 +00:00
|
|
|
if !ret {
|
2020-03-05 05:41:52 +00:00
|
|
|
return nil, nil, errors.New("No matching data node found! \n" + strings.Join(errs, "\n"))
|
2014-03-03 06:16:54 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-09-08 23:25:44 +00:00
|
|
|
func (n *NodeImpl) IsDataNode() bool {
|
|
|
|
return n.nodeType == "DataNode"
|
2012-09-02 21:33:48 +00:00
|
|
|
}
|
|
|
|
func (n *NodeImpl) IsRack() bool {
|
|
|
|
return n.nodeType == "Rack"
|
|
|
|
}
|
|
|
|
func (n *NodeImpl) IsDataCenter() bool {
|
|
|
|
return n.nodeType == "DataCenter"
|
|
|
|
}
|
|
|
|
func (n *NodeImpl) String() string {
|
|
|
|
if n.parent != nil {
|
|
|
|
return n.parent.String() + ":" + string(n.id)
|
|
|
|
}
|
|
|
|
return string(n.id)
|
|
|
|
}
|
|
|
|
func (n *NodeImpl) Id() NodeId {
|
|
|
|
return n.id
|
|
|
|
}
|
2020-12-14 03:44:57 +00:00
|
|
|
func (n *NodeImpl) AvailableSpaceFor(option *VolumeGrowOption) int64 {
|
|
|
|
freeVolumeSlotCount := n.maxVolumeCount + n.remoteVolumeCount - n.volumeCount
|
|
|
|
if option.DiskType == storage.SsdType {
|
|
|
|
freeVolumeSlotCount = n.maxSsdVolumeCount - n.ssdVolumeCount
|
|
|
|
}
|
|
|
|
if n.ecShardCount > 0 {
|
|
|
|
freeVolumeSlotCount = freeVolumeSlotCount - n.ecShardCount/erasure_coding.DataShardsCount - 1
|
|
|
|
}
|
|
|
|
return freeVolumeSlotCount
|
|
|
|
}
|
2019-04-05 02:27:00 +00:00
|
|
|
func (n *NodeImpl) FreeSpace() int64 {
|
2020-12-13 11:11:24 +00:00
|
|
|
freeVolumeSlotCount := n.maxVolumeCount + n.maxSsdVolumeCount + n.remoteVolumeCount - n.volumeCount - n.ssdVolumeCount
|
2019-06-05 06:41:56 +00:00
|
|
|
if n.ecShardCount > 0 {
|
2019-12-04 05:36:42 +00:00
|
|
|
freeVolumeSlotCount = freeVolumeSlotCount - n.ecShardCount/erasure_coding.DataShardsCount - 1
|
2019-06-05 06:41:56 +00:00
|
|
|
}
|
2019-12-04 05:36:42 +00:00
|
|
|
return freeVolumeSlotCount
|
2012-09-02 21:33:48 +00:00
|
|
|
}
|
2012-09-19 08:45:30 +00:00
|
|
|
func (n *NodeImpl) SetParent(node Node) {
|
2012-09-02 21:33:48 +00:00
|
|
|
n.parent = node
|
|
|
|
}
|
2016-05-20 06:57:31 +00:00
|
|
|
func (n *NodeImpl) Children() (ret []Node) {
|
|
|
|
n.RLock()
|
|
|
|
defer n.RUnlock()
|
|
|
|
for _, c := range n.children {
|
|
|
|
ret = append(ret, c)
|
|
|
|
}
|
|
|
|
return ret
|
2012-09-03 08:50:04 +00:00
|
|
|
}
|
|
|
|
func (n *NodeImpl) Parent() Node {
|
2012-09-10 07:18:07 +00:00
|
|
|
return n.parent
|
2012-09-03 08:50:04 +00:00
|
|
|
}
|
2012-10-10 03:53:31 +00:00
|
|
|
func (n *NodeImpl) GetValue() interface{} {
|
|
|
|
return n.value
|
2012-09-19 08:45:30 +00:00
|
|
|
}
|
2020-12-17 21:25:05 +00:00
|
|
|
func (n *NodeImpl) ReserveOneVolume(r int64, option *VolumeGrowOption) (assignedNode *DataNode, err error) {
|
2016-05-20 06:57:31 +00:00
|
|
|
n.RLock()
|
|
|
|
defer n.RUnlock()
|
2012-08-29 07:58:03 +00:00
|
|
|
for _, node := range n.children {
|
2020-12-17 21:25:05 +00:00
|
|
|
freeSpace := node.AvailableSpaceFor(option)
|
2013-06-20 01:10:38 +00:00
|
|
|
// fmt.Println("r =", r, ", node =", node, ", freeSpace =", freeSpace)
|
2012-09-02 21:33:48 +00:00
|
|
|
if freeSpace <= 0 {
|
|
|
|
continue
|
|
|
|
}
|
2012-09-01 09:20:59 +00:00
|
|
|
if r >= freeSpace {
|
2012-08-29 07:58:03 +00:00
|
|
|
r -= freeSpace
|
|
|
|
} else {
|
2020-12-17 21:25:05 +00:00
|
|
|
if node.IsDataNode() && node.AvailableSpaceFor(option) > 0 {
|
2013-06-20 01:10:38 +00:00
|
|
|
// fmt.Println("vid =", vid, " assigned to node =", node, ", freeSpace =", node.FreeSpace())
|
2014-03-03 06:16:54 +00:00
|
|
|
return node.(*DataNode), nil
|
2012-09-03 08:50:04 +00:00
|
|
|
}
|
2020-12-17 21:25:05 +00:00
|
|
|
assignedNode, err = node.ReserveOneVolume(r, option)
|
2018-01-17 11:53:41 +00:00
|
|
|
if err == nil {
|
2014-03-03 06:16:54 +00:00
|
|
|
return
|
2012-09-02 21:33:48 +00:00
|
|
|
}
|
2012-08-29 07:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-10 17:26:19 +00:00
|
|
|
return nil, errors.New("No free volume slot found!")
|
2012-08-29 07:58:03 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 02:27:00 +00:00
|
|
|
func (n *NodeImpl) UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int64) { //can be negative
|
2020-03-23 01:32:49 +00:00
|
|
|
if maxVolumeCountDelta == 0 {
|
|
|
|
return
|
|
|
|
}
|
2019-04-05 02:27:00 +00:00
|
|
|
atomic.AddInt64(&n.maxVolumeCount, maxVolumeCountDelta)
|
2012-09-02 21:33:48 +00:00
|
|
|
if n.parent != nil {
|
|
|
|
n.parent.UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta)
|
2012-08-31 08:35:11 +00:00
|
|
|
}
|
2012-09-02 21:33:48 +00:00
|
|
|
}
|
2020-12-13 11:11:24 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2019-04-05 02:27:00 +00:00
|
|
|
func (n *NodeImpl) UpAdjustVolumeCountDelta(volumeCountDelta int64) { //can be negative
|
2020-03-23 01:32:49 +00:00
|
|
|
if volumeCountDelta == 0 {
|
|
|
|
return
|
|
|
|
}
|
2019-04-05 02:27:00 +00:00
|
|
|
atomic.AddInt64(&n.volumeCount, volumeCountDelta)
|
2012-12-04 05:27:57 +00:00
|
|
|
if n.parent != nil {
|
|
|
|
n.parent.UpAdjustVolumeCountDelta(volumeCountDelta)
|
|
|
|
}
|
|
|
|
}
|
2019-12-04 05:36:42 +00:00
|
|
|
func (n *NodeImpl) UpAdjustRemoteVolumeCountDelta(remoteVolumeCountDelta int64) { //can be negative
|
2020-03-23 01:32:49 +00:00
|
|
|
if remoteVolumeCountDelta == 0 {
|
|
|
|
return
|
|
|
|
}
|
2019-12-04 05:36:42 +00:00
|
|
|
atomic.AddInt64(&n.remoteVolumeCount, remoteVolumeCountDelta)
|
|
|
|
if n.parent != nil {
|
|
|
|
n.parent.UpAdjustRemoteVolumeCountDelta(remoteVolumeCountDelta)
|
|
|
|
}
|
|
|
|
}
|
2020-12-13 11:11:24 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2019-06-05 06:41:56 +00:00
|
|
|
func (n *NodeImpl) UpAdjustEcShardCountDelta(ecShardCountDelta int64) { //can be negative
|
2020-03-23 01:32:49 +00:00
|
|
|
if ecShardCountDelta == 0 {
|
|
|
|
return
|
|
|
|
}
|
2019-06-05 06:41:56 +00:00
|
|
|
atomic.AddInt64(&n.ecShardCount, ecShardCountDelta)
|
|
|
|
if n.parent != nil {
|
|
|
|
n.parent.UpAdjustEcShardCountDelta(ecShardCountDelta)
|
|
|
|
}
|
|
|
|
}
|
2019-04-05 02:27:00 +00:00
|
|
|
func (n *NodeImpl) UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int64) { //can be negative
|
2020-03-23 01:32:49 +00:00
|
|
|
if activeVolumeCountDelta == 0 {
|
|
|
|
return
|
|
|
|
}
|
2019-04-05 02:27:00 +00:00
|
|
|
atomic.AddInt64(&n.activeVolumeCount, activeVolumeCountDelta)
|
2012-08-29 07:58:03 +00:00
|
|
|
if n.parent != nil {
|
2012-09-02 21:33:48 +00:00
|
|
|
n.parent.UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta)
|
2012-08-29 07:58:03 +00:00
|
|
|
}
|
2012-08-27 20:52:02 +00:00
|
|
|
}
|
2019-04-19 04:43:36 +00:00
|
|
|
func (n *NodeImpl) UpAdjustMaxVolumeId(vid needle.VolumeId) { //can be negative
|
2012-09-02 21:33:48 +00:00
|
|
|
if n.maxVolumeId < vid {
|
|
|
|
n.maxVolumeId = vid
|
|
|
|
if n.parent != nil {
|
|
|
|
n.parent.UpAdjustMaxVolumeId(vid)
|
|
|
|
}
|
|
|
|
}
|
2012-09-01 09:20:59 +00:00
|
|
|
}
|
2019-04-19 04:43:36 +00:00
|
|
|
func (n *NodeImpl) GetMaxVolumeId() needle.VolumeId {
|
2012-08-31 08:35:11 +00:00
|
|
|
return n.maxVolumeId
|
2012-08-29 08:37:40 +00:00
|
|
|
}
|
2019-04-05 02:27:00 +00:00
|
|
|
func (n *NodeImpl) GetVolumeCount() int64 {
|
2012-12-04 05:27:57 +00:00
|
|
|
return n.volumeCount
|
|
|
|
}
|
2020-12-13 11:11:24 +00:00
|
|
|
func (n *NodeImpl) GetSsdVolumeCount() int64 {
|
|
|
|
return n.ssdVolumeCount
|
|
|
|
}
|
2019-06-05 06:41:56 +00:00
|
|
|
func (n *NodeImpl) GetEcShardCount() int64 {
|
|
|
|
return n.ecShardCount
|
|
|
|
}
|
2019-12-04 05:36:42 +00:00
|
|
|
func (n *NodeImpl) GetRemoteVolumeCount() int64 {
|
|
|
|
return n.remoteVolumeCount
|
|
|
|
}
|
2019-04-05 02:27:00 +00:00
|
|
|
func (n *NodeImpl) GetActiveVolumeCount() int64 {
|
2012-09-02 21:33:48 +00:00
|
|
|
return n.activeVolumeCount
|
|
|
|
}
|
2019-04-05 02:27:00 +00:00
|
|
|
func (n *NodeImpl) GetMaxVolumeCount() int64 {
|
2012-09-02 21:33:48 +00:00
|
|
|
return n.maxVolumeCount
|
|
|
|
}
|
2020-12-13 11:11:24 +00:00
|
|
|
func (n *NodeImpl) GetMaxSsdVolumeCount() int64 {
|
|
|
|
return n.maxSsdVolumeCount
|
|
|
|
}
|
2012-08-29 08:37:40 +00:00
|
|
|
|
2012-09-02 21:33:48 +00:00
|
|
|
func (n *NodeImpl) LinkChildNode(node Node) {
|
2016-05-20 06:57:31 +00:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
2012-09-02 21:33:48 +00:00
|
|
|
if n.children[node.Id()] == nil {
|
|
|
|
n.children[node.Id()] = node
|
2012-09-17 00:31:15 +00:00
|
|
|
n.UpAdjustMaxVolumeCountDelta(node.GetMaxVolumeCount())
|
2020-12-13 11:11:24 +00:00
|
|
|
n.UpAdjustMaxSsdVolumeCountDelta(node.GetMaxSsdVolumeCount())
|
2012-09-17 00:31:15 +00:00
|
|
|
n.UpAdjustMaxVolumeId(node.GetMaxVolumeId())
|
2012-12-04 05:27:57 +00:00
|
|
|
n.UpAdjustVolumeCountDelta(node.GetVolumeCount())
|
2020-12-13 11:11:24 +00:00
|
|
|
n.UpAdjustSsdVolumeCountDelta(node.GetSsdVolumeCount())
|
2019-12-04 05:36:42 +00:00
|
|
|
n.UpAdjustRemoteVolumeCountDelta(node.GetRemoteVolumeCount())
|
2019-06-05 06:41:56 +00:00
|
|
|
n.UpAdjustEcShardCountDelta(node.GetEcShardCount())
|
2012-09-17 00:31:15 +00:00
|
|
|
n.UpAdjustActiveVolumeCountDelta(node.GetActiveVolumeCount())
|
2012-09-19 08:45:30 +00:00
|
|
|
node.SetParent(n)
|
2013-08-09 06:57:22 +00:00
|
|
|
glog.V(0).Infoln(n, "adds child", node.Id())
|
2012-08-29 07:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 21:33:48 +00:00
|
|
|
func (n *NodeImpl) UnlinkChildNode(nodeId NodeId) {
|
2016-05-20 06:57:31 +00:00
|
|
|
n.Lock()
|
|
|
|
defer n.Unlock()
|
2012-09-01 09:20:59 +00:00
|
|
|
node := n.children[nodeId]
|
|
|
|
if node != nil {
|
2016-04-11 10:17:22 +00:00
|
|
|
node.SetParent(nil)
|
2012-09-02 21:33:48 +00:00
|
|
|
delete(n.children, node.Id())
|
2012-12-04 05:27:57 +00:00
|
|
|
n.UpAdjustVolumeCountDelta(-node.GetVolumeCount())
|
2020-12-13 11:11:24 +00:00
|
|
|
n.UpAdjustSsdVolumeCountDelta(-node.GetSsdVolumeCount())
|
2019-12-04 05:36:42 +00:00
|
|
|
n.UpAdjustRemoteVolumeCountDelta(-node.GetRemoteVolumeCount())
|
2019-06-05 06:41:56 +00:00
|
|
|
n.UpAdjustEcShardCountDelta(-node.GetEcShardCount())
|
2012-09-02 21:33:48 +00:00
|
|
|
n.UpAdjustActiveVolumeCountDelta(-node.GetActiveVolumeCount())
|
|
|
|
n.UpAdjustMaxVolumeCountDelta(-node.GetMaxVolumeCount())
|
2020-12-13 11:11:24 +00:00
|
|
|
n.UpAdjustMaxSsdVolumeCountDelta(-node.GetMaxSsdVolumeCount())
|
2017-01-10 09:30:00 +00:00
|
|
|
glog.V(0).Infoln(n, "removes", node.Id())
|
2012-08-29 07:58:03 +00:00
|
|
|
}
|
2012-08-27 20:52:02 +00:00
|
|
|
}
|
2012-09-10 07:18:07 +00:00
|
|
|
|
2012-09-18 21:05:12 +00:00
|
|
|
func (n *NodeImpl) CollectDeadNodeAndFullVolumes(freshThreshHold int64, volumeSizeLimit uint64) {
|
2012-09-10 07:18:07 +00:00
|
|
|
if n.IsRack() {
|
|
|
|
for _, c := range n.Children() {
|
|
|
|
dn := c.(*DataNode) //can not cast n to DataNode
|
2016-05-20 06:32:56 +00:00
|
|
|
for _, v := range dn.GetVolumes() {
|
2012-09-19 08:45:30 +00:00
|
|
|
if uint64(v.Size) >= volumeSizeLimit {
|
2012-12-04 05:27:57 +00:00
|
|
|
//fmt.Println("volume",v.Id,"size",v.Size,">",volumeSizeLimit)
|
2012-12-04 04:28:12 +00:00
|
|
|
n.GetTopology().chanFullVolumes <- v
|
2012-09-10 07:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for _, c := range n.Children() {
|
2012-09-18 21:05:12 +00:00
|
|
|
c.CollectDeadNodeAndFullVolumes(freshThreshHold, volumeSizeLimit)
|
2012-09-10 07:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-18 21:05:12 +00:00
|
|
|
}
|
2012-09-10 07:18:07 +00:00
|
|
|
|
2012-10-10 03:53:31 +00:00
|
|
|
func (n *NodeImpl) GetTopology() *Topology {
|
|
|
|
var p Node
|
|
|
|
p = n
|
|
|
|
for p.Parent() != nil {
|
|
|
|
p = p.Parent()
|
|
|
|
}
|
|
|
|
return p.GetValue().(*Topology)
|
2012-09-10 07:18:07 +00:00
|
|
|
}
|