Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.cloudstack.engine.subsystem.api.storage;

import com.cloud.storage.Snapshot;
import com.cloud.utils.exception.CloudRuntimeException;

public interface SnapshotInfo extends DataObject, Snapshot {
SnapshotInfo getParent();
Expand All @@ -42,4 +43,6 @@ public interface SnapshotInfo extends DataObject, Snapshot {
boolean isRevertable();

long getPhysicalSize();

void markBackedUp() throws CloudRuntimeException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ public long getPhysicalSize() {
return physicalSize;
}

@Override
public void markBackedUp() throws CloudRuntimeException{
try {
processEvent(Event.OperationNotPerformed);
} catch (NoTransitionException ex) {
s_logger.error("no transition error: ", ex);
throw new CloudRuntimeException("Error marking snapshot backed up: " +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you maintain the history of the stack of the exception that is re-thrown here?
I mean, it is a matter of using throw new CloudRuntimeException(<message>, <exception>)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathanejohnson I see this point as critical. Doing as @rafaelweingartner proposed would allow having the full stack on the log, which helps on debugging.
Could you please address this point? Thanks! Overall LGTM.

this.snapshot.getId() + " " + ex.getMessage());
}
}

@Override
public VolumeInfo getBaseVolume() {
return volFactory.getVolume(snapshot.getVolumeId());
Expand Down
3 changes: 3 additions & 0 deletions server/src/com/cloud/storage/snapshot/SnapshotManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public interface SnapshotManager extends Configurable {
public static final ConfigKey<Integer> BackupRetryInterval = new ConfigKey<Integer>(Integer.class, "backup.retry.interval", "Advanced", "300",
"Time in seconds between retries in backing up snapshot to secondary", false, ConfigKey.Scope.Global, null);

public static final ConfigKey<Boolean> BackupSnapshotAfterTakingSnapshot = new ConfigKey<Boolean>(Boolean.class, "snapshot.backup.to.secondary", "Snapshots", "true",
"Indicates whether to always backup primary storage snapshot to secondary storage", false, ConfigKey.Scope.Global, null);

void deletePoliciesForVolume(Long volumeId);

/**
Expand Down
26 changes: 20 additions & 6 deletions server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public String getConfigComponentName() {

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {BackupRetryAttempts, BackupRetryInterval, SnapshotHourlyMax, SnapshotDailyMax, SnapshotMonthlyMax, SnapshotWeeklyMax, usageSnapshotSelection};
return new ConfigKey<?>[] {BackupRetryAttempts, BackupRetryInterval, SnapshotHourlyMax, SnapshotDailyMax, SnapshotMonthlyMax, SnapshotWeeklyMax, usageSnapshotSelection, BackupSnapshotAfterTakingSnapshot};
}

@Override
Expand Down Expand Up @@ -1123,13 +1123,16 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
}

SnapshotInfo snapshotOnPrimary = snapshotStrategy.takeSnapshot(snapshot);
if (payload.getAsyncBackup()) {
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshotOnPrimary, snapshotBackupRetries - 1, snapshotStrategy), 0, TimeUnit.SECONDS);
boolean backupSnapToSecondary = BackupSnapshotAfterTakingSnapshot.value() == null ||

This comment was marked as outdated.

BackupSnapshotAfterTakingSnapshot.value();

if (backupSnapToSecondary) {
backupSnapshotToSecondary(payload.getAsyncBackup(), snapshotStrategy, snapshotOnPrimary);
} else {
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
if (backupedSnapshot != null) {
snapshotStrategy.postSnapshotCreation(snapshotOnPrimary);
if(s_logger.isDebugEnabled()) {
s_logger.debug("skipping backup of snapshot " + snapshotId + " to secondary due to configuration");
}
snapshotOnPrimary.markBackedUp();
}

try {
Expand Down Expand Up @@ -1171,6 +1174,17 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
return snapshot;
}

protected void backupSnapshotToSecondary(boolean asyncBackup, SnapshotStrategy snapshotStrategy, SnapshotInfo snapshotOnPrimary) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind documenting this method, and then creating unit test cases for it?

if (asyncBackup) {
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshotOnPrimary, snapshotBackupRetries - 1, snapshotStrategy), 0, TimeUnit.SECONDS);
} else {
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
if (backupedSnapshot != null) {
snapshotStrategy.postSnapshotCreation(snapshotOnPrimary);
}
}
}

protected class BackupSnapshotTask extends ManagedContextRunnable {
SnapshotInfo snapshot;
int attempts;
Expand Down