Skip to content

<fix>[eip]: expose attaching EIP to release#4168

Open
ZStack-Robot wants to merge 1 commit into
5.5.28from
sync/dejing.liu/codex/ZSTAC-83309-eip-attach-race-5.5.28
Open

<fix>[eip]: expose attaching EIP to release#4168
ZStack-Robot wants to merge 1 commit into
5.5.28from
sync/dejing.liu/codex/ZSTAC-83309-eip-attach-race-5.5.28

Conversation

@ZStack-Robot
Copy link
Copy Markdown
Collaborator

Persist vmNicUuid and guestIp before applying an EIP on the backend. This lets VM stop and migration release paths see the in-flight EIP and enqueue cleanup while the backend apply is still running.

Roll back the binding only when the same EIP, NIC, and guest IP are still present if backend apply fails.

Related: ZSTAC-83309

Change-Id: Ia9b75acc82004755b905a02acca1a6a82c207332

sync from gitlab !10074

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

Warning

Review limit reached

@MatheMatrix, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 51 minutes and 6 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 2ca0b14b-3eb4-4b85-9692-f7dc65ab8ba8

📥 Commits

Reviewing files that changed from the base of the PR and between 02ffcce and 9877fbb.

📒 Files selected for processing (2)
  • plugin/eip/src/main/java/org/zstack/network/service/eip/EipManagerImpl.java
  • test/src/test/groovy/org/zstack/test/integration/networkservice/provider/flat/eip/AttachEipRaceCase.groovy

总体概述

本PR通过在EIP attach流程中引入早期绑定和失败回滚机制,改进了并发场景下的数据一致性。实现缓存绑定目标后立即写库,attach失败时通过条件SQL回滚清理绑定数据。新增集成测试验证VM停止期间的EIP释放和失败回滚场景。

变更详情

EIP Attach早期绑定与失败回滚

层级 / 文件 描述
核心绑定与回滚逻辑
plugin/eip/src/main/java/org/zstack/network/service/eip/EipManagerImpl.java
在APIAttachEipMsg处理中先缓存vmNicUuid和guestIp为局部变量,对EipVO执行updateAndRefresh后基于更新结果生成EipInventory。Attach成功回调改为基于updated执行dbf.reload再发布事件;失败回调新增条件SQL更新仅在uuid和绑定值均匹配时清空vmNicUuid/guestIp,并在回滚未命中时记录warn日志。
并发与回滚验证测试
test/src/test/groovy/org/zstack/test/integration/networkservice/provider/flat/eip/AttachEipRaceCase.groovy
新增AttachEipRaceCase集成测试类,通过拦截FlatEipBackend的apply/delete路径模拟后端延迟和故障。testStopVmDuringAttachReleasesEip验证VM停止期间EIP attach的释放流程,testAttachFailureRollsBackEarlyBinding验证attach失败时早期绑定的清空一致性。使用CountDownLatch控制并发时序,重试轮询验证数据库状态。

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 在网络的田野里,EIP蹦蹦跳
绑定与回滚,精准一刀切
竞态并发试,安全铁闸把
数据一致性,逻辑写得亮
验证测试全,放心往前跳! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰地反映了本次变更的主要目的:在 EIP 附加过程中早期暴露绑定信息以支持释放操作。
Description check ✅ Passed 描述详细说明了变更的核心内容:在后端申请前持久化 vmNicUuid/guestIp,以及失败时的回滚策略,与代码变更内容相符。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/dejing.liu/codex/ZSTAC-83309-eip-attach-race-5.5.28

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/src/test/groovy/org/zstack/test/integration/networkservice/provider/flat/eip/AttachEipRaceCase.groovy (1)

152-226: 💤 Low value

测试方法名称与实际逻辑不符。

方法名 testStopVmDuringAttachReleasesEip 暗示在 attach 进行中停止 VM,但实际流程是:

  1. Line 211: attachThread.join(30000) 等待 attach 完成
  2. Line 217-225: attach 完成后才停止 VM

当前测试实际验证的是:

  • 后端处理期间早期绑定在 DB 可见
  • attach 成功完成
  • attach 完成后停止 VM 触发 EIP 释放

如果要测试"attach 进行中停止 VM 触发清理",应在 releaseApply.countDown() 之前执行 StopVmInstanceAction,然后验证清理行为。

建议将方法名改为 testEarlyBindingVisibleAndVmStopReleasesEip 或调整测试逻辑以匹配原名称。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@test/src/test/groovy/org/zstack/test/integration/networkservice/provider/flat/eip/AttachEipRaceCase.groovy`
around lines 152 - 226, The test method name testStopVmDuringAttachReleasesEip
is misleading because the code waits for attach to finish (attachThread.join)
before calling StopVmInstanceAction; either rename the method to reflect current
behavior (e.g., testEarlyBindingVisibleAndVmStopReleasesEip) or change the
control flow so StopVmInstanceAction is invoked while apply is blocked: move the
StopVmInstanceAction call to before releaseApply.countDown() (after
applyEntered.await and DB assertions) and remove the attachThread.join wait that
forces attach to complete first; update assertions accordingly to verify EIP
release during the blocked attach using deleteCalled and deleteCmd.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@test/src/test/groovy/org/zstack/test/integration/networkservice/provider/flat/eip/AttachEipRaceCase.groovy`:
- Around line 152-226: The test method name testStopVmDuringAttachReleasesEip is
misleading because the code waits for attach to finish (attachThread.join)
before calling StopVmInstanceAction; either rename the method to reflect current
behavior (e.g., testEarlyBindingVisibleAndVmStopReleasesEip) or change the
control flow so StopVmInstanceAction is invoked while apply is blocked: move the
StopVmInstanceAction call to before releaseApply.countDown() (after
applyEntered.await and DB assertions) and remove the attachThread.join wait that
forces attach to complete first; update assertions accordingly to verify EIP
release during the blocked attach using deleteCalled and deleteCmd.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9918d773-e295-4668-b26f-76421777e2d6

📥 Commits

Reviewing files that changed from the base of the PR and between 6e889f1 and 02ffcce.

📒 Files selected for processing (2)
  • plugin/eip/src/main/java/org/zstack/network/service/eip/EipManagerImpl.java
  • test/src/test/groovy/org/zstack/test/integration/networkservice/provider/flat/eip/AttachEipRaceCase.groovy

Persist vmNicUuid/guestIp before backend apply so VM release can see
in-flight EIP bindings. Roll back only when the failed attach still
matches the same EIP/NIC/IP tuple.

Test: real Flat EIP flow and AttachEipRaceCase
JIRA: ZSTAC-83309
Change-Id: Ie8795d5bd1c3e90aa10e18cfef19d4968c73cfee
@MatheMatrix MatheMatrix force-pushed the sync/dejing.liu/codex/ZSTAC-83309-eip-attach-race-5.5.28 branch from 02ffcce to 9877fbb Compare June 2, 2026 06:11
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.

1 participant