Skip to content

Commit 9c6f2a9

Browse files
committed
Merge release branch 4.20 to main
* 4.20: Fix Stats Collector to not divide by zero (#10492) linstor: try to delete -rst resource before snapshot backup (#10443)
2 parents b387bc1 + f8adedc commit 9c6f2a9

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

plugins/storage/volume/linstor/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to Linstor CloudStack plugin will be documented in this file
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2025-02-21]
9+
10+
### Fixed
11+
12+
- Always try to delete cs-...-rst resource before doing a snapshot backup
13+
814
## [2025-01-27]
915

1016
### Fixed

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,8 @@ private String restoreResourceFromSnapshot(
11191119
String snapshotName,
11201120
String restoredName) throws ApiException {
11211121
final String rscGrp = getRscGrp(storagePoolVO);
1122+
// try to delete -rst resource, could happen if the copy failed and noone deleted it.
1123+
deleteResourceDefinition(storagePoolVO, restoredName);
11221124
ResourceDefinitionCreate rdc = createResourceDefinitionCreate(restoredName, rscGrp);
11231125
api.resourceDefinitionCreate(rdc);
11241126

@@ -1261,19 +1263,22 @@ private Answer copyFromTemporaryResource(
12611263
throws ApiException {
12621264
Answer answer;
12631265
String restoreName = rscName + "-rst";
1264-
String devName = restoreResourceFromSnapshot(api, pool, rscName, snapshotName, restoreName);
1265-
1266-
Optional<RemoteHostEndPoint> optEPAny = getLinstorEP(api, restoreName);
1267-
if (optEPAny.isPresent()) {
1268-
// patch the src device path to the temporary linstor resource
1269-
snapshotObject.setPath(devName);
1270-
origCmd.setSrcTO(snapshotObject.getTO());
1271-
answer = optEPAny.get().sendMessage(origCmd);
1272-
} else{
1273-
answer = new Answer(origCmd, false, "Unable to get matching Linstor endpoint.");
1266+
try {
1267+
String devName = restoreResourceFromSnapshot(api, pool, rscName, snapshotName, restoreName);
1268+
1269+
Optional<RemoteHostEndPoint> optEPAny = getLinstorEP(api, restoreName);
1270+
if (optEPAny.isPresent()) {
1271+
// patch the src device path to the temporary linstor resource
1272+
snapshotObject.setPath(devName);
1273+
origCmd.setSrcTO(snapshotObject.getTO());
1274+
answer = optEPAny.get().sendMessage(origCmd);
1275+
} else{
1276+
answer = new Answer(origCmd, false, "Unable to get matching Linstor endpoint.");
1277+
}
1278+
} finally {
1279+
// delete the temporary resource, noop if already gone
1280+
api.resourceDefinitionDelete(restoreName);
12741281
}
1275-
// delete the temporary resource, noop if already gone
1276-
api.resourceDefinitionDelete(restoreName);
12771282
return answer;
12781283
}
12791284

server/src/main/java/com/cloud/server/StatsCollector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,10 @@ protected void runInContext() {
718718
getDynamicDataFromDB();
719719
long interval = (Long) dbStats.get(uptime) - lastUptime;
720720
long activity = (Long) dbStats.get(queries) - lastQueries;
721-
loadHistory.add(0, Double.valueOf(activity / interval));
721+
loadHistory.add(0, interval == 0 ? -1 : Double.valueOf(activity / interval));
722722
int maxsize = DATABASE_SERVER_LOAD_HISTORY_RETENTION_NUMBER.value();
723723
while (loadHistory.size() > maxsize) {
724-
loadHistory.remove(maxsize - 1);
724+
loadHistory.remove(maxsize);
725725
}
726726
} catch (Throwable e) {
727727
// pokemon catch to make sure the thread stays running

0 commit comments

Comments
 (0)