HDDS-1238. Fix Ratis Snapshot creation error if the snapshot file already exists in ContainerStateMachine. Contributed by Shashikant Banerjee.
This commit is contained in:
parent
0cbe9ad8c2
commit
8458ced11e
|
@ -249,20 +249,13 @@ public class ContainerStateMachine extends BaseStateMachine {
|
||||||
public long takeSnapshot() throws IOException {
|
public long takeSnapshot() throws IOException {
|
||||||
TermIndex ti = getLastAppliedTermIndex();
|
TermIndex ti = getLastAppliedTermIndex();
|
||||||
LOG.info("Taking snapshot at termIndex:" + ti);
|
LOG.info("Taking snapshot at termIndex:" + ti);
|
||||||
if (ti != null) {
|
if (ti != null && ti.getIndex() != RaftServerConstants.INVALID_LOG_INDEX) {
|
||||||
final File snapshotFile =
|
final File snapshotFile =
|
||||||
storage.getSnapshotFile(ti.getTerm(), ti.getIndex());
|
storage.getSnapshotFile(ti.getTerm(), ti.getIndex());
|
||||||
LOG.info("Taking a snapshot to file {}", snapshotFile);
|
LOG.info("Taking a snapshot to file {}", snapshotFile);
|
||||||
try {
|
try (FileOutputStream fos = new FileOutputStream(snapshotFile)) {
|
||||||
//TODO: For now, just create the file to save the term index,
|
persistContainerSet(fos);
|
||||||
boolean created = snapshotFile.createNewFile();
|
} catch (IOException ioe) {
|
||||||
if (!created) {
|
|
||||||
throw new IOException("Failed to create ratis snapshot file");
|
|
||||||
}
|
|
||||||
try (FileOutputStream fos = new FileOutputStream(snapshotFile)) {
|
|
||||||
persistContainerSet(fos);
|
|
||||||
}
|
|
||||||
} catch(IOException ioe) {
|
|
||||||
LOG.warn("Failed to write snapshot file \"" + snapshotFile
|
LOG.warn("Failed to write snapshot file \"" + snapshotFile
|
||||||
+ "\", last applied index=" + ti);
|
+ "\", last applied index=" + ti);
|
||||||
throw ioe;
|
throw ioe;
|
||||||
|
|
Loading…
Reference in New Issue