param_table.go 10.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
package master

import (
	"log"
	"strconv"
	"strings"

	"github.com/zilliztech/milvus-distributed/internal/util/paramtable"
	"github.com/zilliztech/milvus-distributed/internal/util/tsoutil"
	"github.com/zilliztech/milvus-distributed/internal/util/typeutil"
)

type ParamTable struct {
	paramtable.BaseTable

	Address string
	Port    int

	EtcdAddress   string
G
godchen 已提交
20
	EtcdRootPath  string
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
	PulsarAddress string

	// nodeID
	ProxyIDList     []typeutil.UniqueID
	WriteNodeIDList []typeutil.UniqueID

	TopicNum                    int
	QueryNodeNum                int
	SoftTimeTickBarrierInterval typeutil.Timestamp

	// segment
	SegmentSize           float64
	SegmentSizeFactor     float64
	DefaultRecordSize     int64
	MinSegIDAssignCnt     int64
	MaxSegIDAssignCnt     int64
	SegIDAssignExpiration int64

	// msgChannel
	ProxyTimeTickChannelNames     []string
	WriteNodeTimeTickChannelNames []string
G
godchen 已提交
42
	DDChannelNames                []string
43 44 45 46
	InsertChannelNames            []string
	K2SChannelNames               []string
	QueryNodeStatsChannelName     string
	MsgChannelSubName             string
N
neza2017 已提交
47 48 49

	MaxPartitionNum     int64
	DefaultPartitionTag string
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
}

var Params ParamTable

func (p *ParamTable) Init() {
	// load yaml
	p.BaseTable.Init()
	err := p.LoadYaml("milvus.yaml")
	if err != nil {
		panic(err)
	}
	err = p.LoadYaml("advanced/channel.yaml")
	if err != nil {
		panic(err)
	}
	err = p.LoadYaml("advanced/master.yaml")
	if err != nil {
		panic(err)
	}
N
neza2017 已提交
69 70 71 72
	err = p.LoadYaml("advanced/common.yaml")
	if err != nil {
		panic(err)
	}
73 74 75 76 77 78

	// set members
	p.initAddress()
	p.initPort()

	p.initEtcdAddress()
G
godchen 已提交
79
	p.initEtcdRootPath()
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
	p.initPulsarAddress()

	p.initProxyIDList()
	p.initWriteNodeIDList()

	p.initTopicNum()
	p.initQueryNodeNum()
	p.initSoftTimeTickBarrierInterval()

	p.initSegmentSize()
	p.initSegmentSizeFactor()
	p.initDefaultRecordSize()
	p.initMinSegIDAssignCnt()
	p.initMaxSegIDAssignCnt()
	p.initSegIDAssignExpiration()

	p.initProxyTimeTickChannelNames()
	p.initWriteNodeTimeTickChannelNames()
	p.initInsertChannelNames()
G
godchen 已提交
99
	p.initDDChannelNames()
100 101 102
	p.initK2SChannelNames()
	p.initQueryNodeStatsChannelName()
	p.initMsgChannelSubName()
N
neza2017 已提交
103 104
	p.initMaxPartitionNum()
	p.initDefaultPartitionTag()
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
}

func (p *ParamTable) initAddress() {
	masterAddress, err := p.Load("master.address")
	if err != nil {
		panic(err)
	}
	p.Address = masterAddress
}

func (p *ParamTable) initPort() {
	masterPort, err := p.Load("master.port")
	if err != nil {
		panic(err)
	}
	port, err := strconv.Atoi(masterPort)
	if err != nil {
		panic(err)
	}
	p.Port = port
}

func (p *ParamTable) initEtcdAddress() {
	addr, err := p.Load("_EtcdAddress")
	if err != nil {
		panic(err)
	}
	p.EtcdAddress = addr
}

func (p *ParamTable) initPulsarAddress() {
	addr, err := p.Load("_PulsarAddress")
	if err != nil {
		panic(err)
	}
	p.PulsarAddress = addr
}

G
godchen 已提交
143 144
func (p *ParamTable) initEtcdRootPath() {
	path, err := p.Load("etcd.rootpath")
145 146 147
	if err != nil {
		panic(err)
	}
G
godchen 已提交
148
	p.EtcdRootPath = path
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
}

func (p *ParamTable) initTopicNum() {
	insertChannelRange, err := p.Load("msgChannel.channelRange.insert")
	if err != nil {
		panic(err)
	}

	channelRange := strings.Split(insertChannelRange, ",")
	if len(channelRange) != 2 {
		panic("Illegal channel range num")
	}
	channelBegin, err := strconv.Atoi(channelRange[0])
	if err != nil {
		panic(err)
	}
	channelEnd, err := strconv.Atoi(channelRange[1])
	if err != nil {
		panic(err)
	}
	if channelBegin < 0 || channelEnd < 0 {
		panic("Illegal channel range value")
	}
	if channelBegin > channelEnd {
		panic("Illegal channel range value")
	}
	p.TopicNum = channelEnd
}

func (p *ParamTable) initSegmentSize() {
	threshold, err := p.Load("master.segment.size")
	if err != nil {
		panic(err)
	}
	segmentThreshold, err := strconv.ParseFloat(threshold, 64)
	if err != nil {
		panic(err)
	}
	p.SegmentSize = segmentThreshold
}

func (p *ParamTable) initSegmentSizeFactor() {
	segFactor, err := p.Load("master.segment.sizeFactor")
	if err != nil {
		panic(err)
	}
	factor, err := strconv.ParseFloat(segFactor, 64)
	if err != nil {
		panic(err)
	}
	p.SegmentSizeFactor = factor
}

func (p *ParamTable) initDefaultRecordSize() {
	size, err := p.Load("master.segment.defaultSizePerRecord")
	if err != nil {
		panic(err)
	}
	res, err := strconv.ParseInt(size, 10, 64)
	if err != nil {
		panic(err)
	}
	p.DefaultRecordSize = res
}

func (p *ParamTable) initMinSegIDAssignCnt() {
	size, err := p.Load("master.segment.minIDAssignCnt")
	if err != nil {
		panic(err)
	}
	res, err := strconv.ParseInt(size, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MinSegIDAssignCnt = res
}

func (p *ParamTable) initMaxSegIDAssignCnt() {
	size, err := p.Load("master.segment.maxIDAssignCnt")
	if err != nil {
		panic(err)
	}
	res, err := strconv.ParseInt(size, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxSegIDAssignCnt = res
}

func (p *ParamTable) initSegIDAssignExpiration() {
	duration, err := p.Load("master.segment.IDAssignExpiration")
	if err != nil {
		panic(err)
	}
	res, err := strconv.ParseInt(duration, 10, 64)
	if err != nil {
		panic(err)
	}
	p.SegIDAssignExpiration = res
}

func (p *ParamTable) initQueryNodeNum() {
	id, err := p.Load("nodeID.queryNodeIDList")
	if err != nil {
		panic(err)
	}
	ids := strings.Split(id, ",")
	for _, i := range ids {
		_, err := strconv.ParseInt(i, 10, 64)
		if err != nil {
			log.Panicf("load proxy id list error, %s", err.Error())
		}
	}
	p.QueryNodeNum = len(ids)
}

func (p *ParamTable) initQueryNodeStatsChannelName() {
	channels, err := p.Load("msgChannel.chanNamePrefix.queryNodeStats")
	if err != nil {
		panic(err)
	}
	p.QueryNodeStatsChannelName = channels
}

func (p *ParamTable) initProxyIDList() {
	id, err := p.Load("nodeID.proxyIDList")
	if err != nil {
		log.Panicf("load proxy id list error, %s", err.Error())
	}
	ids := strings.Split(id, ",")
	idList := make([]typeutil.UniqueID, 0, len(ids))
	for _, i := range ids {
		v, err := strconv.ParseInt(i, 10, 64)
		if err != nil {
			log.Panicf("load proxy id list error, %s", err.Error())
		}
		idList = append(idList, typeutil.UniqueID(v))
	}
	p.ProxyIDList = idList
}

func (p *ParamTable) initProxyTimeTickChannelNames() {
	ch, err := p.Load("msgChannel.chanNamePrefix.proxyTimeTick")
	if err != nil {
		log.Panic(err)
	}
	id, err := p.Load("nodeID.proxyIDList")
	if err != nil {
		log.Panicf("load proxy id list error, %s", err.Error())
	}
	ids := strings.Split(id, ",")
	channels := make([]string, 0, len(ids))
	for _, i := range ids {
		_, err := strconv.ParseInt(i, 10, 64)
		if err != nil {
			log.Panicf("load proxy id list error, %s", err.Error())
		}
		channels = append(channels, ch+"-"+i)
	}
	p.ProxyTimeTickChannelNames = channels
}

func (p *ParamTable) initMsgChannelSubName() {
	name, err := p.Load("msgChannel.subNamePrefix.masterSubNamePrefix")
	if err != nil {
		log.Panic(err)
	}
	p.MsgChannelSubName = name
}

func (p *ParamTable) initSoftTimeTickBarrierInterval() {
	t, err := p.Load("master.timeSync.softTimeTickBarrierInterval")
	if err != nil {
		log.Panic(err)
	}
	v, err := strconv.ParseInt(t, 10, 64)
	if err != nil {
		log.Panic(err)
	}
	p.SoftTimeTickBarrierInterval = tsoutil.ComposeTS(v, 0)
}

func (p *ParamTable) initWriteNodeIDList() {
	id, err := p.Load("nodeID.writeNodeIDList")
	if err != nil {
		log.Panic(err)
	}
	ids := strings.Split(id, ",")
	idlist := make([]typeutil.UniqueID, 0, len(ids))
	for _, i := range ids {
		v, err := strconv.ParseInt(i, 10, 64)
		if err != nil {
			log.Panicf("load proxy id list error, %s", err.Error())
		}
		idlist = append(idlist, typeutil.UniqueID(v))
	}
	p.WriteNodeIDList = idlist
}

func (p *ParamTable) initWriteNodeTimeTickChannelNames() {
	ch, err := p.Load("msgChannel.chanNamePrefix.writeNodeTimeTick")
	if err != nil {
		log.Fatal(err)
	}
	id, err := p.Load("nodeID.writeNodeIDList")
	if err != nil {
		log.Panicf("load write node id list error, %s", err.Error())
	}
	ids := strings.Split(id, ",")
	channels := make([]string, 0, len(ids))
	for _, i := range ids {
		_, err := strconv.ParseInt(i, 10, 64)
		if err != nil {
			log.Panicf("load write node id list error, %s", err.Error())
		}
		channels = append(channels, ch+"-"+i)
	}
	p.WriteNodeTimeTickChannelNames = channels
}

G
godchen 已提交
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
func (p *ParamTable) initDDChannelNames() {
	ch, err := p.Load("msgChannel.chanNamePrefix.dataDefinition")
	if err != nil {
		log.Fatal(err)
	}
	id, err := p.Load("nodeID.queryNodeIDList")
	if err != nil {
		log.Panicf("load query node id list error, %s", err.Error())
	}
	ids := strings.Split(id, ",")
	channels := make([]string, 0, len(ids))
	for _, i := range ids {
		_, err := strconv.ParseInt(i, 10, 64)
		if err != nil {
			log.Panicf("load query node id list error, %s", err.Error())
		}
		channels = append(channels, ch+"-"+i)
	}
	p.DDChannelNames = channels
}

390 391 392 393 394
func (p *ParamTable) initInsertChannelNames() {
	ch, err := p.Load("msgChannel.chanNamePrefix.insert")
	if err != nil {
		log.Fatal(err)
	}
N
neza2017 已提交
395
	channelRange, err := p.Load("msgChannel.channelRange.insert")
Z
zhenshan.cao 已提交
396
	if err != nil {
N
neza2017 已提交
397
		panic(err)
Z
zhenshan.cao 已提交
398
	}
N
neza2017 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421

	chanRange := strings.Split(channelRange, ",")
	if len(chanRange) != 2 {
		panic("Illegal channel range num")
	}
	channelBegin, err := strconv.Atoi(chanRange[0])
	if err != nil {
		panic(err)
	}
	channelEnd, err := strconv.Atoi(chanRange[1])
	if err != nil {
		panic(err)
	}
	if channelBegin < 0 || channelEnd < 0 {
		panic("Illegal channel range value")
	}
	if channelBegin > channelEnd {
		panic("Illegal channel range value")
	}

	channels := make([]string, channelEnd-channelBegin)
	for i := 0; i < channelEnd-channelBegin; i++ {
		channels[i] = ch + "-" + strconv.Itoa(channelBegin+i)
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
	}
	p.InsertChannelNames = channels
}

func (p *ParamTable) initK2SChannelNames() {
	ch, err := p.Load("msgChannel.chanNamePrefix.k2s")
	if err != nil {
		log.Fatal(err)
	}
	id, err := p.Load("nodeID.writeNodeIDList")
	if err != nil {
		log.Panicf("load write node id list error, %s", err.Error())
	}
	ids := strings.Split(id, ",")
	channels := make([]string, 0, len(ids))
	for _, i := range ids {
		_, err := strconv.ParseInt(i, 10, 64)
		if err != nil {
			log.Panicf("load write node id list error, %s", err.Error())
		}
		channels = append(channels, ch+"-"+i)
	}
	p.K2SChannelNames = channels
}
N
neza2017 已提交
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466

func (p *ParamTable) initMaxPartitionNum() {
	str, err := p.Load("master.maxPartitionNum")
	if err != nil {
		panic(err)
	}
	maxPartitionNum, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxPartitionNum = maxPartitionNum
}

func (p *ParamTable) initDefaultPartitionTag() {
	defaultTag, err := p.Load("common.defaultPartitionTag")
	if err != nil {
		panic(err)
	}

	p.DefaultPartitionTag = defaultTag
}