Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache: Coherence #13137

Merged
merged 1 commit into from Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion core/cache/lxdprofilewatcher.go
Expand Up @@ -342,7 +342,6 @@ func (w *MachineLXDProfileWatcher) removeUnit(_ string, value interface{}) {
if len(w.applications) > 0 && !profile.Empty() {
notify = true
}
return
}

// provisionedChanged notifies when called. Topic subscribed to is specific to
Expand Down
39 changes: 38 additions & 1 deletion core/cache/model_test.go
Expand Up @@ -120,7 +120,7 @@ func (s *ModelSuite) TestConfigWatcherOneValue(c *gc.C) {
wc.AssertOneChange()
}

func (s *ModelSuite) TestConfigWatcherOneValueOtherChange(c *gc.C) {
func (s *ModelSuite) TestConfigWatcherSameValueHasNoChange(c *gc.C) {
m := s.NewModel(modelChange)
w := m.WatchConfig("key")

Expand All @@ -146,6 +146,43 @@ func (s *ModelSuite) TestConfigWatcherOneValueOtherChange(c *gc.C) {
wc.AssertNoChange()
}

func (s *ModelSuite) TestConfigWatcherValueHasChangeBackToOriginalValue(c *gc.C) {
m := s.NewModel(modelChange)
w := m.WatchConfig("key")

// The worker is the first and only resource (1).
resourceId := uint64(1)
s.AssertWorkerResource(c, m.Resident, resourceId, true)
defer func() {
workertest.CleanKill(c, w)
s.AssertWorkerResource(c, m.Resident, resourceId, false)
}()

wc := cache.NewNotifyWatcherC(c, w)
// Sends initial event.
wc.AssertOneChange()

change := modelChange
change.Config = map[string]interface{}{
"key": "other",
"another": "changed",
}

m.SetDetails(change)
wc.AssertOneChange()

// Set it back to the original value and ensure that we do get
// a change event again.
change = modelChange
change.Config = map[string]interface{}{
"key": "value",
"another": "changed",
}

m.SetDetails(change)
wc.AssertOneChange()
}

func (s *ModelSuite) TestConfigWatcherSameValuesCacheHit(c *gc.C) {
m := s.NewModel(modelChange)

Expand Down
10 changes: 1 addition & 9 deletions core/cache/watcher.go
Expand Up @@ -156,6 +156,7 @@ func (w *ConfigWatcher) configChanged(topic string, value interface{}) {
return
}
w.notify()
w.hash = hash
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you play around with whether this should happen before or after the notify? (I think after is correct, but I wanted to make sure we thought about it.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I did, but the conclusion I came to was the same.

}

// StringsWatcher will return what has changed.
Expand Down Expand Up @@ -272,15 +273,6 @@ type PredicateStringsWatcher struct {
fn predicateFunc
}

// newChangeWatcher provides a PredicateStringsWatcher which notifies
// with all strings passed to it.
func newChangeWatcher(values ...string) *PredicateStringsWatcher {
return &PredicateStringsWatcher{
stringsWatcherBase: newStringsWatcherBase(values...),
fn: func(string) bool { return true },
}
}

func regexpPredicate(compiled *regexp.Regexp) func(string) bool {
return func(value string) bool { return compiled.MatchString(value) }
}
Expand Down