diff --git a/priam/src/main/java/com/netflix/priam/restore/AbstractRestore.java b/priam/src/main/java/com/netflix/priam/restore/AbstractRestore.java index 49592bac7..1074206e5 100644 --- a/priam/src/main/java/com/netflix/priam/restore/AbstractRestore.java +++ b/priam/src/main/java/com/netflix/priam/restore/AbstractRestore.java @@ -42,6 +42,7 @@ import javax.inject.Named; import javax.inject.Provider; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -217,6 +218,13 @@ public void restore(DateUtil.DateRange dateRange) throws Exception { instanceIdentity.getInstance().setToken(restoreToken.toString()); } + // Stop cassandra if its running + stopCassProcess(); + + // Cleanup local data + File dataDir = new File(config.getDataFileLocation()); + if (dataDir.exists() && dataDir.isDirectory()) FileUtils.cleanDirectory(dataDir); + // Find latest valid meta file. Optional latestValidMetaFile = BackupRestoreUtil.getLatestValidMetaPath(metaProxy, dateRange); @@ -247,6 +255,7 @@ public void restore(DateUtil.DateRange dateRange) throws Exception { List> futureList = new ArrayList<>(); futureList.addAll(download(allFiles.iterator(), false)); + // Downloading CommitLogs // Note for Backup V2.0 we do not backup commit logs, as saving them is cost-expensive. if (config.isBackingUpCommitLogs()) { logger.info( @@ -267,9 +276,20 @@ public void restore(DateUtil.DateRange dateRange) throws Exception { // Wait for all the futures to finish. waitForCompletion(futureList); + // Given that files are restored now, kick off post restore hook + logger.info("Starting post restore hook"); + postRestoreHook.execute(); + logger.info("Completed executing post restore hook"); + // Declare restore as finished. instanceState.getRestoreStatus().setExecutionEndTime(LocalDateTime.now()); instanceState.setRestoreStatus(Status.FINISHED); + + // Start cassandra if restore is successful. + if (!config.doesCassandraStartManually()) cassProcess.start(true); + else + logger.info( + "config.doesCassandraStartManually() is set to True, hence Cassandra needs to be started manually ..."); } catch (Exception e) { instanceState.setRestoreStatus(Status.FAILED); instanceState.getRestoreStatus().setExecutionEndTime(LocalDateTime.now());