Skip to content

fix: scope discovery informer known objects to each mesh - #1638

Merged
robocanic merged 4 commits into
apache:developfrom
AsperforMias:fix-zk-service-catalog
Nov 22, 2026
Merged

robocanic merged 4 commits into
apache:developfrom
AsperforMias:fix-zk-service-catalog

Conversation

@AsperforMias

Copy link
Copy Markdown
Contributor

Please provide a description of this PR:

Discovery informers list resources for one mesh, but use a resource store shared across meshes. During a list replacement, an informer can therefore treat another mesh's resources as deleted. For example, a Nacos refresh can remove ZooKeeper service metadata from the Admin catalog even though the ZooKeeper nodes still exist.

Scope each discovery informer's known-object view to its mesh. Both ListKeys and GetByKey use exact mesh identity, while stale-resource deletion and watch updates/deletions within the same mesh remain unchanged. The change stays within discovery and does not modify the shared controller.

Tests cover both cross-mesh ordering directions, mesh names containing slashes, stale-resource deletion, watch updates/deletions, and relisting. The regression fails on the original implementation and passes with this change. Targeted tests, race tests, vet, and lint for the changed package pass.

Real Nacos/ZooKeeper checks passed after two independent Admin restarts using this patch. Service lists, details, methods, and non-IDL invocation remained available.

The adapter scans the existing per-kind List view. It does not change the store's existing list-error handling contract.

To help us figure out who should review this PR, please put an X in all the areas that this PR affects.

  • Docs
  • Installation
  • User Experience
  • Dubboctl
  • Console
  • Core Component

Please check any characteristics that apply to this pull request.

@robocanic robocanic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I traced the relist through DeltaFIFO.KnownObjects and the discovery store adapter. Filtering both ListKeys and GetByKey by exact mesh identity keeps another registry’s metadata out of replacement tombstones, while a missing key in the same mesh can still generate a delete. The regression tests cover both registry orderings and same-mesh stale deletion. I found no blocking issue in this change. The discovery package passed in Actions; the failing metric dashboard assertion is addressed separately in #1642.

@robocanic

robocanic commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

把 informer 用于对账的已知对象限定在当前 mesh,修复方向是对的。建议在 meshScopedStore.ListKeys() 里复用已有的 ByMeshIndex。目前每次 relist 都会调用 s.List()。使用 MySQL 或 PostgreSQL 时,即使只需要一个 mesh 的 key,也会读取并反序列化所有 mesh 下该资源类型的完整对象。

这个改动可以放在 discovery 层:

keys, err := s.ResourceStore.IndexKeys(index.ByMeshIndex, s.mesh)
if err == nil {
    return keys
}
// 记录索引查询错误,回退到现有的按 mesh 精确过滤的扫描逻辑。

内存后端已经能通过索引直接返回 key。GORM 也能把查询范围缩小到当前 mesh,不过现有的 IndexKeys() 仍会加载命中的完整对象来提取 key。让 SQL 只查 key 可以单独优化。

建议保留扫描作为出错时的回退路径。ListKeys() 无法向上层返回错误,如果索引查询失败就直接返回空列表,本轮 relist 会跳过当前 mesh 的陈旧资源清理。查询成功且没有匹配项时,直接返回空列表即可。

A relist only needs the keys of the informer's mesh, but ListKeys
scanned every mesh, which SQL stores load and decode in full. Read the
keys from the mesh index, or, for the GORM store, from the indexed mesh
column of its rows, since the index table can briefly miss rows while a
replica rebuilds it. A failed lookup falls back to the scan, since an
empty result would skip deleting stale objects.
@AsperforMias

Copy link
Copy Markdown
Contributor Author

done

@sonarqubecloud

Copy link
Copy Markdown

@robocanic
robocanic merged commit 8fed060 into apache:develop Nov 22, 2026
7 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