Skip to content

Commit fa51f8e

Browse files
committed
MB-65809 MB-71120 Return string representation of plan stability settings
When selecting from system:settings, for plan stability settings we currently return the actual settings in metakv, which uses int64 to represent the different settings for plan stability mode and plan stability error policy. This can be confusing to end users since these integers do not make sense. Add a translation (remapping) step such that after getting the plan stability settings, we map the integers to string representations. Change-Id: I1788520b3c930a558a4bd6470f807a6fac42e01d Reviewed-on: https://review.couchbase.org/c/query/+/242293 Reviewed-by: Sitaram Vemulapalli <sitaram.vemulapalli@couchbase.com> Tested-by: Bingjie Miao <bingjie.miao@couchbase.com>
1 parent e117042 commit fa51f8e

4 files changed

Lines changed: 73 additions & 2 deletions

File tree

datastore/system/system_keyspace_settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (b *settingsKeyspace) Fetch(keys []string, keysMap map[string]value.Annotat
7878
continue
7979
}
8080

81-
val, err := settings.FetchSettings()
81+
val, err := settings.FetchSettings(true)
8282
if err != nil {
8383
return errors.Errors{err}
8484
}

settings/plan_stability_ce.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ func PlanStabilityAvailable() bool {
2121
func updatePlanStabilitySetting(requestId string, val interface{}) errors.Error {
2222
return errors.NewSettingsEnterpriseOnly("Plan Stability")
2323
}
24+
25+
func remapPlanStabilitySetting(psSetting interface{}) (map[string]interface{}, errors.Error) {
26+
return nil, errors.NewSettingsEnterpriseOnly("Plan Stability")
27+
}

settings/plan_stability_ee.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,60 @@ func updatePlanStabilitySetting(requestId string, val interface{}) errors.Error
103103

104104
return nil
105105
}
106+
107+
// Given plan stability settings in integer form, remap to string form for easier understanding
108+
func remapPlanStabilitySetting(psSetting interface{}) (map[string]interface{}, errors.Error) {
109+
planStability, ok := psSetting.(map[string]interface{})
110+
if !ok {
111+
return nil, errors.NewSettingsInvalidValue(PLAN_STABILITY, "map[string]interface{}", psSetting)
112+
}
113+
for kk, vv := range planStability {
114+
if actual, ok := vv.(value.Value); ok {
115+
vv = actual.Actual()
116+
}
117+
118+
// When JSON is unmarshalled into an interface, numbers are unmarshalled into float.
119+
if f, ok := vv.(float64); ok && value.IsInt(f) {
120+
vv = int64(f)
121+
}
122+
123+
switch kk {
124+
case "mode":
125+
switch vv := vv.(type) {
126+
case string:
127+
// when user sets the setting
128+
// no-op
129+
case int64:
130+
// when setting comes from metakv
131+
mode := PlanStabilityMode(vv)
132+
if mode >= PS_MODE_OFF && mode <= PS_MODE_AD_HOC_READ_ONLY {
133+
planStability[kk] = mode.String()
134+
} else {
135+
return nil, errors.NewSettingsInvalidValue(PLAN_STABILITY+".mode", "", vv)
136+
}
137+
default:
138+
return nil, errors.NewSettingsInvalidType(PLAN_STABILITY+".mode", "string", vv)
139+
}
140+
case "error_policy":
141+
switch vv := vv.(type) {
142+
case string:
143+
// when user sets the setting
144+
// no-op
145+
case int64:
146+
// when setting comes from metakv
147+
error_policy := PlanStabilityErrorPolicy(vv)
148+
if error_policy >= PS_ERROR_FLEXIBLE && error_policy <= PS_ERROR_STRICT {
149+
planStability[kk] = error_policy.String()
150+
} else {
151+
return nil, errors.NewSettingsInvalidValue(PLAN_STABILITY+".error_policy", "", vv)
152+
}
153+
default:
154+
return nil, errors.NewSettingsInvalidType(PLAN_STABILITY+".error_policy", "string", vv)
155+
}
156+
default:
157+
return nil, errors.NewSettingsInvalidValue(PLAN_STABILITY+"."+kk, "", nil)
158+
}
159+
}
160+
161+
return planStability, nil
162+
}

settings/settings.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func defaultSettings() map[string]interface{} {
128128
return rv
129129
}
130130

131-
func FetchSettings() (map[string]interface{}, errors.Error) {
131+
func FetchSettings(remap bool) (map[string]interface{}, errors.Error) {
132132
val, _, err := metakv.Get(_SETTINGS_SETTINGS)
133133
if err != nil {
134134
return nil, errors.NewSettingsMetaKVError(err, "Error getting global settings from metakv")
@@ -141,6 +141,16 @@ func FetchSettings() (map[string]interface{}, errors.Error) {
141141
}
142142
delete(vmap, "node")
143143

144+
if remap {
145+
if planStability, ok := vmap[PLAN_STABILITY]; ok {
146+
remapPlanStability, err := remapPlanStabilitySetting(planStability)
147+
if err != nil {
148+
return nil, err
149+
}
150+
vmap[PLAN_STABILITY] = remapPlanStability
151+
}
152+
}
153+
144154
return vmap, nil
145155
}
146156

0 commit comments

Comments
 (0)