diff --git a/configs/advanced/data_coord.yaml b/configs/advanced/data_coord.yaml index 4e0ffa5f4e..36cbb5d102 100644 --- a/configs/advanced/data_coord.yaml +++ b/configs/advanced/data_coord.yaml @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -datacoord: +dataCoord: segment: maxSize: 512 # Maximum size of a segment in MB sealProportion: 0.75 # It's the minimum proportion for a segment which can be sealed diff --git a/internal/datacoord/param_table.go b/internal/datacoord/param_table.go index 2b8e4c0b6a..40dd4d06fd 100644 --- a/internal/datacoord/param_table.go +++ b/internal/datacoord/param_table.go @@ -182,15 +182,15 @@ func (p *ParamTable) initCollectionBinlogSubPath() { } func (p *ParamTable) initSegmentMaxSize() { - p.SegmentMaxSize = p.ParseFloat("datacoord.segment.maxSize") + p.SegmentMaxSize = p.ParseFloatWithDefault("dataCoord.segment.maxSize", 512.0) } func (p *ParamTable) initSegmentSealProportion() { - p.SegmentSealProportion = p.ParseFloat("datacoord.segment.sealProportion") + p.SegmentSealProportion = p.ParseFloatWithDefault("dataCoord.segment.sealProportion", 0.75) } func (p *ParamTable) initSegAssignmentExpiration() { - p.SegAssignmentExpiration = p.ParseInt64("datacoord.segment.assignmentExpiration") + p.SegAssignmentExpiration = p.ParseInt64WithDefault("dataCoord.segment.assignmentExpiration", 2000) } func (p *ParamTable) initClusterMsgChannelPrefix() { diff --git a/internal/indexnode/param_table.go b/internal/indexnode/param_table.go index 7177dfbd0d..ec9ec0e1f8 100644 --- a/internal/indexnode/param_table.go +++ b/internal/indexnode/param_table.go @@ -172,16 +172,7 @@ func (pt *ParamTable) initRoleName() { } func (pt *ParamTable) initKnowhereSimdType() { - simdType, err := pt.LoadWithDefault("knowhere.simdType", "auto") - if err != nil { - log.Error("failed to initialize the simd type", - zap.Error(err)) - - panic(err) - } - + simdType := pt.LoadWithDefault("knowhere.simdType", "auto") pt.SimdType = simdType - - log.Debug("initialize the knowhere simd type", - zap.String("simd_type", pt.SimdType)) + log.Debug("initialize the knowhere simd type", zap.String("simd_type", pt.SimdType)) } diff --git a/internal/kv/mem/mem_kv.go b/internal/kv/mem/mem_kv.go index d65fe61058..88403319d5 100644 --- a/internal/kv/mem/mem_kv.go +++ b/internal/kv/mem/mem_kv.go @@ -50,15 +50,15 @@ func (kv *MemoryKV) Load(key string) (string, error) { return item.(memoryKVItem).value, nil } -func (kv *MemoryKV) LoadWithDefault(key, defaultValue string) (string, error) { +func (kv *MemoryKV) LoadWithDefault(key, defaultValue string) string { kv.RLock() defer kv.RUnlock() item := kv.tree.Get(memoryKVItem{key, ""}) if item == nil { - return defaultValue, nil + return defaultValue } - return item.(memoryKVItem).value, nil + return item.(memoryKVItem).value } func (kv *MemoryKV) LoadRange(key, endKey string, limit int) ([]string, []string, error) { diff --git a/internal/querynode/param_table.go b/internal/querynode/param_table.go index bf10bdda54..8adf77a3c0 100644 --- a/internal/querynode/param_table.go +++ b/internal/querynode/param_table.go @@ -335,11 +335,9 @@ func (p *ParamTable) initSegcoreChunkRows() { } func (p *ParamTable) initKnowhereSimdType() { - simdType, err := p.LoadWithDefault("knowhere.simdType", "auto") - if err != nil { - panic(err) - } + simdType := p.LoadWithDefault("knowhere.simdType", "auto") p.SimdType = simdType + log.Debug("initialize the knowhere simd type", zap.String("simd_type", p.SimdType)) } func (p *ParamTable) initRoleName() { diff --git a/internal/rootcoord/param_table.go b/internal/rootcoord/param_table.go index 4c6faa8f27..17e885268a 100644 --- a/internal/rootcoord/param_table.go +++ b/internal/rootcoord/param_table.go @@ -179,15 +179,15 @@ func (p *ParamTable) initDmlChannelName() { } func (p *ParamTable) initDmlChannelNum() { - p.DmlChannelNum = p.ParseInt64("rootcoord.dmlChannelNum") + p.DmlChannelNum = p.ParseInt64WithDefault("rootCoord.dmlChannelNum", 256) } func (p *ParamTable) initMaxPartitionNum() { - p.MaxPartitionNum = p.ParseInt64("rootcoord.maxPartitionNum") + p.MaxPartitionNum = p.ParseInt64WithDefault("rootCoord.maxPartitionNum", 4096) } func (p *ParamTable) initMinSegmentSizeToEnableIndex() { - p.MinSegmentSizeToEnableIndex = p.ParseInt64("rootcoord.minSegmentSizeToEnableIndex") + p.MinSegmentSizeToEnableIndex = p.ParseInt64WithDefault("rootCoord.minSegmentSizeToEnableIndex", 1024) } func (p *ParamTable) initDefaultPartitionName() { @@ -207,11 +207,11 @@ func (p *ParamTable) initDefaultIndexName() { } func (p *ParamTable) initTimeout() { - p.Timeout = p.ParseInt("rootcoord.timeout") + p.Timeout = p.ParseIntWithDefault("rootCoord.timeout", 3600) } func (p *ParamTable) initTimeTickInterval() { - p.TimeTickInterval = p.ParseInt("rootcoord.timeTickInterval") + p.TimeTickInterval = p.ParseIntWithDefault("rootCoord.timeTickInterval", 200) } func (p *ParamTable) initRoleName() { diff --git a/internal/util/paramtable/basetable.go b/internal/util/paramtable/basetable.go index 827a0693c7..5a1ed963de 100644 --- a/internal/util/paramtable/basetable.go +++ b/internal/util/paramtable/basetable.go @@ -12,6 +12,7 @@ package paramtable import ( + "fmt" "os" "path" "runtime" @@ -312,7 +313,7 @@ func (gp *BaseTable) Load(key string) (string, error) { return gp.params.Load(strings.ToLower(key)) } -func (gp *BaseTable) LoadWithDefault(key string, defaultValue string) (string, error) { +func (gp *BaseTable) LoadWithDefault(key string, defaultValue string) string { return gp.params.LoadWithDefault(strings.ToLower(key), defaultValue) } @@ -374,10 +375,7 @@ func (gp *BaseTable) Save(key, value string) error { } func (gp *BaseTable) ParseBool(key string, defaultValue bool) bool { - valueStr, err := gp.LoadWithDefault(key, strconv.FormatBool(defaultValue)) - if err != nil { - panic(err) - } + valueStr := gp.LoadWithDefault(key, strconv.FormatBool(defaultValue)) value, err := strconv.ParseBool(valueStr) if err != nil { panic(err) @@ -397,6 +395,15 @@ func (gp *BaseTable) ParseFloat(key string) float64 { return value } +func (gp *BaseTable) ParseFloatWithDefault(key string, defaultValue float64) float64 { + valueStr := gp.LoadWithDefault(key, fmt.Sprintf("%f", defaultValue)) + value, err := strconv.ParseFloat(valueStr, 64) + if err != nil { + panic(err) + } + return value +} + func (gp *BaseTable) ParseInt64(key string) int64 { valueStr, err := gp.Load(key) if err != nil { @@ -409,6 +416,15 @@ func (gp *BaseTable) ParseInt64(key string) int64 { return value } +func (gp *BaseTable) ParseInt64WithDefault(key string, defaultValue int64) int64 { + valueStr := gp.LoadWithDefault(key, strconv.FormatInt(defaultValue, 10)) + value, err := strconv.ParseInt(valueStr, 10, 64) + if err != nil { + panic(err) + } + return value +} + func (gp *BaseTable) ParseInt32(key string) int32 { valueStr, err := gp.Load(key) if err != nil { @@ -421,6 +437,15 @@ func (gp *BaseTable) ParseInt32(key string) int32 { return int32(value) } +func (gp *BaseTable) ParseInt32WithDefault(key string, defaultValue int32) int32 { + valueStr := gp.LoadWithDefault(key, strconv.FormatInt(int64(defaultValue), 10)) + value, err := strconv.ParseInt(valueStr, 10, 32) + if err != nil { + panic(err) + } + return int32(value) +} + func (gp *BaseTable) ParseInt(key string) int { valueStr, err := gp.Load(key) if err != nil { @@ -433,6 +458,15 @@ func (gp *BaseTable) ParseInt(key string) int { return value } +func (gp *BaseTable) ParseIntWithDefault(key string, defaultValue int) int { + valueStr := gp.LoadWithDefault(key, strconv.FormatInt(int64(defaultValue), 10)) + value, err := strconv.Atoi(valueStr) + if err != nil { + panic(err) + } + return value +} + // package methods func ConvertRangeToIntRange(rangeStr, sep string) []int { diff --git a/internal/util/paramtable/basetable_test.go b/internal/util/paramtable/basetable_test.go index 5a1dc2186c..5e673807fe 100644 --- a/internal/util/paramtable/basetable_test.go +++ b/internal/util/paramtable/basetable_test.go @@ -185,6 +185,15 @@ func TestBaseTable_Parse(t *testing.T) { assert.Panics(t, func() { baseParams.ParseFloat("key") }) }) + t.Run("ParseFloatWithDefault", func(t *testing.T) { + baseParams.Remove("key") + assert.Equal(t, float64(0.0), baseParams.ParseFloatWithDefault("key", 0.0)) + assert.Equal(t, float64(3.14), baseParams.ParseFloatWithDefault("key", 3.14)) + + assert.Nil(t, baseParams.Save("key", "2")) + assert.Equal(t, float64(2.0), baseParams.ParseFloatWithDefault("key", 3.14)) + }) + t.Run("ParseInt32", func(t *testing.T) { assert.Nil(t, baseParams.Save("key", "0")) assert.Equal(t, int32(0), baseParams.ParseInt32("key")) @@ -197,6 +206,13 @@ func TestBaseTable_Parse(t *testing.T) { assert.Panics(t, func() { baseParams.ParseInt32("key") }) }) + t.Run("ParseInt32WithDefault", func(t *testing.T) { + baseParams.Remove("key") + assert.Equal(t, int32(1), baseParams.ParseInt32WithDefault("key", 1)) + assert.Nil(t, baseParams.Save("key", "2")) + assert.Equal(t, int32(2), baseParams.ParseInt32WithDefault("key", 1)) + }) + t.Run("ParseInt64", func(t *testing.T) { assert.Nil(t, baseParams.Save("key", "0")) assert.Equal(t, int64(0), baseParams.ParseInt64("key")) @@ -208,6 +224,20 @@ func TestBaseTable_Parse(t *testing.T) { assert.Nil(t, baseParams.Save("key", "abc")) assert.Panics(t, func() { baseParams.ParseInt64("key") }) }) + + t.Run("ParseInt64WithDefault", func(t *testing.T) { + baseParams.Remove("key") + assert.Equal(t, int64(1), baseParams.ParseInt64WithDefault("key", 1)) + assert.Nil(t, baseParams.Save("key", "2")) + assert.Equal(t, int64(2), baseParams.ParseInt64WithDefault("key", 1)) + }) + + t.Run("ParseIntWithDefault", func(t *testing.T) { + baseParams.Remove("key") + assert.Equal(t, int(1), baseParams.ParseIntWithDefault("key", 1)) + assert.Nil(t, baseParams.Save("key", "2")) + assert.Equal(t, int(2), baseParams.ParseIntWithDefault("key", 1)) + }) } func Test_ConvertRangeToIntSlice(t *testing.T) { diff --git a/internal/util/paramtable/param.go b/internal/util/paramtable/param.go index c57bf77818..09ee64c173 100644 --- a/internal/util/paramtable/param.go +++ b/internal/util/paramtable/param.go @@ -80,18 +80,12 @@ func (p *BaseParamTable) initUseEmbedEtcd() { } func (p *BaseParamTable) initConfigPath() { - addr, err := p.LoadWithDefault("etcd.config.path", "") - if err != nil { - panic(err) - } + addr := p.LoadWithDefault("etcd.config.path", "") p.EtcdConfigPath = addr } func (p *BaseParamTable) initEtcdDataDir() { - addr, err := p.LoadWithDefault("etcd.data.dir", "default.etcd") - if err != nil { - panic(err) - } + addr := p.LoadWithDefault("etcd.data.dir", "default.etcd") p.EtcdDataDir = addr }