forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
<feature>[vm_local_volume_cache]: vm local volume cache imp #3406
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
1
commit into
feature-5.5.6-local-cache
Choose a base branch
from
sync/haidong.pang/feature/ZSTAC-81715
base: feature-5.5.6-local-cache
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
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,11 +23,8 @@ | |
| import org.zstack.header.image.ImageConstant; | ||
| import org.zstack.header.image.ImageConstant.ImageMediaType; | ||
| import org.zstack.header.message.MessageReply; | ||
| import org.zstack.header.vm.VmInstanceConstant; | ||
| import org.zstack.header.vm.VmInstanceSpec; | ||
| import org.zstack.header.vm.*; | ||
| import org.zstack.header.vm.VmInstanceSpec.VolumeSpec; | ||
| import org.zstack.header.vm.VmInstanceVO; | ||
| import org.zstack.header.vm.VmInstanceVO_; | ||
| import org.zstack.header.volume.*; | ||
| import org.zstack.header.volume.VolumeDeletionPolicyManager.VolumeDeletionPolicy; | ||
| import org.zstack.identity.AccountManager; | ||
|
|
@@ -76,6 +73,19 @@ protected List<CreateVolumeMsg> prepareMsg(Map<String, Object> ctx) { | |
| } | ||
| }); | ||
| } | ||
| if (!spec.getDataDiskCacheConfigOnIndex().isEmpty() && !CollectionUtils.isEmpty(spec.getDataDiskOfferings())) { | ||
| List<VolumeSpec> dataVolumeSpecs = spec.getVolumeSpecs().stream() | ||
| .filter(s -> s.getType().equals(VolumeType.Data.toString())).collect(Collectors.toList()); | ||
|
|
||
| IntStream.range(0, dataVolumeSpecs.size()).forEach(index -> { | ||
| APICreateVmInstanceMsg.VolumeCacheConfig config = spec.getDataDiskCacheConfigOnIndex().get(index); | ||
| if (config != null) { | ||
| dataVolumeSpecs.get(index).setEnableVolumeCache(true); | ||
| dataVolumeSpecs.get(index).setCachePoolUuid(config.getCachePoolUuid()); | ||
| dataVolumeSpecs.get(index).setCacheMode(config.getCacheMode()); | ||
| } | ||
| }); | ||
| } | ||
|
Comment on lines
+76
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 空指针会让未配置数据盘缓存的建机流程直接失败。 Line 76 这里先对 🛠 建议修改- if (!spec.getDataDiskCacheConfigOnIndex().isEmpty() && !CollectionUtils.isEmpty(spec.getDataDiskOfferings())) {
+ if (!MapUtils.isEmpty(spec.getDataDiskCacheConfigOnIndex()) && !CollectionUtils.isEmpty(spec.getDataDiskOfferings())) {🤖 Prompt for AI Agents |
||
|
|
||
| List<VolumeSpec> volumeSpecs = spec.getVolumeSpecs(); | ||
| List<CreateVolumeMsg> msgs = new ArrayList<>(volumeSpecs.size()); | ||
|
|
@@ -93,6 +103,9 @@ protected List<CreateVolumeMsg> prepareMsg(Map<String, Object> ctx) { | |
| DebugUtils.Assert(vspec.getType() != null, "VolumeType can not be null!"); | ||
|
|
||
| if (VolumeType.Root.toString().equals(vspec.getType())) { | ||
| vspec.setEnableVolumeCache(spec.getEnableRootVolumeCache()); | ||
| vspec.setCachePoolUuid(spec.getRootVolumeCachePoolUuid()); | ||
| vspec.setCacheMode(spec.getRootVolumeCacheMode()); | ||
| msg.setResourceUuid((String) ctx.get("uuid")); | ||
| msg.setName("ROOT-for-" + spec.getVmInventory().getName()); | ||
| msg.setDescription(String.format("Root volume for VM[uuid:%s]", spec.getVmInventory().getUuid())); | ||
|
|
@@ -116,7 +129,13 @@ protected List<CreateVolumeMsg> prepareMsg(Map<String, Object> ctx) { | |
| } else { | ||
| continue; | ||
| } | ||
|
|
||
| if (vspec.getEnableVolumeCache()) { | ||
| tags.add("volumeCache::enable"); | ||
| tags.add("volumeCache::cacheMode::" + vspec.getCacheMode()); | ||
| if(vspec.getCachePoolUuid() != null) { | ||
| tags.add("volumeCache::poolUuid::" + vspec.getCachePoolUuid()); | ||
| } | ||
| } | ||
| msg.setSystemTags(new ArrayList<>(tags)); | ||
| msg.setDiskOfferingUuid(vspec.getDiskOfferingUuid()); | ||
| msg.setSize(vspec.getSize()); | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| CREATE TABLE IF NOT EXISTS `VmLocalVolumeCachePoolVO` ( | ||
| `uuid` VARCHAR(32) NOT NULL, | ||
| `hostUuid` VARCHAR(32) NOT NULL, | ||
| `name` VARCHAR(255) DEFAULT NULL, | ||
| `description` VARCHAR(2048) DEFAULT NULL, | ||
| `metadata` VARCHAR(2048) DEFAULT NULL, | ||
| `state` VARCHAR(32) NOT NULL, | ||
| `status` VARCHAR(32) NOT NULL, | ||
| `createDate` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', | ||
| `lastOpDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
| PRIMARY KEY (`uuid`), | ||
| CONSTRAINT `fkVmLocalVolumeCachePoolVOHostEO` | ||
| FOREIGN KEY (`hostUuid`) REFERENCES `HostEO` (`uuid`) | ||
| ON DELETE CASCADE | ||
| ) ENGINE = InnoDB DEFAULT CHARSET = utf8; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS `VmLocalVolumeCachePoolCapacityVO` ( | ||
| `uuid` VARCHAR(32) NOT NULL, | ||
| `totalCapacity` BIGINT NOT NULL DEFAULT 0, | ||
| `availableCapacity` BIGINT NOT NULL DEFAULT 0, | ||
| `allocated` BIGINT NOT NULL DEFAULT 0, | ||
| `dirty` BIGINT NOT NULL DEFAULT 0, | ||
| PRIMARY KEY (`uuid`), | ||
| CONSTRAINT `fkVmLocalVolumeCachePoolCapacityVOVmLocalVolumeCachePoolVO` | ||
| FOREIGN KEY (`uuid`) REFERENCES `VmLocalVolumeCachePoolVO` (`uuid`) | ||
| ON DELETE CASCADE | ||
| ) ENGINE = InnoDB DEFAULT CHARSET = utf8; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS `VmLocalVolumeCacheVO` ( | ||
| `uuid` VARCHAR(32) NOT NULL, | ||
| `volumeUuid` VARCHAR(32) NOT NULL, | ||
| `poolUuid` VARCHAR(32) DEFAULT NULL, | ||
| `installPath` VARCHAR(2048) DEFAULT NULL, | ||
| `cacheMode` VARCHAR(32) NOT NULL, | ||
| `state` VARCHAR(32) NOT NULL, | ||
| `createDate` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', | ||
| `lastOpDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
| PRIMARY KEY (`uuid`), | ||
| UNIQUE KEY `uniVmLocalVolumeCacheVOVolumeUuid` (`volumeUuid`), | ||
| CONSTRAINT `fkVmLocalVolumeCacheVOVolumeEO` | ||
| FOREIGN KEY (`volumeUuid`) REFERENCES `VolumeEO` (`uuid`) | ||
| ON DELETE CASCADE, | ||
| CONSTRAINT `fkVmLocalVolumeCacheVOPoolUuid` | ||
| FOREIGN KEY (`poolUuid`) REFERENCES `VmLocalVolumeCachePoolVO` (`uuid`) | ||
| ON DELETE SET NULL | ||
| ) ENGINE = InnoDB DEFAULT CHARSET = utf8; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
数据盘缓存容量的索引基准和卷创建流程不一致。
Line 157-161 这里按
spec.getDataDiskOfferings().get(index)取大小,但同一份dataDiskCacheConfigOnIndex在compute/src/main/java/org/zstack/compute/vm/VmAllocateVolumeFlow.java的 Line 77-86 是按dataVolumeSpecs套用的。两边一旦出现非 offering 数据卷或索引不完全一致,这里就会把requiredSize算错,甚至直接IndexOutOfBoundsException。🤖 Prompt for AI Agents