2022-01-10 23:59:43 +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-06-18 15:20:08 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2022-01-10 23:59:43 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-06-18 15:20:08 +08:00
|
|
|
//
|
2022-01-10 23:59:43 +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-06-18 15:20:08 +08:00
|
|
|
|
|
|
|
package paramtable
|
|
|
|
|
|
|
|
import (
|
2021-08-24 09:45:51 +08:00
|
|
|
"os"
|
2021-12-21 15:53:51 +08:00
|
|
|
"path"
|
2022-02-07 10:09:45 +08:00
|
|
|
"strconv"
|
2021-08-24 09:45:51 +08:00
|
|
|
"strings"
|
2021-06-18 15:20:08 +08:00
|
|
|
|
2021-09-03 19:35:47 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2021-06-18 15:20:08 +08:00
|
|
|
)
|
|
|
|
|
2022-02-08 20:57:47 +08:00
|
|
|
const (
|
|
|
|
// SuggestPulsarMaxMessageSize defines the maximum size of Pulsar message.
|
|
|
|
SuggestPulsarMaxMessageSize = 5 * 1024 * 1024
|
|
|
|
)
|
|
|
|
|
2022-02-09 14:41:45 +08:00
|
|
|
// ServiceParam is used to quickly and easily access all basic service configurations.
|
2022-02-08 20:57:47 +08:00
|
|
|
type ServiceParam struct {
|
2021-06-18 15:20:08 +08:00
|
|
|
BaseTable
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
EtcdCfg EtcdConfig
|
|
|
|
PulsarCfg PulsarConfig
|
|
|
|
RocksmqCfg RocksmqConfig
|
|
|
|
MinioCfg MinioConfig
|
2021-06-18 15:20:08 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 20:57:47 +08:00
|
|
|
func (p *ServiceParam) Init() {
|
2022-02-07 10:09:45 +08:00
|
|
|
p.BaseTable.Init()
|
|
|
|
|
|
|
|
p.EtcdCfg.init(&p.BaseTable)
|
|
|
|
p.PulsarCfg.init(&p.BaseTable)
|
|
|
|
p.RocksmqCfg.init(&p.BaseTable)
|
|
|
|
p.MinioCfg.init(&p.BaseTable)
|
2021-06-18 15:20:08 +08:00
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// --- etcd ---
|
|
|
|
type EtcdConfig struct {
|
|
|
|
Base *BaseTable
|
|
|
|
|
|
|
|
// --- ETCD ---
|
|
|
|
Endpoints []string
|
|
|
|
MetaRootPath string
|
|
|
|
KvRootPath string
|
|
|
|
|
|
|
|
// --- Embed ETCD ---
|
|
|
|
UseEmbedEtcd bool
|
|
|
|
ConfigPath string
|
|
|
|
DataDir string
|
2021-08-24 09:45:51 +08:00
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
func (p *EtcdConfig) init(base *BaseTable) {
|
|
|
|
p.Base = base
|
|
|
|
p.LoadCfgToMemory()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *EtcdConfig) LoadCfgToMemory() {
|
2021-08-24 09:45:51 +08:00
|
|
|
p.initUseEmbedEtcd()
|
|
|
|
if p.UseEmbedEtcd {
|
|
|
|
p.initConfigPath()
|
2022-02-07 10:09:45 +08:00
|
|
|
p.initDataDir()
|
2021-08-24 09:45:51 +08:00
|
|
|
} else {
|
2022-02-07 10:09:45 +08:00
|
|
|
p.initEndpoints()
|
2021-08-24 09:45:51 +08:00
|
|
|
}
|
2022-02-07 10:09:45 +08:00
|
|
|
p.initMetaRootPath()
|
|
|
|
p.initKvRootPath()
|
2021-08-24 09:45:51 +08:00
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
func (p *EtcdConfig) initUseEmbedEtcd() {
|
|
|
|
p.UseEmbedEtcd = p.Base.ParseBool("etcd.use.embed", false)
|
2021-09-03 19:35:47 +08:00
|
|
|
if p.UseEmbedEtcd && (os.Getenv(metricsinfo.DeployModeEnvKey) != metricsinfo.StandaloneDeployMode) {
|
2021-08-24 09:45:51 +08:00
|
|
|
panic("embedded etcd can not be used under distributed mode")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
func (p *EtcdConfig) initConfigPath() {
|
|
|
|
addr := p.Base.LoadWithDefault("etcd.config.path", "")
|
|
|
|
p.ConfigPath = addr
|
2021-08-24 09:45:51 +08:00
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
func (p *EtcdConfig) initDataDir() {
|
|
|
|
addr := p.Base.LoadWithDefault("etcd.data.dir", "default.etcd")
|
|
|
|
p.DataDir = addr
|
2021-08-24 09:45:51 +08:00
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
func (p *EtcdConfig) initEndpoints() {
|
|
|
|
endpoints, err := p.Base.Load("_EtcdEndpoints")
|
2021-08-24 09:45:51 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-02-07 10:09:45 +08:00
|
|
|
p.Endpoints = strings.Split(endpoints, ",")
|
2021-08-24 09:45:51 +08:00
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
func (p *EtcdConfig) initMetaRootPath() {
|
|
|
|
rootPath, err := p.Base.Load("etcd.rootPath")
|
2021-08-24 09:45:51 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-02-07 10:09:45 +08:00
|
|
|
subPath, err := p.Base.Load("etcd.metaSubPath")
|
2021-08-24 09:45:51 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-12-21 15:53:51 +08:00
|
|
|
p.MetaRootPath = path.Join(rootPath, subPath)
|
2021-08-24 09:45:51 +08:00
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
func (p *EtcdConfig) initKvRootPath() {
|
|
|
|
rootPath, err := p.Base.Load("etcd.rootPath")
|
2021-08-24 09:45:51 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-02-07 10:09:45 +08:00
|
|
|
subPath, err := p.Base.Load("etcd.kvSubPath")
|
2021-08-24 09:45:51 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-12-21 15:53:51 +08:00
|
|
|
p.KvRootPath = path.Join(rootPath, subPath)
|
2021-08-24 09:45:51 +08:00
|
|
|
}
|
2022-02-07 10:09:45 +08:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// --- pulsar ---
|
|
|
|
type PulsarConfig struct {
|
|
|
|
Base *BaseTable
|
|
|
|
|
|
|
|
Address string
|
|
|
|
MaxMessageSize int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PulsarConfig) init(base *BaseTable) {
|
|
|
|
p.Base = base
|
|
|
|
|
|
|
|
p.initAddress()
|
|
|
|
p.initMaxMessageSize()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PulsarConfig) initAddress() {
|
|
|
|
addr, err := p.Base.Load("_PulsarAddress")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
p.Address = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PulsarConfig) initMaxMessageSize() {
|
|
|
|
maxMessageSizeStr, err := p.Base.Load("pulsar.maxMessageSize")
|
|
|
|
if err != nil {
|
|
|
|
p.MaxMessageSize = SuggestPulsarMaxMessageSize
|
|
|
|
} else {
|
|
|
|
maxMessageSize, err := strconv.Atoi(maxMessageSizeStr)
|
|
|
|
if err != nil {
|
|
|
|
p.MaxMessageSize = SuggestPulsarMaxMessageSize
|
|
|
|
} else {
|
|
|
|
p.MaxMessageSize = maxMessageSize
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// --- rocksmq ---
|
|
|
|
type RocksmqConfig struct {
|
|
|
|
Base *BaseTable
|
|
|
|
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *RocksmqConfig) init(base *BaseTable) {
|
|
|
|
p.Base = base
|
|
|
|
|
|
|
|
p.initPath()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *RocksmqConfig) initPath() {
|
|
|
|
path, err := p.Base.Load("_RocksmqPath")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
p.Path = path
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// --- minio ---
|
|
|
|
type MinioConfig struct {
|
|
|
|
Base *BaseTable
|
|
|
|
|
|
|
|
Address string
|
|
|
|
AccessKeyID string
|
|
|
|
SecretAccessKey string
|
|
|
|
UseSSL bool
|
|
|
|
BucketName string
|
|
|
|
RootPath string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *MinioConfig) init(base *BaseTable) {
|
|
|
|
p.Base = base
|
|
|
|
|
|
|
|
p.initAddress()
|
|
|
|
p.initAccessKeyID()
|
|
|
|
p.initSecretAccessKey()
|
|
|
|
p.initUseSSL()
|
|
|
|
p.initBucketName()
|
|
|
|
p.initRootPath()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *MinioConfig) initAddress() {
|
|
|
|
endpoint, err := p.Base.Load("_MinioAddress")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
p.Address = endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *MinioConfig) initAccessKeyID() {
|
|
|
|
keyID, err := p.Base.Load("_MinioAccessKeyID")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
p.AccessKeyID = keyID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *MinioConfig) initSecretAccessKey() {
|
|
|
|
key, err := p.Base.Load("_MinioSecretAccessKey")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
p.SecretAccessKey = key
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *MinioConfig) initUseSSL() {
|
|
|
|
usessl, err := p.Base.Load("_MinioUseSSL")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
p.UseSSL, _ = strconv.ParseBool(usessl)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *MinioConfig) initBucketName() {
|
|
|
|
bucketName, err := p.Base.Load("_MinioBucketName")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
p.BucketName = bucketName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *MinioConfig) initRootPath() {
|
|
|
|
rootPath, err := p.Base.Load("minio.rootPath")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
p.RootPath = rootPath
|
|
|
|
}
|