You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ms...@apache.org on 2019/03/09 17:17:00 UTC

[hadoop] branch trunk updated: HDDS-1238. Fix Ratis Snapshot creation error if the snapshot file already exists in ContainerStateMachine. Contributed by Shashikant Banerjee.

This is an automated email from the ASF dual-hosted git repository.

msingh pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 8458ced  HDDS-1238. Fix Ratis Snapshot creation error if the snapshot file already exists in ContainerStateMachine. Contributed by Shashikant Banerjee.
8458ced is described below

commit 8458ced11e5b6690a41593c247c1190bf3f31c0b
Author: Mukul Kumar Singh <ms...@apache.org>
AuthorDate: Sat Mar 9 22:46:20 2019 +0530

    HDDS-1238. Fix Ratis Snapshot creation error if the snapshot file already exists in ContainerStateMachine. Contributed by Shashikant Banerjee.
---
 .../transport/server/ratis/ContainerStateMachine.java     | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java
index 0fc2d0d..7caf0c2 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java
@@ -249,20 +249,13 @@ public class ContainerStateMachine extends BaseStateMachine {
   public long takeSnapshot() throws IOException {
     TermIndex ti = getLastAppliedTermIndex();
     LOG.info("Taking snapshot at termIndex:" + ti);
-    if (ti != null) {
+    if (ti != null && ti.getIndex() != RaftServerConstants.INVALID_LOG_INDEX) {
       final File snapshotFile =
           storage.getSnapshotFile(ti.getTerm(), ti.getIndex());
       LOG.info("Taking a snapshot to file {}", snapshotFile);
-      try {
-        //TODO: For now, just create the file to save the term index,
-        boolean created = snapshotFile.createNewFile();
-        if (!created) {
-          throw new IOException("Failed to create ratis snapshot file");
-        }
-        try (FileOutputStream fos = new FileOutputStream(snapshotFile)) {
-          persistContainerSet(fos);
-        }
-      } catch(IOException ioe) {
+      try (FileOutputStream fos = new FileOutputStream(snapshotFile)) {
+        persistContainerSet(fos);
+      } catch (IOException ioe) {
         LOG.warn("Failed to write snapshot file \"" + snapshotFile
             + "\", last applied index=" + ti);
         throw ioe;


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org