forked from true1064/cubefs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodeinfo.go
94 lines (78 loc) · 2.27 KB
/
nodeinfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package metanode
import (
"sync/atomic"
"time"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/log"
)
const (
UpdateNodeInfoTicket = 1 * time.Minute
DefaultDeleteBatchCounts = 128
)
type NodeInfo struct {
deleteBatchCount uint64
}
var (
nodeInfo = &NodeInfo{}
nodeInfoStopC = make(chan struct{}, 0)
deleteWorkerSleepMs uint64 = 0
dirChildrenNumLimit uint32 = proto.DefaultDirChildrenNumLimit
)
func DeleteBatchCount() uint64 {
val := atomic.LoadUint64(&nodeInfo.deleteBatchCount)
if val == 0 {
val = DefaultDeleteBatchCounts
}
return val
}
func updateDeleteBatchCount(val uint64) {
atomic.StoreUint64(&nodeInfo.deleteBatchCount, val)
}
func updateDeleteWorkerSleepMs(val uint64) {
atomic.StoreUint64(&deleteWorkerSleepMs, val)
}
func updateDirChildrenNumLimit(val uint32) {
atomic.StoreUint32(&dirChildrenNumLimit, val)
}
func DeleteWorkerSleepMs() {
val := atomic.LoadUint64(&deleteWorkerSleepMs)
if val > 0 {
time.Sleep(time.Duration(val) * time.Millisecond)
}
}
func (m *MetaNode) startUpdateNodeInfo() {
ticker := time.NewTicker(UpdateNodeInfoTicket)
defer ticker.Stop()
for {
select {
case <-nodeInfoStopC:
log.LogInfo("metanode nodeinfo gorutine stopped")
return
case <-ticker.C:
m.updateNodeInfo()
m.metadataManager.checkVolVerList()
}
}
}
func (m *MetaNode) stopUpdateNodeInfo() {
nodeInfoStopC <- struct{}{}
}
func (m *MetaNode) updateNodeInfo() {
//clusterInfo, err := getClusterInfo()
clusterInfo, err := masterClient.AdminAPI().GetClusterInfo()
if err != nil {
log.LogErrorf("[updateNodeInfo] %s", err.Error())
return
}
updateDeleteBatchCount(clusterInfo.MetaNodeDeleteBatchCount)
updateDeleteWorkerSleepMs(clusterInfo.MetaNodeDeleteWorkerSleepMs)
if clusterInfo.DirChildrenNumLimit < proto.MinDirChildrenNumLimit {
log.LogWarnf("updateNodeInfo: DirChildrenNumLimit probably not enabled on master, set to default value(%v)",
proto.DefaultDirChildrenNumLimit)
atomic.StoreUint32(&dirChildrenNumLimit, proto.DefaultDirChildrenNumLimit)
} else {
atomic.StoreUint32(&dirChildrenNumLimit, clusterInfo.DirChildrenNumLimit)
log.LogInfof("updateNodeInfo: DirChildrenNumLimit(%v)", clusterInfo.DirChildrenNumLimit)
}
//updateDirChildrenNumLimit(clusterInfo.DirChildrenNumLimit)
}