未验证 提交 7da870f5 编写于 作者: Y yah01 提交者: GitHub

Remove useCustomConfig and simpilify the session type (#23166)

Signed-off-by: Nyah01 <yang.cen@zilliz.com>
上级 17d3190f
...@@ -88,8 +88,13 @@ func (r *Runner) initEtcdCli() { ...@@ -88,8 +88,13 @@ func (r *Runner) initEtcdCli() {
func (r *Runner) init() { func (r *Runner) init() {
r.initEtcdCli() r.initEtcdCli()
r.session = sessionutil.NewSession(r.ctx, r.cfg.EtcdCfg.MetaRootPath.GetValue(), r.etcdCli, r.session = sessionutil.NewSession(
sessionutil.WithCustomConfigEnable(), sessionutil.WithTTL(60), sessionutil.WithRetryTimes(30)) r.ctx,
r.cfg.EtcdCfg.MetaRootPath.GetValue(),
r.etcdCli,
sessionutil.WithTTL(60),
sessionutil.WithRetryTimes(30),
)
// address not important here. // address not important here.
address := time.Now().String() address := time.Now().String()
r.address = address r.address = address
......
...@@ -107,7 +107,6 @@ type Session struct { ...@@ -107,7 +107,6 @@ type Session struct {
enableActiveStandBy bool enableActiveStandBy bool
activeKey string activeKey string
useCustomConfig bool
sessionTTL int64 sessionTTL int64
sessionRetryTimes int64 sessionRetryTimes int64
reuseNodeID bool reuseNodeID bool
...@@ -115,10 +114,6 @@ type Session struct { ...@@ -115,10 +114,6 @@ type Session struct {
type SessionOption func(session *Session) type SessionOption func(session *Session)
func WithCustomConfigEnable() SessionOption {
return func(session *Session) { session.useCustomConfig = true }
}
func WithTTL(ttl int64) SessionOption { func WithTTL(ttl int64) SessionOption {
return func(session *Session) { session.sessionTTL = ttl } return func(session *Session) { session.sessionTTL = ttl }
} }
...@@ -204,9 +199,8 @@ func NewSession(ctx context.Context, metaRoot string, client *clientv3.Client, o ...@@ -204,9 +199,8 @@ func NewSession(ctx context.Context, metaRoot string, client *clientv3.Client, o
Version: common.Version, Version: common.Version,
// options // options
useCustomConfig: false, sessionTTL: paramtable.Get().CommonCfg.SessionTTL.GetAsInt64(),
sessionTTL: 60, sessionRetryTimes: paramtable.Get().CommonCfg.SessionRetryTimes.GetAsInt64(),
sessionRetryTimes: 30,
reuseNodeID: true, reuseNodeID: true,
} }
...@@ -247,14 +241,11 @@ func (s *Session) Init(serverName, address string, exclusive bool, triggerKill b ...@@ -247,14 +241,11 @@ func (s *Session) Init(serverName, address string, exclusive bool, triggerKill b
s.Exclusive = exclusive s.Exclusive = exclusive
s.TriggerKill = triggerKill s.TriggerKill = triggerKill
s.checkIDExist() s.checkIDExist()
// TO AVOID PANIC IN MIGRATION SCRIPT. serverID, err := s.getServerID()
if !s.useCustomConfig { if err != nil {
serverID, err := s.getServerID() panic(err)
if err != nil {
panic(err)
}
s.ServerID = serverID
} }
s.ServerID = serverID
log.Info("start server", zap.String("name", serverName), zap.String("address", address), zap.Int64("id", s.ServerID)) log.Info("start server", zap.String("name", serverName), zap.String("address", address), zap.Int64("id", s.ServerID))
} }
...@@ -374,15 +365,8 @@ func (s *Session) registerService() (<-chan *clientv3.LeaseKeepAliveResponse, er ...@@ -374,15 +365,8 @@ func (s *Session) registerService() (<-chan *clientv3.LeaseKeepAliveResponse, er
var ch <-chan *clientv3.LeaseKeepAliveResponse var ch <-chan *clientv3.LeaseKeepAliveResponse
log.Debug("service begin to register to etcd", zap.String("serverName", s.ServerName), zap.Int64("ServerID", s.ServerID)) log.Debug("service begin to register to etcd", zap.String("serverName", s.ServerName), zap.Int64("ServerID", s.ServerID))
ttl := s.sessionTTL
retryTimes := s.sessionRetryTimes
if !s.useCustomConfig {
ttl = paramtable.Get().CommonCfg.SessionTTL.GetAsInt64()
retryTimes = paramtable.Get().CommonCfg.SessionRetryTimes.GetAsInt64()
}
registerFn := func() error { registerFn := func() error {
resp, err := s.etcdCli.Grant(s.ctx, ttl) resp, err := s.etcdCli.Grant(s.ctx, s.sessionTTL)
if err != nil { if err != nil {
log.Error("register service", zap.Error(err)) log.Error("register service", zap.Error(err))
return err return err
...@@ -424,7 +408,7 @@ func (s *Session) registerService() (<-chan *clientv3.LeaseKeepAliveResponse, er ...@@ -424,7 +408,7 @@ func (s *Session) registerService() (<-chan *clientv3.LeaseKeepAliveResponse, er
log.Info("Service registered successfully", zap.String("ServerName", s.ServerName), zap.Int64("serverID", s.ServerID)) log.Info("Service registered successfully", zap.String("ServerName", s.ServerName), zap.Int64("serverID", s.ServerID))
return nil return nil
} }
err := retry.Do(s.ctx, registerFn, retry.Attempts(uint(retryTimes))) err := retry.Do(s.ctx, registerFn, retry.Attempts(uint(s.sessionRetryTimes)))
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -704,9 +704,8 @@ func TestSessionEventType_String(t *testing.T) { ...@@ -704,9 +704,8 @@ func TestSessionEventType_String(t *testing.T) {
func TestSession_apply(t *testing.T) { func TestSession_apply(t *testing.T) {
session := &Session{} session := &Session{}
opts := []SessionOption{WithCustomConfigEnable(), WithTTL(100), WithRetryTimes(200)} opts := []SessionOption{WithTTL(100), WithRetryTimes(200)}
session.apply(opts...) session.apply(opts...)
assert.True(t, session.useCustomConfig)
assert.Equal(t, int64(100), session.sessionTTL) assert.Equal(t, int64(100), session.sessionTTL)
assert.Equal(t, int64(200), session.sessionRetryTimes) assert.Equal(t, int64(200), session.sessionRetryTimes)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册