Skip to content

fix listen config namespace bug #13405

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

Merged
merged 1 commit into from
May 21, 2025

Conversation

Sunrisea
Copy link
Contributor

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

XXXXX

Brief changelog

XX

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

Copy link

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

Copy link

lingma-agents bot commented May 21, 2025

修复配置监听命名空间处理逻辑的缺陷

变更文件

文件路径 变更说明
config/​src/​main/​java/​com/​alibaba/​nacos/​config/​server/​utils/​MD5Util.java 在getClientMd5Map方法中新增NamespaceUtil.isNeedTransferNamespace判断,动态确定ifNamespaceTransfer标志位; 通过NamespaceUtil.processNamespaceParameter对tenant参数进行标准化处理; 移除原固定设置ifNamespaceTransfer为false的逻辑,改为根据实际判断结果赋值; 补充将ifNamespaceTransfer状态写入ConfigListenState对象的完整流程。

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

Copy link

@lingma-agents lingma-agents bot left a comment

Choose a reason for hiding this comment

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

🔍 代码评审报告

🎯 评审意见概览

严重度 数量 说明
🔴 Blocker 0 阻断性问题,需立即修复。例如:系统崩溃、关键功能不可用或严重安全漏洞。
🟠 Critical 1 严重问题,高优先级修复。例如:核心功能异常或性能瓶颈影响用户体验。
🟡 Major 0 主要问题,建议修复。例如:非核心功能缺陷或代码维护性较差。
🟢 Minor 0 次要问题,酌情优化。例如:代码格式不规范或注释缺失。

总计: 1 个问题


📋 评审意见详情

💡 单文件建议

以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
☕ config/src/main/java/com/alibaba/nacos/config/server/utils/MD5Util.java (1 💬)

🚀 跨文件建议

以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍 1. 架构职责分离问题:MD5Util类承担了非核心的命名空间处理逻辑

MD5Util类原本应专注于MD5计算相关的功能,但此次变更引入了命名空间参数处理逻辑(调用NamespaceUtil的两个方法)。这违反了单一职责原则,可能导致类职责扩散。建议将命名空间转换逻辑移至专门的NamespaceService或ConfigProcessor模块,保持工具类的功能纯粹性。此问题可能引发未来维护时职责不明确,导致其他开发者继续在此类中添加无关逻辑。

📌 关键代码:

ifNamespaceTransfer = NamespaceUtil.isNeedTransferNamespace(tenant);
tenant = NamespaceUtil.processNamespaceParameter(tenant);

⚠️ 潜在风险: 长期维护中可能因职责混杂导致代码难以维护,其他开发者可能继续在此类中添加非MD5相关的逻辑,最终形成"上帝类"问题。建议将命名空间处理逻辑集中到专门的业务逻辑层实现。

🔍 2. 跨模块状态一致性风险:未同步更新监听状态存储逻辑

新增的ifNamespaceTransfer标志虽然在ConfigListenState中设置,但未检查其他存储或传输ConfigListenState的模块(如监听服务、持久层)是否能正确解析此标志。可能存在以下隐患:1) 其他模块未识别此新字段导致状态丢失 2) 反序列化时因字段新增引发兼容性问题。需确认所有处理ConfigListenState的组件(如服务端监听管理器、客户端通信协议)是否同步支持该标志。

⚠️ 潜在风险: 可能导致命名空间转换状态在跨组件传递时丢失,引发配置监听不准确或数据不一致等问题,特别是在分布式环境中的数据同步场景。

🔍 3. 潜在性能隐患:高频调用的命名空间处理未评估性能影响

NamespaceUtil的两个方法被嵌入到获取客户端MD5信息的核心路径中(getClientMd5Map方法)。需评估这两个方法的执行效率,特别是在高并发场景下。若isNeedTransferNamespace涉及数据库查询或复杂计算,可能对配置监听性能产生显著影响。建议在方法调用前添加性能监控或考虑缓存策略。

⚠️ 潜在风险: 在高负载场景下可能导致请求延迟增加,影响配置服务的响应能力,特别是在大规模集群环境中问题会更突出。


💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

Comment on lines +147 to +148
ifNamespaceTransfer = NamespaceUtil.isNeedTransferNamespace(tenant);
tenant = NamespaceUtil.processNamespaceParameter(tenant);
Copy link

Choose a reason for hiding this comment

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

调整命名空间处理顺序以确保参数一致性

🟠 Critical | 🐞 Bugs

📋 问题详情

当前代码先调用isNeedTransferNamespace判断是否需要转换命名空间,随后才调用processNamespaceParameter处理tenant参数。这可能导致判断逻辑基于未处理的原始tenant值,而后续处理后的tenant可能已改变命名空间状态。例如当processNamespaceParameter修改tenant内容后,ifNamespaceTransfer的值仍基于原始值,导致配置状态不一致。

💡 解决方案

应先处理tenant参数再进行命名空间转换判断,确保判断逻辑基于最终处理后的tenant值:

- ifNamespaceTransfer = NamespaceUtil.isNeedTransferNamespace(tenant);
- tenant = NamespaceUtil.processNamespaceParameter(tenant);
+ tenant = NamespaceUtil.processNamespaceParameter(tenant);
+ ifNamespaceTransfer = NamespaceUtil.isNeedTransferNamespace(tenant);

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.41%. Comparing base (bc79756) to head (35837a3).

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             develop   #13405      +/-   ##
=============================================
- Coverage      70.41%   70.41%   -0.01%     
  Complexity     11717    11717              
=============================================
  Files           1592     1592              
  Lines          50977    50978       +1     
  Branches        5148     5148              
=============================================
- Hits           35895    35894       -1     
- Misses         12650    12653       +3     
+ Partials        2432     2431       -1     
Files with missing lines Coverage Δ
...com/alibaba/nacos/config/server/utils/MD5Util.java 82.43% <100.00%> (+0.24%) ⬆️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc79756...35837a3. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KomachiSion KomachiSion merged commit f00ed95 into alibaba:develop May 21, 2025
5 checks passed
@wuyfee
Copy link

wuyfee commented May 21, 2025

$\color{red}{FAILURE}$
DETAILS
✅ - docker: success
❌ - deploy (standalone & cluster & standalone_auth): failure
❌ - e2e-java-test (standalone & cluster & standalone_auth): skipped
❌ - e2e-go-test (standalone & cluster): skipped
❌ - e2e-cpp-test (standalone & cluster): skipped
❌ - e2e-csharp-test (standalone & cluster): skipped
❌ - e2e-nodejs-test (standalone & cluster): skipped
❌ - e2e-python-test (standalone & cluster): skipped
✅ - clean (standalone & cluster & standalone_auth): success

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.

4 participants