From e4f73cc805dea84fbcb71f7092eb4f80ee033b20 Mon Sep 17 00:00:00 2001 From: Jiquan Long Date: Sun, 8 Oct 2023 20:05:31 +0800 Subject: [PATCH] Add host & enable_disk to session (#27507) Signed-off-by: longjiquan --- internal/indexnode/indexnode.go | 2 +- internal/util/sessionutil/session_util.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/indexnode/indexnode.go b/internal/indexnode/indexnode.go index 730521f949..5a01b41e4e 100644 --- a/internal/indexnode/indexnode.go +++ b/internal/indexnode/indexnode.go @@ -189,7 +189,7 @@ func (i *IndexNode) CloseSegcore() { } func (i *IndexNode) initSession() error { - i.session = sessionutil.NewSession(i.loopCtx, Params.EtcdCfg.MetaRootPath.GetValue(), i.etcdCli) + i.session = sessionutil.NewSession(i.loopCtx, Params.EtcdCfg.MetaRootPath.GetValue(), i.etcdCli, sessionutil.WithEnableDisk(Params.IndexNodeCfg.EnableDisk.GetAsBool())) if i.session == nil { return errors.New("failed to initialize session") } diff --git a/internal/util/sessionutil/session_util.go b/internal/util/sessionutil/session_util.go index e0d923805f..07ca9d9cb2 100644 --- a/internal/util/sessionutil/session_util.go +++ b/internal/util/sessionutil/session_util.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "fmt" + "os" "path" "strconv" "sync" @@ -94,6 +95,9 @@ type SessionRaw struct { Version string `json:"Version"` IndexEngineVersion IndexEngineVersion `json:"IndexEngineVersion,omitempty"` LeaseID *clientv3.LeaseID `json:"LeaseID,omitempty"` + + HostName string `json:"HostName,omitempty"` + EnableDisk bool `json:"EnableDisk,omitempty"` } // Session is a struct to store service's session, including ServerID, ServerName, @@ -155,6 +159,12 @@ func WithIndexEngineVersion(minimal, current int32) SessionOption { } } +func WithEnableDisk(enableDisk bool) SessionOption { + return func(s *Session) { + s.EnableDisk = enableDisk + } +} + func (s *Session) apply(opts ...SessionOption) { for _, opt := range opts { opt(s) @@ -189,11 +199,20 @@ func (s *Session) MarshalJSON() ([]byte, error) { // metaRoot is a path in etcd to save session information. // etcdEndpoints is to init etcdCli when NewSession func NewSession(ctx context.Context, metaRoot string, client *clientv3.Client, opts ...SessionOption) *Session { + hostName, hostNameErr := os.Hostname() + if hostNameErr != nil { + log.Error("get host name fail", zap.Error(hostNameErr)) + } + session := &Session{ ctx: ctx, metaRoot: metaRoot, Version: common.Version, + SessionRaw: SessionRaw{ + HostName: hostName, + }, + // options sessionTTL: paramtable.Get().CommonCfg.SessionTTL.GetAsInt64(), sessionRetryTimes: paramtable.Get().CommonCfg.SessionRetryTimes.GetAsInt64(),