component_param.go 34.3 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
	"path"
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 29
	// DefaultRetentionDuration defines the default duration for retention which is 5 days in seconds.
	DefaultRetentionDuration = 3600 * 24 * 5
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
	CommonCfg commonConfig
42 43 44 45 46 47 48 49 50 51 52 53

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

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

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

64
	p.CommonCfg.init(&p.BaseTable)
65

66 67 68 69 70 71 72 73
	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)
74 75
}

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

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

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

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

94
///////////////////////////////////////////////////////////////////////////////
95
// --- common ---
96
type commonConfig struct {
97
	Base *BaseTable
98

99
	ClusterPrefix string
100

101 102
	ProxySubName string

103 104 105 106 107
	RootCoordTimeTick   string
	RootCoordStatistics string
	RootCoordDml        string
	RootCoordDelta      string
	RootCoordSubName    string
108

109 110 111
	QueryCoordSearch       string
	QueryCoordSearchResult string
	QueryCoordTimeTick     string
112
	QueryNodeSubName       string
113

114 115 116 117
	DataCoordStatistic   string
	DataCoordTimeTick    string
	DataCoordSegmentInfo string
	DataCoordSubName     string
118
	DataNodeSubName      string
119 120 121 122

	DefaultPartitionName string
	DefaultIndexName     string
	RetentionDuration    int64
X
Xiaofan 已提交
123
	EntityExpirationTTL  time.Duration
124

125
	IndexSliceSize int64
126 127 128 129
	GracefulTime   int64

	StorageType string
	SimdType    string
C
codeman 已提交
130 131

	AuthorizationEnabled bool
132 133

	ClusterName string
134 135
}

136
func (p *commonConfig) init(base *BaseTable) {
137
	p.Base = base
138

139 140
	// must init cluster prefix first
	p.initClusterPrefix()
141 142
	p.initProxySubName()

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

	p.initQueryCoordSearch()
	p.initQueryCoordSearchResult()
	p.initQueryCoordTimeTick()
152
	p.initQueryNodeSubName()
153 154 155 156 157

	p.initDataCoordStatistic()
	p.initDataCoordTimeTick()
	p.initDataCoordSegmentInfo()
	p.initDataCoordSubName()
158
	p.initDataNodeSubName()
159 160 161 162

	p.initDefaultPartitionName()
	p.initDefaultIndexName()
	p.initRetentionDuration()
X
Xiaofan 已提交
163
	p.initEntityExpiration()
164 165

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

	p.initEnableAuthorization()
171 172

	p.initClusterName()
173 174
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	Address string
	Port    int

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

398 399 400
	// --- ETCD Path ---
	ImportTaskSubPath string

401 402 403 404
	CreatedTime time.Time
	UpdatedTime time.Time
}

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

///////////////////////////////////////////////////////////////////////////////
// --- proxy ---
type proxyConfig struct {
422
	Base *BaseTable
423 424

	// NetworkPort & IP are not used
425 426
	NetworkPort    int
	IP             string
427 428 429 430
	NetworkAddress string

	Alias string

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

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

	MaxTaskNum int64

	CreatedTime time.Time
	UpdatedTime time.Time
}

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

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

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

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

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

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

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

498 499 500 501 502 503 504 505 506
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
}

507 508 509 510 511 512 513 514 515
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
}

516 517 518 519 520 521 522 523 524
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
}

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

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

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

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

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

X
Xiaofan 已提交
561 562 563 564 565 566 567 568 569 570 571 572
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
}

573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
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)
}

591 592 593
///////////////////////////////////////////////////////////////////////////////
// --- querycoord ---
type queryCoordConfig struct {
594
	Base *BaseTable
595

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

	CreatedTime time.Time
	UpdatedTime time.Time

603 604 605 606
	//---- Task ---
	RetryNum      int32
	RetryInterval int64

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

	//---- Balance ---
	AutoBalance                         bool
	OverloadedMemoryThresholdPercentage float64
	BalanceIntervalSeconds              int64
	MemoryUsageMaxDifferencePercentage  float64
}

617 618
func (p *queryCoordConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
619
	p.NodeID.Store(UniqueID(0))
620 621 622 623 624

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

625 626 627 628 629 630 631 632 633 634
	//---- Handoff ---
	p.initAutoHandoff()

	//---- Balance ---
	p.initAutoBalance()
	p.initOverloadedMemoryThresholdPercentage()
	p.initBalanceIntervalSeconds()
	p.initMemoryUsageMaxDifferencePercentage()
}

635 636 637 638 639 640 641 642
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))
}

643
func (p *queryCoordConfig) initAutoHandoff() {
644
	handoff, err := p.Base.Load("queryCoord.autoHandoff")
645 646 647 648 649 650 651 652 653 654
	if err != nil {
		panic(err)
	}
	p.AutoHandoff, err = strconv.ParseBool(handoff)
	if err != nil {
		panic(err)
	}
}

func (p *queryCoordConfig) initAutoBalance() {
655
	balanceStr := p.Base.LoadWithDefault("queryCoord.autoBalance", "false")
656 657 658 659 660 661 662 663
	autoBalance, err := strconv.ParseBool(balanceStr)
	if err != nil {
		panic(err)
	}
	p.AutoBalance = autoBalance
}

func (p *queryCoordConfig) initOverloadedMemoryThresholdPercentage() {
664
	overloadedMemoryThresholdPercentage := p.Base.LoadWithDefault("queryCoord.overloadedMemoryThresholdPercentage", "90")
665 666 667 668 669 670 671 672
	thresholdPercentage, err := strconv.ParseInt(overloadedMemoryThresholdPercentage, 10, 64)
	if err != nil {
		panic(err)
	}
	p.OverloadedMemoryThresholdPercentage = float64(thresholdPercentage) / 100
}

func (p *queryCoordConfig) initBalanceIntervalSeconds() {
673
	balanceInterval := p.Base.LoadWithDefault("queryCoord.balanceIntervalSeconds", "60")
674 675 676 677 678 679 680 681
	interval, err := strconv.ParseInt(balanceInterval, 10, 64)
	if err != nil {
		panic(err)
	}
	p.BalanceIntervalSeconds = interval
}

func (p *queryCoordConfig) initMemoryUsageMaxDifferencePercentage() {
682
	maxDiff := p.Base.LoadWithDefault("queryCoord.memoryUsageMaxDifferencePercentage", "30")
683 684 685 686 687 688 689
	diffPercentage, err := strconv.ParseInt(maxDiff, 10, 64)
	if err != nil {
		panic(err)
	}
	p.MemoryUsageMaxDifferencePercentage = float64(diffPercentage) / 100
}

X
Xiaofan 已提交
690 691 692 693 694 695 696 697 698 699 700 701
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
}

702 703 704
///////////////////////////////////////////////////////////////////////////////
// --- querynode ---
type queryNodeConfig struct {
705
	Base *BaseTable
706 707 708 709

	Alias         string
	QueryNodeIP   string
	QueryNodePort int64
X
Xiaofan 已提交
710
	NodeID        atomic.Value
711 712 713 714 715 716 717

	FlowGraphMaxQueueLength int32
	FlowGraphMaxParallelism int32

	// stats
	StatsPublishInterval int

718
	SliceIndex int
719 720

	// segcore
721 722 723
	ChunkRows        int64
	SmallIndexNlist  int64
	SmallIndexNProbe int64
724 725 726 727 728

	CreatedTime time.Time
	UpdatedTime time.Time

	// memory limit
729
	LoadMemoryUsageFactor               float64
730
	OverloadedMemoryThresholdPercentage float64
G
godchen 已提交
731 732

	// cache limit
G
godchen 已提交
733 734
	CacheEnabled     bool
	CacheMemoryLimit int64
735 736 737 738

	GroupEnabled         bool
	MaxReceiveChanSize   int32
	MaxUnsolvedQueueSize int32
739
	MaxReadConcurrency   int32
740 741
	MaxGroupNQ           int64
	TopKMergeRatio       float64
742
	CPURatio             float64
743 744
}

745 746
func (p *queryNodeConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
747
	p.NodeID.Store(UniqueID(0))
748 749 750 751 752 753

	p.initFlowGraphMaxQueueLength()
	p.initFlowGraphMaxParallelism()

	p.initStatsPublishInterval()

754
	p.initSmallIndexParams()
755

756
	p.initLoadMemoryUsageFactor()
757
	p.initOverloadedMemoryThresholdPercentage()
G
godchen 已提交
758

G
godchen 已提交
759 760
	p.initCacheMemoryLimit()
	p.initCacheEnabled()
761 762 763

	p.initGroupEnabled()
	p.initMaxReceiveChanSize()
764
	p.initMaxReadConcurrency()
765 766 767
	p.initMaxUnsolvedQueueSize()
	p.initMaxGroupNQ()
	p.initTopKMergeRatio()
768
	p.initCPURatio()
769 770 771 772 773 774 775 776 777 778
}

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

// advanced params
// stats
func (p *queryNodeConfig) initStatsPublishInterval() {
779
	p.StatsPublishInterval = p.Base.ParseIntWithDefault("queryNode.stats.publishInterval", 1000)
780 781 782 783
}

// dataSync:
func (p *queryNodeConfig) initFlowGraphMaxQueueLength() {
784
	p.FlowGraphMaxQueueLength = p.Base.ParseInt32WithDefault("queryNode.dataSync.flowGraph.maxQueueLength", 1024)
785 786 787
}

func (p *queryNodeConfig) initFlowGraphMaxParallelism() {
788
	p.FlowGraphMaxParallelism = p.Base.ParseInt32WithDefault("queryNode.dataSync.flowGraph.maxParallelism", 1024)
789 790
}

791
func (p *queryNodeConfig) initSmallIndexParams() {
J
Jiquan Long 已提交
792
	p.ChunkRows = p.Base.ParseInt64WithDefault("queryNode.segcore.chunkRows", 1024)
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
	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
	}
819 820
}

821 822 823 824 825 826 827 828 829
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
}

830
func (p *queryNodeConfig) initOverloadedMemoryThresholdPercentage() {
831
	overloadedMemoryThresholdPercentage := p.Base.LoadWithDefault("queryCoord.overloadedMemoryThresholdPercentage", "90")
832 833 834 835 836 837 838
	thresholdPercentage, err := strconv.ParseInt(overloadedMemoryThresholdPercentage, 10, 64)
	if err != nil {
		panic(err)
	}
	p.OverloadedMemoryThresholdPercentage = float64(thresholdPercentage) / 100
}

G
godchen 已提交
839 840 841 842 843 844 845 846
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 已提交
847

G
godchen 已提交
848 849 850 851
func (p *queryNodeConfig) initCacheEnabled() {
	var err error
	cacheEnabled := p.Base.LoadWithDefault("queryNode.cache.enabled", "true")
	p.CacheEnabled, err = strconv.ParseBool(cacheEnabled)
G
godchen 已提交
852 853 854 855 856
	if err != nil {
		panic(err)
	}
}

857 858 859 860 861
func (p *queryNodeConfig) initGroupEnabled() {
	p.GroupEnabled = p.Base.ParseBool("queryNode.grouping.enabled", true)
}

func (p *queryNodeConfig) initMaxReceiveChanSize() {
862
	p.MaxReceiveChanSize = p.Base.ParseInt32WithDefault("queryNode.scheduler.receiveChanSize", 10240)
863 864 865
}

func (p *queryNodeConfig) initMaxUnsolvedQueueSize() {
866 867 868 869 870 871 872 873 874 875 876 877
	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() {
	p.MaxReadConcurrency = p.Base.ParseInt32WithDefault("queryNode.scheduler.maxReadConcurrency", 0)
	if p.MaxReadConcurrency <= 0 {
		p.MaxReadConcurrency = math.MaxInt32
	}
878 879 880 881 882 883 884 885 886 887
}

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 已提交
888 889 890 891 892 893 894 895 896 897 898 899
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
}

900 901 902
///////////////////////////////////////////////////////////////////////////////
// --- datacoord ---
type dataCoordConfig struct {
903
	Base *BaseTable
904

X
Xiaofan 已提交
905
	NodeID atomic.Value
906 907 908 909 910 911

	IP      string
	Port    int
	Address string

	// --- ETCD ---
X
XuanYang-cn 已提交
912
	ChannelWatchSubPath string
913 914 915 916 917

	// --- SEGMENTS ---
	SegmentMaxSize          float64
	SegmentSealProportion   float64
	SegAssignmentExpiration int64
918
	SegmentMaxLifetime      time.Duration
919 920 921 922

	CreatedTime time.Time
	UpdatedTime time.Time

923 924 925 926 927 928 929 930 931 932 933 934 935
	// compaction
	EnableCompaction     bool
	EnableAutoCompaction atomic.Value

	MinSegmentToMerge                 int
	MaxSegmentToMerge                 int
	SegmentSmallProportion            float64
	CompactionTimeoutInSeconds        int32
	SingleCompactionRatioThreshold    float32
	SingleCompactionDeltaLogMaxSize   int64
	SingleCompactionExpiredLogMaxSize int64
	SingleCompactionBinlogMaxNum      int64
	GlobalCompactionInterval          time.Duration
936 937

	// Garbage Collection
938 939 940 941
	EnableGarbageCollection bool
	GCInterval              time.Duration
	GCMissingTolerance      time.Duration
	GCDropTolerance         time.Duration
942 943
}

944 945
func (p *dataCoordConfig) init(base *BaseTable) {
	p.Base = base
946 947 948 949 950
	p.initChannelWatchPrefix()

	p.initSegmentMaxSize()
	p.initSegmentSealProportion()
	p.initSegAssignmentExpiration()
951
	p.initSegmentMaxLifetime()
952 953 954 955

	p.initEnableCompaction()
	p.initEnableAutoCompaction()

956 957 958 959 960 961 962 963 964 965
	p.initCompactionMinSegment()
	p.initCompactionMaxSegment()
	p.initSegmentSmallProportion()
	p.initCompactionTimeoutInSeconds()
	p.initSingleCompactionRatioThreshold()
	p.initSingleCompactionDeltaLogMaxSize()
	p.initSingleCompactionExpiredLogMaxSize()
	p.initSingleCompactionBinlogMaxNum()
	p.initGlobalCompactionInterval()

966 967 968 969 970 971 972
	p.initEnableGarbageCollection()
	p.initGCInterval()
	p.initGCMissingTolerance()
	p.initGCDropTolerance()
}

func (p *dataCoordConfig) initSegmentMaxSize() {
973
	p.SegmentMaxSize = p.Base.ParseFloatWithDefault("dataCoord.segment.maxSize", 512.0)
974 975 976
}

func (p *dataCoordConfig) initSegmentSealProportion() {
977
	p.SegmentSealProportion = p.Base.ParseFloatWithDefault("dataCoord.segment.sealProportion", 0.25)
978 979 980
}

func (p *dataCoordConfig) initSegAssignmentExpiration() {
981
	p.SegAssignmentExpiration = p.Base.ParseInt64WithDefault("dataCoord.segment.assignmentExpiration", 2000)
982 983
}

984 985 986 987
func (p *dataCoordConfig) initSegmentMaxLifetime() {
	p.SegmentMaxLifetime = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.segment.maxLife", 24*60*60)) * time.Second
}

988 989 990 991 992 993 994
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() {
995
	p.EnableCompaction = p.Base.ParseBool("dataCoord.enableCompaction", false)
996 997
}

998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
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)
}

// 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)))
}

1044 1045
// -- GC --
func (p *dataCoordConfig) initEnableGarbageCollection() {
1046
	p.EnableGarbageCollection = p.Base.ParseBool("dataCoord.enableGarbageCollection", true)
1047 1048 1049
}

func (p *dataCoordConfig) initGCInterval() {
1050
	p.GCInterval = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.gc.interval", 60*60)) * time.Second
1051 1052 1053
}

func (p *dataCoordConfig) initGCMissingTolerance() {
1054
	p.GCMissingTolerance = time.Duration(p.Base.ParseInt64WithDefault("dataCoord.gc.missingTolerance", 24*60*60)) * time.Second
1055 1056 1057
}

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

1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
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
1071 1072
}

X
Xiaofan 已提交
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
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
}

1085 1086 1087
///////////////////////////////////////////////////////////////////////////////
// --- datanode ---
type dataNodeConfig struct {
1088
	Base *BaseTable
1089

X
Xiaofan 已提交
1090 1091 1092
	// ID of the current node
	//NodeID atomic.Value
	NodeID atomic.Value
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
	// IP of the current DataNode
	IP string

	// Port of the current DataNode
	Port                    int
	FlowGraphMaxQueueLength int32
	FlowGraphMaxParallelism int32
	FlushInsertBufferSize   int64
	InsertBinlogRootPath    string
	StatsBinlogRootPath     string
	DeleteBinlogRootPath    string
	Alias                   string // Different datanode in one machine

	// etcd
	ChannelWatchSubPath string

1109 1110 1111
	// io concurrency to fetch stats logs
	IOConcurrency int

1112 1113 1114 1115
	CreatedTime time.Time
	UpdatedTime time.Time
}

1116 1117
func (p *dataNodeConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
1118
	p.NodeID.Store(UniqueID(0))
1119 1120 1121 1122 1123 1124
	p.initFlowGraphMaxQueueLength()
	p.initFlowGraphMaxParallelism()
	p.initFlushInsertBufferSize()
	p.initInsertBinlogRootPath()
	p.initStatsBinlogRootPath()
	p.initDeleteBinlogRootPath()
1125
	p.initIOConcurrency()
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135

	p.initChannelWatchPath()
}

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

func (p *dataNodeConfig) initFlowGraphMaxQueueLength() {
1136
	p.FlowGraphMaxQueueLength = p.Base.ParseInt32WithDefault("dataNode.dataSync.flowGraph.maxQueueLength", 1024)
1137 1138 1139
}

func (p *dataNodeConfig) initFlowGraphMaxParallelism() {
1140
	p.FlowGraphMaxParallelism = p.Base.ParseInt32WithDefault("dataNode.dataSync.flowGraph.maxParallelism", 1024)
1141 1142 1143
}

func (p *dataNodeConfig) initFlushInsertBufferSize() {
E
Enwei Jiao 已提交
1144 1145 1146 1147 1148 1149
	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
1150 1151 1152
}

func (p *dataNodeConfig) initInsertBinlogRootPath() {
1153
	// GOOSE TODO: rootPath change to TenentID
1154
	rootPath, err := p.Base.Load("minio.rootPath")
1155 1156 1157 1158 1159 1160 1161
	if err != nil {
		panic(err)
	}
	p.InsertBinlogRootPath = path.Join(rootPath, "insert_log")
}

func (p *dataNodeConfig) initStatsBinlogRootPath() {
1162
	rootPath, err := p.Base.Load("minio.rootPath")
1163 1164 1165 1166 1167 1168 1169
	if err != nil {
		panic(err)
	}
	p.StatsBinlogRootPath = path.Join(rootPath, "stats_log")
}

func (p *dataNodeConfig) initDeleteBinlogRootPath() {
1170
	rootPath, err := p.Base.Load("minio.rootPath")
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
	if err != nil {
		panic(err)
	}
	p.DeleteBinlogRootPath = path.Join(rootPath, "delta_log")
}

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

1181 1182 1183 1184
func (p *dataNodeConfig) initIOConcurrency() {
	p.IOConcurrency = p.Base.ParseIntWithDefault("dataNode.dataSync.ioConcurrency", 10)
}

X
Xiaofan 已提交
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
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
}

1197 1198 1199
///////////////////////////////////////////////////////////////////////////////
// --- indexcoord ---
type indexCoordConfig struct {
1200
	Base *BaseTable
1201 1202 1203 1204 1205 1206

	Address string
	Port    int

	IndexStorageRootPath string

1207 1208
	GCInterval time.Duration

1209 1210 1211 1212
	CreatedTime time.Time
	UpdatedTime time.Time
}

1213 1214
func (p *indexCoordConfig) init(base *BaseTable) {
	p.Base = base
1215 1216

	p.initIndexStorageRootPath()
1217
	p.initGCInterval()
1218 1219 1220 1221
}

// initIndexStorageRootPath initializes the root path of index files.
func (p *indexCoordConfig) initIndexStorageRootPath() {
1222
	rootPath, err := p.Base.Load("minio.rootPath")
1223 1224 1225 1226 1227 1228
	if err != nil {
		panic(err)
	}
	p.IndexStorageRootPath = path.Join(rootPath, "index_files")
}

1229 1230 1231 1232
func (p *indexCoordConfig) initGCInterval() {
	p.GCInterval = time.Duration(p.Base.ParseInt64WithDefault("indexCoord.gc.interval", 60*10)) * time.Second
}

1233 1234 1235
///////////////////////////////////////////////////////////////////////////////
// --- indexnode ---
type indexNodeConfig struct {
1236
	Base *BaseTable
1237 1238 1239 1240 1241

	IP      string
	Address string
	Port    int

X
Xiaofan 已提交
1242 1243 1244
	NodeID atomic.Value

	Alias string
1245 1246

	IndexStorageRootPath string
1247
	BuildParallel        int
1248 1249 1250 1251 1252

	CreatedTime time.Time
	UpdatedTime time.Time
}

1253 1254
func (p *indexNodeConfig) init(base *BaseTable) {
	p.Base = base
X
Xiaofan 已提交
1255
	p.NodeID.Store(UniqueID(0))
1256
	p.initIndexStorageRootPath()
1257
	p.initBuildParallel()
1258 1259 1260 1261 1262 1263 1264 1265
}

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

func (p *indexNodeConfig) initIndexStorageRootPath() {
1266
	rootPath, err := p.Base.Load("minio.rootPath")
1267 1268 1269 1270 1271
	if err != nil {
		panic(err)
	}
	p.IndexStorageRootPath = path.Join(rootPath, "index_files")
}
X
Xiaofan 已提交
1272

1273 1274 1275 1276
func (p *indexNodeConfig) initBuildParallel() {
	p.BuildParallel = p.Base.ParseIntWithDefault("indexNode.scheduler.buildParallel", 1)
}

X
Xiaofan 已提交
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
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
}