forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[storage]: exclude deleted volumes from recalculate and sync physical capacity on reconnect #3677
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
Open
zstack-robot-2
wants to merge
6
commits into
master
Choose a base branch
from
sync/jin.ma/fix/ZSTAC-80937
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
<fix>[storage]: exclude deleted volumes from recalculate and sync physical capacity on reconnect #3677
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d3137fd
<fix>[storage]: exclude deleted volumes from recalculate and sync phy…
MaJin1996 c43fbb3
<fix>[storage]: prevent Spring Bean mutation in SelectBackupStorageMs…
MaJin1996 8a71c38
<fix>[storage]: adjust PS availableCapacity when volume size changes …
MaJin1996 7da801e
<fix>[test]: fix
MaJin1996 2d721c3
<fix>[storage]: adjust PS capacity on syncVolumeSize
MaJin1996 e1ecdd3
<fix>[storage]: adjust PS capacity on syncVolumeSize
MaJin1996 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "phase": 5, | ||
| "issue": "ZSTAC-80937", | ||
| "title": "TDD GREEN - Fix PS availableCapacity drift on syncVolumeSize", | ||
| "status": "GREEN", | ||
| "data": { | ||
| "root_cause": "VolumeBase.syncVolumeVolumeSize() updates VolumeVO.size from the agent-reported value but does not send DecreasePrimaryStorageCapacityMsg/IncreasePrimaryStorageCapacityMsg to adjust the primary storage availableCapacity. Over time, every syncVolumeSize that reports a different size causes availableCapacity to drift from reality, inflating the storage pool allocation rate.", | ||
| "bug_location": "storage/src/main/java/org/zstack/storage/volume/VolumeBase.java:syncVolumeVolumeSize()", | ||
| "solution": "In syncVolumeVolumeSize(), capture oldSize before updating. After dbf.updateAndRefresh(), compare newSize vs oldSize: if size grew, send DecreasePrimaryStorageCapacityMsg with the diff; if size shrank, send IncreasePrimaryStorageCapacityMsg with the abs diff. This keeps PS availableCapacity in sync with actual volume size changes.", | ||
| "files_modified": [ | ||
| "storage/src/main/java/org/zstack/storage/volume/VolumeBase.java" | ||
| ], | ||
| "tdd_cycle": { | ||
| "phase": "GREEN", | ||
| "test_file": "test/src/test/groovy/org/zstack/test/integration/storage/primary/nfs/capacity/NfsSyncVolumeSizeCapacityCase.groovy", | ||
| "test_class": "NfsSyncVolumeSizeCapacityCase", | ||
| "test_method": "testSyncVolumeSizeAdjustsCapacity", | ||
| "expected_result": "PASS - availableCapacity decreases by 10GB after syncVolumeSize reports a larger volume size", | ||
| "reproduction_steps": [ | ||
| "1. Create a VM with a root volume on NFS primary storage", | ||
| "2. Record baseline PS availableCapacity", | ||
| "3. Mock NFS GET_VOLUME_SIZE_PATH to return volume size + 10GB", | ||
| "4. Call APISyncVolumeSizeMsg on the root volume", | ||
| "5. Assert VolumeVO.size is updated (passes)", | ||
| "6. Assert PS availableCapacity decreased by 10GB (passes with fix)" | ||
| ] | ||
| }, | ||
| "fix_reverted": false, | ||
| "fix_file": "storage/src/main/java/org/zstack/storage/volume/VolumeBase.java", | ||
| "fix_description": "After updating VolumeVO.size in syncVolumeVolumeSize(), compare newSize vs oldSize and send DecreasePrimaryStorageCapacityMsg (size grew) or IncreasePrimaryStorageCapacityMsg (size shrank) to keep PS availableCapacity in sync." | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...ge/src/test/java/org/zstack/storage/addon/primary/ExternalPrimaryStorageSelectBsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package org.zstack.storage.addon.primary; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.zstack.header.storage.addon.primary.BackupStorageSelector; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Regression test for ZSTAC-80789. | ||
| * | ||
| * BackupStorageSelector implementations (e.g. XInfiniStorageFactory, ExponStorageFactory) | ||
| * are Spring beans whose getPreferBackupStorageTypes() returns a direct reference to an | ||
| * internal field. If the caller mutates that list (e.g. via retainAll), the bean's state | ||
| * is permanently corrupted, causing all subsequent SelectBackupStorageMsg handling to fail. | ||
| * | ||
| * The fix in ExternalPrimaryStorage wraps the returned list with {@code new ArrayList<>(...)}. | ||
| * This test verifies that pattern. | ||
| */ | ||
| public class ExternalPrimaryStorageSelectBsTest { | ||
|
|
||
| /** | ||
| * Simulates a BackupStorageSelector that returns its internal field directly, | ||
| * just like XInfiniStorageFactory and ExponStorageFactory do. | ||
| */ | ||
| private static class FakeBackupStorageSelector implements BackupStorageSelector { | ||
| private List<String> preferBackupStorageTypes; | ||
|
|
||
| FakeBackupStorageSelector(List<String> types) { | ||
| this.preferBackupStorageTypes = types; | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> getPreferBackupStorageTypes() { | ||
| return preferBackupStorageTypes; | ||
| } | ||
|
|
||
| @Override | ||
| public String getIdentity() { | ||
| return "fake"; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testDefensiveCopyPreventsBeaMutation() { | ||
| // Setup: simulate a Spring bean with mutable internal state | ||
| List<String> beanInternalList = new ArrayList<>(Arrays.asList("ImageStore", "Ceph", "FusionStor")); | ||
| FakeBackupStorageSelector selector = new FakeBackupStorageSelector(beanInternalList); | ||
|
|
||
| List<String> originalTypes = new ArrayList<>(beanInternalList); | ||
|
|
||
| // First call: simulate handle(SelectBackupStorageMsg) with requiredBackupStorageTypes = ["ImageStore"] | ||
| // The fix: defensive copy before retainAll | ||
| List<String> preferBsTypes = new ArrayList<>(selector.getPreferBackupStorageTypes()); | ||
| List<String> requiredTypes = Arrays.asList("ImageStore"); | ||
| preferBsTypes.retainAll(requiredTypes); | ||
|
|
||
| // After retainAll, the working copy should be filtered | ||
| Assert.assertEquals(Arrays.asList("ImageStore"), preferBsTypes); | ||
|
|
||
| // The bean's internal state must remain unchanged | ||
| Assert.assertEquals(originalTypes, selector.getPreferBackupStorageTypes()); | ||
| Assert.assertEquals(3, selector.getPreferBackupStorageTypes().size()); | ||
|
|
||
| // Second call: simulate another handle(SelectBackupStorageMsg) with requiredBackupStorageTypes = ["Ceph"] | ||
| List<String> preferBsTypes2 = new ArrayList<>(selector.getPreferBackupStorageTypes()); | ||
| List<String> requiredTypes2 = Arrays.asList("Ceph"); | ||
| preferBsTypes2.retainAll(requiredTypes2); | ||
|
|
||
| Assert.assertEquals(Arrays.asList("Ceph"), preferBsTypes2); | ||
|
|
||
| // Bean's internal state still unchanged after two calls | ||
| Assert.assertEquals(originalTypes, selector.getPreferBackupStorageTypes()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testWithoutDefensiveCopyBeanIsMutated() { | ||
| // This test demonstrates the original bug: without defensive copy, retainAll mutates the bean | ||
| List<String> beanInternalList = new ArrayList<>(Arrays.asList("ImageStore", "Ceph", "FusionStor")); | ||
| FakeBackupStorageSelector selector = new FakeBackupStorageSelector(beanInternalList); | ||
|
|
||
| // Without defensive copy (the old buggy code path) | ||
| List<String> preferBsTypes = selector.getPreferBackupStorageTypes(); | ||
| preferBsTypes.retainAll(Arrays.asList("ImageStore")); | ||
|
|
||
| // The bean's internal list is now corrupted | ||
| Assert.assertEquals(1, selector.getPreferBackupStorageTypes().size()); | ||
| Assert.assertEquals(Arrays.asList("ImageStore"), selector.getPreferBackupStorageTypes()); | ||
|
|
||
| // Second call with "Ceph" now fails because the bean only has "ImageStore" left | ||
| List<String> preferBsTypes2 = selector.getPreferBackupStorageTypes(); | ||
| preferBsTypes2.retainAll(Arrays.asList("Ceph")); | ||
|
|
||
| // The list is now empty - this is the bug that caused clone VM to fail | ||
| Assert.assertTrue(selector.getPreferBackupStorageTypes().isEmpty()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
测试方法名有拼写错误,建议改为
Bean。Line [47] 的
testDefensiveCopyPreventsBeaMutation中Bea应为Bean,建议修正以提升可读性和检索一致性。✏️ 建议修改
As per coding guidelines, “命名应尽量用完整的单词组合表达意图”。
📝 Committable suggestion
🤖 Prompt for AI Agents