-
Notifications
You must be signed in to change notification settings - Fork 0
WIP <fix>[cloudbus]: remove some db op #3202
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
base: 5.4.2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,7 +78,9 @@ private class CallbackWrapper { | |
|
|
||
| CallbackWrapper(String path, AbstractEventFacadeCallback callback) { | ||
| this.path = path; | ||
| this.glob = createRegexFromGlob(path.replaceAll("\\{.*\\}", ".*")); | ||
| if (isGlobPath(path)) { | ||
| this.glob = createRegexFromGlob(path.replaceAll("\\{.*\\}", ".*")); | ||
| } | ||
| this.callback = callback; | ||
| if (callback instanceof AutoOffEventCallback) { | ||
| hasRun = new AtomicBoolean(false); | ||
|
|
@@ -127,6 +129,10 @@ void call(CanonicalEvent e) { | |
| } | ||
| } | ||
|
|
||
| private boolean isGlobPath(String path) { | ||
| return path.contains("*") || path.contains("?") || path.contains("{"); | ||
| } | ||
|
|
||
| public String createRegexFromGlob(String glob) { | ||
| String out = "^"; | ||
| for(int i = 0; i < glob.length(); ++i) { | ||
|
|
@@ -223,7 +229,7 @@ public void fire(String path, Object data) { | |
|
|
||
| fireLocal(evt); | ||
|
|
||
| callWebhooks(evt); | ||
| // callWebhooks(evt); | ||
|
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. Webhook 功能被静默禁用,缺少必要的注释说明 直接注释掉
建议添加 TODO 注释并关联 issue,或者如果这是永久性移除,应删除 - // callWebhooks(evt);
+ // TODO(QI-1170): Webhook dispatch is temporarily disabled for performance optimization.
+ // Will be replaced with cached/event-based mechanism in a future PR.
+ // callWebhooks(evt);🤖 Prompt for AI Agents |
||
|
|
||
| bus.publish(evt); | ||
| } | ||
|
|
@@ -250,7 +256,8 @@ private void fireLocal(CanonicalEvent cevt) { | |
| wrappers.putAll(local); | ||
|
|
||
| for (CallbackWrapper w : wrappers.values()) { | ||
| if (cevt.getPath().matches(w.getGlob())) { | ||
| boolean match = w.getGlob() == null ? cevt.getPath().equals(w.path) : cevt.getPath().matches(w.getGlob()); | ||
| if (match) { | ||
| w.call(cevt); | ||
| } | ||
| } | ||
|
|
@@ -271,7 +278,8 @@ public boolean handleEvent(Event evt) { | |
| Map<String, CallbackWrapper> wrappers = new HashMap<>(); | ||
| wrappers.putAll(global); | ||
| for (CallbackWrapper w : wrappers.values()) { | ||
| if (cevt.getPath().matches(w.getGlob())) { | ||
| boolean match = w.getGlob() == null ? cevt.getPath().equals(w.path) : cevt.getPath().matches(w.getGlob()); | ||
| if (match) { | ||
| w.call(cevt); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,6 +129,10 @@ public void done(ErrorCodeList errorCodeList) { | |
|
|
||
| @Override | ||
| public Flow createKvmHostConnectingFlow(final KVMHostConnectedContext context) { | ||
| if (!context.getAttachedPrimaryStorageTypes().contains(CephConstants.CEPH_PRIMARY_STORAGE_TYPE)) { | ||
| return new NopeFlow(); | ||
| } | ||
|
|
||
|
Comment on lines
+132
to
+135
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. 潜在的空指针异常风险,与其他存储扩展存在相同问题。 与 🔧 建议修复+ if (context.getAttachedPrimaryStorageTypes() == null ||
+ !context.getAttachedPrimaryStorageTypes().contains(CephConstants.CEPH_PRIMARY_STORAGE_TYPE)) {
- if (!context.getAttachedPrimaryStorageTypes().contains(CephConstants.CEPH_PRIMARY_STORAGE_TYPE)) {
return new NopeFlow();
}🤖 Prompt for AI Agents |
||
| return new NoRollbackFlow() { | ||
| String __name__ = "prepare-ceph-primary-storage"; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |||||||||||||||
| import org.zstack.header.volume.VolumeVO; | ||||||||||||||||
| import org.zstack.header.volume.VolumeVO_; | ||||||||||||||||
| import org.zstack.kvm.*; | ||||||||||||||||
| import org.zstack.storage.addon.primary.ExternalPrimaryStorageConstants; | ||||||||||||||||
|
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. 删除未使用的导入。
🔧 建议修复-import org.zstack.storage.addon.primary.ExternalPrimaryStorageConstants;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| import org.zstack.storage.addon.primary.ExternalPrimaryStorageFactory; | ||||||||||||||||
| import org.zstack.utils.CollectionUtils; | ||||||||||||||||
| import org.zstack.utils.Utils; | ||||||||||||||||
|
|
@@ -79,6 +80,10 @@ private Map<String, PrimaryStorageHostStatus> getHostStatus(List<ExternalPrimary | |||||||||||||||
|
|
||||||||||||||||
| @Override | ||||||||||||||||
| public Flow createKvmHostConnectingFlow(KVMHostConnectedContext context) { | ||||||||||||||||
| if (!context.getAttachedPrimaryStorageTypes().contains(PrimaryStorageConstant.EXTERNAL_PRIMARY_STORAGE_TYPE)) { | ||||||||||||||||
| return new NopeFlow(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+83
to
+86
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. 潜在的空指针异常风险,与其他存储扩展存在相同问题。 与 🔧 建议修复+ if (context.getAttachedPrimaryStorageTypes() == null ||
+ !context.getAttachedPrimaryStorageTypes().contains(PrimaryStorageConstant.EXTERNAL_PRIMARY_STORAGE_TYPE)) {
- if (!context.getAttachedPrimaryStorageTypes().contains(PrimaryStorageConstant.EXTERNAL_PRIMARY_STORAGE_TYPE)) {
return new NopeFlow();
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| List<ExternalPrimaryStorageVO> extPss = findExternalPsByClusterUuid(context.getInventory().getClusterUuid()); | ||||||||||||||||
| if (extPss.isEmpty()) { | ||||||||||||||||
| return new NopeFlow(); | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| import org.zstack.compute.vm.*; | ||
| import org.zstack.core.timeout.TimeHelper; | ||
| import org.zstack.header.core.*; | ||
| import org.zstack.header.storage.addon.primary.ExternalPrimaryStorageVO; | ||
| import org.zstack.header.vm.devices.VirtualDeviceInfo; | ||
| import org.zstack.header.vm.devices.VmInstanceDeviceManager; | ||
| import org.zstack.core.CoreGlobalProperty; | ||
|
|
@@ -507,11 +508,11 @@ public void fail(ErrorCode err) { | |
|
|
||
| @Override | ||
| public void success(T ret) { | ||
| if (dbf.isExist(self.getUuid(), HostVO.class)) { | ||
| //if (dbf.isExist(self.getUuid(), HostVO.class)) { | ||
| completion.success(ret); | ||
| } else { | ||
| completion.fail(operr("host[uuid:%s] has been deleted", self.getUuid())); | ||
| } | ||
| //} else { | ||
| // completion.fail(operr("host[uuid:%s] has been deleted", self.getUuid())); | ||
| //} | ||
| } | ||
|
Comment on lines
510
to
516
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. 异步 HTTP 回调对“Host 已删除”的处理现在不一致,可能改变语义 🤖 Prompt for AI Agents |
||
|
|
||
| @Override | ||
|
|
@@ -5188,13 +5189,19 @@ private void continueConnect(final ConnectHostInfo info, final Completion comple | |
| chain.setName(String.format("continue-connecting-kvm-host-%s-%s", self.getManagementIp(), self.getUuid())); | ||
| chain.getData().put(KVMConstant.CONNECT_HOST_PRIMARYSTORAGE_ERROR, new ErrorCodeList()); | ||
| chain.allowWatch(); | ||
|
|
||
| Set<String> attachedPsTypes = new HashSet(SQL.New("select pri.type from PrimaryStorageVO pri, PrimaryStorageClusterRefVO ref" + | ||
| " where pri.uuid = ref.primaryStorageUuid" + | ||
| " and ref.clusterUuid = :cuuid", String.class) | ||
| .param("cuuid", self.getClusterUuid()) | ||
| .list()); | ||
| for (KVMHostConnectExtensionPoint extp : factory.getConnectExtensions()) { | ||
| KVMHostConnectedContext ctx = new KVMHostConnectedContext(); | ||
| ctx.setInventory((KVMHostInventory) getSelfInventory()); | ||
| ctx.setNewAddedHost(info.isNewAdded()); | ||
| ctx.setBaseUrl(baseUrl); | ||
| ctx.setSkipPackages(info.getSkipPackages()); | ||
|
|
||
| ctx.setAttachedPrimaryStorageTypes(attachedPsTypes); | ||
| chain.then(extp.createKvmHostConnectingFlow(ctx)); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,7 +241,7 @@ private List<AddKVMHostMsg> loadMsgFromFile(String content, ValidateFunction<? s | |
| @Override | ||
| public Host getHost(HostVO vo) { | ||
| KVMHostVO kvo = dbf.findByUuid(vo.getUuid(), KVMHostVO.class); | ||
| KVMHostContext context = getHostContext(vo.getUuid()); | ||
| KVMHostContext context = getHostContext(kvo); | ||
| if (context == null) { | ||
| context = createHostContext(kvo); | ||
| } | ||
|
|
@@ -1025,7 +1025,11 @@ public KVMHostContext createHostContext(KVMHostVO vo) { | |
| return context; | ||
| } | ||
|
|
||
| public KVMHostContext getHostContext(String hostUuid) { | ||
| public KVMHostContext getHostContext(KVMHostVO kvo) { | ||
| return createHostContext(kvo); | ||
| } | ||
|
|
||
| public KVMHostContext getHostContextByUuid(String hostUuid) { | ||
| KVMHostVO kvo = dbf.findByUuid(hostUuid, KVMHostVO.class); | ||
| return createHostContext(kvo); | ||
| } | ||
|
Comment on lines
+1032
to
1035
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. 🧩 Analysis chain🏁 Script executed: # Find all usages of getHostContextByUuid method
rg -n 'getHostContextByUuid' --type javaRepository: MatheMatrix/zstack Length of output: 192 🏁 Script executed: # Check the createHostContext method implementation
cd plugin/kvm/src/main/java/org/zstack/kvm && grep -n -A 15 'private KVMHostContext createHostContext' KVMHostFactory.javaRepository: MatheMatrix/zstack Length of output: 44 🏁 Script executed: # Search for all places that might call this method indirectly
rg -n 'KVMHostFactory' --type java -A 3 -B 1 | head -100Repository: MatheMatrix/zstack Length of output: 10742 🏁 Script executed: # Read the KVMHostFactory file around the methods in question
cat -n plugin/kvm/src/main/java/org/zstack/kvm/KVMHostFactory.java | sed -n '1010,1040p'Repository: MatheMatrix/zstack Length of output: 1348 🏁 Script executed: # Search for actual invocations/calls to getHostContextByUuid method
rg -n '\.getHostContextByUuid\(' --type javaRepository: MatheMatrix/zstack Length of output: 44 🏁 Script executed: # Search for any reference to getHostContextByUuid to see if it's used at all
rg -n 'getHostContextByUuid' --type java -C 2Repository: MatheMatrix/zstack Length of output: 565 🏁 Script executed: # Check if method is referenced in any way (tests, groovy, etc)
rg -i 'getHostContextByUuid' --type groovy --type javaRepository: MatheMatrix/zstack Length of output: 187 🏁 Script executed: # Check git history to see when this method was added and why
cd plugin/kvm/src/main/java/org/zstack/kvm && git log --oneline -p KVMHostFactory.java | grep -A 10 -B 5 'getHostContextByUuid' | head -50Repository: MatheMatrix/zstack Length of output: 515 该方法是未使用的死代码,应删除或完善
若此方法的确无实际用途,应将其删除。若该方法是计划中的 API,则必须在调用 🤖 Prompt for AI Agents |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1740,6 +1740,11 @@ public void fail(ErrorCode errorCode) { | |
|
|
||
| @Override | ||
| public Flow createKvmHostConnectingFlow(final KVMHostConnectedContext context) { | ||
| if (!context.getAttachedPrimaryStorageTypes().contains(NfsPrimaryStorageConstant.NFS_PRIMARY_STORAGE_TYPE)) { | ||
| return new NopeFlow(); | ||
| } | ||
|
|
||
|
|
||
|
Comment on lines
+1743
to
+1747
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. 潜在空指针风险:与 LocalStorageKvmFactory 相同的 null 检查问题
🐛 建议修复- if (!context.getAttachedPrimaryStorageTypes().contains(NfsPrimaryStorageConstant.NFS_PRIMARY_STORAGE_TYPE)) {
+ Set<String> attachedTypes = context.getAttachedPrimaryStorageTypes();
+ if (attachedTypes == null || !attachedTypes.contains(NfsPrimaryStorageConstant.NFS_PRIMARY_STORAGE_TYPE)) {
return new NopeFlow();
}
-另外,第 1747 行有多余的空行,可以删除以保持代码整洁。 🤖 Prompt for AI Agents |
||
| return new NoRollbackFlow() { | ||
| String __name__ = "remount-nfs-primary-storage"; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |||||||||||||||
| import org.zstack.header.core.workflow.Flow; | ||||||||||||||||
| import org.zstack.header.core.workflow.FlowTrigger; | ||||||||||||||||
| import org.zstack.header.core.workflow.NoRollbackFlow; | ||||||||||||||||
| import org.zstack.header.core.workflow.NopeFlow; | ||||||||||||||||
| import org.zstack.header.errorcode.ErrorCode; | ||||||||||||||||
| import org.zstack.header.message.MessageReply; | ||||||||||||||||
| import org.zstack.header.storage.primary.*; | ||||||||||||||||
|
|
@@ -58,6 +59,10 @@ private PrimaryStorageInventory findSMPByHostUuid(String clusterUuid) { | |||||||||||||||
|
|
||||||||||||||||
| @Override | ||||||||||||||||
| public Flow createKvmHostConnectingFlow(final KVMHostConnectedContext context) { | ||||||||||||||||
| if (!context.getAttachedPrimaryStorageTypes().contains(SMPConstants.SMP_TYPE)) { | ||||||||||||||||
| return new NopeFlow(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+62
to
+65
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. 存在空指针异常风险。 与 建议统一在 🔧 建议修复- if (!context.getAttachedPrimaryStorageTypes().contains(SMPConstants.SMP_TYPE)) {
+ if (context.getAttachedPrimaryStorageTypes() == null ||
+ !context.getAttachedPrimaryStorageTypes().contains(SMPConstants.SMP_TYPE)) {
return new NopeFlow();
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| return new NoRollbackFlow() { | ||||||||||||||||
| String __init__ = "init-smp-primary-storage"; | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||
| package org.zstack.storage.addon.primary; | ||||
|
|
||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.security.core.parameters.P; | ||||
|
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. 删除未使用的导入。
🔧 建议修复-import org.springframework.security.core.parameters.P;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
| import org.zstack.core.Platform; | ||||
| import org.zstack.core.asyncbatch.While; | ||||
| import org.zstack.core.cloudbus.CloudBus; | ||||
|
|
@@ -265,6 +266,10 @@ public void validateStorageProtocol(String protocol) { | |||
| } | ||||
| } | ||||
|
|
||||
| public List<PrimaryStorageControllerSvc> getAllControllerSvcs() { | ||||
| return new ArrayList<>(controllers.values()); | ||||
| } | ||||
|
|
||||
| public PrimaryStorageControllerSvc getControllerSvc(String primaryStorageUuid) { | ||||
| return controllers.get(primaryStorageUuid); | ||||
| } | ||||
|
|
||||
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: 2676
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 16485
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 14887
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 11083
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 6749
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 679
明确升级迁移策略或添加配置保留机制。
将
ENABLE_ELABORATION的默认值从"true"改为"false"在升级现有部署时会产生破坏性变更。经代码分析,GlobalConfigFacadeImpl 的升级逻辑会在以下场景改写该配置:defaultValue == value),升级时会将配置值同时更新为新的默认值"false"(详见 GlobalConfigFacadeImpl 第 390-441 行)由于 recordElaboration 性能优化的需要,禁用 elaboration 是合理的。但根据编码规范的向后兼容原则,建议:
enableElaboration=true,以保留现有行为