From 95c24810ab43810550ed70b3ebc4ba131082f7d3 Mon Sep 17 00:00:00 2001 From: Rene Peinthor Date: Mon, 10 Mar 2025 16:23:01 +0100 Subject: [PATCH 1/2] linstor: try to delete -rst resource before snapshot backup (#10443) If a -rst resource wasn't deleted because of a failed copy, a reoccurring snapshot attempt couldn't be done, because there was still the "old" -rst resource. To prevent this always try to remove the -rst resource before, if it doesn't exist it is a noop. --- plugins/storage/volume/linstor/CHANGELOG.md | 6 +++++ .../LinstorPrimaryDataStoreDriverImpl.java | 27 +++++++++++-------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/plugins/storage/volume/linstor/CHANGELOG.md b/plugins/storage/volume/linstor/CHANGELOG.md index fb247eef5df..e27e521bcd8 100644 --- a/plugins/storage/volume/linstor/CHANGELOG.md +++ b/plugins/storage/volume/linstor/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to Linstor CloudStack plugin will be documented in this file The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2025-02-21] + +### Fixed + +- Always try to delete cs-...-rst resource before doing a snapshot backup + ## [2025-01-27] ### Fixed diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java index 22cb4eb8911..a0cb5d17444 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java @@ -1117,6 +1117,8 @@ public class LinstorPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver String snapshotName, String restoredName) throws ApiException { final String rscGrp = getRscGrp(storagePoolVO); + // try to delete -rst resource, could happen if the copy failed and noone deleted it. + deleteResourceDefinition(storagePoolVO, restoredName); ResourceDefinitionCreate rdc = createResourceDefinitionCreate(restoredName, rscGrp); api.resourceDefinitionCreate(rdc); @@ -1259,19 +1261,22 @@ public class LinstorPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver throws ApiException { Answer answer; String restoreName = rscName + "-rst"; - String devName = restoreResourceFromSnapshot(api, pool, rscName, snapshotName, restoreName); + try { + String devName = restoreResourceFromSnapshot(api, pool, rscName, snapshotName, restoreName); - Optional optEPAny = getLinstorEP(api, restoreName); - if (optEPAny.isPresent()) { - // patch the src device path to the temporary linstor resource - snapshotObject.setPath(devName); - origCmd.setSrcTO(snapshotObject.getTO()); - answer = optEPAny.get().sendMessage(origCmd); - } else{ - answer = new Answer(origCmd, false, "Unable to get matching Linstor endpoint."); + Optional optEPAny = getLinstorEP(api, restoreName); + if (optEPAny.isPresent()) { + // patch the src device path to the temporary linstor resource + snapshotObject.setPath(devName); + origCmd.setSrcTO(snapshotObject.getTO()); + answer = optEPAny.get().sendMessage(origCmd); + } else{ + answer = new Answer(origCmd, false, "Unable to get matching Linstor endpoint."); + } + } finally { + // delete the temporary resource, noop if already gone + api.resourceDefinitionDelete(restoreName); } - // delete the temporary resource, noop if already gone - api.resourceDefinitionDelete(restoreName); return answer; } From 54c1f92efd2664d5316c67c451e69e97f880a5f3 Mon Sep 17 00:00:00 2001 From: Lucas Martins <56271185+lucas-a-martins@users.noreply.github.com> Date: Mon, 10 Mar 2025 12:39:08 -0300 Subject: [PATCH 2/2] Fix Stats Collector to not divide by zero (#10492) * Set loadHistory value to zero when interval is zero to not throw arithmatic exception * Change loadHistory value to -1 and fix maxsize bug --------- Co-authored-by: Lucas Martins --- server/src/main/java/com/cloud/server/StatsCollector.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/cloud/server/StatsCollector.java b/server/src/main/java/com/cloud/server/StatsCollector.java index 5934716da66..27ac0bb725d 100644 --- a/server/src/main/java/com/cloud/server/StatsCollector.java +++ b/server/src/main/java/com/cloud/server/StatsCollector.java @@ -718,10 +718,10 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc getDynamicDataFromDB(); long interval = (Long) dbStats.get(uptime) - lastUptime; long activity = (Long) dbStats.get(queries) - lastQueries; - loadHistory.add(0, Double.valueOf(activity / interval)); + loadHistory.add(0, interval == 0 ? -1 : Double.valueOf(activity / interval)); int maxsize = DATABASE_SERVER_LOAD_HISTORY_RETENTION_NUMBER.value(); while (loadHistory.size() > maxsize) { - loadHistory.remove(maxsize - 1); + loadHistory.remove(maxsize); } } catch (Throwable e) { // pokemon catch to make sure the thread stays running