mirror of https://github.com/milvus-io/milvus.git
Initiatively release session in etcd when service close (#19825)
Signed-off-by: wayblink <anyang.wang@zilliz.com> Signed-off-by: wayblink <anyang.wang@zilliz.com>pull/19810/head
parent
6f5ff61ac3
commit
4cc57adc5d
|
@ -347,7 +347,15 @@ func (s *Session) registerService() (<-chan *clientv3.LeaseKeepAliveResponse, er
|
|||
log.Debug("put session key into etcd", zap.String("key", completeKey), zap.String("value", string(sessionJSON)))
|
||||
|
||||
keepAliveCtx, keepAliveCancel := context.WithCancel(context.Background())
|
||||
s.keepAliveCancel = keepAliveCancel
|
||||
s.keepAliveCancel = func() {
|
||||
// delete the session key to make roll update faster
|
||||
// ignore the resp and error handle, just delete
|
||||
_, _ = s.etcdCli.Delete(keepAliveCtx, completeKey)
|
||||
if s.enableActiveStandBy && !s.isStandby.Load().(bool) {
|
||||
_, _ = s.etcdCli.Delete(keepAliveCtx, s.activeKey)
|
||||
}
|
||||
keepAliveCancel()
|
||||
}
|
||||
ch, err = s.etcdCli.KeepAlive(keepAliveCtx, resp.ID)
|
||||
if err != nil {
|
||||
fmt.Printf("got error during keeping alive with etcd, err: %s\n", err)
|
||||
|
|
|
@ -651,9 +651,6 @@ func TestSessionProcessActiveStandBy(t *testing.T) {
|
|||
flag = true
|
||||
signal <- struct{}{}
|
||||
s1.keepAliveCancel()
|
||||
// directly delete the primary key to make this UT fast,
|
||||
// or the session2 has to wait for session1 release after ttl(60s)
|
||||
etcdCli.Delete(ctx1, s1.activeKey)
|
||||
})
|
||||
assert.False(t, s1.isStandby.Load().(bool))
|
||||
|
||||
|
@ -670,8 +667,6 @@ func TestSessionProcessActiveStandBy(t *testing.T) {
|
|||
})
|
||||
assert.True(t, s2.isStandby.Load().(bool))
|
||||
|
||||
// sleep 20 seconds, the standby service will start watching primary key
|
||||
time.Sleep(time.Second * 20)
|
||||
//assert.True(t, s2.watchingPrimaryKeyLock)
|
||||
// stop session 1, session 2 will take over primary service
|
||||
log.Debug("Stop session 1, session 2 will take over primary service")
|
||||
|
|
Loading…
Reference in New Issue