@@ -28,7 +28,7 @@ import (
28
28
commonlog "github.com/polarismesh/polaris-server/common/log"
29
29
)
30
30
31
- func (s * Server ) GetServerConnections (ctx context.Context , req * ConnReq ) (* ConnCountResp , error ) {
31
+ func (s * Server ) GetServerConnections (_ context.Context , req * ConnReq ) (* ConnCountResp , error ) {
32
32
if req .Protocol == "" {
33
33
return nil , errors .New ("missing param protocol" )
34
34
}
@@ -38,11 +38,11 @@ func (s *Server) GetServerConnections(ctx context.Context, req *ConnReq) (*ConnC
38
38
return nil , errors .New ("not found the protocol" )
39
39
}
40
40
41
- var resp ConnCountResp
42
-
43
- resp . Protocol = req . Protocol
44
- resp . Total = lis . GetListenerConnCount ()
45
- resp . Host = make ( map [ string ] int32 )
41
+ var resp = ConnCountResp {
42
+ Protocol : req . Protocol ,
43
+ Total : lis . GetListenerConnCount (),
44
+ Host : map [ string ] int32 {},
45
+ }
46
46
if req .Host != "" {
47
47
resp .Host [req .Host ] = lis .GetHostConnCount (req .Host )
48
48
} else {
@@ -55,7 +55,7 @@ func (s *Server) GetServerConnections(ctx context.Context, req *ConnReq) (*ConnC
55
55
return & resp , nil
56
56
}
57
57
58
- func (s * Server ) GetServerConnStats (ctx context.Context , req * ConnReq ) (* ConnStatsResp , error ) {
58
+ func (s * Server ) GetServerConnStats (_ context.Context , req * ConnReq ) (* ConnStatsResp , error ) {
59
59
if req .Protocol == "" {
60
60
return nil , errors .New ("missing param protocol" )
61
61
}
@@ -83,22 +83,23 @@ func (s *Server) GetServerConnStats(ctx context.Context, req *ConnReq) (*ConnSta
83
83
} else {
84
84
resp .Stats = stats
85
85
}
86
- resp .StatsSize = len (resp .Stats )
87
86
88
- if resp .Stats == nil {
87
+ resp .StatsSize = len (resp .Stats )
88
+ if len (resp .Stats ) == 0 {
89
89
resp .Stats = make ([]* connlimit.HostConnStat , 0 )
90
90
}
91
91
92
92
return & resp , nil
93
93
}
94
94
95
- func (s * Server ) CloseConnections (ctx context.Context , reqs []ConnReq ) error {
95
+ func (s * Server ) CloseConnections (_ context.Context , reqs []ConnReq ) error {
96
96
for _ , entry := range reqs {
97
97
listener := connlimit .GetLimitListener (entry .Protocol )
98
98
if listener == nil {
99
99
log .Warnf ("[MAINTAIN] not found listener for protocol(%s)" , entry .Protocol )
100
100
continue
101
101
}
102
+
102
103
if entry .Port != 0 {
103
104
if conn := listener .GetHostConnection (entry .Host , entry .Port ); conn != nil {
104
105
log .Infof ("[MAINTAIN] address(%s:%d) to be closed" , entry .Host , entry .Port )
@@ -109,22 +110,23 @@ func (s *Server) CloseConnections(ctx context.Context, reqs []ConnReq) error {
109
110
110
111
log .Infof ("[MAINTAIN] host(%s) connections to be closed" , entry .Host )
111
112
activeConns := listener .GetHostActiveConns (entry .Host )
112
- for _ , conn := range activeConns {
113
- if conn != nil {
114
- _ = conn .Close ()
113
+ for k := range activeConns {
114
+ if activeConns [ k ] != nil {
115
+ _ = activeConns [ k ] .Close ()
115
116
}
116
117
}
117
118
}
119
+
118
120
return nil
119
121
}
120
122
121
- func (s * Server ) FreeOSMemory (ctx context.Context ) error {
123
+ func (s * Server ) FreeOSMemory (_ context.Context ) error {
122
124
log .Info ("[MAINTAIN] start doing free os memory" )
123
125
// 防止并发释放
124
126
start := time .Now ()
125
- s .freeMemMu .Lock ()
127
+ s .mu .Lock ()
126
128
debug .FreeOSMemory ()
127
- s .freeMemMu .Unlock ()
129
+ s .mu .Unlock ()
128
130
log .Infof ("[MAINTAIN] finish doing free os memory, used time: %v" , time .Since (start ))
129
131
return nil
130
132
}
@@ -133,19 +135,20 @@ func (s *Server) CleanInstance(ctx context.Context, req *api.Instance) *api.Resp
133
135
return s .namingServer .CleanInstance (ctx , req )
134
136
}
135
137
136
- func (s * Server ) GetLastHeartbeat (ctx context.Context , req * api.Instance ) * api.Response {
138
+ func (s * Server ) GetLastHeartbeat (_ context.Context , req * api.Instance ) * api.Response {
137
139
return s .healthCheckServer .GetLastHeartbeat (req )
138
140
}
139
141
140
- func (s * Server ) GetLogOutputLevel (ctx context.Context ) (map [string ]string , error ) {
142
+ func (s * Server ) GetLogOutputLevel (_ context.Context ) (map [string ]string , error ) {
141
143
scopes := commonlog .Scopes ()
142
144
out := make (map [string ]string , len (scopes ))
143
- for k , v := range scopes {
144
- out [k ] = v .GetOutputLevel ().Name ()
145
+ for k := range scopes {
146
+ out [k ] = scopes [ k ] .GetOutputLevel ().Name ()
145
147
}
148
+
146
149
return out , nil
147
150
}
148
151
149
- func (s * Server ) SetLogOutputLevel (ctx context.Context , scope string , level string ) error {
152
+ func (s * Server ) SetLogOutputLevel (_ context.Context , scope string , level string ) error {
150
153
return commonlog .SetLogOutputLevel (scope , level )
151
154
}
0 commit comments