2021-01-15 14:38:36 +08:00
|
|
|
package proxynode
|
2020-11-16 21:10:43 +08:00
|
|
|
|
|
|
|
import (
|
2021-01-29 09:27:26 +08:00
|
|
|
"bytes"
|
2020-11-21 19:12:59 +08:00
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2021-02-06 13:39:15 +08:00
|
|
|
"sync"
|
2020-11-21 19:12:59 +08:00
|
|
|
"time"
|
|
|
|
|
2021-01-29 09:27:26 +08:00
|
|
|
"github.com/spf13/cast"
|
2021-01-29 17:29:31 +08:00
|
|
|
|
2021-01-29 09:27:26 +08:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
|
|
|
|
|
2020-11-16 21:10:43 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/util/paramtable"
|
|
|
|
)
|
|
|
|
|
2021-01-29 09:27:26 +08:00
|
|
|
const (
|
|
|
|
StartParamsKey = "START_PARAMS"
|
|
|
|
)
|
|
|
|
|
2020-11-16 21:10:43 +08:00
|
|
|
type ParamTable struct {
|
|
|
|
paramtable.BaseTable
|
2021-01-28 20:51:44 +08:00
|
|
|
|
2021-01-29 09:27:26 +08:00
|
|
|
NetworkPort int
|
|
|
|
IP string
|
|
|
|
NetworkAddress string
|
|
|
|
|
|
|
|
MasterAddress string
|
|
|
|
PulsarAddress string
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
QueryNodeNum int
|
|
|
|
QueryNodeIDList []UniqueID
|
|
|
|
ProxyID UniqueID
|
|
|
|
TimeTickInterval time.Duration
|
|
|
|
InsertChannelNames []string
|
|
|
|
DeleteChannelNames []string
|
|
|
|
K2SChannelNames []string
|
|
|
|
SearchChannelNames []string
|
|
|
|
SearchResultChannelNames []string
|
|
|
|
ProxySubName string
|
|
|
|
ProxyTimeTickChannelNames []string
|
|
|
|
DataDefinitionChannelNames []string
|
|
|
|
MsgStreamInsertBufSize int64
|
|
|
|
MsgStreamSearchBufSize int64
|
|
|
|
MsgStreamSearchResultBufSize int64
|
|
|
|
MsgStreamSearchResultPulsarBufSize int64
|
|
|
|
MsgStreamTimeTickBufSize int64
|
|
|
|
MaxNameLength int64
|
|
|
|
MaxFieldNum int64
|
|
|
|
MaxDimension int64
|
|
|
|
DefaultPartitionTag string
|
2021-02-08 14:20:29 +08:00
|
|
|
DefaultIndexName string
|
2020-11-16 21:10:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var Params ParamTable
|
2021-02-06 13:39:15 +08:00
|
|
|
var once sync.Once
|
2020-11-16 21:10:43 +08:00
|
|
|
|
2021-01-29 09:27:26 +08:00
|
|
|
func (pt *ParamTable) LoadConfigFromInitParams(initParams *internalpb2.InitParams) error {
|
|
|
|
pt.ProxyID = initParams.NodeID
|
|
|
|
|
|
|
|
config := viper.New()
|
|
|
|
config.SetConfigType("yaml")
|
2021-01-29 17:29:31 +08:00
|
|
|
save := func() error {
|
|
|
|
for _, key := range config.AllKeys() {
|
|
|
|
val := config.Get(key)
|
|
|
|
str, err := cast.ToStringE(val)
|
2021-01-29 09:27:26 +08:00
|
|
|
if err != nil {
|
2021-01-29 17:29:31 +08:00
|
|
|
switch val := val.(type) {
|
|
|
|
case []interface{}:
|
|
|
|
str = str[:0]
|
|
|
|
for _, v := range val {
|
|
|
|
ss, err := cast.ToStringE(v)
|
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
if len(str) == 0 {
|
|
|
|
str = ss
|
|
|
|
} else {
|
|
|
|
str = str + "," + ss
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
log.Panicf("undefine config type, key=%s", key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Println("key: ", key, ", value: ", str)
|
|
|
|
err = pt.Save(key, str)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2021-01-29 09:27:26 +08:00
|
|
|
}
|
|
|
|
}
|
2021-01-29 17:29:31 +08:00
|
|
|
return nil
|
2021-01-29 09:27:26 +08:00
|
|
|
}
|
|
|
|
|
2021-01-29 17:29:31 +08:00
|
|
|
for _, pair := range initParams.StartParams {
|
|
|
|
if strings.HasPrefix(pair.Key, StartParamsKey) {
|
|
|
|
err := config.ReadConfig(bytes.NewBuffer([]byte(pair.Value)))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = save()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-01-29 09:27:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pt.initParams()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-21 19:12:59 +08:00
|
|
|
func (pt *ParamTable) Init() {
|
2021-02-06 13:39:15 +08:00
|
|
|
once.Do(func() {
|
|
|
|
pt.BaseTable.Init()
|
|
|
|
// err := pt.LoadYaml("advanced/proxy_node.yaml")
|
|
|
|
// if err != nil {
|
|
|
|
// panic(err)
|
|
|
|
// }
|
|
|
|
// pt.initParams()
|
|
|
|
})
|
2021-01-29 09:27:26 +08:00
|
|
|
}
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2021-01-29 09:27:26 +08:00
|
|
|
func (pt *ParamTable) initParams() {
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.initPulsarAddress()
|
|
|
|
pt.initQueryNodeIDList()
|
|
|
|
pt.initQueryNodeNum()
|
2021-01-29 17:29:31 +08:00
|
|
|
// pt.initProxyID()
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.initTimeTickInterval()
|
|
|
|
pt.initInsertChannelNames()
|
|
|
|
pt.initDeleteChannelNames()
|
|
|
|
pt.initK2SChannelNames()
|
|
|
|
pt.initSearchChannelNames()
|
|
|
|
pt.initSearchResultChannelNames()
|
|
|
|
pt.initProxySubName()
|
|
|
|
pt.initProxyTimeTickChannelNames()
|
|
|
|
pt.initDataDefinitionChannelNames()
|
|
|
|
pt.initMsgStreamInsertBufSize()
|
|
|
|
pt.initMsgStreamSearchBufSize()
|
|
|
|
pt.initMsgStreamSearchResultBufSize()
|
|
|
|
pt.initMsgStreamSearchResultPulsarBufSize()
|
|
|
|
pt.initMsgStreamTimeTickBufSize()
|
|
|
|
pt.initMaxNameLength()
|
|
|
|
pt.initMaxFieldNum()
|
|
|
|
pt.initMaxDimension()
|
|
|
|
pt.initDefaultPartitionTag()
|
2021-02-08 14:20:29 +08:00
|
|
|
pt.initDefaultIndexName()
|
|
|
|
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initPulsarAddress() {
|
2020-11-21 19:12:59 +08:00
|
|
|
ret, err := pt.Load("_PulsarAddress")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.PulsarAddress = ret
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initQueryNodeNum() {
|
|
|
|
pt.QueryNodeNum = len(pt.QueryNodeIDList)
|
2020-11-26 16:01:31 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initQueryNodeIDList() []UniqueID {
|
2020-11-26 16:01:31 +08:00
|
|
|
queryNodeIDStr, err := pt.Load("nodeID.queryNodeIDList")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
var ret []UniqueID
|
|
|
|
queryNodeIDs := strings.Split(queryNodeIDStr, ",")
|
|
|
|
for _, i := range queryNodeIDs {
|
|
|
|
v, err := strconv.Atoi(i)
|
|
|
|
if err != nil {
|
2021-01-15 14:38:36 +08:00
|
|
|
log.Panicf("load proxynode id list error, %s", err.Error())
|
2020-11-26 16:01:31 +08:00
|
|
|
}
|
|
|
|
ret = append(ret, UniqueID(v))
|
|
|
|
}
|
2021-02-22 10:44:38 +08:00
|
|
|
pt.QueryNodeIDList = ret
|
2020-11-26 16:01:31 +08:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initProxyID() {
|
2020-11-21 19:12:59 +08:00
|
|
|
proxyID, err := pt.Load("_proxyID")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
ID, err := strconv.Atoi(proxyID)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.ProxyID = UniqueID(ID)
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initTimeTickInterval() {
|
2021-01-29 17:29:31 +08:00
|
|
|
intervalStr, err := pt.Load("proxyNode.timeTickInterval")
|
2020-11-21 19:12:59 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-01-29 17:29:31 +08:00
|
|
|
interval, err := strconv.Atoi(intervalStr)
|
2020-11-21 19:12:59 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.TimeTickInterval = time.Duration(interval) * time.Millisecond
|
2020-11-16 21:10:43 +08:00
|
|
|
}
|
2020-11-21 15:06:46 +08:00
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initInsertChannelNames() {
|
2020-11-21 19:12:59 +08:00
|
|
|
prefix, err := pt.Load("msgChannel.chanNamePrefix.insert")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
prefix += "-"
|
|
|
|
iRangeStr, err := pt.Load("msgChannel.channelRange.insert")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-12-08 14:41:04 +08:00
|
|
|
channelIDs := paramtable.ConvertRangeToIntSlice(iRangeStr, ",")
|
2020-11-21 19:12:59 +08:00
|
|
|
var ret []string
|
|
|
|
for _, ID := range channelIDs {
|
|
|
|
ret = append(ret, prefix+strconv.Itoa(ID))
|
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.InsertChannelNames = ret
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initDeleteChannelNames() {
|
2020-11-21 19:12:59 +08:00
|
|
|
prefix, err := pt.Load("msgChannel.chanNamePrefix.delete")
|
2020-11-21 15:06:46 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-11-21 19:12:59 +08:00
|
|
|
prefix += "-"
|
|
|
|
dRangeStr, err := pt.Load("msgChannel.channelRange.delete")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-12-08 14:41:04 +08:00
|
|
|
channelIDs := paramtable.ConvertRangeToIntSlice(dRangeStr, ",")
|
2020-11-21 19:12:59 +08:00
|
|
|
var ret []string
|
|
|
|
for _, ID := range channelIDs {
|
|
|
|
ret = append(ret, prefix+strconv.Itoa(ID))
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.DeleteChannelNames = ret
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initK2SChannelNames() {
|
2020-11-21 19:12:59 +08:00
|
|
|
prefix, err := pt.Load("msgChannel.chanNamePrefix.k2s")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
prefix += "-"
|
|
|
|
k2sRangeStr, err := pt.Load("msgChannel.channelRange.k2s")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-12-08 14:41:04 +08:00
|
|
|
channelIDs := paramtable.ConvertRangeToIntSlice(k2sRangeStr, ",")
|
2020-11-21 19:12:59 +08:00
|
|
|
var ret []string
|
|
|
|
for _, ID := range channelIDs {
|
|
|
|
ret = append(ret, prefix+strconv.Itoa(ID))
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.K2SChannelNames = ret
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initSearchChannelNames() {
|
2020-11-21 19:12:59 +08:00
|
|
|
prefix, err := pt.Load("msgChannel.chanNamePrefix.search")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-12-08 14:41:04 +08:00
|
|
|
prefix += "-"
|
|
|
|
sRangeStr, err := pt.Load("msgChannel.channelRange.search")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
channelIDs := paramtable.ConvertRangeToIntSlice(sRangeStr, ",")
|
|
|
|
var ret []string
|
|
|
|
for _, ID := range channelIDs {
|
|
|
|
ret = append(ret, prefix+strconv.Itoa(ID))
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.SearchChannelNames = ret
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initSearchResultChannelNames() {
|
2020-11-21 19:12:59 +08:00
|
|
|
prefix, err := pt.Load("msgChannel.chanNamePrefix.searchResult")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
prefix += "-"
|
|
|
|
sRangeStr, err := pt.Load("msgChannel.channelRange.searchResult")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-12-08 14:41:04 +08:00
|
|
|
channelIDs := paramtable.ConvertRangeToIntSlice(sRangeStr, ",")
|
2020-11-21 19:12:59 +08:00
|
|
|
var ret []string
|
|
|
|
for _, ID := range channelIDs {
|
|
|
|
ret = append(ret, prefix+strconv.Itoa(ID))
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.SearchResultChannelNames = ret
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initProxySubName() {
|
2020-11-21 19:12:59 +08:00
|
|
|
prefix, err := pt.Load("msgChannel.subNamePrefix.proxySubNamePrefix")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-01-29 17:29:31 +08:00
|
|
|
pt.ProxySubName = prefix
|
|
|
|
// proxyIDStr, err := pt.Load("_proxyID")
|
|
|
|
// if err != nil {
|
|
|
|
// panic(err)
|
|
|
|
// }
|
|
|
|
pt.ProxySubName = prefix + "-" + strconv.Itoa(int(pt.ProxyID))
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initProxyTimeTickChannelNames() {
|
2020-11-21 19:12:59 +08:00
|
|
|
prefix, err := pt.Load("msgChannel.chanNamePrefix.proxyTimeTick")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
prefix += "-0"
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.ProxyTimeTickChannelNames = []string{prefix}
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initDataDefinitionChannelNames() {
|
2020-11-21 19:12:59 +08:00
|
|
|
prefix, err := pt.Load("msgChannel.chanNamePrefix.dataDefinition")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
prefix += "-0"
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.DataDefinitionChannelNames = []string{prefix}
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initMsgStreamInsertBufSize() {
|
|
|
|
pt.MsgStreamInsertBufSize = pt.ParseInt64("proxyNode.msgStream.insert.bufSize")
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initMsgStreamSearchBufSize() {
|
|
|
|
pt.MsgStreamSearchBufSize = pt.ParseInt64("proxyNode.msgStream.search.bufSize")
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initMsgStreamSearchResultBufSize() {
|
|
|
|
pt.MsgStreamSearchResultBufSize = pt.ParseInt64("proxyNode.msgStream.searchResult.recvBufSize")
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initMsgStreamSearchResultPulsarBufSize() {
|
|
|
|
pt.MsgStreamSearchResultPulsarBufSize = pt.ParseInt64("proxyNode.msgStream.searchResult.pulsarBufSize")
|
2020-11-21 19:12:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initMsgStreamTimeTickBufSize() {
|
|
|
|
pt.MsgStreamTimeTickBufSize = pt.ParseInt64("proxyNode.msgStream.timeTick.bufSize")
|
2020-11-26 16:01:31 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initMaxNameLength() {
|
2021-01-15 14:38:36 +08:00
|
|
|
str, err := pt.Load("proxyNode.maxNameLength")
|
2020-11-26 16:01:31 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
maxNameLength, err := strconv.ParseInt(str, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.MaxNameLength = maxNameLength
|
2020-11-26 16:01:31 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initMaxFieldNum() {
|
2021-01-15 14:38:36 +08:00
|
|
|
str, err := pt.Load("proxyNode.maxFieldNum")
|
2020-11-26 16:01:31 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
maxFieldNum, err := strconv.ParseInt(str, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.MaxFieldNum = maxFieldNum
|
2020-11-26 16:01:31 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initMaxDimension() {
|
2021-01-15 14:38:36 +08:00
|
|
|
str, err := pt.Load("proxyNode.maxDimension")
|
2020-11-26 16:01:31 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
maxDimension, err := strconv.ParseInt(str, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.MaxDimension = maxDimension
|
2020-11-26 16:01:31 +08:00
|
|
|
}
|
|
|
|
|
2021-01-28 20:51:44 +08:00
|
|
|
func (pt *ParamTable) initDefaultPartitionTag() {
|
2020-11-26 16:01:31 +08:00
|
|
|
tag, err := pt.Load("common.defaultPartitionTag")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-01-28 20:51:44 +08:00
|
|
|
pt.DefaultPartitionTag = tag
|
2020-11-26 16:01:31 +08:00
|
|
|
}
|
2021-02-08 14:20:29 +08:00
|
|
|
|
|
|
|
func (pt *ParamTable) initDefaultIndexName() {
|
|
|
|
name, err := pt.Load("common.defaultIndexName")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
pt.DefaultIndexName = name
|
|
|
|
}
|