param_table.go 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// 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.

12 13 14 15 16
package grpcquerynode

import (
	"sync"

17 18 19 20
	"github.com/milvus-io/milvus/internal/distributed/grpcconfigs"
	"github.com/milvus-io/milvus/internal/log"
	"go.uber.org/zap"

X
Xiangyu Wang 已提交
21 22
	"github.com/milvus-io/milvus/internal/util/funcutil"
	"github.com/milvus-io/milvus/internal/util/paramtable"
23 24 25 26 27 28 29 30 31 32 33 34
)

var Params ParamTable
var once sync.Once

type ParamTable struct {
	paramtable.BaseTable

	QueryNodeIP   string
	QueryNodePort int
	QueryNodeID   UniqueID

35 36 37 38
	RootCoordAddress  string
	IndexCoordAddress string
	DataCoordAddress  string
	QueryCoordAddress string
39 40 41

	ServerMaxSendSize int
	ServerMaxRecvSize int
42 43 44 45 46
}

func (pt *ParamTable) Init() {
	once.Do(func() {
		pt.BaseTable.Init()
Z
zhenshan.cao 已提交
47
		pt.initPort()
48 49
		pt.initRootCoordAddress()
		pt.initIndexCoordAddress()
50
		pt.initDataCoordAddress()
51
		pt.initQueryCoordAddress()
52 53 54

		pt.initServerMaxSendSize()
		pt.initServerMaxRecvSize()
55 56 57 58 59 60 61 62 63 64 65
	})
}

func (pt *ParamTable) LoadFromArgs() {

}

func (pt *ParamTable) LoadFromEnv() {
	Params.QueryNodeIP = funcutil.GetLocalIP()
}

66 67
func (pt *ParamTable) initRootCoordAddress() {
	ret, err := pt.Load("_RootCoordAddress")
68 69 70
	if err != nil {
		panic(err)
	}
71
	pt.RootCoordAddress = ret
72 73
}

74 75
func (pt *ParamTable) initIndexCoordAddress() {
	ret, err := pt.Load("_IndexCoordAddress")
76 77 78
	if err != nil {
		panic(err)
	}
79
	pt.IndexCoordAddress = ret
80 81
}

82 83
func (pt *ParamTable) initDataCoordAddress() {
	ret, err := pt.Load("_DataCoordAddress")
84 85 86
	if err != nil {
		panic(err)
	}
87
	pt.DataCoordAddress = ret
88 89
}

90 91
func (pt *ParamTable) initQueryCoordAddress() {
	ret, err := pt.Load("_QueryCoordAddress")
92 93 94
	if err != nil {
		panic(err)
	}
95
	pt.QueryCoordAddress = ret
96
}
Z
zhenshan.cao 已提交
97 98 99 100 101

func (pt *ParamTable) initPort() {
	port := pt.ParseInt("queryNode.port")
	pt.QueryNodePort = port
}
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

func (pt *ParamTable) initServerMaxSendSize() {
	var err error
	pt.ServerMaxSendSize, err = pt.ParseIntWithErr("queryNode.grpc.serverMaxSendSize")
	if err != nil {
		pt.ServerMaxSendSize = grpcconfigs.DefaultServerMaxSendSize
		log.Debug("queryNode.grpc.serverMaxSendSize not set, set to default")
	}
	log.Debug("initServerMaxSendSize",
		zap.Int("queryNode.grpc.serverMaxSendSize", pt.ServerMaxSendSize))
}

func (pt *ParamTable) initServerMaxRecvSize() {
	var err error
	pt.ServerMaxRecvSize, err = pt.ParseIntWithErr("queryNode.grpc.serverMaxRecvSize")
	if err != nil {
		pt.ServerMaxRecvSize = grpcconfigs.DefaultServerMaxRecvSize
		log.Debug("queryNode.grpc.serverMaxRecvSize not set, set to default")
	}
	log.Debug("initServerMaxRecvSize",
		zap.Int("queryNode.grpc.serverMaxRecvSize", pt.ServerMaxRecvSize))
}