Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kesonan
Copy link
Collaborator

@kesonan kesonan commented Dec 21, 2025

No description provided.

@codecov
Copy link

codecov bot commented Dec 21, 2025

Codecov Report

❌ Patch coverage is 81.81818% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
core/discov/subscriber.go 44.44% 5 Missing ⚠️
core/configcenter/subscriber/etcd.go 95.83% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a 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 configCenterContainer that 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 Container interface 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

},
{
act: actionAdd,
key: "forth",
Copy link

Copilot AI Dec 21, 2025

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).

Suggested change
key: "forth",
key: "fourth",

Copilot uses AI. Check for mistakes.
Comment on lines 96 to 101
// WithConfigCenter indicates whether the subscriber is used in config center.
func WithConfigCenter() SubOption {
return func(sub *Subscriber) {
sub.configCenter = true
}
}
Copy link

Copilot AI Dec 21, 2025

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.

Copilot uses AI. Check for mistakes.
key: "first",
},
},
expect: []string(nil),
Copy link

Copilot AI Dec 21, 2025

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.

Suggested change
expect: []string(nil),
expect: []string{"b"},

Copilot uses AI. Check for mistakes.
Comment on lines 107 to 109
addListener(listener func())
getValues() []string
notifyChange()
Copy link

Copilot AI Dec 21, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 231 to 235
type configCenterContainer struct {
value atomic.Value
lock sync.Mutex
listeners []func()
}
Copy link

Copilot AI Dec 21, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 241 to 249
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()
}
Copy link

Copilot AI Dec 21, 2025

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.

Copilot uses AI. Check for mistakes.
@kevwan kevwan merged commit 52df1c5 into zeromicro:master Dec 23, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants