-
Notifications
You must be signed in to change notification settings - Fork 0
<feature>[storage]: support cleanAllVmMetadata param #3795
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: zsv_5.0.0
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 |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ | |
| import java.io.File; | ||
| import java.util.*; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
|
|
@@ -3560,6 +3561,11 @@ public void done(ErrorCodeList errorCodeList) { | |
|
|
||
| @Override | ||
| protected void handle(final CleanupVmInstanceMetadataOnPrimaryStorageMsg msg) { | ||
| if (msg.isCleanAllVmMetadata()) { | ||
| handleCleanAllVmMetadataOnLocalStorage(msg); | ||
| return; | ||
| } | ||
|
|
||
| thdf.chainSubmit(new ChainTask(msg) { | ||
| @Override | ||
| public String getSyncSignature() { | ||
|
|
@@ -3625,4 +3631,64 @@ public String getName() { | |
| } | ||
| }); | ||
| } | ||
|
|
||
| private void handleCleanAllVmMetadataOnLocalStorage(final CleanupVmInstanceMetadataOnPrimaryStorageMsg msg) { | ||
| CleanupVmInstanceMetadataOnPrimaryStorageReply reply = new CleanupVmInstanceMetadataOnPrimaryStorageReply(); | ||
|
|
||
| List<String> connectedHostUuids = SQL.New( | ||
| "select h.hostUuid from LocalStorageHostRefVO h, HostVO host" + | ||
| " where h.primaryStorageUuid = :psUuid" + | ||
| " and h.hostUuid = host.uuid" + | ||
| " and host.status = :hstatus", String.class) | ||
| .param("psUuid", self.getUuid()) | ||
| .param("hstatus", HostStatus.Connected) | ||
| .list(); | ||
| if (connectedHostUuids.isEmpty()) { | ||
| logger.warn(String.format("[MetadataCleanup] cleanAll: no connected host found for local ps[uuid:%s]", self.getUuid())); | ||
| reply.setCleanedCount(0); | ||
| bus.reply(msg, reply); | ||
| return; | ||
|
Comment on lines
+3638
to
+3650
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.
这里仅查询 可参考的修正方向- List<String> connectedHostUuids = SQL.New(
+ List<String> allHostUuids = SQL.New(
+ "select h.hostUuid from LocalStorageHostRefVO h, HostVO host" +
+ " where h.primaryStorageUuid = :psUuid" +
+ " and h.hostUuid = host.uuid", String.class)
+ .param("psUuid", self.getUuid())
+ .list();
+
+ List<String> connectedHostUuids = SQL.New(
"select h.hostUuid from LocalStorageHostRefVO h, HostVO host" +
" where h.primaryStorageUuid = :psUuid" +
" and h.hostUuid = host.uuid" +
" and host.status = :hstatus", String.class)
.param("psUuid", self.getUuid())
.param("hstatus", HostStatus.Connected)
.list();
- if (connectedHostUuids.isEmpty()) {
- logger.warn(String.format("[MetadataCleanup] cleanAll: no connected host found for local ps[uuid:%s]", self.getUuid()));
- reply.setCleanedCount(0);
+
+ List<String> disconnectedHostUuids = new ArrayList<>(allHostUuids);
+ disconnectedHostUuids.removeAll(connectedHostUuids);
+ if (!disconnectedHostUuids.isEmpty()) {
+ reply.setError(operr("cannot clean all vm metadata on local primary storage[uuid:%s], disconnected hosts=%s",
+ self.getUuid(), disconnectedHostUuids));
bus.reply(msg, reply);
return;
}Also applies to: 3684-3690 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| AtomicInteger totalCleaned = new AtomicInteger(0); | ||
| new While<>(connectedHostUuids).all((hostUuid, com) -> { | ||
| final LocalStorageHypervisorBackend bkd; | ||
| try { | ||
| LocalStorageHypervisorFactory f = getHypervisorBackendFactoryByHostUuid(hostUuid); | ||
| bkd = f.getHypervisorBackend(self); | ||
| } catch (Exception e) { | ||
| logger.warn(String.format("[MetadataCleanup] cleanAll: failed to prepare backend for host[uuid:%s] on ps[uuid:%s]: %s", | ||
| hostUuid, self.getUuid(), e.getMessage())); | ||
| com.addError(operr("failed to prepare backend for host[uuid:%s]: %s", hostUuid, e.getMessage())); | ||
| com.done(); | ||
| return; | ||
| } | ||
| bkd.handle(msg, hostUuid, new ReturnValueCompletion<CleanupVmInstanceMetadataOnPrimaryStorageReply>(com) { | ||
| @Override | ||
| public void success(CleanupVmInstanceMetadataOnPrimaryStorageReply returnValue) { | ||
| totalCleaned.addAndGet(returnValue.getCleanedCount()); | ||
| com.done(); | ||
| } | ||
|
|
||
| @Override | ||
| public void fail(ErrorCode errorCode) { | ||
| logger.warn(String.format("[MetadataCleanup] cleanAll: failed on host[uuid:%s] on ps[uuid:%s]: %s", | ||
| hostUuid, self.getUuid(), errorCode)); | ||
| com.addError(errorCode); | ||
| com.done(); | ||
| } | ||
| }); | ||
| }).run(new WhileDoneCompletion(msg) { | ||
| @Override | ||
| public void done(ErrorCodeList errorCodeList) { | ||
| if (!errorCodeList.getCauses().isEmpty() && errorCodeList.getCauses().size() == connectedHostUuids.size()) { | ||
| reply.setError(operr("failed to cleanup all vm metadata from all hosts on local primary storage[uuid:%s], causes: %s", | ||
| self.getUuid(), errorCodeList)); | ||
| } else { | ||
| reply.setCleanedCount(totalCleaned.get()); | ||
| } | ||
| bus.reply(msg, reply); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
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.
cleanAll分支绕过了现有的元数据串行化队列。这里直接
return到新的全量清理逻辑,导致它不再经过下面单 VM cleanup 使用的thdf.chainSubmit(...),也和 Line 3368 的 metadata update 路径失去了同一个串行化边界。这样全量清理可以和更新/单 VM 清理并发修改同一套 metadata,结果会依赖时序。建议把cleanAllVmMetadata=true也放进同一个 per-PS sync chain,再在 chain 内部做 host 级 fan-out。🤖 Prompt for AI Agents