Skip to content

Commit 4372205

Browse files
updates per review
1 parent 509410b commit 4372205

3 files changed

Lines changed: 21 additions & 18 deletions

File tree

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.cloudstack.engine.subsystem.api.storage;
1818

1919
import com.cloud.storage.Snapshot;
20+
import com.cloud.utils.exception.CloudRuntimeException;
2021

2122
public interface SnapshotInfo extends DataObject, Snapshot {
2223
SnapshotInfo getParent();
@@ -43,5 +44,5 @@ public interface SnapshotInfo extends DataObject, Snapshot {
4344

4445
long getPhysicalSize();
4546

46-
boolean markBackedUp();
47+
void markBackedUp() throws CloudRuntimeException;
4748
}

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ public long getPhysicalSize() {
150150
}
151151

152152
@Override
153-
public boolean markBackedUp() {
153+
public void markBackedUp() throws CloudRuntimeException{
154154
try {
155155
processEvent(Event.OperationNotPerformed);
156156
} catch (NoTransitionException ex) {
157157
s_logger.error("no transition error: ", ex);
158-
return false;
158+
throw new CloudRuntimeException("Error marking snapshot backed up: " +
159+
this.snapshot.getId() + " " + ex.getMessage());
159160
}
160-
return true;
161161
}
162162

163163
@Override

server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,25 +1123,16 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
11231123
}
11241124

11251125
SnapshotInfo snapshotOnPrimary = snapshotStrategy.takeSnapshot(snapshot);
1126-
boolean backupFlag = BackupSnapshotAfterTakingSnapshot.value() == null ||
1126+
boolean backupSnapToSecondary = BackupSnapshotAfterTakingSnapshot.value() == null ||
11271127
BackupSnapshotAfterTakingSnapshot.value();
11281128

1129-
if (backupFlag) {
1130-
if (payload.getAsyncBackup()) {
1131-
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshotOnPrimary, snapshotBackupRetries - 1, snapshotStrategy), 0, TimeUnit.SECONDS);
1132-
} else {
1133-
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
1134-
if (backupedSnapshot != null) {
1135-
snapshotStrategy.postSnapshotCreation(snapshotOnPrimary);
1136-
}
1137-
}
1129+
if (backupSnapToSecondary) {
1130+
backupSnapshotToSecondary(payload.getAsyncBackup(), snapshotStrategy, snapshotOnPrimary);
11381131
} else {
11391132
if(s_logger.isDebugEnabled()) {
1140-
s_logger.debug("skipping backup of snapshot to secondary due to configuration");
1141-
}
1142-
if (!snapshotOnPrimary.markBackedUp()) {
1143-
throw new CloudRuntimeException("Can't mark snapshot as backed up!");
1133+
s_logger.debug("skipping backup of snapshot " + snapshotId + " to secondary due to configuration");
11441134
}
1135+
snapshotOnPrimary.markBackedUp();
11451136
}
11461137

11471138
try {
@@ -1183,6 +1174,17 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
11831174
return snapshot;
11841175
}
11851176

1177+
protected void backupSnapshotToSecondary(boolean asyncBackup, SnapshotStrategy snapshotStrategy, SnapshotInfo snapshotOnPrimary) {
1178+
if (asyncBackup) {
1179+
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshotOnPrimary, snapshotBackupRetries - 1, snapshotStrategy), 0, TimeUnit.SECONDS);
1180+
} else {
1181+
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
1182+
if (backupedSnapshot != null) {
1183+
snapshotStrategy.postSnapshotCreation(snapshotOnPrimary);
1184+
}
1185+
}
1186+
}
1187+
11861188
protected class BackupSnapshotTask extends ManagedContextRunnable {
11871189
SnapshotInfo snapshot;
11881190
int attempts;

0 commit comments

Comments
 (0)