2021-01-15 06:38:36 +00:00
|
|
|
package indexnode
|
2020-12-10 09:55:55 +00:00
|
|
|
|
|
|
|
import (
|
2021-01-29 09:08:31 +00:00
|
|
|
"bytes"
|
2021-03-10 01:56:09 +00:00
|
|
|
"fmt"
|
|
|
|
"path"
|
2020-12-10 09:55:55 +00:00
|
|
|
"strconv"
|
2021-02-06 05:39:15 +00:00
|
|
|
"sync"
|
2020-12-10 09:55:55 +00:00
|
|
|
|
2021-03-10 01:56:09 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-01-29 09:08:31 +00:00
|
|
|
"github.com/spf13/cast"
|
|
|
|
"github.com/spf13/viper"
|
2021-03-10 01:56:09 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/log"
|
2021-01-29 09:08:31 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
|
2020-12-10 09:55:55 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/util/paramtable"
|
|
|
|
)
|
|
|
|
|
2021-01-29 09:08:31 +00:00
|
|
|
const (
|
|
|
|
StartParamsKey = "START_PARAMS"
|
|
|
|
)
|
|
|
|
|
2020-12-10 09:55:55 +00:00
|
|
|
type ParamTable struct {
|
|
|
|
paramtable.BaseTable
|
|
|
|
|
2021-01-29 09:08:31 +00:00
|
|
|
IP string
|
2020-12-10 09:55:55 +00:00
|
|
|
Address string
|
|
|
|
Port int
|
|
|
|
|
2021-01-20 10:26:20 +00:00
|
|
|
NodeID int64
|
|
|
|
|
2020-12-10 09:55:55 +00:00
|
|
|
MasterAddress string
|
|
|
|
|
2020-12-22 00:14:36 +00:00
|
|
|
MinIOAddress string
|
|
|
|
MinIOAccessKeyID string
|
|
|
|
MinIOSecretAccessKey string
|
|
|
|
MinIOUseSSL bool
|
2021-01-05 07:58:13 +00:00
|
|
|
MinioBucketName string
|
2021-03-10 01:56:09 +00:00
|
|
|
|
|
|
|
Log log.Config
|
2020-12-10 09:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var Params ParamTable
|
2021-02-06 05:39:15 +00:00
|
|
|
var once sync.Once
|
2020-12-10 09:55:55 +00:00
|
|
|
|
|
|
|
func (pt *ParamTable) Init() {
|
2021-02-06 05:39:15 +00:00
|
|
|
once.Do(func() {
|
|
|
|
pt.BaseTable.Init()
|
|
|
|
pt.initParams()
|
|
|
|
})
|
2021-01-29 09:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ParamTable) initParams() {
|
2020-12-30 08:41:24 +00:00
|
|
|
pt.initMinIOAddress()
|
|
|
|
pt.initMinIOAccessKeyID()
|
|
|
|
pt.initMinIOSecretAccessKey()
|
|
|
|
pt.initMinIOUseSSL()
|
2021-01-05 07:58:13 +00:00
|
|
|
pt.initMinioBucketName()
|
2021-03-10 01:56:09 +00:00
|
|
|
pt.initLogCfg()
|
2020-12-10 09:55:55 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 09:08:31 +00:00
|
|
|
func (pt *ParamTable) LoadConfigFromInitParams(initParams *internalpb2.InitParams) error {
|
|
|
|
pt.NodeID = initParams.NodeID
|
2020-12-10 09:55:55 +00:00
|
|
|
|
2021-01-29 09:08:31 +00:00
|
|
|
config := viper.New()
|
|
|
|
config.SetConfigType("yaml")
|
|
|
|
for _, pair := range initParams.StartParams {
|
|
|
|
if pair.Key == StartParamsKey {
|
|
|
|
err := config.ReadConfig(bytes.NewBuffer([]byte(pair.Value)))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
break
|
2020-12-10 09:55:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 09:08:31 +00:00
|
|
|
for _, key := range config.AllKeys() {
|
|
|
|
val := config.Get(key)
|
|
|
|
str, err := cast.ToStringE(val)
|
2021-01-20 10:26:20 +00:00
|
|
|
if err != nil {
|
2021-01-29 09:08:31 +00:00
|
|
|
switch val := val.(type) {
|
|
|
|
case []interface{}:
|
|
|
|
str = str[:0]
|
|
|
|
for _, v := range val {
|
|
|
|
ss, err := cast.ToStringE(v)
|
|
|
|
if err != nil {
|
2021-03-10 01:56:09 +00:00
|
|
|
log.Debug("indexnode", zap.String("error", err.Error()))
|
2021-01-29 09:08:31 +00:00
|
|
|
}
|
|
|
|
if len(str) == 0 {
|
|
|
|
str = ss
|
|
|
|
} else {
|
|
|
|
str = str + "," + ss
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2021-03-10 01:56:09 +00:00
|
|
|
log.Debug("indexnode", zap.String("undefine config type, key=", key))
|
2021-01-20 10:26:20 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-29 09:08:31 +00:00
|
|
|
err = pt.Save(key, str)
|
2021-01-20 10:26:20 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-29 09:08:31 +00:00
|
|
|
pt.initParams()
|
|
|
|
return nil
|
2021-01-20 10:26:20 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 00:14:36 +00:00
|
|
|
func (pt *ParamTable) initMinIOAddress() {
|
|
|
|
ret, err := pt.Load("_MinioAddress")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinIOAddress = ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ParamTable) initMinIOAccessKeyID() {
|
|
|
|
ret, err := pt.Load("minio.accessKeyID")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinIOAccessKeyID = ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ParamTable) initMinIOSecretAccessKey() {
|
|
|
|
ret, err := pt.Load("minio.secretAccessKey")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinIOSecretAccessKey = ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ParamTable) initMinIOUseSSL() {
|
|
|
|
ret, err := pt.Load("minio.useSSL")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinIOUseSSL, err = strconv.ParseBool(ret)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2021-01-05 07:58:13 +00:00
|
|
|
|
|
|
|
func (pt *ParamTable) initMinioBucketName() {
|
|
|
|
bucketName, err := pt.Load("minio.bucketName")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinioBucketName = bucketName
|
|
|
|
}
|
2021-03-10 01:56:09 +00:00
|
|
|
|
|
|
|
func (pt *ParamTable) initLogCfg() {
|
|
|
|
pt.Log = log.Config{}
|
|
|
|
format, err := pt.Load("log.format")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.Log.Format = format
|
|
|
|
level, err := pt.Load("log.level")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.Log.Level = level
|
|
|
|
devStr, err := pt.Load("log.dev")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
dev, err := strconv.ParseBool(devStr)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.Log.Development = dev
|
|
|
|
pt.Log.File.MaxSize = pt.ParseInt("log.file.maxSize")
|
|
|
|
pt.Log.File.MaxBackups = pt.ParseInt("log.file.maxBackups")
|
|
|
|
pt.Log.File.MaxDays = pt.ParseInt("log.file.maxAge")
|
|
|
|
rootPath, err := pt.Load("log.file.rootPath")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.Log.File.Filename = path.Join(rootPath, fmt.Sprintf("indexnode-%d.log", pt.NodeID))
|
|
|
|
}
|