From 8f78f0b864fe217f0217f31f1aa7e5aa9b10dd5c Mon Sep 17 00:00:00 2001 From: "yaohua.wu" Date: Tue, 31 Mar 2026 13:01:21 +0800 Subject: [PATCH] [kvm]: prevent metadata deletion when DVD returns empty When hypervisor metadata collection from DVD returns an empty list, the existing metadata was deleted before the empty check, causing all hosts to lose their hypervisor version metadata and matchState to become Unknown. 1. Why is this change necessary? saveHostOsCategoryList first deleted all existing metadata for the management node, then checked if the input was empty. When DVD collection returned empty, this wiped all metadata, causing matchTargetVersion to be null and matchState to become Unknown. 2. How does it address the problem? Move the empty-list check before the delete operation so that an empty input preserves existing metadata. A warning is logged to indicate the skip. 3. Are there any side effects? None. Non-empty input behavior is unchanged. # Summary of changes (by module): - kvm: move empty check before metadata delete in KvmHypervisorInfoManagerImpl.saveHostOsCategoryList() Related: ZSTAC-83682 Change-Id: I81f9baacac7fce9af2363a0ce5c960532d383890 --- .../kvm/hypervisor/KvmHypervisorInfoManagerImpl.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugin/kvm/src/main/java/org/zstack/kvm/hypervisor/KvmHypervisorInfoManagerImpl.java b/plugin/kvm/src/main/java/org/zstack/kvm/hypervisor/KvmHypervisorInfoManagerImpl.java index f9501fe279e..df330171cf6 100644 --- a/plugin/kvm/src/main/java/org/zstack/kvm/hypervisor/KvmHypervisorInfoManagerImpl.java +++ b/plugin/kvm/src/main/java/org/zstack/kvm/hypervisor/KvmHypervisorInfoManagerImpl.java @@ -275,13 +275,15 @@ private boolean saveMetadataList(List definitions) @Transactional protected boolean saveHostOsCategoryList(List categoryVOS) { + if (CollectionUtils.isEmpty(categoryVOS)) { + logger.warn("no hypervisor metadata collected from DVD, skip refresh to preserve existing metadata"); + return false; + } + // refresh all metadata with current management node SQL.New(KvmHostHypervisorMetadataVO.class) .eq(KvmHostHypervisorMetadataVO_.managementNodeUuid, Platform.getManagementServerId()) .delete(); - if (CollectionUtils.isEmpty(categoryVOS)) { - return false; - } Set requestArchitectures = categoryVOS.stream() .map(HostOsCategoryVO::getArchitecture)