Add back ability to disable backup of snapshot to secondary (#3122)

* The snapshot.backup.rightafter configuration variable was removed by:

SHA: 6bb0ca2f85

This adds it back, though named snapshot.backup.to.secondary now instead.

This global parameter, once set, will allow you to prevent automatic backups of
     snapshots to secondary storage, unless they're actually needed.

Fixes #3096

* updates per review
This commit is contained in:
Nathan Johnson 2019-02-04 15:08:42 -06:00 committed by Gabriel Beims Bräscher
parent 463372bc7e
commit bf805d1483
4 changed files with 37 additions and 6 deletions

View File

@ -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();
@ -42,4 +43,6 @@ public interface SnapshotInfo extends DataObject, Snapshot {
boolean isRevertable();
long getPhysicalSize();
void markBackedUp() throws CloudRuntimeException;
}

View File

@ -149,6 +149,17 @@ public class SnapshotObject implements SnapshotInfo {
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: " +
this.snapshot.getId() + " " + ex.getMessage());
}
}
@Override
public VolumeInfo getBaseVolume() {
return volFactory.getVolume(snapshot.getVolumeId());

View File

@ -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);
/**

View File

@ -206,7 +206,7 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
@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
@ -1123,13 +1123,16 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
}
SnapshotInfo snapshotOnPrimary = snapshotStrategy.takeSnapshot(snapshot);
if (payload.getAsyncBackup()) {
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshotOnPrimary, snapshotBackupRetries - 1, snapshotStrategy), 0, TimeUnit.SECONDS);
boolean backupSnapToSecondary = BackupSnapshotAfterTakingSnapshot.value() == null ||
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 {
@ -1171,6 +1174,17 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
return snapshot;
}
protected void backupSnapshotToSecondary(boolean asyncBackup, SnapshotStrategy snapshotStrategy, SnapshotInfo snapshotOnPrimary) {
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;