MCPcopy
hub / github.com/CodisLabs/codis / KeepAlive

Method KeepAlive

pkg/proxy/backend.go:81–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

79}
80
81func (bc *BackendConn) KeepAlive() bool {
82 if len(bc.input) != 0 {
83 return false
84 }
85 switch bc.state.Int64() {
86 default:
87 m := &Request{}
88 m.Multi = []*redis.Resp{
89 redis.NewBulkBytes([]byte("PING")),
90 }
91 bc.PushBack(m)
92
93 case stateDataStale:
94 m := &Request{}
95 m.Multi = []*redis.Resp{
96 redis.NewBulkBytes([]byte("INFO")),
97 }
98 m.Batch = &sync.WaitGroup{}
99 bc.PushBack(m)
100
101 keepAliveCallback <- func() {
102 m.Batch.Wait()
103 var err = func() error {
104 if err := m.Err; err != nil {
105 return err
106 }
107 switch resp := m.Resp; {
108 case resp == nil:
109 return ErrRespIsRequired
110 case resp.IsError():
111 return fmt.Errorf("bad info resp: %s", resp.Value)
112 case resp.IsBulkBytes():
113 var info = make(map[string]string)
114 for _, line := range strings.Split(string(resp.Value), "\n") {
115 kv := strings.SplitN(line, ":", 2)
116 if len(kv) != 2 {
117 continue
118 }
119 if key := strings.TrimSpace(kv[0]); key != "" {
120 info[key] = strings.TrimSpace(kv[1])
121 }
122 }
123 if info["master_link_status"] == "down" {
124 return nil
125 }
126 if info["loading"] == "1" {
127 return nil
128 }
129 if bc.state.CompareAndSwap(stateDataStale, stateConnected) {
130 log.Warnf("backend conn [%p] to %s, db-%d state = Connected (keepalive)",
131 bc, bc.addr, bc.database)
132 }
133 return nil
134 default:
135 return fmt.Errorf("bad info resp: should be string, but got %s", resp.Type)
136 }
137 }()
138 if err != nil && bc.closed.IsFalse() {

Callers 2

KeepAliveMethod · 0.45
KeepAliveMethod · 0.45

Calls 10

PushBackMethod · 0.95
IsErrorMethod · 0.80
ErrorfMethod · 0.80
IsBulkBytesMethod · 0.80
WarnfMethod · 0.80
IsFalseMethod · 0.80
WarnErrorfMethod · 0.80
Int64Method · 0.45
WaitMethod · 0.45
CompareAndSwapMethod · 0.45

Tested by

no test coverage detected