use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class BackupOps method deleteBackup.
/**
* Delete backup file on all nodes
*
* @param backupTag
* The tag of the backup
*/
public void deleteBackup(String backupTag) {
checkOnStandby();
validateBackupName(backupTag);
InterProcessLock lock = null;
try {
lock = getLock(BackupConstants.BACKUP_LOCK, BackupConstants.LOCK_TIMEOUT, TimeUnit.MILLISECONDS);
deleteBackupWithoutLock(backupTag, false);
} finally {
releaseLock(lock);
}
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class BackupOps method createBackup.
/**
* Create backup file on all nodes
*
* @param backupTag
* The tag of this backup
* @param force
* Ignore the errors during the creation
*/
public void createBackup(String backupTag, boolean force) {
checkOnStandby();
if (backupTag == null) {
backupTag = createBackupName();
} else {
validateBackupName(backupTag);
}
precheckForCreation(backupTag);
InterProcessLock backupLock = null;
InterProcessLock recoveryLock = null;
try {
backupLock = getLock(BackupConstants.BACKUP_LOCK, BackupConstants.LOCK_TIMEOUT, TimeUnit.MILLISECONDS);
recoveryLock = getLock(RecoveryConstants.RECOVERY_LOCK, BackupConstants.LOCK_TIMEOUT, TimeUnit.MILLISECONDS);
createBackupWithoutLock(backupTag, force);
} finally {
releaseLock(recoveryLock);
releaseLock(backupLock);
}
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class BackupOps method getLock.
public InterProcessLock getLock(String name, long time, TimeUnit unit) {
InterProcessLock lock = null;
log.info("Try to acquire lock: {}", name);
try {
lock = coordinatorClient.getLock(name);
if (time >= 0) {
boolean acquired = lock.acquire(time, unit);
if (!acquired) {
log.error("Unable to acquire lock: {}", name);
if (name.equals(RecoveryConstants.RECOVERY_LOCK)) {
throw BackupException.fatals.unableToGetRecoveryLock(name);
}
throw BackupException.fatals.unableToGetLock(name);
}
} else {
// no timeout
lock.acquire();
}
} catch (Exception e) {
log.error("Failed to acquire lock: {}", name);
throw BackupException.fatals.failedToGetLock(name, e);
}
log.info("Got lock: {}", name);
return lock;
}
Aggregations