-
Notifications
You must be signed in to change notification settings - Fork 490
meshcontroller: improve service instance search performance in Master #1503
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,18 +139,21 @@ func (m *Master) checkServiceInstances() { | |
| statuses := m.service.ListAllServiceInstanceStatuses() | ||
| specs := m.service.ListAllServiceInstanceSpecs() | ||
|
|
||
| type instanceKey struct { | ||
| serviceName string | ||
| instanceID string | ||
| } | ||
| statusMap := make(map[instanceKey]*spec.ServiceInstanceStatus, len(statuses)) | ||
| for _, s := range statuses { | ||
| statusMap[instanceKey{s.ServiceName, s.InstanceID}] = s | ||
| } | ||
|
|
||
| for _, _spec := range specs { | ||
| if !m.isMeshRegistryName(_spec.RegistryName) { | ||
| continue | ||
| } | ||
|
|
||
| // TODO: improve search performance | ||
| var status *spec.ServiceInstanceStatus | ||
| for _, s := range statuses { | ||
| if s.ServiceName == _spec.ServiceName && s.InstanceID == _spec.InstanceID { | ||
| status = s | ||
| } | ||
| } | ||
| status := statusMap[instanceKey{_spec.ServiceName, _spec.InstanceID}] | ||
|
||
|
|
||
| if status == nil { | ||
| format := "status of %s/%s not found, need to delete" | ||
|
|
||
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 composite key literals rely on positional field order, which is easy to accidentally swap later. Prefer keyed struct literals for clarity and safety (e.g.,
instanceKey{serviceName: ..., instanceID: ...}).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.
@copilot open a new pull request to apply changes based on this feedback