component_param.go 38.9 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
	"os"
17
	"runtime"
18
	"strconv"
19
	"strings"
20
	"sync"
X
Xiaofan 已提交
21
	"sync/atomic"
22
	"time"
23

24
	"github.com/shirou/gopsutil/disk"
25
	"go.uber.org/zap"
26 27

	"github.com/milvus-io/milvus/internal/log"
28 29 30
)

const (
31
	// DefaultRetentionDuration defines the default duration for retention which is 5 days in seconds.
32
	DefaultRetentionDuration = 3600 * 24
33 34

	// DefaultIndexSliceSize defines the default slice size of index file when serializing.
35
	DefaultIndexSliceSize = 16
36
	DefaultGracefulTime   = 5000 //ms
37 38
)

39
// ComponentParam is used to quickly and easily access all components' configurations.
40 41
type ComponentParam struct {
	ServiceParam
42
	once sync.Once
43

44 45
	CommonCfg   commonConfig
	QuotaConfig quotaConfig
46 47 48 49 50 51 52 53 54 55 56 57

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

// InitOnce initialize once
58
func (p *ComponentParam) InitOnce() {
59 60 61 62 63
	p.once.Do(func() {
		p.Init()
	})
}

64
// Init initialize the global param table
65 66
func (p *ComponentParam) Init() {
	p.ServiceParam.Init()
67

68
	p.CommonCfg.init(&p.BaseTable)
69
	p.QuotaConfig.init(&p.BaseTable)
70

71 72 73 74 75 76 77 78
	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)
79 80
}

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

87 88 89 90 91 92 93 94
func (p *ComponentParam) RocksmqEnable() bool {
	return p.RocksmqCfg.Path != ""
}

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

J
jaime 已提交
95 96 97 98
func (p *ComponentParam) KafkaEnable() bool {
	return p.KafkaCfg.Address != ""
}

99
///////////////////////////////////////////////////////////////////////////////
100
// --- common ---
101
type commonConfig struct {
102
	Base *BaseTable
103

104
	ClusterPrefix string
105

106 107
	ProxySubName string

108 109 110 111 112
	RootCoordTimeTick   string
	RootCoordStatistics string
	RootCoordDml        string
	RootCoordDelta      string
	RootCoordSubName    string
113

114 115 116
	QueryCoordSearch       string
	QueryCoordSearchResult string
	QueryCoordTimeTick     string
117
	QueryNodeSubName       string
118

119 120 121 122
	DataCoordStatistic   string
	DataCoordTimeTick    string
	DataCoordSegmentInfo string
	DataCoordSubName     string
123
	DataNodeSubName      string
124 125 126 127

	DefaultPartitionName string
	DefaultIndexName     string
	RetentionDuration    int64
X
Xiaofan 已提交
128
	EntityExpirationTTL  time.Duration
129

130
	IndexSliceSize int64
131 132 133 134
	GracefulTime   int64

	StorageType string
	SimdType    string
C
codeman 已提交
135 136

	AuthorizationEnabled bool
137 138

	ClusterName string
139 140
}

141
func (p *commonConfig) init(base *BaseTable) {
142
	p.Base = base
143

144 145
	// must init cluster prefix first
	p.initClusterPrefix()
146 147
	p.initProxySubName()

148 149 150 151 152 153 154 155 156
	p.initRootCoordTimeTick()
	p.initRootCoordStatistics()
	p.initRootCoordDml()
	p.initRootCoordDelta()
	p.initRootCoordSubName()

	p.initQueryCoordSearch()
	p.initQueryCoordSearchResult()
	p.initQueryCoordTimeTick()
157
	p.initQueryNodeSubName()
158 159 160 161 162

	p.initDataCoordStatistic()
	p.initDataCoordTimeTick()
	p.initDataCoordSegmentInfo()
	p.initDataCoordSubName()
163
	p.initDataNodeSubName()
164 165 166 167

	p.initDefaultPartitionName()
	p.initDefaultIndexName()
	p.initRetentionDuration()
X
Xiaofan 已提交
168
	p.initEntityExpiration()
169 170

	p.initSimdType()
171
	p.initIndexSliceSize()
172
	p.initGracefulTime()
J
jaime 已提交
173
	p.initStorageType()
C
codeman 已提交
174 175

	p.initEnableAuthorization()
176 177

	p.initClusterName()
178 179
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

322 323 324
func (p *commonConfig) initDataNodeSubName() {
	keys := []string{
		"msgChannel.subNamePrefix.dataNodeSubNamePrefix",
X
Xiaofan 已提交
325
		"common.subNamePrefix.dataNodeSubNamePrefix",
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
	}
	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 已提交
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
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
	}
}

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

365 366 367 368
func (p *commonConfig) initIndexSliceSize() {
	p.IndexSliceSize = p.Base.ParseInt64WithDefault("common.indexSliceSize", DefaultIndexSliceSize)
}

369 370 371 372
func (p *commonConfig) initGracefulTime() {
	p.GracefulTime = p.Base.ParseInt64WithDefault("common.gracefulTime", DefaultGracefulTime)
}

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

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

381 382 383 384
func (p *commonConfig) initClusterName() {
	p.ClusterName = p.Base.LoadWithDefault("common.cluster.name", "")
}

385 386 387
///////////////////////////////////////////////////////////////////////////////
// --- rootcoord ---
type rootCoordConfig struct {
388
	Base *BaseTable
389 390 391 392

	Address string
	Port    int

393 394 395 396 397 398 399 400 401
	DmlChannelNum                   int64
	MaxPartitionNum                 int64
	MinSegmentSizeToEnableIndex     int64
	ImportTaskExpiration            float64
	ImportTaskRetention             float64
	ImportSegmentStateCheckInterval float64
	ImportSegmentStateWaitLimit     float64
	ImportIndexCheckInterval        float64
	ImportIndexWaitLimit            float64
402

403 404 405
	// --- ETCD Path ---
	ImportTaskSubPath string

406 407 408 409
	CreatedTime time.Time
	UpdatedTime time.Time
}

410 411 412 413 414
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)
415 416
	p.ImportTaskExpiration = p.Base.ParseFloatWithDefault("rootCoord.importTaskExpiration", 15*60)
	p.ImportTaskRetention = p.Base.ParseFloatWithDefault("rootCoord.importTaskRetention", 24*60*60)
417 418
	p.ImportSegmentStateCheckInterval = p.Base.ParseFloatWithDefault("rootCoord.importSegmentStateCheckInterval", 10)
	p.ImportSegmentStateWaitLimit = p.Base.ParseFloatWithDefault("rootCoord.importSegmentStateWaitLimit", 60)
419 420
	p.ImportIndexCheckInterval = p.Base.ParseFloatWithDefault("rootCoord.importIndexCheckInterval", 10)
	p.ImportIndexWaitLimit = p.Base.ParseFloatWithDefault("rootCoord.importIndexWaitLimit", 10*60)
421
	p.ImportTaskSubPath = "importtask"
422 423 424 425 426
}

///////////////////////////////////////////////////////////////////////////////
// --- proxy ---
type proxyConfig struct {
427
	Base *BaseTable
428 429

	// NetworkPort & IP are not used
430 431
	NetworkPort    int
	IP             string
432 433 434 435
	NetworkAddress string

	Alias string

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

450
	// required from QueryCoord
451 452 453 454 455 456 457 458 459
	SearchResultChannelNames   []string
	RetrieveResultChannelNames []string

	MaxTaskNum int64

	CreatedTime time.Time
	UpdatedTime time.Time
}

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

	p.initMsgStreamTimeTickBufSize()
	p.initMaxNameLength()
467
	p.initMinPasswordLength()
468 469
	p.initMaxUsernameLength()
	p.initMaxPasswordLength()
470 471 472 473 474
	p.initMaxFieldNum()
	p.initMaxShardNum()
	p.initMaxDimension()

	p.initMaxTaskNum()
475
	p.initGinLogging()
476 477
	p.initMaxUserNum()
	p.initMaxRoleNum()
478 479 480 481 482 483 484 485
}

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

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

func (p *proxyConfig) initMsgStreamTimeTickBufSize() {
491
	p.MsgStreamTimeTickBufSize = p.Base.ParseInt64WithDefault("proxy.msgStream.timeTick.bufSize", 512)
492 493 494
}

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

503 504 505 506 507 508 509 510 511
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
}

512 513 514 515 516 517 518 519 520
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
}

521 522 523 524 525 526 527 528 529
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
}

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

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

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

func (p *proxyConfig) initMaxTaskNum() {
558
	p.MaxTaskNum = p.Base.ParseInt64WithDefault("proxy.maxTaskNum", 1024)
559 560
}

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

X
Xiaofan 已提交
566 567 568 569 570 571 572 573 574 575 576 577
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
}

578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
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)
}

596 597 598
///////////////////////////////////////////////////////////////////////////////
// --- querycoord ---
type queryCoordConfig struct {
599
	Base *BaseTable
600

X
Xiaofan 已提交
601 602 603
	Address string
	Port    int
	NodeID  atomic.Value
604 605 606 607

	CreatedTime time.Time
	UpdatedTime time.Time

608 609 610 611
	//---- Task ---
	RetryNum      int32
	RetryInterval int64

612 613 614 615 616 617 618 619
	//---- Handoff ---
	AutoHandoff bool

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

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

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

636 637 638 639 640 641 642 643
	//---- Handoff ---
	p.initAutoHandoff()

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

652 653 654 655 656 657 658 659
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))
}

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

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

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

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

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

B
Bingyi Sun 已提交
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 758 759 760
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 已提交
761 762 763 764 765 766 767 768 769 770 771 772
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
}

773 774 775
///////////////////////////////////////////////////////////////////////////////
// --- querynode ---
type queryNodeConfig struct {
776
	Base *BaseTable
777 778 779 780

	Alias         string
	QueryNodeIP   string
	QueryNodePort int64
X
Xiaofan 已提交
781
	NodeID        atomic.Value
782 783 784 785 786 787 788

	FlowGraphMaxQueueLength int32
	FlowGraphMaxParallelism int32

	// stats
	StatsPublishInterval int

789
	SliceIndex int
790 791

	// segcore
792 793 794
	ChunkRows        int64
	SmallIndexNlist  int64
	SmallIndexNProbe int64
795 796 797 798 799

	CreatedTime time.Time
	UpdatedTime time.Time

	// memory limit
800
	LoadMemoryUsageFactor               float64
801
	OverloadedMemoryThresholdPercentage float64
G
godchen 已提交
802

803 804 805 806 807
	// enable disk
	EnableDisk             bool
	DiskCapacityLimit      int64
	MaxDiskUsagePercentage float64

G
godchen 已提交
808
	// cache limit
G
godchen 已提交
809 810
	CacheEnabled     bool
	CacheMemoryLimit int64
811 812 813 814

	GroupEnabled         bool
	MaxReceiveChanSize   int32
	MaxUnsolvedQueueSize int32
815
	MaxReadConcurrency   int32
816 817
	MaxGroupNQ           int64
	TopKMergeRatio       float64
818
	CPURatio             float64
819 820
}

821 822
func (p *queryNodeConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
823
	p.NodeID.Store(UniqueID(0))
824 825 826 827 828 829

	p.initFlowGraphMaxQueueLength()
	p.initFlowGraphMaxParallelism()

	p.initStatsPublishInterval()

830
	p.initSmallIndexParams()
831

832
	p.initLoadMemoryUsageFactor()
833
	p.initOverloadedMemoryThresholdPercentage()
G
godchen 已提交
834

G
godchen 已提交
835 836
	p.initCacheMemoryLimit()
	p.initCacheEnabled()
837 838 839

	p.initGroupEnabled()
	p.initMaxReceiveChanSize()
840
	p.initMaxReadConcurrency()
841 842 843
	p.initMaxUnsolvedQueueSize()
	p.initMaxGroupNQ()
	p.initTopKMergeRatio()
844
	p.initCPURatio()
845 846 847
	p.initEnableDisk()
	p.initDiskCapacity()
	p.initMaxDiskUsagePercentage()
848 849 850 851 852 853 854 855 856 857
}

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

// advanced params
// stats
func (p *queryNodeConfig) initStatsPublishInterval() {
858
	p.StatsPublishInterval = p.Base.ParseIntWithDefault("queryNode.stats.publishInterval", 1000)
859 860 861 862
}

// dataSync:
func (p *queryNodeConfig) initFlowGraphMaxQueueLength() {
863
	p.FlowGraphMaxQueueLength = p.Base.ParseInt32WithDefault("queryNode.dataSync.flowGraph.maxQueueLength", 1024)
864 865 866
}

func (p *queryNodeConfig) initFlowGraphMaxParallelism() {
867
	p.FlowGraphMaxParallelism = p.Base.ParseInt32WithDefault("queryNode.dataSync.flowGraph.maxParallelism", 1024)
868 869
}

870
func (p *queryNodeConfig) initSmallIndexParams() {
J
Jiquan Long 已提交
871
	p.ChunkRows = p.Base.ParseInt64WithDefault("queryNode.segcore.chunkRows", 1024)
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
	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
	}
898 899
}

900 901 902 903 904 905 906 907 908
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
}

909
func (p *queryNodeConfig) initOverloadedMemoryThresholdPercentage() {
910
	overloadedMemoryThresholdPercentage := p.Base.LoadWithDefault("queryCoord.overloadedMemoryThresholdPercentage", "90")
911 912 913 914 915 916 917
	thresholdPercentage, err := strconv.ParseInt(overloadedMemoryThresholdPercentage, 10, 64)
	if err != nil {
		panic(err)
	}
	p.OverloadedMemoryThresholdPercentage = float64(thresholdPercentage) / 100
}

G
godchen 已提交
918 919 920 921 922 923 924 925
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 已提交
926

G
godchen 已提交
927 928 929 930
func (p *queryNodeConfig) initCacheEnabled() {
	var err error
	cacheEnabled := p.Base.LoadWithDefault("queryNode.cache.enabled", "true")
	p.CacheEnabled, err = strconv.ParseBool(cacheEnabled)
G
godchen 已提交
931 932 933 934 935
	if err != nil {
		panic(err)
	}
}

936 937 938 939 940
func (p *queryNodeConfig) initGroupEnabled() {
	p.GroupEnabled = p.Base.ParseBool("queryNode.grouping.enabled", true)
}

func (p *queryNodeConfig) initMaxReceiveChanSize() {
941
	p.MaxReceiveChanSize = p.Base.ParseInt32WithDefault("queryNode.scheduler.receiveChanSize", 10240)
942 943 944
}

func (p *queryNodeConfig) initMaxUnsolvedQueueSize() {
945 946 947 948 949 950 951 952
	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() {
953 954 955 956 957 958 959
	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
960
	}
961 962 963 964 965 966 967 968 969 970
}

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 已提交
971 972 973 974 975 976 977 978 979 980 981 982
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
}

983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
func (p *queryNodeConfig) initEnableDisk() {
	var err error
	enableDisk := p.Base.LoadWithDefault("queryNode.enableDisk", "false")
	p.EnableDisk, err = strconv.ParseBool(enableDisk)
	if err != nil {
		panic(err)
	}
}

func (p *queryNodeConfig) initMaxDiskUsagePercentage() {
	maxDiskUsagePercentageStr := p.Base.LoadWithDefault("queryNode.maxDiskUsagePercentage", "95")
	maxDiskUsagePercentage, err := strconv.ParseInt(maxDiskUsagePercentageStr, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxDiskUsagePercentage = float64(maxDiskUsagePercentage) / 100
}

func (p *queryNodeConfig) initDiskCapacity() {
	diskSizeStr := os.Getenv("LOCAL_STORAGE_SIZE")
	if len(diskSizeStr) == 0 {
		diskUsage, err := disk.Usage("/")
		if err != nil {
			panic(err)
		}
		p.DiskCapacityLimit = int64(diskUsage.Total)

		return
	}

	diskSize, err := strconv.ParseInt(diskSizeStr, 10, 64)
	if err != nil {
		panic(err)
	}
	p.DiskCapacityLimit = diskSize * 1024 * 1024 * 1024
}

1020 1021 1022
///////////////////////////////////////////////////////////////////////////////
// --- datacoord ---
type dataCoordConfig struct {
1023
	Base *BaseTable
1024

X
Xiaofan 已提交
1025
	NodeID atomic.Value
1026 1027 1028 1029 1030 1031

	IP      string
	Port    int
	Address string

	// --- ETCD ---
X
XuanYang-cn 已提交
1032
	ChannelWatchSubPath string
1033 1034

	// --- SEGMENTS ---
1035 1036 1037 1038 1039 1040
	SegmentMaxSize                 float64
	SegmentSealProportion          float64
	SegAssignmentExpiration        int64
	SegmentMaxLifetime             time.Duration
	SegmentMaxIdleTime             time.Duration
	SegmentMinSizeFromIdleToSealed float64
1041 1042 1043 1044

	CreatedTime time.Time
	UpdatedTime time.Time

1045 1046 1047 1048 1049 1050 1051 1052
	// compaction
	EnableCompaction     bool
	EnableAutoCompaction atomic.Value

	MinSegmentToMerge                 int
	MaxSegmentToMerge                 int
	SegmentSmallProportion            float64
	CompactionTimeoutInSeconds        int32
1053
	CompactionCheckIntervalInSeconds  int64
1054 1055 1056 1057 1058
	SingleCompactionRatioThreshold    float32
	SingleCompactionDeltaLogMaxSize   int64
	SingleCompactionExpiredLogMaxSize int64
	SingleCompactionBinlogMaxNum      int64
	GlobalCompactionInterval          time.Duration
1059 1060

	// Garbage Collection
1061 1062 1063 1064
	EnableGarbageCollection bool
	GCInterval              time.Duration
	GCMissingTolerance      time.Duration
	GCDropTolerance         time.Duration
1065 1066
}

1067 1068
func (p *dataCoordConfig) init(base *BaseTable) {
	p.Base = base
1069 1070 1071 1072 1073
	p.initChannelWatchPrefix()

	p.initSegmentMaxSize()
	p.initSegmentSealProportion()
	p.initSegAssignmentExpiration()
1074
	p.initSegmentMaxLifetime()
1075 1076
	p.initSegmentMaxIdleTime()
	p.initSegmentMinSizeFromIdleToSealed()
1077 1078 1079 1080

	p.initEnableCompaction()
	p.initEnableAutoCompaction()

1081 1082 1083 1084
	p.initCompactionMinSegment()
	p.initCompactionMaxSegment()
	p.initSegmentSmallProportion()
	p.initCompactionTimeoutInSeconds()
1085
	p.initCompactionCheckIntervalInSeconds()
1086 1087 1088 1089 1090 1091
	p.initSingleCompactionRatioThreshold()
	p.initSingleCompactionDeltaLogMaxSize()
	p.initSingleCompactionExpiredLogMaxSize()
	p.initSingleCompactionBinlogMaxNum()
	p.initGlobalCompactionInterval()

1092 1093 1094 1095 1096 1097 1098
	p.initEnableGarbageCollection()
	p.initGCInterval()
	p.initGCMissingTolerance()
	p.initGCDropTolerance()
}

func (p *dataCoordConfig) initSegmentMaxSize() {
1099
	p.SegmentMaxSize = p.Base.ParseFloatWithDefault("dataCoord.segment.maxSize", 512.0)
1100 1101 1102
}

func (p *dataCoordConfig) initSegmentSealProportion() {
1103
	p.SegmentSealProportion = p.Base.ParseFloatWithDefault("dataCoord.segment.sealProportion", 0.25)
1104 1105 1106
}

func (p *dataCoordConfig) initSegAssignmentExpiration() {
1107
	p.SegAssignmentExpiration = p.Base.ParseInt64WithDefault("dataCoord.segment.assignmentExpiration", 2000)
1108 1109
}

1110 1111 1112 1113
func (p *dataCoordConfig) initSegmentMaxLifetime() {
	p.SegmentMaxLifetime = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.segment.maxLife", 24*60*60)) * time.Second
}

1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
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))
}

1124 1125 1126 1127 1128 1129 1130
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() {
1131
	p.EnableCompaction = p.Base.ParseBool("dataCoord.enableCompaction", false)
1132 1133
}

1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
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)
}

1155 1156 1157 1158
func (p *dataCoordConfig) initCompactionCheckIntervalInSeconds() {
	p.CompactionCheckIntervalInSeconds = p.Base.ParseInt64WithDefault("dataCoord.compaction.check.interval", 10)
}

1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
// 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)))
}

1184 1185
// -- GC --
func (p *dataCoordConfig) initEnableGarbageCollection() {
1186
	p.EnableGarbageCollection = p.Base.ParseBool("dataCoord.enableGarbageCollection", true)
1187 1188 1189
}

func (p *dataCoordConfig) initGCInterval() {
1190
	p.GCInterval = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.gc.interval", 60*60)) * time.Second
1191 1192 1193
}

func (p *dataCoordConfig) initGCMissingTolerance() {
1194
	p.GCMissingTolerance = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.gc.missingTolerance", 24*60*60)) * time.Second
1195 1196 1197
}

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

1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
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
1211 1212
}

X
Xiaofan 已提交
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224
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
}

1225 1226 1227
///////////////////////////////////////////////////////////////////////////////
// --- datanode ---
type dataNodeConfig struct {
1228
	Base *BaseTable
1229

X
Xiaofan 已提交
1230 1231 1232
	// ID of the current node
	//NodeID atomic.Value
	NodeID atomic.Value
1233 1234 1235 1236 1237 1238 1239 1240
	// IP of the current DataNode
	IP string

	// Port of the current DataNode
	Port                    int
	FlowGraphMaxQueueLength int32
	FlowGraphMaxParallelism int32
	FlushInsertBufferSize   int64
1241 1242

	Alias string // Different datanode in one machine
1243 1244 1245 1246

	// etcd
	ChannelWatchSubPath string

1247 1248 1249
	// io concurrency to fetch stats logs
	IOConcurrency int

1250 1251 1252 1253
	CreatedTime time.Time
	UpdatedTime time.Time
}

1254 1255
func (p *dataNodeConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
1256
	p.NodeID.Store(UniqueID(0))
1257 1258 1259
	p.initFlowGraphMaxQueueLength()
	p.initFlowGraphMaxParallelism()
	p.initFlushInsertBufferSize()
1260
	p.initIOConcurrency()
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270

	p.initChannelWatchPath()
}

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

func (p *dataNodeConfig) initFlowGraphMaxQueueLength() {
1271
	p.FlowGraphMaxQueueLength = p.Base.ParseInt32WithDefault("dataNode.dataSync.flowGraph.maxQueueLength", 1024)
1272 1273 1274
}

func (p *dataNodeConfig) initFlowGraphMaxParallelism() {
1275
	p.FlowGraphMaxParallelism = p.Base.ParseInt32WithDefault("dataNode.dataSync.flowGraph.maxParallelism", 1024)
1276 1277 1278
}

func (p *dataNodeConfig) initFlushInsertBufferSize() {
E
Enwei Jiao 已提交
1279 1280 1281 1282 1283 1284
	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
1285 1286 1287 1288 1289 1290
}

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

1291 1292 1293 1294
func (p *dataNodeConfig) initIOConcurrency() {
	p.IOConcurrency = p.Base.ParseIntWithDefault("dataNode.dataSync.ioConcurrency", 10)
}

X
Xiaofan 已提交
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
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
}

1307 1308 1309
///////////////////////////////////////////////////////////////////////////////
// --- indexcoord ---
type indexCoordConfig struct {
1310
	Base *BaseTable
1311 1312 1313 1314

	Address string
	Port    int

1315
	MinSegmentNumRowsToEnableIndex int64
1316

1317 1318
	GCInterval time.Duration

1319 1320 1321 1322
	CreatedTime time.Time
	UpdatedTime time.Time
}

1323 1324
func (p *indexCoordConfig) init(base *BaseTable) {
	p.Base = base
1325

1326
	p.initGCInterval()
1327
	p.initMinSegmentNumRowsToEnableIndex()
1328 1329
}

1330 1331 1332 1333
func (p *indexCoordConfig) initMinSegmentNumRowsToEnableIndex() {
	p.MinSegmentNumRowsToEnableIndex = p.Base.ParseInt64WithDefault("indexCoord.minSegmentNumRowsToEnableIndex", 1024)
}

1334 1335 1336 1337
func (p *indexCoordConfig) initGCInterval() {
	p.GCInterval = time.Duration(p.Base.ParseInt64WithDefault("indexCoord.gc.interval", 60*10)) * time.Second
}

1338 1339 1340
///////////////////////////////////////////////////////////////////////////////
// --- indexnode ---
type indexNodeConfig struct {
1341
	Base *BaseTable
1342 1343 1344 1345 1346

	IP      string
	Address string
	Port    int

X
Xiaofan 已提交
1347 1348 1349
	NodeID atomic.Value

	Alias string
1350

1351
	BuildParallel int
1352 1353 1354

	CreatedTime time.Time
	UpdatedTime time.Time
1355 1356 1357 1358 1359

	// enable disk
	EnableDisk             bool
	DiskCapacityLimit      int64
	MaxDiskUsagePercentage float64
1360 1361
}

1362 1363
func (p *indexNodeConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
1364
	p.NodeID.Store(UniqueID(0))
1365
	p.initBuildParallel()
1366 1367 1368
	p.initEnableDisk()
	p.initDiskCapacity()
	p.initMaxDiskUsagePercentage()
1369 1370 1371 1372 1373 1374 1375
}

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

1376 1377 1378 1379
func (p *indexNodeConfig) initBuildParallel() {
	p.BuildParallel = p.Base.ParseIntWithDefault("indexNode.scheduler.buildParallel", 1)
}

X
Xiaofan 已提交
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
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
}
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427

func (p *indexNodeConfig) initEnableDisk() {
	var err error
	enableDisk := p.Base.LoadWithDefault("indexNode.enableDisk", "false")
	p.EnableDisk, err = strconv.ParseBool(enableDisk)
	if err != nil {
		panic(err)
	}
}

func (p *indexNodeConfig) initDiskCapacity() {
	diskSizeStr := os.Getenv("LOCAL_STORAGE_SIZE")
	if len(diskSizeStr) == 0 {
		diskUsage, err := disk.Usage("/")
		if err != nil {
			panic(err)
		}

		p.DiskCapacityLimit = int64(diskUsage.Total)
		return
	}

	diskSize, err := strconv.ParseInt(diskSizeStr, 10, 64)
	if err != nil {
		panic(err)
	}
	p.DiskCapacityLimit = diskSize * 1024 * 1024 * 1024
}

func (p *indexNodeConfig) initMaxDiskUsagePercentage() {
	maxDiskUsagePercentageStr := p.Base.LoadWithDefault("indexNode.maxDiskUsagePercentage", "95")
	maxDiskUsagePercentage, err := strconv.ParseInt(maxDiskUsagePercentageStr, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MaxDiskUsagePercentage = float64(maxDiskUsagePercentage) / 100
}