forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[vm]: add MetadataImpact #3560
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
Closed
ZStack-Robot
wants to merge
1
commit into
feature-zsv-5.0.0-vm-registration
from
sync/tao.gan/ZSV-11559@@3
Closed
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
90 changes: 90 additions & 0 deletions
90
compute/src/main/java/org/zstack/compute/vm/VmExpungeMetadataFlow.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,90 @@ | ||
| package org.zstack.compute.vm; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowire; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Configurable; | ||
| import org.zstack.core.cloudbus.CloudBus; | ||
| import org.zstack.core.cloudbus.CloudBusCallBack; | ||
| import org.zstack.core.componentloader.PluginRegistry; | ||
| import org.zstack.core.db.Q; | ||
| import org.zstack.header.core.workflow.FlowTrigger; | ||
| import org.zstack.header.core.workflow.NoRollbackFlow; | ||
| import org.zstack.header.message.MessageReply; | ||
| import org.zstack.header.storage.primary.CleanupVmInstanceMetadataOnPrimaryStorageMsg; | ||
| import org.zstack.header.storage.primary.PrimaryStorageConstant; | ||
| import org.zstack.header.storage.primary.PrimaryStorageVO; | ||
| import org.zstack.header.storage.primary.PrimaryStorageVO_; | ||
| import org.zstack.header.vm.VmInstanceConstant; | ||
| import org.zstack.header.vm.VmInstanceSpec; | ||
| import org.zstack.header.vm.metadata.VmMetadataPathBuildExtensionPoint; | ||
| import org.zstack.header.volume.VolumeVO; | ||
| import org.zstack.header.volume.VolumeVO_; | ||
| import org.zstack.utils.Utils; | ||
| import org.zstack.utils.logging.CLogger; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Configurable(preConstruction = true, autowire = Autowire.BY_TYPE) | ||
| public class VmExpungeMetadataFlow extends NoRollbackFlow { | ||
| private static final CLogger logger = Utils.getLogger(VmExpungeMetadataFlow.class); | ||
|
|
||
| @Autowired | ||
| private CloudBus bus; | ||
| @Autowired | ||
| private PluginRegistry pluginRgty; | ||
|
|
||
| @Override | ||
| public void run(FlowTrigger trigger, Map data) { | ||
| final VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); | ||
| if (spec == null || spec.getVmInventory() == null) { | ||
| logger.warn("[MetadataExpunge] missing VmInstanceSpec or VmInventory, skip metadata cleanup"); | ||
| trigger.next(); | ||
| return; | ||
| } | ||
|
|
||
| final String vmUuid = spec.getVmInventory().getUuid(); | ||
|
|
||
| String rootVolumeUuid = spec.getVmInventory().getRootVolumeUuid(); | ||
| if (rootVolumeUuid == null) { | ||
| logger.debug(String.format("[MetadataExpunge] vm[uuid:%s] has no root volume, skipping metadata cleanup", vmUuid)); | ||
| trigger.next(); | ||
| return; | ||
| } | ||
|
|
||
| String psUuid = Q.New(VolumeVO.class).eq(VolumeVO_.uuid, rootVolumeUuid).select(VolumeVO_.primaryStorageUuid).findValue(); | ||
| if (psUuid == null) { | ||
| logger.debug(String.format("[MetadataExpunge] vm[uuid:%s] root volume[uuid:%s] has no primaryStorageUuid, " + | ||
| "skipping metadata cleanup", vmUuid, rootVolumeUuid)); | ||
| trigger.next(); | ||
| return; | ||
| } | ||
|
|
||
| String psType = Q.New(PrimaryStorageVO.class).select(PrimaryStorageVO_.type).eq(PrimaryStorageVO_.uuid, psUuid).findValue(); | ||
| VmMetadataPathBuildExtensionPoint ext = pluginRgty.getExtensionFromMap(psType, VmMetadataPathBuildExtensionPoint.class); | ||
| if (ext == null) { | ||
| trigger.next(); | ||
| return; | ||
| } | ||
| String metadataPath = ext.buildVmMetadataPath(psUuid, vmUuid); | ||
|
|
||
| CleanupVmInstanceMetadataOnPrimaryStorageMsg cmsg = new CleanupVmInstanceMetadataOnPrimaryStorageMsg(); | ||
| cmsg.setPrimaryStorageUuid(psUuid); | ||
| cmsg.setVmUuid(vmUuid); | ||
| cmsg.setMetadataPath(metadataPath); | ||
| bus.makeTargetServiceIdByResourceUuid(cmsg, PrimaryStorageConstant.SERVICE_ID, psUuid); | ||
| bus.send(cmsg, new CloudBusCallBack(trigger) { | ||
| @Override | ||
| public void run(MessageReply reply) { | ||
| if (reply.isSuccess()) { | ||
| logger.info(String.format("[MetadataExpunge] successfully deleted metadata for vm[uuid:%s] on ps[uuid:%s]", | ||
| vmUuid, psUuid)); | ||
| } else { | ||
| // best-effort: do not fail the expunge flow, MetadataStorageOrphanDetector will clean up later | ||
| logger.warn(String.format("[MetadataExpunge] failed to delete metadata for vm[uuid:%s] on ps[uuid:%s]: %s", | ||
| vmUuid, psUuid, reply.getError())); | ||
| } | ||
| trigger.next(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
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,24 @@ | ||
| CREATE TABLE IF NOT EXISTS `zstack`.`VmMetadataDirtyVO` ( | ||
| `vmInstanceUuid` VARCHAR(32) NOT NULL, | ||
| `managementNodeUuid` VARCHAR(32) DEFAULT NULL, | ||
| `dirtyVersion` BIGINT NOT NULL DEFAULT 1, | ||
| `lastClaimTime` TIMESTAMP NULL DEFAULT NULL, | ||
| `storageStructureChange` TINYINT(1) NOT NULL DEFAULT 0, | ||
| `retryCount` INT NOT NULL DEFAULT 0, | ||
| `nextRetryTime` TIMESTAMP NULL DEFAULT NULL, | ||
| `lastOpDate` timestamp on update CURRENT_TIMESTAMP, | ||
| `createDate` timestamp, | ||
| PRIMARY KEY (`vmInstanceUuid`), | ||
| CONSTRAINT `fkVmMetadataDirtyVOVmInstanceEO` FOREIGN KEY (`vmInstanceUuid`) REFERENCES `VmInstanceEO` (`uuid`) ON DELETE CASCADE, | ||
| CONSTRAINT `fkVmMetadataDirtyVOManagementNodeVO` FOREIGN KEY (`managementNodeUuid`) REFERENCES `ManagementNodeVO` (`uuid`) ON DELETE SET NULL | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS `zstack`.`VmMetadataFingerprintVO` ( | ||
| `vmInstanceUuid` VARCHAR(32) NOT NULL, | ||
| `metadataSnapshot` LONGTEXT, | ||
| `lastFlushTime` TIMESTAMP NULL DEFAULT NULL, | ||
| `lastFlushFailed` TINYINT(1) NOT NULL DEFAULT 0, | ||
| `staleRecoveryCount` INT NOT NULL DEFAULT 0, | ||
| PRIMARY KEY (`vmInstanceUuid`), | ||
| CONSTRAINT `fkVmMetadataFingerprintVOVmInstanceEO` FOREIGN KEY (`vmInstanceUuid`) REFERENCES `VmInstanceEO` (`uuid`) ON DELETE CASCADE | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
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.
🧩 Analysis chain
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 7118
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 166
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 2882
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 14118
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 2062
设置
rootVolumeUuid到消息中LocalStorageBase.handle()方法使用msg.getRootVolumeUuid()来确定处理主机,但当前代码未设置该字段。虽然 NFS 存储实现不需要此字段,但本地存储实现依赖它来解析主机。rootVolumeUuid在第 47 行已获取,应在第 73 行后添加cmsg.setRootVolumeUuid(rootVolumeUuid);。修复方案
CleanupVmInstanceMetadataOnPrimaryStorageMsg cmsg = new CleanupVmInstanceMetadataOnPrimaryStorageMsg(); cmsg.setPrimaryStorageUuid(psUuid); cmsg.setVmUuid(vmUuid); cmsg.setMetadataPath(metadataPath); +cmsg.setRootVolumeUuid(rootVolumeUuid);📝 Committable suggestion
🤖 Prompt for AI Agents