ratis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msi...@apache.org
Subject [incubator-ratis] branch master updated: RATIS-460. Once a snapshot is created an exception will be thrown when reply entries after restarting cluster. Contributed by Tsz Wo Nicholas Sze.
Date Wed, 30 Jan 2019 08:50:02 GMT
This is an automated email from the ASF dual-hosted git repository.

msingh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new f283ffa  RATIS-460. Once a snapshot is created an exception will be thrown when reply
entries after restarting cluster. Contributed by Tsz Wo Nicholas Sze.
f283ffa is described below

commit f283ffacb771130c70bdebb61d020fbc0c2aca46
Author: Mukul Kumar Singh <msingh@apache.org>
AuthorDate: Wed Jan 30 14:18:39 2019 +0530

    RATIS-460. Once a snapshot is created an exception will be thrown when reply entries after
restarting cluster. Contributed by Tsz Wo Nicholas Sze.
---
 .../org/apache/ratis/server/impl/ConfigurationManager.java   | 12 ++++--------
 .../org/apache/ratis/statemachine/RaftSnapshotBaseTest.java  | 12 ++++++++----
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/ConfigurationManager.java
b/ratis-server/src/main/java/org/apache/ratis/server/impl/ConfigurationManager.java
index a95683b..5106cb4 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/ConfigurationManager.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/ConfigurationManager.java
@@ -30,8 +30,7 @@ import java.util.*;
  */
 public class ConfigurationManager {
   private final RaftConfiguration initialConf;
-  private final NavigableMap<Long, RaftConfiguration> configurations =
-      new TreeMap<>();
+  private final NavigableMap<Long, RaftConfiguration> configurations = new TreeMap<>();
   /**
    * The current raft configuration. If configurations is not empty, should be
    * the last entry of the map. Otherwise is initialConf.
@@ -49,13 +48,10 @@ public class ConfigurationManager {
       Preconditions.assertTrue(found.equals(conf));
       return;
     }
-    if (!configurations.isEmpty()) {
-      final Map.Entry<Long, RaftConfiguration> lastEntry = configurations.lastEntry();
-      Preconditions.assertTrue(lastEntry.getKey() < logIndex,
-          () -> "lastEntry = " + lastEntry + ", lastEntry.index >= logIndex = " + logIndex);
-    }
     configurations.put(logIndex, conf);
-    this.currentConf = conf;
+    if (logIndex == configurations.lastEntry().getKey()) {
+      currentConf = conf;
+    }
   }
 
   synchronized RaftConfiguration getCurrent() {
diff --git a/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java
b/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java
index 61fc1ad..f734ae6 100644
--- a/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java
+++ b/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -135,7 +135,7 @@ public abstract class RaftSnapshotBaseTest extends BaseTest {
     // wait for the snapshot to be done
     final List<File> snapshotFiles = getSnapshotFiles(cluster, nextIndex - SNAPSHOT_TRIGGER_THRESHOLD,
nextIndex);
     JavaUtils.attempt(() -> snapshotFiles.stream().anyMatch(RaftSnapshotBaseTest::exists),
-        10, 1000, "snapshotFile.exist", LOG);
+        10, ONE_SECOND, "snapshotFile.exist", LOG);
 
     // restart the peer and check if it can correctly load snapshot
     cluster.restart(false);
@@ -163,11 +163,11 @@ public abstract class RaftSnapshotBaseTest extends BaseTest {
   @Test
   public void testBasicInstallSnapshot() throws Exception {
     final List<LogPathAndIndex> logs;
+    int i = 0;
     try {
       RaftTestUtil.waitForLeader(cluster);
       final RaftPeerId leaderId = cluster.getLeader().getId();
 
-      int i = 0;
       try(final RaftClient client = cluster.createClient(leaderId)) {
         for (; i < SNAPSHOT_TRIGGER_THRESHOLD * 2 - 1; i++) {
           RaftClientReply reply = client.send(new SimpleMessage("m" + i));
@@ -202,7 +202,7 @@ public abstract class RaftSnapshotBaseTest extends BaseTest {
 
       // generate some more traffic
       try(final RaftClient client = cluster.createClient(cluster.getLeader().getId())) {
-        Assert.assertTrue(client.send(new SimpleMessage("test")).isSuccess());
+        Assert.assertTrue(client.send(new SimpleMessage("m" + i)).isSuccess());
       }
 
       // add two more peers
@@ -212,6 +212,10 @@ public abstract class RaftSnapshotBaseTest extends BaseTest {
       cluster.setConfiguration(change.allPeersInNewConf);
 
       RaftServerTestUtil.waitAndCheckNewConf(cluster, change.allPeersInNewConf, 0, null);
+
+      // restart the peer and check if it can correctly handle conf change
+      cluster.restartServer(cluster.getLeader().getId(), false);
+      assertLeaderContent(cluster);
     } finally {
       cluster.shutdown();
     }


Mime
View raw message