diff --git a/internal/util/sessionutil/session_util.go b/internal/util/sessionutil/session_util.go index 40245b607acb48bb289defd45091c5e4ebbf056b..d0dee90e7c1ea2bd7a0ae6354734aef1f07cbecb 100644 --- a/internal/util/sessionutil/session_util.go +++ b/internal/util/sessionutil/session_util.go @@ -355,12 +355,14 @@ func (s *Session) getCompleteKey() string { // RegisterService will save a key-value in etcd // key: metaRootPath + "/services" + "/ServerName-ServerID" // value: json format -// { -// ServerID int64 `json:"ServerID,omitempty"` -// ServerName string `json:"ServerName,omitempty"` -// Address string `json:"Address,omitempty"` -// Exclusive bool `json:"Exclusive,omitempty"` -// } +// +// { +// ServerID int64 `json:"ServerID,omitempty"` +// ServerName string `json:"ServerName,omitempty"` +// Address string `json:"Address,omitempty"` +// Exclusive bool `json:"Exclusive,omitempty"` +// } +// // Exclusive means whether this service can exist two at the same time, if so, // it is false. Otherwise, set it to true. func (s *Session) registerService() (<-chan *clientv3.LeaseKeepAliveResponse, error) { @@ -410,12 +412,7 @@ func (s *Session) registerService() (<-chan *clientv3.LeaseKeepAliveResponse, er keepAliveCtx, keepAliveCancel := context.WithCancel(context.Background()) 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) - } + s.Revoke(time.Second) keepAliveCancel() } ch, err = s.etcdCli.KeepAlive(keepAliveCtx, resp.ID) @@ -776,6 +773,7 @@ func (s *Session) updateStandby(b bool) { // 3, If 2. return true, this service becomes ACTIVE. Exit STANDBY mode. // 4, If 2. return false, which means an ACTIVE service already exist. // Start watching the active key. Whenever active key disappears, STANDBY node will go backup to 2. +// // activateFunc is the function to re-active the service. func (s *Session) ProcessActiveStandBy(activateFunc func()) error { s.activeKey = path.Join(s.metaRoot, DefaultServiceRoot, s.ServerName)