Skip to content

Commit

Permalink
settings: simplify the container
Browse files Browse the repository at this point in the history
This commit uses the "value origin" field now throughout to decide
whether or not a setting was modified.

Release note: None
  • Loading branch information
knz committed Sep 25, 2023
1 parent 3bc6d7a commit e94de87
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
11 changes: 1 addition & 10 deletions pkg/settings/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func (u updater) setInternal(
) error {
// Mark the setting as modified, such that
// (updater).ResetRemaining() does not touch it.
u.sv.container.modified[d.getSlot()] = true
u.sv.setValueOrigin(ctx, d.getSlot(), origin)

switch setting := d.(type) {
Expand Down Expand Up @@ -218,7 +217,6 @@ func (u updater) SetToDefault(ctx context.Context, key InternalKey) error {
return errors.Errorf("unknown setting '%s'", key)
}

u.sv.container.modified[d.getSlot()] = false
u.sv.setValueOrigin(ctx, d.getSlot(), OriginDefault)
d.setToDefault(ctx, u.sv)
return nil
Expand All @@ -227,18 +225,11 @@ func (u updater) SetToDefault(ctx context.Context, key InternalKey) error {
// ResetRemaining sets all settings not updated by the updater to their default values.
func (u updater) ResetRemaining(ctx context.Context) {
for _, v := range registry {
slot := v.getSlot()
if hasOverride := u.sv.container.modified[slot]; hasOverride {
u.sv.setValueOrigin(ctx, slot, OriginExplicitlySet)
} else {
u.sv.setValueOrigin(ctx, slot, OriginDefault)
}

if u.sv.SpecializedToVirtualCluster() && v.Class() == SystemOnly {
// Don't try to reset system settings on a non-system tenant.
continue
}
if m := u.sv.container.modified[slot]; !m {
if u.sv.getValueOrigin(ctx, v.getSlot()) == OriginDefault {
v.setToDefault(ctx, u.sv)
}
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/settings/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,8 @@ type valuesContainer struct {
// tenant). Reading or writing such a setting causes panics in test builds.
forbidden [numSlots]bool

// hasValue contains the origin of the current value of the setting.
hasValue [numSlots]uint32

// modified is set when a setting is explictly set via Set()
// in the updater.
// TODO(knz): Check if this can be merged with hasValue above.
modified [numSlots]bool
}

func (c *valuesContainer) setGenericVal(slot slotIdx, newVal interface{}) {
Expand Down

0 comments on commit e94de87

Please sign in to comment.