use of alluxio.exception.status.AbortedException in project alluxio by Alluxio.
the class SnapshotReplicationManager method installDownloadedSnapshot.
/**
* Installs a downloaded snapshot in the journal snapshot directory.
*
* @return the index of the installed snapshot
*/
private long installDownloadedSnapshot() {
if (!transitionState(DownloadState.DOWNLOADED, DownloadState.INSTALLING)) {
return RaftLog.INVALID_LOG_INDEX;
}
File tempFile = null;
try (Timer.Context ctx = MetricsSystem.timer(MetricKey.MASTER_EMBEDDED_JOURNAL_SNAPSHOT_INSTALL_TIMER.getName()).time()) {
SnapshotInfo snapshot = mDownloadedSnapshot;
if (snapshot == null) {
throw new IllegalStateException("Snapshot is not completed");
}
FileInfo fileInfo = snapshot.getFiles().get(0);
tempFile = fileInfo.getPath().toFile();
if (!tempFile.exists()) {
throw new FileNotFoundException(String.format("Snapshot file %s is not found", tempFile));
}
SnapshotInfo latestSnapshot = mStorage.getLatestSnapshot();
TermIndex lastInstalled = latestSnapshot == null ? null : latestSnapshot.getTermIndex();
TermIndex downloaded = snapshot.getTermIndex();
if (lastInstalled != null && downloaded.compareTo(lastInstalled) < 0) {
throw new AbortedException(String.format("Snapshot to be installed %s is older than current snapshot %s", downloaded, lastInstalled));
}
final File snapshotFile = mStorage.getSnapshotFile(downloaded.getTerm(), downloaded.getIndex());
LOG.debug("Moving temp snapshot {} to file {}", tempFile, snapshotFile);
MD5FileUtil.saveMD5File(snapshotFile, fileInfo.getFileDigest());
if (!tempFile.renameTo(snapshotFile)) {
throw new IOException(String.format("Failed to rename %s to %s", tempFile, snapshotFile));
}
mStorage.loadLatestSnapshot();
LOG.info("Completed storing snapshot at {} to file {}", downloaded, snapshotFile);
return downloaded.getIndex();
} catch (Exception e) {
LOG.error("Failed to install snapshot", e);
if (tempFile != null) {
tempFile.delete();
}
return RaftLog.INVALID_LOG_INDEX;
} finally {
transitionState(DownloadState.INSTALLING, DownloadState.IDLE);
}
}
Aggregations