You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2020/12/09 15:43:01 UTC

[GitHub] [incubator-ratis] errose28 opened a new pull request #344: RATIS-1216. State machine preAppend callback can throw exception without having leader to step down.

errose28 opened a new pull request #344:
URL: https://github.com/apache/incubator-ratis/pull/344


   ## What changes were proposed in this pull request?
   
   Add a flag to `StateMachineException` to indicate whether the exception should cause the leader to step down. In `RaftServerImpl#appendTransaction`, only trigger a leader step down if the flag in the StateMachineException is enabled.
   
   ## What is the link to the Apache JIRA
   
   RATIS-1216
   
   ## How was this patch tested?
   
   Integration tests added.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] szetszwo merged pull request #344: RATIS-1216. State machine preAppend callback can throw exception without having leader to step down.

Posted by GitBox <gi...@apache.org>.
szetszwo merged pull request #344:
URL: https://github.com/apache/incubator-ratis/pull/344


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] errose28 commented on a change in pull request #344: RATIS-1216. State machine preAppend callback can throw exception without having leader to step down.

Posted by GitBox <gi...@apache.org>.
errose28 commented on a change in pull request #344:
URL: https://github.com/apache/incubator-ratis/pull/344#discussion_r540301572



##########
File path: ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/StateMachineException.java
##########
@@ -20,18 +20,31 @@
 import org.apache.ratis.protocol.RaftGroupMemberId;
 
 public class StateMachineException extends RaftException {
+  private boolean leaderShouldStepDown;

Review comment:
       Yes, I'll fix this, thanks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] errose28 commented on a change in pull request #344: RATIS-1216. State machine preAppend callback can throw exception without having leader to step down.

Posted by GitBox <gi...@apache.org>.
errose28 commented on a change in pull request #344:
URL: https://github.com/apache/incubator-ratis/pull/344#discussion_r540301156



##########
File path: ratis-server/src/test/java/org/apache/ratis/server/impl/PreAppendLeaderStepDownTest.java
##########
@@ -0,0 +1,115 @@
+/*
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ratis.server.impl;
+
+import org.apache.log4j.Level;
+import org.apache.ratis.BaseTest;
+import org.apache.ratis.RaftTestUtil;
+import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.client.RaftClientRpc;
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.protocol.RaftClientRequest;
+import org.apache.ratis.protocol.exceptions.StateMachineException;
+import org.apache.ratis.server.RaftServer;
+import org.apache.ratis.server.raftlog.RaftLog;
+import org.apache.ratis.statemachine.SimpleStateMachine4Testing;
+import org.apache.ratis.statemachine.StateMachine;
+import org.apache.ratis.statemachine.TransactionContext;
+import org.apache.ratis.util.Log4jUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * Tests the leader step down flag in {@link StateMachineException}, which
+ * determines whether the leader should step down or not when it receives the
+ * exception from {@link StateMachine#preAppendTransaction}.
+ */
+public abstract class PreAppendLeaderStepDownTest<CLUSTER extends MiniRaftCluster>
+    extends BaseTest implements MiniRaftCluster.Factory.Get<CLUSTER> {
+  {
+    Log4jUtils.setLogLevel(RaftServer.Division.LOG, Level.DEBUG);
+    Log4jUtils.setLogLevel(RaftLog.LOG, Level.DEBUG);
+    Log4jUtils.setLogLevel(RaftClient.LOG, Level.DEBUG);
+  }
+
+  private static volatile boolean leaderShouldStepDown = false;
+
+  protected static class StateMachineWithException extends
+      SimpleStateMachine4Testing {
+
+    @Override
+    public TransactionContext preAppendTransaction(TransactionContext trx)
+        throws IOException {
+      StateMachineException ex = new StateMachineException(
+          "Fake Exception in preAppend");
+      if (!leaderShouldStepDown) {
+        ex.setLeaderShouldStepDown(false);

Review comment:
       Will do




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] errose28 commented on pull request #344: RATIS-1216. State machine preAppend callback can throw exception without having leader to step down.

Posted by GitBox <gi...@apache.org>.
errose28 commented on pull request #344:
URL: https://github.com/apache/incubator-ratis/pull/344#issuecomment-741864208


   cc @hanishakoneru @szetszwo @lokeshj1703 Could you please help review? Thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] szetszwo commented on a change in pull request #344: RATIS-1216. State machine preAppend callback can throw exception without having leader to step down.

Posted by GitBox <gi...@apache.org>.
szetszwo commented on a change in pull request #344:
URL: https://github.com/apache/incubator-ratis/pull/344#discussion_r539737458



##########
File path: ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/StateMachineException.java
##########
@@ -20,18 +20,31 @@
 import org.apache.ratis.protocol.RaftGroupMemberId;
 
 public class StateMachineException extends RaftException {
+  private boolean leaderShouldStepDown;

Review comment:
       Please make it final and remove setLeaderShouldStepDown(..).  Exception objects should be immutable.

##########
File path: ratis-server/src/test/java/org/apache/ratis/server/impl/PreAppendLeaderStepDownTest.java
##########
@@ -0,0 +1,115 @@
+/*
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ratis.server.impl;
+
+import org.apache.log4j.Level;
+import org.apache.ratis.BaseTest;
+import org.apache.ratis.RaftTestUtil;
+import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.client.RaftClientRpc;
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.protocol.RaftClientRequest;
+import org.apache.ratis.protocol.exceptions.StateMachineException;
+import org.apache.ratis.server.RaftServer;
+import org.apache.ratis.server.raftlog.RaftLog;
+import org.apache.ratis.statemachine.SimpleStateMachine4Testing;
+import org.apache.ratis.statemachine.StateMachine;
+import org.apache.ratis.statemachine.TransactionContext;
+import org.apache.ratis.util.Log4jUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * Tests the leader step down flag in {@link StateMachineException}, which
+ * determines whether the leader should step down or not when it receives the
+ * exception from {@link StateMachine#preAppendTransaction}.
+ */
+public abstract class PreAppendLeaderStepDownTest<CLUSTER extends MiniRaftCluster>
+    extends BaseTest implements MiniRaftCluster.Factory.Get<CLUSTER> {
+  {
+    Log4jUtils.setLogLevel(RaftServer.Division.LOG, Level.DEBUG);
+    Log4jUtils.setLogLevel(RaftLog.LOG, Level.DEBUG);
+    Log4jUtils.setLogLevel(RaftClient.LOG, Level.DEBUG);
+  }
+
+  private static volatile boolean leaderShouldStepDown = false;
+
+  protected static class StateMachineWithException extends
+      SimpleStateMachine4Testing {
+
+    @Override
+    public TransactionContext preAppendTransaction(TransactionContext trx)
+        throws IOException {
+      StateMachineException ex = new StateMachineException(
+          "Fake Exception in preAppend");
+      if (!leaderShouldStepDown) {
+        ex.setLeaderShouldStepDown(false);

Review comment:
       We should pass leaderShouldStepDown using constructors.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] errose28 commented on pull request #344: RATIS-1216. State machine preAppend callback can throw exception without having leader to step down.

Posted by GitBox <gi...@apache.org>.
errose28 commented on pull request #344:
URL: https://github.com/apache/incubator-ratis/pull/344#issuecomment-742624192


   Thanks for the review @szetszwo, I have updated the StateMachineException to be immutable.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org