component_param.go 36.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// 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.

package paramtable

import (
15
	"math"
16
	"runtime"
17
	"strconv"
18
	"strings"
19
	"sync"
X
Xiaofan 已提交
20
	"sync/atomic"
21
	"time"
22

G
godchen 已提交
23
	"github.com/milvus-io/milvus/internal/log"
24
	"go.uber.org/zap"
25 26 27
)

const (
28
	// DefaultRetentionDuration defines the default duration for retention which is 5 days in seconds.
29
	DefaultRetentionDuration = 3600 * 24
30 31

	// DefaultIndexSliceSize defines the default slice size of index file when serializing.
32
	DefaultIndexSliceSize = 16
33
	DefaultGracefulTime   = 5000 //ms
34 35
)

36
// ComponentParam is used to quickly and easily access all components' configurations.
37 38
type ComponentParam struct {
	ServiceParam
39
	once sync.Once
40

41 42
	CommonCfg   commonConfig
	QuotaConfig quotaConfig
43 44 45 46 47 48 49 50 51 52 53 54

	RootCoordCfg  rootCoordConfig
	ProxyCfg      proxyConfig
	QueryCoordCfg queryCoordConfig
	QueryNodeCfg  queryNodeConfig
	DataCoordCfg  dataCoordConfig
	DataNodeCfg   dataNodeConfig
	IndexCoordCfg indexCoordConfig
	IndexNodeCfg  indexNodeConfig
}

// InitOnce initialize once
55
func (p *ComponentParam) InitOnce() {
56 57 58 59 60
	p.once.Do(func() {
		p.Init()
	})
}

61
// Init initialize the global param table
62 63
func (p *ComponentParam) Init() {
	p.ServiceParam.Init()
64

65
	p.CommonCfg.init(&p.BaseTable)
66
	p.QuotaConfig.init(&p.BaseTable)
67

68 69 70 71 72 73 74 75
	p.RootCoordCfg.init(&p.BaseTable)
	p.ProxyCfg.init(&p.BaseTable)
	p.QueryCoordCfg.init(&p.BaseTable)
	p.QueryNodeCfg.init(&p.BaseTable)
	p.DataCoordCfg.init(&p.BaseTable)
	p.DataNodeCfg.init(&p.BaseTable)
	p.IndexCoordCfg.init(&p.BaseTable)
	p.IndexNodeCfg.init(&p.BaseTable)
76 77
}

78
// SetLogConfig set log config with given role
79
func (p *ComponentParam) SetLogConfig(role string) {
80 81
	p.BaseTable.RoleName = role
	p.BaseTable.SetLogConfig()
82 83
}

84 85 86 87 88 89 90 91
func (p *ComponentParam) RocksmqEnable() bool {
	return p.RocksmqCfg.Path != ""
}

func (p *ComponentParam) PulsarEnable() bool {
	return p.PulsarCfg.Address != ""
}

J
jaime 已提交
92 93 94 95
func (p *ComponentParam) KafkaEnable() bool {
	return p.KafkaCfg.Address != ""
}

96
///////////////////////////////////////////////////////////////////////////////
97
// --- common ---
98
type commonConfig struct {
99
	Base *BaseTable
100

101
	ClusterPrefix string
102

103 104
	ProxySubName string

105 106 107 108 109
	RootCoordTimeTick   string
	RootCoordStatistics string
	RootCoordDml        string
	RootCoordDelta      string
	RootCoordSubName    string
110

111 112 113
	QueryCoordSearch       string
	QueryCoordSearchResult string
	QueryCoordTimeTick     string
114
	QueryNodeSubName       string
115

116 117 118 119
	DataCoordStatistic   string
	DataCoordTimeTick    string
	DataCoordSegmentInfo string
	DataCoordSubName     string
120
	DataNodeSubName      string
121 122 123 124

	DefaultPartitionName string
	DefaultIndexName     string
	RetentionDuration    int64
X
Xiaofan 已提交
125
	EntityExpirationTTL  time.Duration
126

127
	IndexSliceSize int64
128 129 130 131
	GracefulTime   int64

	StorageType string
	SimdType    string
C
codeman 已提交
132 133

	AuthorizationEnabled bool
134 135

	ClusterName string
136 137
}

138
func (p *commonConfig) init(base *BaseTable) {
139
	p.Base = base
140

141 142
	// must init cluster prefix first
	p.initClusterPrefix()
143 144
	p.initProxySubName()

145 146 147 148 149 150 151 152 153
	p.initRootCoordTimeTick()
	p.initRootCoordStatistics()
	p.initRootCoordDml()
	p.initRootCoordDelta()
	p.initRootCoordSubName()

	p.initQueryCoordSearch()
	p.initQueryCoordSearchResult()
	p.initQueryCoordTimeTick()
154
	p.initQueryNodeSubName()
155 156 157 158 159

	p.initDataCoordStatistic()
	p.initDataCoordTimeTick()
	p.initDataCoordSegmentInfo()
	p.initDataCoordSubName()
160
	p.initDataNodeSubName()
161 162 163 164

	p.initDefaultPartitionName()
	p.initDefaultIndexName()
	p.initRetentionDuration()
X
Xiaofan 已提交
165
	p.initEntityExpiration()
166 167

	p.initSimdType()
168
	p.initIndexSliceSize()
169
	p.initGracefulTime()
J
jaime 已提交
170
	p.initStorageType()
C
codeman 已提交
171 172

	p.initEnableAuthorization()
173 174

	p.initClusterName()
175 176
}

177 178 179
func (p *commonConfig) initClusterPrefix() {
	keys := []string{
		"msgChannel.chanNamePrefix.cluster",
X
Xiaofan 已提交
180
		"common.chanNamePrefix.cluster",
181
	}
X
Xiaofan 已提交
182
	str, err := p.Base.LoadWithPriority(keys)
183 184 185
	if err != nil {
		panic(err)
	}
186
	p.ClusterPrefix = str
187 188
}

189
func (p *commonConfig) initChanNamePrefix(keys []string) string {
X
Xiaofan 已提交
190
	value, err := p.Base.LoadWithPriority(keys)
191 192 193
	if err != nil {
		panic(err)
	}
194 195
	s := []string{p.ClusterPrefix, value}
	return strings.Join(s, "-")
196 197
}

198
// --- proxy ---
199 200 201
func (p *commonConfig) initProxySubName() {
	keys := []string{
		"msgChannel.subNamePrefix.proxySubNamePrefix",
X
Xiaofan 已提交
202
		"common.subNamePrefix.proxySubNamePrefix",
203 204
	}
	p.ProxySubName = p.initChanNamePrefix(keys)
205 206
}

207
// --- rootcoord ---
X
Xiaofan 已提交
208
// Deprecate
209 210 211
func (p *commonConfig) initRootCoordTimeTick() {
	keys := []string{
		"msgChannel.chanNamePrefix.rootCoordTimeTick",
X
Xiaofan 已提交
212
		"common.chanNamePrefix.rootCoordTimeTick",
213 214
	}
	p.RootCoordTimeTick = p.initChanNamePrefix(keys)
215 216
}

217 218 219
func (p *commonConfig) initRootCoordStatistics() {
	keys := []string{
		"msgChannel.chanNamePrefix.rootCoordStatistics",
X
Xiaofan 已提交
220
		"common.chanNamePrefix.rootCoordStatistics",
221 222
	}
	p.RootCoordStatistics = p.initChanNamePrefix(keys)
223 224
}

225 226 227
func (p *commonConfig) initRootCoordDml() {
	keys := []string{
		"msgChannel.chanNamePrefix.rootCoordDml",
X
Xiaofan 已提交
228
		"common.chanNamePrefix.rootCoordDml",
229 230
	}
	p.RootCoordDml = p.initChanNamePrefix(keys)
231 232
}

233 234 235
func (p *commonConfig) initRootCoordDelta() {
	keys := []string{
		"msgChannel.chanNamePrefix.rootCoordDelta",
X
Xiaofan 已提交
236
		"common.chanNamePrefix.rootCoordDelta",
237 238
	}
	p.RootCoordDelta = p.initChanNamePrefix(keys)
239 240
}

241 242 243
func (p *commonConfig) initRootCoordSubName() {
	keys := []string{
		"msgChannel.subNamePrefix.rootCoordSubNamePrefix",
X
Xiaofan 已提交
244
		"common.subNamePrefix.rootCoordSubNamePrefix",
245 246
	}
	p.RootCoordSubName = p.initChanNamePrefix(keys)
247 248 249
}

// --- querycoord ---
250 251 252
func (p *commonConfig) initQueryCoordSearch() {
	keys := []string{
		"msgChannel.chanNamePrefix.search",
X
Xiaofan 已提交
253
		"common.chanNamePrefix.search",
254 255
	}
	p.QueryCoordSearch = p.initChanNamePrefix(keys)
256 257
}

X
Xiaofan 已提交
258
// Deprecated, search result use grpc instead of a result channel
259 260 261
func (p *commonConfig) initQueryCoordSearchResult() {
	keys := []string{
		"msgChannel.chanNamePrefix.searchResult",
X
Xiaofan 已提交
262
		"common.chanNamePrefix.searchResult",
263 264
	}
	p.QueryCoordSearchResult = p.initChanNamePrefix(keys)
265 266
}

X
Xiaofan 已提交
267
// Deprecate
268 269 270
func (p *commonConfig) initQueryCoordTimeTick() {
	keys := []string{
		"msgChannel.chanNamePrefix.queryTimeTick",
X
Xiaofan 已提交
271
		"common.chanNamePrefix.queryTimeTick",
272 273
	}
	p.QueryCoordTimeTick = p.initChanNamePrefix(keys)
274 275 276
}

// --- querynode ---
277 278 279
func (p *commonConfig) initQueryNodeSubName() {
	keys := []string{
		"msgChannel.subNamePrefix.queryNodeSubNamePrefix",
X
Xiaofan 已提交
280
		"common.subNamePrefix.queryNodeSubNamePrefix",
281 282
	}
	p.QueryNodeSubName = p.initChanNamePrefix(keys)
283 284
}

285
// --- datacoord ---
286 287 288
func (p *commonConfig) initDataCoordStatistic() {
	keys := []string{
		"msgChannel.chanNamePrefix.dataCoordStatistic",
X
Xiaofan 已提交
289
		"common.chanNamePrefix.dataCoordStatistic",
290 291
	}
	p.DataCoordStatistic = p.initChanNamePrefix(keys)
292 293
}

X
Xiaofan 已提交
294
// Deprecate
295 296 297
func (p *commonConfig) initDataCoordTimeTick() {
	keys := []string{
		"msgChannel.chanNamePrefix.dataCoordTimeTick",
X
Xiaofan 已提交
298
		"common.chanNamePrefix.dataCoordTimeTick",
299 300
	}
	p.DataCoordTimeTick = p.initChanNamePrefix(keys)
301 302
}

303 304 305
func (p *commonConfig) initDataCoordSegmentInfo() {
	keys := []string{
		"msgChannel.chanNamePrefix.dataCoordSegmentInfo",
X
Xiaofan 已提交
306
		"common.chanNamePrefix.dataCoordSegmentInfo",
307 308
	}
	p.DataCoordSegmentInfo = p.initChanNamePrefix(keys)
309 310
}

311 312 313
func (p *commonConfig) initDataCoordSubName() {
	keys := []string{
		"msgChannel.subNamePrefix.dataCoordSubNamePrefix",
X
Xiaofan 已提交
314
		"common.subNamePrefix.dataCoordSubNamePrefix",
315 316
	}
	p.DataCoordSubName = p.initChanNamePrefix(keys)
317 318
}

319 320 321
func (p *commonConfig) initDataNodeSubName() {
	keys := []string{
		"msgChannel.subNamePrefix.dataNodeSubNamePrefix",
X
Xiaofan 已提交
322
		"common.subNamePrefix.dataNodeSubNamePrefix",
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
	}
	p.DataNodeSubName = p.initChanNamePrefix(keys)
}

func (p *commonConfig) initDefaultPartitionName() {
	p.DefaultPartitionName = p.Base.LoadWithDefault("common.defaultPartitionName", "_default")
}

func (p *commonConfig) initDefaultIndexName() {
	p.DefaultIndexName = p.Base.LoadWithDefault("common.defaultIndexName", "_default_idx")
}

func (p *commonConfig) initRetentionDuration() {
	p.RetentionDuration = p.Base.ParseInt64WithDefault("common.retentionDuration", DefaultRetentionDuration)
}

X
Xiaofan 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
func (p *commonConfig) initEntityExpiration() {
	ttl := p.Base.ParseInt64WithDefault("common.entityExpiration", -1)
	if ttl < 0 {
		p.EntityExpirationTTL = -1
		return
	}

	// make sure ttl is larger than retention duration to ensure time travel works
	if ttl > p.RetentionDuration {
		p.EntityExpirationTTL = time.Duration(ttl) * time.Second
	} else {
		p.EntityExpirationTTL = time.Duration(p.RetentionDuration) * time.Second
	}
}

354 355 356 357 358 359
func (p *commonConfig) initSimdType() {
	keys := []string{
		"common.simdType",
		"knowhere.simdType",
	}
	p.SimdType = p.Base.LoadWithDefault2(keys, "auto")
360 361
}

362 363 364 365
func (p *commonConfig) initIndexSliceSize() {
	p.IndexSliceSize = p.Base.ParseInt64WithDefault("common.indexSliceSize", DefaultIndexSliceSize)
}

366 367 368 369
func (p *commonConfig) initGracefulTime() {
	p.GracefulTime = p.Base.ParseInt64WithDefault("common.gracefulTime", DefaultGracefulTime)
}

J
jaime 已提交
370
func (p *commonConfig) initStorageType() {
X
Xiaofan 已提交
371
	p.StorageType = p.Base.LoadWithDefault("common.storageType", "minio")
J
jaime 已提交
372 373
}

C
codeman 已提交
374 375 376 377
func (p *commonConfig) initEnableAuthorization() {
	p.AuthorizationEnabled = p.Base.ParseBool("common.security.authorizationEnabled", false)
}

378 379 380 381
func (p *commonConfig) initClusterName() {
	p.ClusterName = p.Base.LoadWithDefault("common.cluster.name", "")
}

382 383 384
///////////////////////////////////////////////////////////////////////////////
// --- rootcoord ---
type rootCoordConfig struct {
385
	Base *BaseTable
386 387 388 389

	Address string
	Port    int

390 391 392 393 394 395 396 397 398
	DmlChannelNum                   int64
	MaxPartitionNum                 int64
	MinSegmentSizeToEnableIndex     int64
	ImportTaskExpiration            float64
	ImportTaskRetention             float64
	ImportSegmentStateCheckInterval float64
	ImportSegmentStateWaitLimit     float64
	ImportIndexCheckInterval        float64
	ImportIndexWaitLimit            float64
399

400 401 402
	// --- ETCD Path ---
	ImportTaskSubPath string

403 404 405 406
	CreatedTime time.Time
	UpdatedTime time.Time
}

407 408 409 410 411
func (p *rootCoordConfig) init(base *BaseTable) {
	p.Base = base
	p.DmlChannelNum = p.Base.ParseInt64WithDefault("rootCoord.dmlChannelNum", 256)
	p.MaxPartitionNum = p.Base.ParseInt64WithDefault("rootCoord.maxPartitionNum", 4096)
	p.MinSegmentSizeToEnableIndex = p.Base.ParseInt64WithDefault("rootCoord.minSegmentSizeToEnableIndex", 1024)
412 413
	p.ImportTaskExpiration = p.Base.ParseFloatWithDefault("rootCoord.importTaskExpiration", 15*60)
	p.ImportTaskRetention = p.Base.ParseFloatWithDefault("rootCoord.importTaskRetention", 24*60*60)
414 415
	p.ImportSegmentStateCheckInterval = p.Base.ParseFloatWithDefault("rootCoord.importSegmentStateCheckInterval", 10)
	p.ImportSegmentStateWaitLimit = p.Base.ParseFloatWithDefault("rootCoord.importSegmentStateWaitLimit", 60)
416 417
	p.ImportIndexCheckInterval = p.Base.ParseFloatWithDefault("rootCoord.importIndexCheckInterval", 10)
	p.ImportIndexWaitLimit = p.Base.ParseFloatWithDefault("rootCoord.importIndexWaitLimit", 10*60)
418
	p.ImportTaskSubPath = "importtask"
419 420 421 422 423
}

///////////////////////////////////////////////////////////////////////////////
// --- proxy ---
type proxyConfig struct {
424
	Base *BaseTable
425 426

	// NetworkPort & IP are not used
427 428
	NetworkPort    int
	IP             string
429 430 431 432
	NetworkAddress string

	Alias string

X
Xiaofan 已提交
433
	NodeID                   atomic.Value
434 435 436
	TimeTickInterval         time.Duration
	MsgStreamTimeTickBufSize int64
	MaxNameLength            int64
437
	MaxUsernameLength        int64
438
	MinPasswordLength        int64
439
	MaxPasswordLength        int64
440 441 442
	MaxFieldNum              int64
	MaxShardNum              int32
	MaxDimension             int64
443
	GinLogging               bool
444 445
	MaxUserNum               int
	MaxRoleNum               int
446

447
	// required from QueryCoord
448 449 450 451 452 453 454 455 456
	SearchResultChannelNames   []string
	RetrieveResultChannelNames []string

	MaxTaskNum int64

	CreatedTime time.Time
	UpdatedTime time.Time
}

457 458
func (p *proxyConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
459
	p.NodeID.Store(UniqueID(0))
460 461 462 463
	p.initTimeTickInterval()

	p.initMsgStreamTimeTickBufSize()
	p.initMaxNameLength()
464
	p.initMinPasswordLength()
465 466
	p.initMaxUsernameLength()
	p.initMaxPasswordLength()
467 468 469 470 471
	p.initMaxFieldNum()
	p.initMaxShardNum()
	p.initMaxDimension()

	p.initMaxTaskNum()
472
	p.initGinLogging()
473 474
	p.initMaxUserNum()
	p.initMaxRoleNum()
475 476 477 478 479 480 481 482
}

// InitAlias initialize Alias member.
func (p *proxyConfig) InitAlias(alias string) {
	p.Alias = alias
}

func (p *proxyConfig) initTimeTickInterval() {
483
	interval := p.Base.ParseIntWithDefault("proxy.timeTickInterval", 200)
484 485 486 487
	p.TimeTickInterval = time.Duration(interval) * time.Millisecond
}

func (p *proxyConfig) initMsgStreamTimeTickBufSize() {
488
	p.MsgStreamTimeTickBufSize = p.Base.ParseInt64WithDefault("proxy.msgStream.timeTick.bufSize", 512)
489 490 491
}

func (p *proxyConfig) initMaxNameLength() {
492
	str := p.Base.LoadWithDefault("proxy.maxNameLength", "255")
493 494 495 496 497 498 499
	maxNameLength, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxNameLength = maxNameLength
}

500 501 502 503 504 505 506 507 508
func (p *proxyConfig) initMaxUsernameLength() {
	str := p.Base.LoadWithDefault("proxy.maxUsernameLength", "32")
	maxUsernameLength, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxUsernameLength = maxUsernameLength
}

509 510 511 512 513 514 515 516 517
func (p *proxyConfig) initMinPasswordLength() {
	str := p.Base.LoadWithDefault("proxy.minPasswordLength", "6")
	minPasswordLength, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MinPasswordLength = minPasswordLength
}

518 519 520 521 522 523 524 525 526
func (p *proxyConfig) initMaxPasswordLength() {
	str := p.Base.LoadWithDefault("proxy.maxPasswordLength", "256")
	maxPasswordLength, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxPasswordLength = maxPasswordLength
}

527
func (p *proxyConfig) initMaxShardNum() {
528
	str := p.Base.LoadWithDefault("proxy.maxShardNum", "256")
529 530 531 532 533 534 535 536
	maxShardNum, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxShardNum = int32(maxShardNum)
}

func (p *proxyConfig) initMaxFieldNum() {
537
	str := p.Base.LoadWithDefault("proxy.maxFieldNum", "64")
538 539 540 541 542 543 544 545
	maxFieldNum, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxFieldNum = maxFieldNum
}

func (p *proxyConfig) initMaxDimension() {
546
	str := p.Base.LoadWithDefault("proxy.maxDimension", "32768")
547 548 549 550 551 552 553 554
	maxDimension, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxDimension = maxDimension
}

func (p *proxyConfig) initMaxTaskNum() {
555
	p.MaxTaskNum = p.Base.ParseInt64WithDefault("proxy.maxTaskNum", 1024)
556 557
}

558 559 560 561 562
func (p *proxyConfig) initGinLogging() {
	// Gin logging is on by default.
	p.GinLogging = p.Base.ParseBool("proxy.ginLogging", true)
}

X
Xiaofan 已提交
563 564 565 566 567 568 569 570 571 572 573 574
func (p *proxyConfig) SetNodeID(id UniqueID) {
	p.NodeID.Store(id)
}

func (p *proxyConfig) GetNodeID() UniqueID {
	val := p.NodeID.Load()
	if val != nil {
		return val.(UniqueID)
	}
	return 0
}

575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
func (p *proxyConfig) initMaxUserNum() {
	str := p.Base.LoadWithDefault("proxy.maxUserNum", "100")
	maxUserNum, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxUserNum = int(maxUserNum)
}

func (p *proxyConfig) initMaxRoleNum() {
	str := p.Base.LoadWithDefault("proxy.maxRoleNum", "10")
	maxRoleNum, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxRoleNum = int(maxRoleNum)
}

593 594 595
///////////////////////////////////////////////////////////////////////////////
// --- querycoord ---
type queryCoordConfig struct {
596
	Base *BaseTable
597

X
Xiaofan 已提交
598 599 600
	Address string
	Port    int
	NodeID  atomic.Value
601 602 603 604

	CreatedTime time.Time
	UpdatedTime time.Time

605 606 607 608
	//---- Task ---
	RetryNum      int32
	RetryInterval int64

609 610 611 612 613 614 615 616
	//---- Handoff ---
	AutoHandoff bool

	//---- Balance ---
	AutoBalance                         bool
	OverloadedMemoryThresholdPercentage float64
	BalanceIntervalSeconds              int64
	MemoryUsageMaxDifferencePercentage  float64
B
Bingyi Sun 已提交
617 618 619 620 621 622
	CheckInterval                       time.Duration
	ChannelTaskTimeout                  time.Duration
	SegmentTaskTimeout                  time.Duration
	DistPullInterval                    time.Duration
	LoadTimeoutSeconds                  time.Duration
	CheckHandoffInterval                time.Duration
623 624
}

625 626
func (p *queryCoordConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
627
	p.NodeID.Store(UniqueID(0))
628 629 630 631 632

	//---- Task ---
	p.initTaskRetryNum()
	p.initTaskRetryInterval()

633 634 635 636 637 638 639 640
	//---- Handoff ---
	p.initAutoHandoff()

	//---- Balance ---
	p.initAutoBalance()
	p.initOverloadedMemoryThresholdPercentage()
	p.initBalanceIntervalSeconds()
	p.initMemoryUsageMaxDifferencePercentage()
B
Bingyi Sun 已提交
641 642 643 644 645 646
	p.initCheckInterval()
	p.initChannelTaskTimeout()
	p.initSegmentTaskTimeout()
	p.initDistPullInterval()
	p.initLoadTimeoutSeconds()
	p.initCheckHandoffInterval()
647 648
}

649 650 651 652 653 654 655 656
func (p *queryCoordConfig) initTaskRetryNum() {
	p.RetryNum = p.Base.ParseInt32WithDefault("queryCoord.task.retrynum", 5)
}

func (p *queryCoordConfig) initTaskRetryInterval() {
	p.RetryInterval = p.Base.ParseInt64WithDefault("queryCoord.task.retryinterval", int64(10*time.Second))
}

657
func (p *queryCoordConfig) initAutoHandoff() {
658
	handoff, err := p.Base.Load("queryCoord.autoHandoff")
659 660 661 662 663 664 665 666 667 668
	if err != nil {
		panic(err)
	}
	p.AutoHandoff, err = strconv.ParseBool(handoff)
	if err != nil {
		panic(err)
	}
}

func (p *queryCoordConfig) initAutoBalance() {
669
	balanceStr := p.Base.LoadWithDefault("queryCoord.autoBalance", "false")
670 671 672 673 674 675 676 677
	autoBalance, err := strconv.ParseBool(balanceStr)
	if err != nil {
		panic(err)
	}
	p.AutoBalance = autoBalance
}

func (p *queryCoordConfig) initOverloadedMemoryThresholdPercentage() {
678
	overloadedMemoryThresholdPercentage := p.Base.LoadWithDefault("queryCoord.overloadedMemoryThresholdPercentage", "90")
679 680 681 682 683 684 685 686
	thresholdPercentage, err := strconv.ParseInt(overloadedMemoryThresholdPercentage, 10, 64)
	if err != nil {
		panic(err)
	}
	p.OverloadedMemoryThresholdPercentage = float64(thresholdPercentage) / 100
}

func (p *queryCoordConfig) initBalanceIntervalSeconds() {
687
	balanceInterval := p.Base.LoadWithDefault("queryCoord.balanceIntervalSeconds", "60")
688 689 690 691 692 693 694 695
	interval, err := strconv.ParseInt(balanceInterval, 10, 64)
	if err != nil {
		panic(err)
	}
	p.BalanceIntervalSeconds = interval
}

func (p *queryCoordConfig) initMemoryUsageMaxDifferencePercentage() {
696
	maxDiff := p.Base.LoadWithDefault("queryCoord.memoryUsageMaxDifferencePercentage", "30")
697 698 699 700 701 702 703
	diffPercentage, err := strconv.ParseInt(maxDiff, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MemoryUsageMaxDifferencePercentage = float64(diffPercentage) / 100
}

B
Bingyi Sun 已提交
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
func (p *queryCoordConfig) initCheckInterval() {
	interval := p.Base.LoadWithDefault("queryCoord.checkInterval", "1000")
	checkInterval, err := strconv.ParseInt(interval, 10, 64)
	if err != nil {
		panic(err)
	}
	p.CheckInterval = time.Duration(checkInterval) * time.Millisecond
}

func (p *queryCoordConfig) initChannelTaskTimeout() {
	timeout := p.Base.LoadWithDefault("queryCoord.channelTaskTimeout", "60000")
	taskTimeout, err := strconv.ParseInt(timeout, 10, 64)
	if err != nil {
		panic(err)
	}
	p.ChannelTaskTimeout = time.Duration(taskTimeout) * time.Millisecond
}

func (p *queryCoordConfig) initSegmentTaskTimeout() {
	timeout := p.Base.LoadWithDefault("queryCoord.segmentTaskTimeout", "15000")
	taskTimeout, err := strconv.ParseInt(timeout, 10, 64)
	if err != nil {
		panic(err)
	}
	p.SegmentTaskTimeout = time.Duration(taskTimeout) * time.Millisecond
}

func (p *queryCoordConfig) initDistPullInterval() {
	interval := p.Base.LoadWithDefault("queryCoord.distPullInterval", "500")
	pullInterval, err := strconv.ParseInt(interval, 10, 64)
	if err != nil {
		panic(err)
	}
	p.DistPullInterval = time.Duration(pullInterval) * time.Millisecond
}

func (p *queryCoordConfig) initLoadTimeoutSeconds() {
	timeout := p.Base.LoadWithDefault("queryCoord.loadTimeoutSeconds", "600")
	loadTimeout, err := strconv.ParseInt(timeout, 10, 64)
	if err != nil {
		panic(err)
	}
	p.LoadTimeoutSeconds = time.Duration(loadTimeout) * time.Second
}

func (p *queryCoordConfig) initCheckHandoffInterval() {
	interval := p.Base.LoadWithDefault("queryCoord.checkHandoffInterval", "5000")
	checkHandoffInterval, err := strconv.ParseInt(interval, 10, 64)
	if err != nil {
		panic(err)
	}
	p.CheckHandoffInterval = time.Duration(checkHandoffInterval) * time.Millisecond
}

X
Xiaofan 已提交
758 759 760 761 762 763 764 765 766 767 768 769
func (p *queryCoordConfig) SetNodeID(id UniqueID) {
	p.NodeID.Store(id)
}

func (p *queryCoordConfig) GetNodeID() UniqueID {
	val := p.NodeID.Load()
	if val != nil {
		return val.(UniqueID)
	}
	return 0
}

770 771 772
///////////////////////////////////////////////////////////////////////////////
// --- querynode ---
type queryNodeConfig struct {
773
	Base *BaseTable
774 775 776 777

	Alias         string
	QueryNodeIP   string
	QueryNodePort int64
X
Xiaofan 已提交
778
	NodeID        atomic.Value
779 780 781 782 783 784 785

	FlowGraphMaxQueueLength int32
	FlowGraphMaxParallelism int32

	// stats
	StatsPublishInterval int

786
	SliceIndex int
787 788

	// segcore
789 790 791
	ChunkRows        int64
	SmallIndexNlist  int64
	SmallIndexNProbe int64
792 793 794 795 796

	CreatedTime time.Time
	UpdatedTime time.Time

	// memory limit
797
	LoadMemoryUsageFactor               float64
798
	OverloadedMemoryThresholdPercentage float64
G
godchen 已提交
799 800

	// cache limit
G
godchen 已提交
801 802
	CacheEnabled     bool
	CacheMemoryLimit int64
803 804 805 806

	GroupEnabled         bool
	MaxReceiveChanSize   int32
	MaxUnsolvedQueueSize int32
807
	MaxReadConcurrency   int32
808 809
	MaxGroupNQ           int64
	TopKMergeRatio       float64
810
	CPURatio             float64
811 812
}

813 814
func (p *queryNodeConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
815
	p.NodeID.Store(UniqueID(0))
816 817 818 819 820 821

	p.initFlowGraphMaxQueueLength()
	p.initFlowGraphMaxParallelism()

	p.initStatsPublishInterval()

822
	p.initSmallIndexParams()
823

824
	p.initLoadMemoryUsageFactor()
825
	p.initOverloadedMemoryThresholdPercentage()
G
godchen 已提交
826

G
godchen 已提交
827 828
	p.initCacheMemoryLimit()
	p.initCacheEnabled()
829 830 831

	p.initGroupEnabled()
	p.initMaxReceiveChanSize()
832
	p.initMaxReadConcurrency()
833 834 835
	p.initMaxUnsolvedQueueSize()
	p.initMaxGroupNQ()
	p.initTopKMergeRatio()
836
	p.initCPURatio()
837 838 839 840 841 842 843 844 845 846
}

// InitAlias initializes an alias for the QueryNode role.
func (p *queryNodeConfig) InitAlias(alias string) {
	p.Alias = alias
}

// advanced params
// stats
func (p *queryNodeConfig) initStatsPublishInterval() {
847
	p.StatsPublishInterval = p.Base.ParseIntWithDefault("queryNode.stats.publishInterval", 1000)
848 849 850 851
}

// dataSync:
func (p *queryNodeConfig) initFlowGraphMaxQueueLength() {
852
	p.FlowGraphMaxQueueLength = p.Base.ParseInt32WithDefault("queryNode.dataSync.flowGraph.maxQueueLength", 1024)
853 854 855
}

func (p *queryNodeConfig) initFlowGraphMaxParallelism() {
856
	p.FlowGraphMaxParallelism = p.Base.ParseInt32WithDefault("queryNode.dataSync.flowGraph.maxParallelism", 1024)
857 858
}

859
func (p *queryNodeConfig) initSmallIndexParams() {
J
Jiquan Long 已提交
860
	p.ChunkRows = p.Base.ParseInt64WithDefault("queryNode.segcore.chunkRows", 1024)
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
	if p.ChunkRows < 1024 {
		log.Warn("chunk rows can not be less than 1024, force set to 1024", zap.Any("current", p.ChunkRows))
		p.ChunkRows = 1024
	}

	// default NList is the first nlist
	var defaultNList int64
	for i := int64(0); i < p.ChunkRows; i++ {
		if math.Pow(2.0, float64(i)) > math.Sqrt(float64(p.ChunkRows)) {
			defaultNList = int64(math.Pow(2, float64(i)))
			break
		}
	}

	p.SmallIndexNlist = p.Base.ParseInt64WithDefault("queryNode.segcore.smallIndex.nlist", defaultNList)
	if p.SmallIndexNlist > p.ChunkRows/8 {
		log.Warn("small index nlist must smaller than chunkRows/8, force set to", zap.Any("nliit", p.ChunkRows/8))
		p.SmallIndexNlist = p.ChunkRows / 8
	}

	defaultNprobe := p.SmallIndexNlist / 16
	p.SmallIndexNProbe = p.Base.ParseInt64WithDefault("queryNode.segcore.smallIndex.nprobe", defaultNprobe)
	if p.SmallIndexNProbe > p.SmallIndexNlist {
		log.Warn("small index nprobe must smaller than nlist, force set to", zap.Any("nprobe", p.SmallIndexNlist))
		p.SmallIndexNProbe = p.SmallIndexNlist
	}
887 888
}

889 890 891 892 893 894 895 896 897
func (p *queryNodeConfig) initLoadMemoryUsageFactor() {
	loadMemoryUsageFactor := p.Base.LoadWithDefault("queryNode.loadMemoryUsageFactor", "3")
	factor, err := strconv.ParseFloat(loadMemoryUsageFactor, 64)
	if err != nil {
		panic(err)
	}
	p.LoadMemoryUsageFactor = factor
}

898
func (p *queryNodeConfig) initOverloadedMemoryThresholdPercentage() {
899
	overloadedMemoryThresholdPercentage := p.Base.LoadWithDefault("queryCoord.overloadedMemoryThresholdPercentage", "90")
900 901 902 903 904 905 906
	thresholdPercentage, err := strconv.ParseInt(overloadedMemoryThresholdPercentage, 10, 64)
	if err != nil {
		panic(err)
	}
	p.OverloadedMemoryThresholdPercentage = float64(thresholdPercentage) / 100
}

G
godchen 已提交
907 908 909 910 911 912 913 914
func (p *queryNodeConfig) initCacheMemoryLimit() {
	overloadedMemoryThresholdPercentage := p.Base.LoadWithDefault("queryNode.cache.memoryLimit", "2147483648")
	cacheMemoryLimit, err := strconv.ParseInt(overloadedMemoryThresholdPercentage, 10, 64)
	if err != nil {
		panic(err)
	}
	p.CacheMemoryLimit = cacheMemoryLimit
}
X
Xiaofan 已提交
915

G
godchen 已提交
916 917 918 919
func (p *queryNodeConfig) initCacheEnabled() {
	var err error
	cacheEnabled := p.Base.LoadWithDefault("queryNode.cache.enabled", "true")
	p.CacheEnabled, err = strconv.ParseBool(cacheEnabled)
G
godchen 已提交
920 921 922 923 924
	if err != nil {
		panic(err)
	}
}

925 926 927 928 929
func (p *queryNodeConfig) initGroupEnabled() {
	p.GroupEnabled = p.Base.ParseBool("queryNode.grouping.enabled", true)
}

func (p *queryNodeConfig) initMaxReceiveChanSize() {
930
	p.MaxReceiveChanSize = p.Base.ParseInt32WithDefault("queryNode.scheduler.receiveChanSize", 10240)
931 932 933
}

func (p *queryNodeConfig) initMaxUnsolvedQueueSize() {
934 935 936 937 938 939 940 941
	p.MaxUnsolvedQueueSize = p.Base.ParseInt32WithDefault("queryNode.scheduler.unsolvedQueueSize", 10240)
}

func (p *queryNodeConfig) initCPURatio() {
	p.CPURatio = p.Base.ParseFloatWithDefault("queryNode.scheduler.cpuRatio", 10.0)
}

func (p *queryNodeConfig) initMaxReadConcurrency() {
942 943 944 945 946 947 948
	readConcurrencyRatio := p.Base.ParseFloatWithDefault("queryNode.scheduler.maxReadConcurrentRatio", 2.0)
	cpuNum := int32(runtime.GOMAXPROCS(0))
	p.MaxReadConcurrency = int32(float64(cpuNum) * readConcurrencyRatio)
	if p.MaxReadConcurrency < 1 {
		p.MaxReadConcurrency = 1 // MaxReadConcurrency must >= 1
	} else if p.MaxReadConcurrency > cpuNum*100 {
		p.MaxReadConcurrency = cpuNum * 100 // MaxReadConcurrency must <= 100*cpuNum
949
	}
950 951 952 953 954 955 956 957 958 959
}

func (p *queryNodeConfig) initMaxGroupNQ() {
	p.MaxGroupNQ = p.Base.ParseInt64WithDefault("queryNode.grouping.maxNQ", 1000)
}

func (p *queryNodeConfig) initTopKMergeRatio() {
	p.TopKMergeRatio = p.Base.ParseFloatWithDefault("queryNode.grouping.topKMergeRatio", 10.0)
}

X
Xiaofan 已提交
960 961 962 963 964 965 966 967 968 969 970 971
func (p *queryNodeConfig) SetNodeID(id UniqueID) {
	p.NodeID.Store(id)
}

func (p *queryNodeConfig) GetNodeID() UniqueID {
	val := p.NodeID.Load()
	if val != nil {
		return val.(UniqueID)
	}
	return 0
}

972 973 974
///////////////////////////////////////////////////////////////////////////////
// --- datacoord ---
type dataCoordConfig struct {
975
	Base *BaseTable
976

X
Xiaofan 已提交
977
	NodeID atomic.Value
978 979 980 981 982 983

	IP      string
	Port    int
	Address string

	// --- ETCD ---
X
XuanYang-cn 已提交
984
	ChannelWatchSubPath string
985 986

	// --- SEGMENTS ---
987 988 989 990 991 992
	SegmentMaxSize                 float64
	SegmentSealProportion          float64
	SegAssignmentExpiration        int64
	SegmentMaxLifetime             time.Duration
	SegmentMaxIdleTime             time.Duration
	SegmentMinSizeFromIdleToSealed float64
993 994 995 996

	CreatedTime time.Time
	UpdatedTime time.Time

997 998 999 1000 1001 1002 1003 1004
	// compaction
	EnableCompaction     bool
	EnableAutoCompaction atomic.Value

	MinSegmentToMerge                 int
	MaxSegmentToMerge                 int
	SegmentSmallProportion            float64
	CompactionTimeoutInSeconds        int32
1005
	CompactionCheckIntervalInSeconds  int64
1006 1007 1008 1009 1010
	SingleCompactionRatioThreshold    float32
	SingleCompactionDeltaLogMaxSize   int64
	SingleCompactionExpiredLogMaxSize int64
	SingleCompactionBinlogMaxNum      int64
	GlobalCompactionInterval          time.Duration
1011 1012

	// Garbage Collection
1013 1014 1015 1016
	EnableGarbageCollection bool
	GCInterval              time.Duration
	GCMissingTolerance      time.Duration
	GCDropTolerance         time.Duration
1017 1018
}

1019 1020
func (p *dataCoordConfig) init(base *BaseTable) {
	p.Base = base
1021 1022 1023 1024 1025
	p.initChannelWatchPrefix()

	p.initSegmentMaxSize()
	p.initSegmentSealProportion()
	p.initSegAssignmentExpiration()
1026
	p.initSegmentMaxLifetime()
1027 1028
	p.initSegmentMaxIdleTime()
	p.initSegmentMinSizeFromIdleToSealed()
1029 1030 1031 1032

	p.initEnableCompaction()
	p.initEnableAutoCompaction()

1033 1034 1035 1036
	p.initCompactionMinSegment()
	p.initCompactionMaxSegment()
	p.initSegmentSmallProportion()
	p.initCompactionTimeoutInSeconds()
1037
	p.initCompactionCheckIntervalInSeconds()
1038 1039 1040 1041 1042 1043
	p.initSingleCompactionRatioThreshold()
	p.initSingleCompactionDeltaLogMaxSize()
	p.initSingleCompactionExpiredLogMaxSize()
	p.initSingleCompactionBinlogMaxNum()
	p.initGlobalCompactionInterval()

1044 1045 1046 1047 1048 1049 1050
	p.initEnableGarbageCollection()
	p.initGCInterval()
	p.initGCMissingTolerance()
	p.initGCDropTolerance()
}

func (p *dataCoordConfig) initSegmentMaxSize() {
1051
	p.SegmentMaxSize = p.Base.ParseFloatWithDefault("dataCoord.segment.maxSize", 512.0)
1052 1053 1054
}

func (p *dataCoordConfig) initSegmentSealProportion() {
1055
	p.SegmentSealProportion = p.Base.ParseFloatWithDefault("dataCoord.segment.sealProportion", 0.25)
1056 1057 1058
}

func (p *dataCoordConfig) initSegAssignmentExpiration() {
1059
	p.SegAssignmentExpiration = p.Base.ParseInt64WithDefault("dataCoord.segment.assignmentExpiration", 2000)
1060 1061
}

1062 1063 1064 1065
func (p *dataCoordConfig) initSegmentMaxLifetime() {
	p.SegmentMaxLifetime = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.segment.maxLife", 24*60*60)) * time.Second
}

1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
func (p *dataCoordConfig) initSegmentMaxIdleTime() {
	p.SegmentMaxIdleTime = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.segment.maxIdleTime", 60*60)) * time.Second
	log.Info("init segment max idle time", zap.String("value", p.SegmentMaxIdleTime.String()))
}

func (p *dataCoordConfig) initSegmentMinSizeFromIdleToSealed() {
	p.SegmentMinSizeFromIdleToSealed = p.Base.ParseFloatWithDefault("dataCoord.segment.minSizeFromIdleToSealed", 16.0)
	log.Info("init segment min size from idle to sealed", zap.Float64("value", p.SegmentMinSizeFromIdleToSealed))
}

1076 1077 1078 1079 1080 1081 1082
func (p *dataCoordConfig) initChannelWatchPrefix() {
	// WARN: this value should not be put to milvus.yaml. It's a default value for channel watch path.
	// This will be removed after we reconstruct our config module.
	p.ChannelWatchSubPath = "channelwatch"
}

func (p *dataCoordConfig) initEnableCompaction() {
1083
	p.EnableCompaction = p.Base.ParseBool("dataCoord.enableCompaction", false)
1084 1085
}

1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
func (p *dataCoordConfig) initEnableAutoCompaction() {
	p.EnableAutoCompaction.Store(p.Base.ParseBool("dataCoord.compaction.enableAutoCompaction", false))
}

func (p *dataCoordConfig) initCompactionMinSegment() {
	p.MinSegmentToMerge = p.Base.ParseIntWithDefault("dataCoord.compaction.min.segment", 4)
}

func (p *dataCoordConfig) initCompactionMaxSegment() {
	p.MaxSegmentToMerge = p.Base.ParseIntWithDefault("dataCoord.compaction.max.segment", 30)
}

func (p *dataCoordConfig) initSegmentSmallProportion() {
	p.SegmentSmallProportion = p.Base.ParseFloatWithDefault("dataCoord.segment.smallProportion", 0.5)
}

// compaction execution timeout
func (p *dataCoordConfig) initCompactionTimeoutInSeconds() {
	p.CompactionTimeoutInSeconds = p.Base.ParseInt32WithDefault("dataCoord.compaction.timeout", 60*3)
}

1107 1108 1109 1110
func (p *dataCoordConfig) initCompactionCheckIntervalInSeconds() {
	p.CompactionCheckIntervalInSeconds = p.Base.ParseInt64WithDefault("dataCoord.compaction.check.interval", 10)
}

1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
// if total delete entities is large than a ratio of total entities, trigger single compaction.
func (p *dataCoordConfig) initSingleCompactionRatioThreshold() {
	p.SingleCompactionRatioThreshold = float32(p.Base.ParseFloatWithDefault("dataCoord.compaction.single.ratio.threshold", 0.2))
}

// if total delta file size > SingleCompactionDeltaLogMaxSize, trigger single compaction
func (p *dataCoordConfig) initSingleCompactionDeltaLogMaxSize() {
	p.SingleCompactionDeltaLogMaxSize = p.Base.ParseInt64WithDefault("dataCoord.compaction.single.deltalog.maxsize", 2*1024*1024)
}

// if total expired file size > SingleCompactionExpiredLogMaxSize, trigger single compaction
func (p *dataCoordConfig) initSingleCompactionExpiredLogMaxSize() {
	p.SingleCompactionExpiredLogMaxSize = p.Base.ParseInt64WithDefault("dataCoord.compaction.single.expiredlog.maxsize", 10*1024*1024)
}

// if total binlog number > SingleCompactionBinlogMaxNum, trigger single compaction to ensure binlog number per segment is limited
func (p *dataCoordConfig) initSingleCompactionBinlogMaxNum() {
	p.SingleCompactionBinlogMaxNum = p.Base.ParseInt64WithDefault("dataCoord.compaction.single.binlog.maxnum", 1000)
}

// interval we check and trigger global compaction
func (p *dataCoordConfig) initGlobalCompactionInterval() {
	p.GlobalCompactionInterval = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.compaction.global.interval", int64(60*time.Second)))
}

1136 1137
// -- GC --
func (p *dataCoordConfig) initEnableGarbageCollection() {
1138
	p.EnableGarbageCollection = p.Base.ParseBool("dataCoord.enableGarbageCollection", true)
1139 1140 1141
}

func (p *dataCoordConfig) initGCInterval() {
1142
	p.GCInterval = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.gc.interval", 60*60)) * time.Second
1143 1144 1145
}

func (p *dataCoordConfig) initGCMissingTolerance() {
1146
	p.GCMissingTolerance = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.gc.missingTolerance", 24*60*60)) * time.Second
1147 1148 1149
}

func (p *dataCoordConfig) initGCDropTolerance() {
1150
	p.GCDropTolerance = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.gc.dropTolerance", 24*60*60)) * time.Second
1151 1152
}

1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
func (p *dataCoordConfig) SetEnableAutoCompaction(enable bool) {
	p.EnableAutoCompaction.Store(enable)
}

func (p *dataCoordConfig) GetEnableAutoCompaction() bool {
	enable := p.EnableAutoCompaction.Load()
	if enable != nil {
		return enable.(bool)
	}
	return false
1163 1164
}

X
Xiaofan 已提交
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
func (p *dataCoordConfig) SetNodeID(id UniqueID) {
	p.NodeID.Store(id)
}

func (p *dataCoordConfig) GetNodeID() UniqueID {
	val := p.NodeID.Load()
	if val != nil {
		return val.(UniqueID)
	}
	return 0
}

1177 1178 1179
///////////////////////////////////////////////////////////////////////////////
// --- datanode ---
type dataNodeConfig struct {
1180
	Base *BaseTable
1181

X
Xiaofan 已提交
1182 1183 1184
	// ID of the current node
	//NodeID atomic.Value
	NodeID atomic.Value
1185 1186 1187 1188 1189 1190 1191 1192
	// IP of the current DataNode
	IP string

	// Port of the current DataNode
	Port                    int
	FlowGraphMaxQueueLength int32
	FlowGraphMaxParallelism int32
	FlushInsertBufferSize   int64
1193 1194

	Alias string // Different datanode in one machine
1195 1196 1197 1198

	// etcd
	ChannelWatchSubPath string

1199 1200 1201
	// io concurrency to fetch stats logs
	IOConcurrency int

1202 1203 1204 1205
	CreatedTime time.Time
	UpdatedTime time.Time
}

1206 1207
func (p *dataNodeConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
1208
	p.NodeID.Store(UniqueID(0))
1209 1210 1211
	p.initFlowGraphMaxQueueLength()
	p.initFlowGraphMaxParallelism()
	p.initFlushInsertBufferSize()
1212
	p.initIOConcurrency()
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222

	p.initChannelWatchPath()
}

// InitAlias init this DataNode alias
func (p *dataNodeConfig) InitAlias(alias string) {
	p.Alias = alias
}

func (p *dataNodeConfig) initFlowGraphMaxQueueLength() {
1223
	p.FlowGraphMaxQueueLength = p.Base.ParseInt32WithDefault("dataNode.dataSync.flowGraph.maxQueueLength", 1024)
1224 1225 1226
}

func (p *dataNodeConfig) initFlowGraphMaxParallelism() {
1227
	p.FlowGraphMaxParallelism = p.Base.ParseInt32WithDefault("dataNode.dataSync.flowGraph.maxParallelism", 1024)
1228 1229 1230
}

func (p *dataNodeConfig) initFlushInsertBufferSize() {
E
Enwei Jiao 已提交
1231 1232 1233 1234 1235 1236
	bufferSize := p.Base.LoadWithDefault2([]string{"DATA_NODE_IBUFSIZE", "datanode.flush.insertBufSize"}, "0")
	bs, err := strconv.ParseInt(bufferSize, 10, 64)
	if err != nil {
		panic(err)
	}
	p.FlushInsertBufferSize = bs
1237 1238 1239 1240 1241 1242
}

func (p *dataNodeConfig) initChannelWatchPath() {
	p.ChannelWatchSubPath = "channelwatch"
}

1243 1244 1245 1246
func (p *dataNodeConfig) initIOConcurrency() {
	p.IOConcurrency = p.Base.ParseIntWithDefault("dataNode.dataSync.ioConcurrency", 10)
}

X
Xiaofan 已提交
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
func (p *dataNodeConfig) SetNodeID(id UniqueID) {
	p.NodeID.Store(id)
}

func (p *dataNodeConfig) GetNodeID() UniqueID {
	val := p.NodeID.Load()
	if val != nil {
		return val.(UniqueID)
	}
	return 0
}

1259 1260 1261
///////////////////////////////////////////////////////////////////////////////
// --- indexcoord ---
type indexCoordConfig struct {
1262
	Base *BaseTable
1263 1264 1265 1266

	Address string
	Port    int

1267
	MinSegmentNumRowsToEnableIndex int64
1268

1269 1270
	GCInterval time.Duration

1271 1272 1273 1274
	CreatedTime time.Time
	UpdatedTime time.Time
}

1275 1276
func (p *indexCoordConfig) init(base *BaseTable) {
	p.Base = base
1277

1278
	p.initGCInterval()
1279
	p.initMinSegmentNumRowsToEnableIndex()
1280 1281
}

1282 1283 1284 1285
func (p *indexCoordConfig) initMinSegmentNumRowsToEnableIndex() {
	p.MinSegmentNumRowsToEnableIndex = p.Base.ParseInt64WithDefault("indexCoord.minSegmentNumRowsToEnableIndex", 1024)
}

1286 1287 1288 1289
func (p *indexCoordConfig) initGCInterval() {
	p.GCInterval = time.Duration(p.Base.ParseInt64WithDefault("indexCoord.gc.interval", 60*10)) * time.Second
}

1290 1291 1292
///////////////////////////////////////////////////////////////////////////////
// --- indexnode ---
type indexNodeConfig struct {
1293
	Base *BaseTable
1294 1295 1296 1297 1298

	IP      string
	Address string
	Port    int

X
Xiaofan 已提交
1299 1300 1301
	NodeID atomic.Value

	Alias string
1302

1303
	BuildParallel int
1304 1305 1306 1307 1308

	CreatedTime time.Time
	UpdatedTime time.Time
}

1309 1310
func (p *indexNodeConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
1311
	p.NodeID.Store(UniqueID(0))
1312
	p.initBuildParallel()
1313 1314 1315 1316 1317 1318 1319
}

// InitAlias initializes an alias for the IndexNode role.
func (p *indexNodeConfig) InitAlias(alias string) {
	p.Alias = alias
}

1320 1321 1322 1323
func (p *indexNodeConfig) initBuildParallel() {
	p.BuildParallel = p.Base.ParseIntWithDefault("indexNode.scheduler.buildParallel", 1)
}

X
Xiaofan 已提交
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
func (p *indexNodeConfig) SetNodeID(id UniqueID) {
	p.NodeID.Store(id)
}

func (p *indexNodeConfig) GetNodeID() UniqueID {
	val := p.NodeID.Load()
	if val != nil {
		return val.(UniqueID)
	}
	return 0
}