2021-04-19 13:50:12 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2021-06-21 17:28:03 +08:00
|
|
|
package indexcoord
|
2021-01-19 18:32:57 +08:00
|
|
|
|
|
|
|
import (
|
2021-03-10 09:56:09 +08:00
|
|
|
"path"
|
2021-01-19 18:32:57 +08:00
|
|
|
"strconv"
|
2021-06-11 22:04:41 +08:00
|
|
|
"strings"
|
2021-02-06 13:39:15 +08:00
|
|
|
"sync"
|
2021-01-19 18:32:57 +08:00
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
2021-01-19 18:32:57 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type ParamTable struct {
|
|
|
|
paramtable.BaseTable
|
|
|
|
|
|
|
|
Address string
|
|
|
|
Port int
|
|
|
|
|
2021-06-11 22:04:41 +08:00
|
|
|
EtcdEndpoints []string
|
|
|
|
KvRootPath string
|
|
|
|
MetaRootPath string
|
2021-01-19 18:32:57 +08:00
|
|
|
|
|
|
|
MinIOAddress string
|
|
|
|
MinIOAccessKeyID string
|
|
|
|
MinIOSecretAccessKey string
|
|
|
|
MinIOUseSSL bool
|
|
|
|
MinioBucketName string
|
2021-03-10 09:56:09 +08:00
|
|
|
|
|
|
|
Log log.Config
|
2021-01-19 18:32:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var Params ParamTable
|
2021-02-06 13:39:15 +08:00
|
|
|
var once sync.Once
|
2021-01-19 18:32:57 +08:00
|
|
|
|
|
|
|
func (pt *ParamTable) Init() {
|
2021-02-06 13:39:15 +08:00
|
|
|
once.Do(func() {
|
|
|
|
pt.BaseTable.Init()
|
2021-03-12 19:47:37 +08:00
|
|
|
pt.initLogCfg()
|
2021-06-11 22:04:41 +08:00
|
|
|
pt.initEtcdEndpoints()
|
2021-02-06 13:39:15 +08:00
|
|
|
pt.initMetaRootPath()
|
|
|
|
pt.initKvRootPath()
|
|
|
|
pt.initMinIOAddress()
|
|
|
|
pt.initMinIOAccessKeyID()
|
|
|
|
pt.initMinIOSecretAccessKey()
|
|
|
|
pt.initMinIOUseSSL()
|
|
|
|
pt.initMinioBucketName()
|
|
|
|
})
|
2021-01-19 18:32:57 +08:00
|
|
|
}
|
|
|
|
|
2021-06-11 22:04:41 +08:00
|
|
|
func (pt *ParamTable) initEtcdEndpoints() {
|
|
|
|
endpoints, err := pt.Load("_EtcdEndpoints")
|
2021-01-19 18:32:57 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-06-11 22:04:41 +08:00
|
|
|
pt.EtcdEndpoints = strings.Split(endpoints, ",")
|
2021-01-19 18:32:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ParamTable) initMetaRootPath() {
|
|
|
|
rootPath, err := pt.Load("etcd.rootPath")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
subPath, err := pt.Load("etcd.metaSubPath")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MetaRootPath = rootPath + "/" + subPath
|
|
|
|
}
|
|
|
|
|
2021-01-26 09:38:40 +08:00
|
|
|
func (pt *ParamTable) initKvRootPath() {
|
|
|
|
rootPath, err := pt.Load("etcd.rootPath")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
subPath, err := pt.Load("etcd.kvSubPath")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.KvRootPath = rootPath + "/" + subPath
|
|
|
|
}
|
|
|
|
|
2021-01-19 18:32:57 +08: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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ParamTable) initMinioBucketName() {
|
|
|
|
bucketName, err := pt.Load("minio.bucketName")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinioBucketName = bucketName
|
|
|
|
}
|
2021-03-10 09:56:09 +08: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
|
|
|
|
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)
|
|
|
|
}
|
2021-03-12 19:47:37 +08:00
|
|
|
if len(rootPath) != 0 {
|
2021-06-21 17:28:03 +08:00
|
|
|
pt.Log.File.Filename = path.Join(rootPath, "indexcoord.log")
|
2021-03-12 19:47:37 +08:00
|
|
|
} else {
|
|
|
|
pt.Log.File.Filename = ""
|
|
|
|
}
|
2021-03-10 09:56:09 +08:00
|
|
|
}
|