Skip to content

Commit e808602

Browse files
derekbitc3y1huang
authored andcommitted
fix(setting): guaranteedInstanceManagerCPU value should not exceed the defined maximum
Longhorn 11864 Signed-off-by: Derek Su <derek.su@suse.com>
1 parent cb4fd81 commit e808602

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

datastore/longhorn.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ func (s *DataStore) syncConsolidatedV2DataEngineSetting(oldSettingName, newSetti
212212
}
213213

214214
func (s *DataStore) syncV2DataEngineGuaranteedInstanceManagerCPU() error {
215+
defaultSetting, ok := types.GetSettingDefinition(types.SettingNameGuaranteedInstanceManagerCPU)
216+
if !ok {
217+
// Skip the sync if the setting is not defined
218+
return nil
219+
}
220+
215221
// Get old setting v2-data-engine-guaranteed-instance-manager-cpu
216222
oldV2Setting, err := s.GetSettingExactRO(types.SettingNameV2DataEngineGuaranteedInstanceManagerCPU)
217223
if err != nil {
@@ -240,13 +246,13 @@ func (s *DataStore) syncV2DataEngineGuaranteedInstanceManagerCPU() error {
240246
return nil
241247
}
242248

243-
if v2DataEngineGuaranteedInstanceManagerCPU > int(numCPUs*1000) {
244-
logrus.Warnf("Skipping the migration for guaranteed-instance-manager-cpu for v2 data engine since old setting %v value %v milliCPUs is larger than the minimum number of CPUs %v among all nodes", types.SettingNameV2DataEngineGuaranteedInstanceManagerCPU, oldV2Setting.Value, numCPUs)
245-
return nil
249+
originalGuaranteedInstanceManagerCPUInPercentage := int64(v2DataEngineGuaranteedInstanceManagerCPU*100) / (numCPUs * 1000)
250+
guaranteedInstanceManagerCPUInPercentage := originalGuaranteedInstanceManagerCPUInPercentage
251+
if guaranteedInstanceManagerCPUInPercentage > 100 {
252+
guaranteedInstanceManagerCPUInPercentage = 100
253+
logrus.Warnf("The calculated guaranteed-instance-manager-cpu percentage %v from old setting %v is larger than 100%%, set it to 100%%", originalGuaranteedInstanceManagerCPUInPercentage, types.SettingNameV2DataEngineGuaranteedInstanceManagerCPU)
246254
}
247255

248-
guaranteedInstanceManagerCPUInPercentage := int64(v2DataEngineGuaranteedInstanceManagerCPU*100) / (numCPUs * 1000)
249-
250256
// Get setting guaranteed-instance-manager-cpu
251257
setting, err := s.GetSettingExact(types.SettingNameGuaranteedInstanceManagerCPU)
252258
if err != nil {
@@ -258,6 +264,16 @@ func (s *DataStore) syncV2DataEngineGuaranteedInstanceManagerCPU() error {
258264
return errors.Wrapf(err, "failed to unmarshal setting %v value %v", types.SettingNameGuaranteedInstanceManagerCPU, setting.Value)
259265
}
260266

267+
// The guaranteedInstanceManagerCPUInPercentage value should not exceed the maximum value allowed
268+
valueMaximum, ok := defaultSetting.ValueFloatRange[types.ValueFloatRangeMaximum]
269+
if ok {
270+
if float64(guaranteedInstanceManagerCPUInPercentage) > valueMaximum {
271+
originalGuaranteedInstanceManagerCPUInPercentage := guaranteedInstanceManagerCPUInPercentage
272+
guaranteedInstanceManagerCPUInPercentage = int64(valueMaximum)
273+
logrus.Warnf("The calculated guaranteed-instance-manager-cpu percentage %v for v2 data engine is larger than the maximum %v%%, set it to the maximum", originalGuaranteedInstanceManagerCPUInPercentage, valueMaximum)
274+
}
275+
}
276+
261277
// Update the value for v2 data engine
262278
dataEngineValues[longhorn.DataEngineTypeV2] = fmt.Sprintf("%d", guaranteedInstanceManagerCPUInPercentage)
263279

0 commit comments

Comments
 (0)