2021-11-01 22:49:57 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 13:50:12 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-01 22:49:57 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:50:12 +08:00
|
|
|
//
|
2021-11-01 22:49:57 +08:00
|
|
|
// 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-04-19 13:50:12 +08:00
|
|
|
|
2021-01-15 14:38:36 +08:00
|
|
|
package indexnode
|
2020-12-10 17:55:55 +08:00
|
|
|
|
|
|
|
import (
|
2021-03-10 09:56:09 +08:00
|
|
|
"path"
|
2020-12-10 17:55:55 +08:00
|
|
|
"strconv"
|
2021-06-11 22:04:41 +08:00
|
|
|
"strings"
|
2021-02-06 13:39:15 +08:00
|
|
|
"sync"
|
2021-09-26 17:56:08 +08:00
|
|
|
"time"
|
2020-12-10 17:55:55 +08:00
|
|
|
|
2021-09-22 16:05:59 +08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
2020-12-10 17:55:55 +08:00
|
|
|
)
|
|
|
|
|
2021-10-01 11:24:43 +08:00
|
|
|
// ParamTable is used to record configuration items.
|
2020-12-10 17:55:55 +08:00
|
|
|
type ParamTable struct {
|
|
|
|
paramtable.BaseTable
|
|
|
|
|
2021-01-29 17:08:31 +08:00
|
|
|
IP string
|
2020-12-10 17:55:55 +08:00
|
|
|
Address string
|
|
|
|
Port int
|
|
|
|
|
2021-01-20 18:26:20 +08:00
|
|
|
NodeID int64
|
2021-06-19 12:38:06 +08:00
|
|
|
Alias string
|
2021-01-20 18:26:20 +08:00
|
|
|
|
2021-06-11 22:04:41 +08:00
|
|
|
EtcdEndpoints []string
|
|
|
|
MetaRootPath string
|
2021-09-26 19:19:57 +08:00
|
|
|
IndexRootPath string
|
2021-05-14 10:05:18 +08:00
|
|
|
|
2020-12-22 08:14:36 +08:00
|
|
|
MinIOAddress string
|
|
|
|
MinIOAccessKeyID string
|
|
|
|
MinIOSecretAccessKey string
|
|
|
|
MinIOUseSSL bool
|
2021-01-05 15:58:13 +08:00
|
|
|
MinioBucketName string
|
2021-03-10 09:56:09 +08:00
|
|
|
|
2021-09-22 16:05:59 +08:00
|
|
|
SimdType string
|
|
|
|
|
2021-09-26 17:56:08 +08:00
|
|
|
CreatedTime time.Time
|
|
|
|
UpdatedTime time.Time
|
2020-12-10 17:55:55 +08:00
|
|
|
}
|
|
|
|
|
2021-10-11 19:17:02 +08:00
|
|
|
// Params is a package scoped variable of type ParamTable.
|
2020-12-10 17:55:55 +08:00
|
|
|
var Params ParamTable
|
2021-02-06 13:39:15 +08:00
|
|
|
var once sync.Once
|
2020-12-10 17:55:55 +08:00
|
|
|
|
2021-10-11 19:17:02 +08:00
|
|
|
// InitAlias initializes an alias for the IndexNode role.
|
2021-06-19 12:38:06 +08:00
|
|
|
func (pt *ParamTable) InitAlias(alias string) {
|
|
|
|
pt.Alias = alias
|
|
|
|
}
|
|
|
|
|
2021-10-01 11:24:43 +08:00
|
|
|
// Init is used to initialize configuration items.
|
2020-12-10 17:55:55 +08:00
|
|
|
func (pt *ParamTable) Init() {
|
2021-09-23 10:53:53 +08:00
|
|
|
pt.BaseTable.Init()
|
|
|
|
// TODO, load index_node.yaml
|
|
|
|
/*err := pt.LoadYaml("advanced/index_node.yaml")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}*/
|
|
|
|
pt.initParams()
|
|
|
|
}
|
|
|
|
|
2021-10-01 11:24:43 +08:00
|
|
|
// InitOnce is used to initialize configuration items, and it will only be called once.
|
2021-09-23 10:53:53 +08:00
|
|
|
func (pt *ParamTable) InitOnce() {
|
2021-02-06 13:39:15 +08:00
|
|
|
once.Do(func() {
|
2021-09-23 10:53:53 +08:00
|
|
|
pt.Init()
|
2021-02-06 13:39:15 +08:00
|
|
|
})
|
2021-01-29 17:08:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ParamTable) initParams() {
|
2020-12-30 16:41:24 +08:00
|
|
|
pt.initMinIOAddress()
|
|
|
|
pt.initMinIOAccessKeyID()
|
|
|
|
pt.initMinIOSecretAccessKey()
|
|
|
|
pt.initMinIOUseSSL()
|
2021-01-05 15:58:13 +08:00
|
|
|
pt.initMinioBucketName()
|
2021-06-11 22:04:41 +08:00
|
|
|
pt.initEtcdEndpoints()
|
2021-05-14 10:05:18 +08:00
|
|
|
pt.initMetaRootPath()
|
2021-09-26 19:19:57 +08:00
|
|
|
pt.initIndexRootPath()
|
2021-10-01 08:52:50 +08:00
|
|
|
pt.initRoleName()
|
2021-11-01 10:26:03 +08:00
|
|
|
pt.initKnowhereSimdType()
|
2020-12-10 17:55:55 +08:00
|
|
|
}
|
|
|
|
|
2020-12-22 08:14:36 +08:00
|
|
|
func (pt *ParamTable) initMinIOAddress() {
|
|
|
|
ret, err := pt.Load("_MinioAddress")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinIOAddress = ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ParamTable) initMinIOAccessKeyID() {
|
2021-10-26 15:10:03 +08:00
|
|
|
ret, err := pt.Load("_MinioAccessKeyID")
|
2020-12-22 08:14:36 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinIOAccessKeyID = ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ParamTable) initMinIOSecretAccessKey() {
|
2021-10-26 15:10:03 +08:00
|
|
|
ret, err := pt.Load("_MinioSecretAccessKey")
|
2020-12-22 08:14:36 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinIOSecretAccessKey = ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ParamTable) initMinIOUseSSL() {
|
2021-10-26 15:10:03 +08:00
|
|
|
ret, err := pt.Load("_MinioUseSSL")
|
2020-12-22 08:14:36 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinIOUseSSL, err = strconv.ParseBool(ret)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2021-01-05 15:58:13 +08:00
|
|
|
|
2021-06-11 22:04:41 +08:00
|
|
|
func (pt *ParamTable) initEtcdEndpoints() {
|
|
|
|
endpoints, err := pt.Load("_EtcdEndpoints")
|
2021-05-14 10:05:18 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-06-11 22:04:41 +08:00
|
|
|
pt.EtcdEndpoints = strings.Split(endpoints, ",")
|
2021-05-14 10:05:18 +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 = path.Join(rootPath, subPath)
|
|
|
|
}
|
|
|
|
|
2021-09-26 19:19:57 +08:00
|
|
|
func (pt *ParamTable) initIndexRootPath() {
|
|
|
|
rootPath, err := pt.Load("minio.rootPath")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.IndexRootPath = path.Join(rootPath, "index_files")
|
|
|
|
}
|
|
|
|
|
2021-01-05 15:58:13 +08:00
|
|
|
func (pt *ParamTable) initMinioBucketName() {
|
2021-10-26 15:10:03 +08:00
|
|
|
bucketName, err := pt.Load("_MinioBucketName")
|
2021-01-05 15:58:13 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.MinioBucketName = bucketName
|
|
|
|
}
|
2021-03-10 09:56:09 +08:00
|
|
|
|
2021-10-01 08:52:50 +08:00
|
|
|
func (pt *ParamTable) initRoleName() {
|
|
|
|
pt.RoleName = "indexnode"
|
2021-03-10 09:56:09 +08:00
|
|
|
}
|
2021-09-22 16:05:59 +08:00
|
|
|
|
|
|
|
func (pt *ParamTable) initKnowhereSimdType() {
|
2021-10-28 23:16:40 +08:00
|
|
|
simdType := pt.LoadWithDefault("knowhere.simdType", "auto")
|
2021-09-22 16:05:59 +08:00
|
|
|
pt.SimdType = simdType
|
2021-10-28 23:16:40 +08:00
|
|
|
log.Debug("initialize the knowhere simd type", zap.String("simd_type", pt.SimdType))
|
2021-09-22 16:05:59 +08:00
|
|
|
}
|