Skip to content

Commit 2f5d717

Browse files
committed
settings: move the 'modified' map to valueContainer
In a later commit, we will want to ensure that `.Override()` sets the modified bit. This is not possible if the modified bits are in the Updater. (The `Override` method is on the setting itself and has no access to the updater.) Release note: None
1 parent cb7c66f commit 2f5d717

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

pkg/settings/settings_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -574,23 +574,19 @@ func TestCache(t *testing.T) {
574574
if expected, actual := true, boolFA.Get(sv); expected != actual {
575575
t.Fatalf("expected %v, got %v", expected, actual)
576576
}
577-
// If the updater doesn't have a key, e.g. if the setting has been deleted,
578-
// Resetting it from the cache.
577+
// The updated status remains in sv. A new updater is able to pick
578+
// it up.
579579
settings.NewUpdater(sv).ResetRemaining(ctx)
580580

581-
if expected, actual := 2, changes.boolTA; expected != actual {
581+
if expected, actual := 1, changes.boolTA; expected != actual {
582582
t.Fatalf("expected %d, got %d", expected, actual)
583583
}
584584

585-
if expected, actual := 2, changes.i1A; expected != actual {
585+
if expected, actual := 1, changes.i1A; expected != actual {
586586
t.Fatalf("expected %d, got %d", expected, actual)
587587
}
588588

589-
if expected, actual := false, boolFA.Get(sv); expected != actual {
590-
t.Fatalf("expected %v, got %v", expected, actual)
591-
}
592-
593-
if expected, actual := false, boolFA.Get(sv); expected != actual {
589+
if expected, actual := true, boolFA.Get(sv); expected != actual {
594590
t.Fatalf("expected %v, got %v", expected, actual)
595591
}
596592
})

pkg/settings/updater.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func EncodeProtobuf(p protoutil.Message) string {
6060

6161
type updater struct {
6262
sv *Values
63-
m map[InternalKey]struct{}
6463
}
6564

6665
// Updater is a helper for updating the in-memory settings.
@@ -92,7 +91,6 @@ func NewUpdater(sv *Values) Updater {
9291
return NoopUpdater{}
9392
}
9493
return updater{
95-
m: make(map[InternalKey]struct{}, len(registry)),
9694
sv: sv,
9795
}
9896
}
@@ -108,7 +106,7 @@ func (u updater) Set(ctx context.Context, key InternalKey, value EncodedValue) e
108106
return errors.Errorf("unknown setting '%s'", key)
109107
}
110108

111-
u.m[key] = struct{}{}
109+
u.sv.container.modified[d.getSlot()] = true
112110

113111
if expected := d.Typ(); value.Type != expected {
114112
return errors.Errorf("setting '%s' defined as type %s, not %s", d.Name(), expected, value.Type)
@@ -167,19 +165,19 @@ func (u updater) Set(ctx context.Context, key InternalKey, value EncodedValue) e
167165

168166
// ResetRemaining sets all settings not updated by the updater to their default values.
169167
func (u updater) ResetRemaining(ctx context.Context) {
170-
for k, v := range registry {
171-
172-
if _, hasOverride := u.m[k]; hasOverride {
173-
u.sv.setValueOrigin(ctx, v.getSlot(), OriginExplicitlySet)
168+
for _, v := range registry {
169+
slot := v.getSlot()
170+
if hasOverride := u.sv.container.modified[slot]; hasOverride {
171+
u.sv.setValueOrigin(ctx, slot, OriginExplicitlySet)
174172
} else {
175-
u.sv.setValueOrigin(ctx, v.getSlot(), OriginDefault)
173+
u.sv.setValueOrigin(ctx, slot, OriginDefault)
176174
}
177175

178176
if u.sv.SpecializedToVirtualCluster() && v.Class() == SystemOnly {
179177
// Don't try to reset system settings on a non-system tenant.
180178
continue
181179
}
182-
if _, ok := u.m[k]; !ok {
180+
if m := u.sv.container.modified[slot]; !m {
183181
v.setToDefault(ctx, u.sv)
184182
}
185183
}

pkg/settings/values.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ type valuesContainer struct {
8787
forbidden [numSlots]bool
8888

8989
hasValue [numSlots]uint32
90+
91+
// modified is set when a setting is explictly set via Set()
92+
// in the updater.
93+
// TODO(knz): Check if this can be merged with hasValue above.
94+
modified [numSlots]bool
9095
}
9196

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

0 commit comments

Comments
 (0)