2022-09-16 09:56:47 +08:00
// Licensed to the LF AI & Data foundation under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 (
2022-10-27 17:37:32 +08:00
"fmt"
2022-09-16 09:56:47 +08:00
"math"
"sync"
"time"
"go.uber.org/zap"
"github.com/milvus-io/milvus/internal/log"
)
const (
// defaultMax is the default unlimited rate or threshold.
2022-10-31 20:59:34 +08:00
defaultMax = float64 ( math . MaxFloat64 )
2022-10-17 16:23:25 +08:00
// MBSize used to convert megabytes and bytes.
MBSize = 1024.0 * 1024.0
// defaultDiskQuotaInMB is the default disk quota in megabytes.
defaultDiskQuotaInMB = defaultMax / MBSize
2022-10-12 10:03:22 +08:00
// defaultMin is the default minimal rate.
2022-09-16 09:56:47 +08:00
defaultMin = float64 ( 0 )
// defaultLowWaterLevel is the default memory low water level.
2022-10-09 14:30:58 +08:00
defaultLowWaterLevel = float64 ( 0.85 )
2022-09-16 09:56:47 +08:00
// defaultHighWaterLevel is the default memory low water level.
2022-10-09 14:30:58 +08:00
defaultHighWaterLevel = float64 ( 0.95 )
2022-09-16 09:56:47 +08:00
)
// quotaConfig is configuration for quota and limitations.
type quotaConfig struct {
Base * BaseTable
once sync . Once
2022-09-26 16:48:53 +08:00
QuotaAndLimitsEnabled bool
2022-09-16 09:56:47 +08:00
QuotaCenterCollectInterval float64
// ddl
2022-09-26 16:48:53 +08:00
DDLLimitEnabled bool
2022-09-16 09:56:47 +08:00
DDLCollectionRate float64
DDLPartitionRate float64
2022-10-09 14:30:58 +08:00
IndexLimitEnabled bool
MaxIndexRate float64
FlushLimitEnabled bool
MaxFlushRate float64
CompactionLimitEnabled bool
MaxCompactionRate float64
2022-09-16 09:56:47 +08:00
// dml
2022-09-26 16:48:53 +08:00
DMLLimitEnabled bool
2022-09-16 09:56:47 +08:00
DMLMaxInsertRate float64
DMLMinInsertRate float64
DMLMaxDeleteRate float64
DMLMinDeleteRate float64
DMLMaxBulkLoadRate float64
DMLMinBulkLoadRate float64
// dql
2022-09-26 16:48:53 +08:00
DQLLimitEnabled bool
2022-09-16 09:56:47 +08:00
DQLMaxSearchRate float64
DQLMinSearchRate float64
DQLMaxQueryRate float64
DQLMinQueryRate float64
// limits
MaxCollectionNum int
2022-09-26 16:48:53 +08:00
// limit writing
2022-09-16 09:56:47 +08:00
ForceDenyWriting bool
2022-09-26 16:48:53 +08:00
TtProtectionEnabled bool
2022-09-16 09:56:47 +08:00
MaxTimeTickDelay time . Duration
2022-09-26 16:48:53 +08:00
MemProtectionEnabled bool
2022-09-16 09:56:47 +08:00
DataNodeMemoryLowWaterLevel float64
DataNodeMemoryHighWaterLevel float64
QueryNodeMemoryLowWaterLevel float64
QueryNodeMemoryHighWaterLevel float64
2022-10-12 10:03:22 +08:00
DiskProtectionEnabled bool
DiskQuota float64
2022-09-16 09:56:47 +08:00
2022-09-26 16:48:53 +08:00
// limit reading
2022-10-13 14:57:24 +08:00
ForceDenyReading bool
QueueProtectionEnabled bool
NQInQueueThreshold int64
QueueLatencyThreshold float64
ResultProtectionEnabled bool
MaxReadResultRate float64
CoolOffSpeed float64
2022-09-16 09:56:47 +08:00
}
func ( p * quotaConfig ) init ( base * BaseTable ) {
p . Base = base
2022-09-26 16:48:53 +08:00
p . initQuotaAndLimitsEnabled ( )
2022-09-16 09:56:47 +08:00
p . initQuotaCenterCollectInterval ( )
2022-09-26 16:48:53 +08:00
// ddl
p . initDDLLimitEnabled ( )
2022-09-16 09:56:47 +08:00
p . initDDLCollectionRate ( )
p . initDDLPartitionRate ( )
2022-10-09 14:30:58 +08:00
p . initIndexLimitEnabled ( )
p . initMaxIndexRate ( )
p . initFlushLimitEnabled ( )
p . initMaxFlushRate ( )
p . initCompactionLimitEnabled ( )
p . initMaxCompactionRate ( )
2022-09-16 09:56:47 +08:00
2022-09-26 16:48:53 +08:00
// dml
p . initDMLLimitEnabled ( )
2022-09-16 09:56:47 +08:00
p . initDMLMaxInsertRate ( )
p . initDMLMinInsertRate ( )
p . initDMLMaxDeleteRate ( )
p . initDMLMinDeleteRate ( )
p . initDMLMaxBulkLoadRate ( )
p . initDMLMinBulkLoadRate ( )
2022-09-26 16:48:53 +08:00
// dql
p . initDQLLimitEnabled ( )
2022-09-16 09:56:47 +08:00
p . initDQLMaxSearchRate ( )
p . initDQLMinSearchRate ( )
p . initDQLMaxQueryRate ( )
p . initDQLMinQueryRate ( )
2022-09-26 16:48:53 +08:00
// limits
2022-09-16 09:56:47 +08:00
p . initMaxCollectionNum ( )
2022-09-26 16:48:53 +08:00
// limit writing
2022-09-16 09:56:47 +08:00
p . initForceDenyWriting ( )
2022-09-26 16:48:53 +08:00
p . initTtProtectionEnabled ( )
2022-09-16 09:56:47 +08:00
p . initMaxTimeTickDelay ( )
2022-09-26 16:48:53 +08:00
p . initMemProtectionEnabled ( )
2022-09-16 09:56:47 +08:00
p . initDataNodeMemoryLowWaterLevel ( )
p . initDataNodeMemoryHighWaterLevel ( )
p . initQueryNodeMemoryLowWaterLevel ( )
p . initQueryNodeMemoryHighWaterLevel ( )
2022-10-12 10:03:22 +08:00
p . initDiskProtectionEnabled ( )
p . initDiskQuota ( )
2022-09-16 09:56:47 +08:00
2022-09-26 16:48:53 +08:00
// limit reading
2022-09-16 09:56:47 +08:00
p . initForceDenyReading ( )
2022-09-26 16:48:53 +08:00
p . initQueueProtectionEnabled ( )
2022-09-16 09:56:47 +08:00
p . initNQInQueueThreshold ( )
p . initQueueLatencyThreshold ( )
2022-10-13 14:57:24 +08:00
p . initResultProtectionEnabled ( )
p . initMaxReadResultRate ( )
2022-09-16 09:56:47 +08:00
p . initCoolOffSpeed ( )
}
2022-09-26 16:48:53 +08:00
func ( p * quotaConfig ) initQuotaAndLimitsEnabled ( ) {
p . QuotaAndLimitsEnabled = p . Base . ParseBool ( "quotaAndLimits.enabled" , false )
2022-09-16 09:56:47 +08:00
}
func ( p * quotaConfig ) initQuotaCenterCollectInterval ( ) {
const defaultInterval = 3.0
p . QuotaCenterCollectInterval = p . Base . ParseFloatWithDefault ( "quotaAndLimits.quotaCenterCollectInterval" , defaultInterval )
// (0 ~ 65536)
if p . QuotaCenterCollectInterval <= 0 || p . QuotaCenterCollectInterval >= 65536 {
p . QuotaCenterCollectInterval = defaultInterval
}
}
2022-09-26 16:48:53 +08:00
func ( p * quotaConfig ) initDDLLimitEnabled ( ) {
p . DDLLimitEnabled = p . Base . ParseBool ( "quotaAndLimits.ddl.enabled" , false )
}
2022-09-16 09:56:47 +08:00
func ( p * quotaConfig ) initDDLCollectionRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DDLLimitEnabled {
p . DDLCollectionRate = defaultMax
return
}
2022-09-16 09:56:47 +08:00
p . DDLCollectionRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.ddl.collectionRate" , defaultMax )
// [0 ~ Inf)
if p . DDLCollectionRate < 0 {
p . DDLCollectionRate = defaultMax
}
}
func ( p * quotaConfig ) initDDLPartitionRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DDLLimitEnabled {
p . DDLPartitionRate = defaultMax
return
}
2022-09-16 09:56:47 +08:00
p . DDLPartitionRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.ddl.partitionRate" , defaultMax )
// [0 ~ Inf)
if p . DDLPartitionRate < 0 {
p . DDLPartitionRate = defaultMax
}
}
2022-10-09 14:30:58 +08:00
func ( p * quotaConfig ) initIndexLimitEnabled ( ) {
p . IndexLimitEnabled = p . Base . ParseBool ( "quotaAndLimits.indexRate.enabled" , false )
}
func ( p * quotaConfig ) initMaxIndexRate ( ) {
if ! p . IndexLimitEnabled {
p . MaxIndexRate = defaultMax
2022-09-26 16:48:53 +08:00
return
}
2022-10-09 14:30:58 +08:00
p . MaxIndexRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.indexRate.max" , defaultMax )
2022-09-16 09:56:47 +08:00
// [0 ~ Inf)
2022-10-09 14:30:58 +08:00
if p . MaxIndexRate < 0 {
p . MaxIndexRate = defaultMax
2022-09-16 09:56:47 +08:00
}
}
2022-10-09 14:30:58 +08:00
func ( p * quotaConfig ) initFlushLimitEnabled ( ) {
p . FlushLimitEnabled = p . Base . ParseBool ( "quotaAndLimits.flushRate.enabled" , false )
}
func ( p * quotaConfig ) initMaxFlushRate ( ) {
if ! p . FlushLimitEnabled {
p . MaxFlushRate = defaultMax
2022-09-26 16:48:53 +08:00
return
}
2022-10-09 14:30:58 +08:00
p . MaxFlushRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.flushRate.max" , defaultMax )
2022-09-16 09:56:47 +08:00
// [0 ~ Inf)
2022-10-09 14:30:58 +08:00
if p . MaxFlushRate < 0 {
p . MaxFlushRate = defaultMax
2022-09-16 09:56:47 +08:00
}
}
2022-10-09 14:30:58 +08:00
func ( p * quotaConfig ) initCompactionLimitEnabled ( ) {
p . CompactionLimitEnabled = p . Base . ParseBool ( "quotaAndLimits.compactionRate.enabled" , false )
}
func ( p * quotaConfig ) initMaxCompactionRate ( ) {
if ! p . CompactionLimitEnabled {
p . MaxCompactionRate = defaultMax
2022-09-26 16:48:53 +08:00
return
}
2022-10-09 14:30:58 +08:00
p . MaxCompactionRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.compactionRate.max" , defaultMax )
2022-09-16 09:56:47 +08:00
// [0 ~ Inf)
2022-10-09 14:30:58 +08:00
if p . MaxCompactionRate < 0 {
p . MaxCompactionRate = defaultMax
2022-09-16 09:56:47 +08:00
}
}
2022-10-17 16:23:25 +08:00
func megaBytes2Bytes ( f float64 ) float64 {
return f * MBSize
2022-09-16 09:56:47 +08:00
}
func ( p * quotaConfig ) checkMinMaxLegal ( min , max float64 ) bool {
if min > max {
log . Warn ( "init QuotaConfig failed, max/high must be greater than or equal to min/low, use default values" ,
2022-10-27 17:37:32 +08:00
zap . String ( "msg" , fmt . Sprintf ( "min: %v, max: %v, defaultMin: %v, defaultMax: %v" , min , max , defaultMin , defaultMax ) ) )
2022-09-16 09:56:47 +08:00
return false
}
return true
}
2022-09-26 16:48:53 +08:00
func ( p * quotaConfig ) initDMLLimitEnabled ( ) {
p . DMLLimitEnabled = p . Base . ParseBool ( "quotaAndLimits.dml.enabled" , false )
}
2022-09-16 09:56:47 +08:00
func ( p * quotaConfig ) initDMLMaxInsertRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DMLLimitEnabled {
p . DMLMaxInsertRate = defaultMax
return
}
2022-09-16 09:56:47 +08:00
p . DMLMaxInsertRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.dml.insertRate.max" , defaultMax )
if math . Abs ( p . DMLMaxInsertRate - defaultMax ) > 0.001 { // maxRate != defaultMax
2022-10-17 16:23:25 +08:00
p . DMLMaxInsertRate = megaBytes2Bytes ( p . DMLMaxInsertRate )
2022-09-16 09:56:47 +08:00
}
// [0, inf)
if p . DMLMaxInsertRate < 0 {
p . DMLMaxInsertRate = defaultMax
}
}
func ( p * quotaConfig ) initDMLMinInsertRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DMLLimitEnabled {
p . DMLMinInsertRate = defaultMin
return
}
2022-09-16 09:56:47 +08:00
p . DMLMinInsertRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.dml.insertRate.min" , defaultMin )
2022-10-17 16:23:25 +08:00
p . DMLMinInsertRate = megaBytes2Bytes ( p . DMLMinInsertRate )
2022-09-16 09:56:47 +08:00
// [0, inf)
if p . DMLMinInsertRate < 0 {
p . DMLMinInsertRate = defaultMin
}
if ! p . checkMinMaxLegal ( p . DMLMinInsertRate , p . DMLMaxInsertRate ) {
p . DMLMinInsertRate = defaultMin
p . DMLMaxInsertRate = defaultMax
}
}
func ( p * quotaConfig ) initDMLMaxDeleteRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DMLLimitEnabled {
p . DMLMaxDeleteRate = defaultMax
return
}
2022-09-16 09:56:47 +08:00
p . DMLMaxDeleteRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.dml.deleteRate.max" , defaultMax )
if math . Abs ( p . DMLMaxDeleteRate - defaultMax ) > 0.001 { // maxRate != defaultMax
2022-10-17 16:23:25 +08:00
p . DMLMaxDeleteRate = megaBytes2Bytes ( p . DMLMaxDeleteRate )
2022-09-16 09:56:47 +08:00
}
// [0, inf)
if p . DMLMaxDeleteRate < 0 {
p . DMLMaxDeleteRate = defaultMax
}
}
func ( p * quotaConfig ) initDMLMinDeleteRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DMLLimitEnabled {
p . DMLMinDeleteRate = defaultMin
return
}
2022-09-16 09:56:47 +08:00
p . DMLMinDeleteRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.dml.deleteRate.min" , defaultMin )
2022-10-17 16:23:25 +08:00
p . DMLMinDeleteRate = megaBytes2Bytes ( p . DMLMinDeleteRate )
2022-09-16 09:56:47 +08:00
// [0, inf)
if p . DMLMinDeleteRate < 0 {
p . DMLMinDeleteRate = defaultMin
}
if ! p . checkMinMaxLegal ( p . DMLMinDeleteRate , p . DMLMaxDeleteRate ) {
p . DMLMinDeleteRate = defaultMin
p . DMLMaxDeleteRate = defaultMax
}
}
func ( p * quotaConfig ) initDMLMaxBulkLoadRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DMLLimitEnabled {
p . DMLMaxBulkLoadRate = defaultMax
return
}
2022-09-16 09:56:47 +08:00
p . DMLMaxBulkLoadRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.dml.bulkLoadRate.max" , defaultMax )
if math . Abs ( p . DMLMaxBulkLoadRate - defaultMax ) > 0.001 { // maxRate != defaultMax
2022-10-17 16:23:25 +08:00
p . DMLMaxBulkLoadRate = megaBytes2Bytes ( p . DMLMaxBulkLoadRate )
2022-09-16 09:56:47 +08:00
}
// [0, inf)
if p . DMLMaxBulkLoadRate < 0 {
p . DMLMaxBulkLoadRate = defaultMax
}
}
func ( p * quotaConfig ) initDMLMinBulkLoadRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DMLLimitEnabled {
p . DMLMinBulkLoadRate = defaultMin
return
}
2022-09-16 09:56:47 +08:00
p . DMLMinBulkLoadRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.dml.bulkLoadRate.min" , defaultMin )
2022-10-17 16:23:25 +08:00
p . DMLMinBulkLoadRate = megaBytes2Bytes ( p . DMLMinBulkLoadRate )
2022-09-16 09:56:47 +08:00
// [0, inf)
if p . DMLMinBulkLoadRate < 0 {
p . DMLMinBulkLoadRate = defaultMin
}
if ! p . checkMinMaxLegal ( p . DMLMinBulkLoadRate , p . DMLMaxBulkLoadRate ) {
p . DMLMinBulkLoadRate = defaultMin
p . DMLMaxBulkLoadRate = defaultMax
}
}
2022-09-26 16:48:53 +08:00
func ( p * quotaConfig ) initDQLLimitEnabled ( ) {
p . DQLLimitEnabled = p . Base . ParseBool ( "quotaAndLimits.dql.enabled" , false )
}
2022-09-16 09:56:47 +08:00
func ( p * quotaConfig ) initDQLMaxSearchRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DQLLimitEnabled {
p . DQLMaxSearchRate = defaultMax
return
}
2022-09-16 09:56:47 +08:00
p . DQLMaxSearchRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.dql.searchRate.max" , defaultMax )
// [0, inf)
if p . DQLMaxSearchRate < 0 {
p . DQLMaxSearchRate = defaultMax
}
}
func ( p * quotaConfig ) initDQLMinSearchRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DQLLimitEnabled {
p . DQLMinSearchRate = defaultMin
return
}
2022-09-16 09:56:47 +08:00
p . DQLMinSearchRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.dql.searchRate.min" , defaultMin )
// [0, inf)
if p . DQLMinSearchRate < 0 {
p . DQLMinSearchRate = defaultMin
}
if ! p . checkMinMaxLegal ( p . DQLMinSearchRate , p . DQLMaxSearchRate ) {
p . DQLMinSearchRate = defaultMax
p . DQLMaxSearchRate = defaultMax
}
}
func ( p * quotaConfig ) initDQLMaxQueryRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DQLLimitEnabled {
p . DQLMaxQueryRate = defaultMax
return
}
2022-09-16 09:56:47 +08:00
p . DQLMaxQueryRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.dql.queryRate.max" , defaultMax )
// [0, inf)
if p . DQLMaxQueryRate < 0 {
p . DQLMaxQueryRate = defaultMax
}
}
func ( p * quotaConfig ) initDQLMinQueryRate ( ) {
2022-09-26 16:48:53 +08:00
if ! p . DQLLimitEnabled {
p . DQLMinQueryRate = defaultMin
return
}
2022-09-16 09:56:47 +08:00
p . DQLMinQueryRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.dql.queryRate.min" , defaultMin )
// [0, inf)
if p . DQLMinQueryRate < 0 {
p . DQLMinQueryRate = defaultMin
}
if ! p . checkMinMaxLegal ( p . DQLMinQueryRate , p . DQLMaxQueryRate ) {
p . DQLMinQueryRate = defaultMin
p . DQLMaxQueryRate = defaultMax
}
}
func ( p * quotaConfig ) initMaxCollectionNum ( ) {
p . MaxCollectionNum = p . Base . ParseIntWithDefault ( "quotaAndLimits.limits.collection.maxNum" , 64 )
}
func ( p * quotaConfig ) initForceDenyWriting ( ) {
p . ForceDenyWriting = p . Base . ParseBool ( "quotaAndLimits.limitWriting.forceDeny" , false )
}
2022-09-26 16:48:53 +08:00
func ( p * quotaConfig ) initTtProtectionEnabled ( ) {
2022-10-13 16:15:25 +08:00
p . TtProtectionEnabled = p . Base . ParseBool ( "quotaAndLimits.limitWriting.ttProtection.enabled" , true )
2022-09-26 16:48:53 +08:00
}
2022-09-16 09:56:47 +08:00
func ( p * quotaConfig ) initMaxTimeTickDelay ( ) {
2022-09-26 16:48:53 +08:00
if ! p . TtProtectionEnabled {
2022-10-14 14:27:25 +08:00
p . MaxTimeTickDelay = math . MaxInt64
2022-09-26 16:48:53 +08:00
return
}
2022-10-27 17:37:32 +08:00
const defaultMaxTtDelay = 300.0
2022-09-26 16:48:53 +08:00
delay := p . Base . ParseFloatWithDefault ( "quotaAndLimits.limitWriting.ttProtection.maxTimeTickDelay" , defaultMaxTtDelay )
2022-09-16 09:56:47 +08:00
// (0, 65536)
if delay <= 0 || delay >= 65536 {
delay = defaultMaxTtDelay
}
p . MaxTimeTickDelay = time . Duration ( delay * float64 ( time . Second ) )
}
2022-09-26 16:48:53 +08:00
func ( p * quotaConfig ) initMemProtectionEnabled ( ) {
p . MemProtectionEnabled = p . Base . ParseBool ( "quotaAndLimits.limitWriting.memProtection.enabled" , true )
}
2022-09-16 09:56:47 +08:00
func ( p * quotaConfig ) initDataNodeMemoryLowWaterLevel ( ) {
2022-09-26 16:48:53 +08:00
if ! p . MemProtectionEnabled {
return
}
p . DataNodeMemoryLowWaterLevel = p . Base . ParseFloatWithDefault ( "quotaAndLimits.limitWriting.memProtection.dataNodeMemoryLowWaterLevel" , defaultLowWaterLevel )
2022-09-16 09:56:47 +08:00
// (0, 1]
if p . DataNodeMemoryLowWaterLevel <= 0 || p . DataNodeMemoryLowWaterLevel > 1 {
log . Warn ( "MemoryLowWaterLevel must in the range of `(0, 1]`, use default value" , zap . Float64 ( "low" , p . DataNodeMemoryLowWaterLevel ) , zap . Float64 ( "default" , defaultLowWaterLevel ) )
p . DataNodeMemoryLowWaterLevel = defaultLowWaterLevel
}
}
func ( p * quotaConfig ) initDataNodeMemoryHighWaterLevel ( ) {
2022-09-26 16:48:53 +08:00
if ! p . MemProtectionEnabled {
2022-10-14 14:27:25 +08:00
p . DataNodeMemoryHighWaterLevel = 1
2022-09-26 16:48:53 +08:00
return
}
p . DataNodeMemoryHighWaterLevel = p . Base . ParseFloatWithDefault ( "quotaAndLimits.limitWriting.memProtection.dataNodeMemoryHighWaterLevel" , defaultHighWaterLevel )
2022-09-16 09:56:47 +08:00
// (0, 1]
if p . DataNodeMemoryHighWaterLevel <= 0 || p . DataNodeMemoryHighWaterLevel > 1 {
log . Warn ( "MemoryLowWaterLevel must in the range of `(0, 1]`, use default value" , zap . Float64 ( "low" , p . DataNodeMemoryHighWaterLevel ) , zap . Float64 ( "default" , defaultHighWaterLevel ) )
p . DataNodeMemoryHighWaterLevel = defaultHighWaterLevel
}
if ! p . checkMinMaxLegal ( p . DataNodeMemoryLowWaterLevel , p . DataNodeMemoryHighWaterLevel ) {
p . DataNodeMemoryHighWaterLevel = defaultHighWaterLevel
p . DataNodeMemoryLowWaterLevel = defaultLowWaterLevel
}
}
func ( p * quotaConfig ) initQueryNodeMemoryLowWaterLevel ( ) {
2022-09-26 16:48:53 +08:00
if ! p . MemProtectionEnabled {
return
}
p . QueryNodeMemoryLowWaterLevel = p . Base . ParseFloatWithDefault ( "quotaAndLimits.limitWriting.memProtection.queryNodeMemoryLowWaterLevel" , defaultLowWaterLevel )
2022-09-16 09:56:47 +08:00
// (0, 1]
if p . QueryNodeMemoryLowWaterLevel <= 0 || p . QueryNodeMemoryLowWaterLevel > 1 {
log . Warn ( "MemoryLowWaterLevel must in the range of `(0, 1]`, use default value" , zap . Float64 ( "low" , p . QueryNodeMemoryLowWaterLevel ) , zap . Float64 ( "default" , defaultLowWaterLevel ) )
p . QueryNodeMemoryLowWaterLevel = defaultLowWaterLevel
}
}
func ( p * quotaConfig ) initQueryNodeMemoryHighWaterLevel ( ) {
2022-09-26 16:48:53 +08:00
if ! p . MemProtectionEnabled {
2022-10-14 14:27:25 +08:00
p . QueryNodeMemoryLowWaterLevel = defaultLowWaterLevel
2022-09-26 16:48:53 +08:00
return
}
p . QueryNodeMemoryHighWaterLevel = p . Base . ParseFloatWithDefault ( "quotaAndLimits.limitWriting.memProtection.queryNodeMemoryHighWaterLevel" , defaultHighWaterLevel )
2022-09-16 09:56:47 +08:00
// (0, 1]
if p . QueryNodeMemoryHighWaterLevel <= 0 || p . QueryNodeMemoryHighWaterLevel > 1 {
log . Warn ( "MemoryLowWaterLevel must in the range of `(0, 1]`, use default value" , zap . Float64 ( "low" , p . QueryNodeMemoryHighWaterLevel ) , zap . Float64 ( "default" , defaultHighWaterLevel ) )
p . QueryNodeMemoryHighWaterLevel = defaultHighWaterLevel
}
if ! p . checkMinMaxLegal ( p . QueryNodeMemoryLowWaterLevel , p . QueryNodeMemoryHighWaterLevel ) {
p . QueryNodeMemoryHighWaterLevel = defaultHighWaterLevel
p . QueryNodeMemoryLowWaterLevel = defaultLowWaterLevel
}
}
2022-10-12 10:03:22 +08:00
func ( p * quotaConfig ) initDiskProtectionEnabled ( ) {
p . DiskProtectionEnabled = p . Base . ParseBool ( "quotaAndLimits.limitWriting.diskProtection.enabled" , true )
}
func ( p * quotaConfig ) initDiskQuota ( ) {
if ! p . DiskProtectionEnabled {
p . DiskQuota = defaultMax
return
}
2022-10-17 16:23:25 +08:00
p . DiskQuota = p . Base . ParseFloatWithDefault ( "quotaAndLimits.limitWriting.diskProtection.diskQuota" , defaultDiskQuotaInMB )
2022-10-12 10:03:22 +08:00
// (0, +inf)
if p . DiskQuota <= 0 {
2022-10-17 16:23:25 +08:00
p . DiskQuota = defaultDiskQuotaInMB
2022-10-12 10:03:22 +08:00
}
2022-10-19 15:13:26 +08:00
if p . DiskQuota < defaultDiskQuotaInMB {
2022-10-27 17:37:32 +08:00
log . Debug ( "init disk quota" , zap . String ( "diskQuota(MB)" , fmt . Sprintf ( "%v" , p . DiskQuota ) ) )
2022-10-19 15:13:26 +08:00
} else {
log . Debug ( "init disk quota" , zap . String ( "diskQuota(MB)" , "+inf" ) )
}
2022-10-17 16:23:25 +08:00
// megabytes to bytes
p . DiskQuota = megaBytes2Bytes ( p . DiskQuota )
2022-10-12 10:03:22 +08:00
}
2022-09-16 09:56:47 +08:00
func ( p * quotaConfig ) initForceDenyReading ( ) {
p . ForceDenyReading = p . Base . ParseBool ( "quotaAndLimits.limitReading.forceDeny" , false )
}
2022-09-26 16:48:53 +08:00
func ( p * quotaConfig ) initQueueProtectionEnabled ( ) {
p . QueueProtectionEnabled = p . Base . ParseBool ( "quotaAndLimits.limitReading.queueProtection.enabled" , false )
}
2022-09-16 09:56:47 +08:00
func ( p * quotaConfig ) initNQInQueueThreshold ( ) {
2022-09-26 16:48:53 +08:00
if ! p . QueueProtectionEnabled {
2022-10-14 14:27:25 +08:00
p . NQInQueueThreshold = math . MaxInt64
2022-09-26 16:48:53 +08:00
return
}
p . NQInQueueThreshold = p . Base . ParseInt64WithDefault ( "quotaAndLimits.limitReading.queueProtection.nqInQueueThreshold" , math . MaxInt64 )
2022-09-16 09:56:47 +08:00
// [0, inf)
if p . NQInQueueThreshold < 0 {
p . NQInQueueThreshold = math . MaxInt64
}
}
func ( p * quotaConfig ) initQueueLatencyThreshold ( ) {
2022-09-26 16:48:53 +08:00
if ! p . QueueProtectionEnabled {
2022-10-14 14:27:25 +08:00
p . QueueLatencyThreshold = defaultMax
2022-09-26 16:48:53 +08:00
return
}
p . QueueLatencyThreshold = p . Base . ParseFloatWithDefault ( "quotaAndLimits.limitReading.queueProtection.queueLatencyThreshold" , defaultMax )
2022-09-16 09:56:47 +08:00
// [0, inf)
if p . QueueLatencyThreshold < 0 {
p . QueueLatencyThreshold = defaultMax
}
}
2022-10-13 14:57:24 +08:00
func ( p * quotaConfig ) initResultProtectionEnabled ( ) {
p . ResultProtectionEnabled = p . Base . ParseBool ( "quotaAndLimits.limitReading.resultProtection.enabled" , false )
}
func ( p * quotaConfig ) initMaxReadResultRate ( ) {
if ! p . ResultProtectionEnabled {
p . MaxReadResultRate = defaultMax
return
}
p . MaxReadResultRate = p . Base . ParseFloatWithDefault ( "quotaAndLimits.limitReading.resultProtection.maxReadResultRate" , defaultMax )
if math . Abs ( p . MaxReadResultRate - defaultMax ) > 0.001 { // maxRate != defaultMax
2022-10-17 16:23:25 +08:00
p . MaxReadResultRate = megaBytes2Bytes ( p . MaxReadResultRate )
2022-10-13 14:57:24 +08:00
}
// [0, inf)
if p . MaxReadResultRate < 0 {
p . MaxReadResultRate = defaultMax
}
}
2022-09-16 09:56:47 +08:00
func ( p * quotaConfig ) initCoolOffSpeed ( ) {
const defaultSpeed = 0.9
2022-09-26 16:48:53 +08:00
p . CoolOffSpeed = defaultSpeed
2022-10-13 14:57:24 +08:00
p . CoolOffSpeed = p . Base . ParseFloatWithDefault ( "quotaAndLimits.limitReading.coolOffSpeed" , defaultSpeed )
2022-09-16 09:56:47 +08:00
// (0, 1]
if p . CoolOffSpeed <= 0 || p . CoolOffSpeed > 1 {
log . Warn ( "CoolOffSpeed must in the range of `(0, 1]`, use default value" , zap . Float64 ( "speed" , p . CoolOffSpeed ) , zap . Float64 ( "default" , defaultSpeed ) )
p . CoolOffSpeed = defaultSpeed
}
}