Fix quota center assignment to entry in nil map (#23819)

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
yihao.dai 2023-04-29 18:22:38 +08:00 committed by GitHub
parent c955c26656
commit 5a9a86ba74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -454,13 +454,13 @@ func (q *QuotaCenter) calculateWriteRates() error {
func (q *QuotaCenter) getTimeTickDelayFactor(ts Timestamp) map[int64]float64 { func (q *QuotaCenter) getTimeTickDelayFactor(ts Timestamp) map[int64]float64 {
log := log.Ctx(context.Background()).WithRateGroup("rootcoord.QuotaCenter", 1.0, 60.0) log := log.Ctx(context.Background()).WithRateGroup("rootcoord.QuotaCenter", 1.0, 60.0)
if !Params.QuotaConfig.TtProtectionEnabled.GetAsBool() { if !Params.QuotaConfig.TtProtectionEnabled.GetAsBool() {
return nil return make(map[int64]float64)
} }
maxDelay := Params.QuotaConfig.MaxTimeTickDelay.GetAsDuration(time.Second) maxDelay := Params.QuotaConfig.MaxTimeTickDelay.GetAsDuration(time.Second)
if maxDelay < 0 { if maxDelay < 0 {
// < 0 means disable tt protection // < 0 means disable tt protection
return nil return make(map[int64]float64)
} }
collectionsMaxDelay := make(map[int64]time.Duration) collectionsMaxDelay := make(map[int64]time.Duration)
@ -526,7 +526,7 @@ func (q *QuotaCenter) getTimeTickDelayFactor(ts Timestamp) map[int64]float64 {
func (q *QuotaCenter) getMemoryFactor() map[int64]float64 { func (q *QuotaCenter) getMemoryFactor() map[int64]float64 {
log := log.Ctx(context.Background()).WithRateGroup("rootcoord.QuotaCenter", 1.0, 60.0) log := log.Ctx(context.Background()).WithRateGroup("rootcoord.QuotaCenter", 1.0, 60.0)
if !Params.QuotaConfig.MemProtectionEnabled.GetAsBool() { if !Params.QuotaConfig.MemProtectionEnabled.GetAsBool() {
return nil return make(map[int64]float64)
} }
dataNodeMemoryLowWaterLevel := Params.QuotaConfig.DataNodeMemoryLowWaterLevel.GetAsFloat() dataNodeMemoryLowWaterLevel := Params.QuotaConfig.DataNodeMemoryLowWaterLevel.GetAsFloat()

View File

@ -320,7 +320,7 @@ func TestQuotaCenter(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
// force deny // force deny
forceBak := Params.QuotaConfig.ForceDenyWriting forceBak := Params.QuotaConfig.ForceDenyWriting.GetValue()
paramtable.Get().Save(Params.QuotaConfig.ForceDenyWriting.Key, "true") paramtable.Get().Save(Params.QuotaConfig.ForceDenyWriting.Key, "true")
quotaCenter.writableCollections = []int64{1, 2, 3} quotaCenter.writableCollections = []int64{1, 2, 3}
quotaCenter.resetAllCurrentRates() quotaCenter.resetAllCurrentRates()
@ -330,7 +330,22 @@ func TestQuotaCenter(t *testing.T) {
assert.Equal(t, Limit(0), quotaCenter.currentRates[collection][internalpb.RateType_DMLInsert]) assert.Equal(t, Limit(0), quotaCenter.currentRates[collection][internalpb.RateType_DMLInsert])
assert.Equal(t, Limit(0), quotaCenter.currentRates[collection][internalpb.RateType_DMLDelete]) assert.Equal(t, Limit(0), quotaCenter.currentRates[collection][internalpb.RateType_DMLDelete])
} }
Params.QuotaConfig.ForceDenyWriting = forceBak paramtable.Get().Save(Params.QuotaConfig.ForceDenyWriting.Key, forceBak)
// disable tt delay protection
disableTtBak := Params.QuotaConfig.TtProtectionEnabled.GetValue()
paramtable.Get().Save(Params.QuotaConfig.TtProtectionEnabled.Key, "false")
quotaCenter.resetAllCurrentRates()
quotaCenter.queryNodeMetrics = make(map[UniqueID]*metricsinfo.QueryNodeQuotaMetrics)
quotaCenter.queryNodeMetrics[0] = &metricsinfo.QueryNodeQuotaMetrics{
Hms: metricsinfo.HardwareMetrics{
Memory: 100,
MemoryUsage: 100,
},
Effect: metricsinfo.NodeEffect{CollectionIDs: []int64{1, 2, 3}},
}
err = quotaCenter.calculateWriteRates()
paramtable.Get().Save(Params.QuotaConfig.TtProtectionEnabled.Key, disableTtBak)
}) })
t.Run("test MemoryFactor factors", func(t *testing.T) { t.Run("test MemoryFactor factors", func(t *testing.T) {