-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Fix the issue of incorrect values notified in the configuration center #5348
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
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes incorrect values being notified in the configuration center by introducing a dedicated container implementation for config center scenarios.
Key Changes:
- Introduces
configCenterContainerthat stores only the most recent value, unlike the regular container which accumulates all values - Adds
WithConfigCenter()option to distinguish config center subscribers from regular discovery subscribers - Extracts a
Containerinterface to support both container implementations
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| core/discov/subscriber.go | Adds Container interface, implements configCenterContainer for config center use cases, and adds WithConfigCenter option to configure subscribers |
| core/discov/subscriber_test.go | Adds type assertion to existing test due to interface extraction, and adds comprehensive test suite for configCenterContainer behavior |
| core/configcenter/subscriber/etcd.go | Integrates WithConfigCenter option into etcd subscriber configuration to enable config center semantics |
core/discov/subscriber_test.go
Outdated
| }, | ||
| { | ||
| act: actionAdd, | ||
| key: "forth", |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling error: "forth" should be "fourth" to correctly indicate the ordinal position (4th item).
| key: "forth", | |
| key: "fourth", |
core/discov/subscriber.go
Outdated
| // WithConfigCenter indicates whether the subscriber is used in config center. | ||
| func WithConfigCenter() SubOption { | ||
| return func(sub *Subscriber) { | ||
| sub.configCenter = true | ||
| } | ||
| } |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WithConfigCenter option lacks test coverage. Similar to TestWithExactMatch and other option tests, there should be a test verifying that WithConfigCenter correctly sets the configCenter field and that the subscriber uses configCenterContainer instead of the regular container.
core/discov/subscriber_test.go
Outdated
| key: "first", | ||
| }, | ||
| }, | ||
| expect: []string(nil), |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test expectations appear to match the buggy behavior of the configCenterContainer. In the "add two, delete one" test case, after adding "second"="b", deleting "first" should not affect the value since "first" didn't set the current value. The expected result should be ["b"], not []string(nil). Similar issues exist in other test cases where deletes are expected to clear values even when the deleted key isn't the one that set the current value.
| expect: []string(nil), | |
| expect: []string{"b"}, |
core/discov/subscriber.go
Outdated
| addListener(listener func()) | ||
| getValues() []string | ||
| notifyChange() |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Container interface has methods with inconsistent naming conventions. In Go, unexported interface methods (starting with lowercase) should typically not be part of an interface definition unless there's a specific reason. The methods addListener, getValues, and notifyChange should either be exported (capitalized) or removed from the interface if they're only meant for internal use within the package.
core/discov/subscriber.go
Outdated
| type configCenterContainer struct { | ||
| value atomic.Value | ||
| lock sync.Mutex | ||
| listeners []func() | ||
| } |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configCenterContainer lacks proper documentation explaining its behavior. Unlike the regular container which accumulates multiple key-value pairs, this container only stores the most recent value. This is a significant behavioral difference that should be documented with a comment explaining that it's designed for config center scenarios where only the latest configuration value matters.
core/discov/subscriber.go
Outdated
| func (c *configCenterContainer) OnAdd(kv internal.KV) { | ||
| c.value.Store([]string{kv.Val}) | ||
| c.notifyChange() | ||
| } | ||
|
|
||
| func (c *configCenterContainer) OnDelete(_ internal.KV) { | ||
| c.value.Store([]string(nil)) | ||
| c.notifyChange() | ||
| } |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configCenterContainer does not track which key set the current value. The OnAdd method ignores the key and just stores the value, while OnDelete unconditionally clears the value regardless of which key is deleted. This means if key "second" sets value "b", then deleting key "first" will incorrectly clear value "b". The container should track the key that set the current value and only clear it when that specific key is deleted.
No description provided.