MCPcopy
hub / github.com/XiaoMi/Gaea / checkInstanceStatus

Function checkInstanceStatus

backend/slice.go:269–307  ·  view source on GitHub ↗
(name string, cp ConnectionPool, healthCheckSql string)

Source from the content-addressed store, hash-verified

267}
268
269func checkInstanceStatus(name string, cp ConnectionPool, healthCheckSql string) (PooledConnect, error) {
270 defer func() {
271 if err := recover(); err != nil {
272 log.Fatal("[ns:%s, %s] check instance status panic:%s", name, cp.Addr(), err)
273 }
274 }()
275
276 pc, err := cp.GetCheck(context.Background())
277 if err != nil {
278 if pc != nil {
279 pc.Close()
280 }
281 return nil, fmt.Errorf("get check conn err:%s", err)
282 }
283
284 if pc == nil {
285 return nil, fmt.Errorf("get nil check conn, ins:%s", cp.Addr())
286 }
287
288 if len(healthCheckSql) > 0 {
289 _, err := pc.ExecuteWithTimeout(healthCheckSql, 0, ExecTimeOut)
290 if err == nil {
291 cp.SetLastChecked()
292 return pc, nil
293 }
294 log.Warn("[ns:%s instance:%s] exec health check sql:%s sqlError:%v", name, cp.Addr(), healthCheckSql, err)
295 if mysql.IsServerShutdownErr(err) || mysql.IsTableSpaceMissingErr(err) || mysql.IsTableSpaceDiscardeErr(err) || err == ErrExecuteTimeout {
296 pc.Close()
297 return nil, fmt.Errorf("exec health check query error:%s", err)
298 }
299 }
300 if err = pc.PingWithTimeout(GetConnTimeout); err != nil {
301 pc.Close()
302 return nil, fmt.Errorf("ping conn error:%s", err)
303 }
304
305 cp.SetLastChecked()
306 return pc, nil
307}
308
309func allSlaveIsOffline(SlaveStatusMap *sync.Map) bool {
310 var result = true

Callers 2

Calls 12

FatalFunction · 0.92
WarnFunction · 0.92
IsServerShutdownErrFunction · 0.92
IsTableSpaceMissingErrFunction · 0.92
IsTableSpaceDiscardeErrFunction · 0.92
AddrMethod · 0.65
GetCheckMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65
ExecuteWithTimeoutMethod · 0.65
SetLastCheckedMethod · 0.65
PingWithTimeoutMethod · 0.65

Tested by

no test coverage detected