You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2018/10/18 22:55:42 UTC
incubator-ratis git commit: RATIS-355. TestBatchAppend and
TestFileStore* are failing.
Repository: incubator-ratis
Updated Branches:
refs/heads/master 48d6a2a42 -> ca0a1271d
RATIS-355. TestBatchAppend and TestFileStore* are failing.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ratis/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ratis/commit/ca0a1271
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ratis/tree/ca0a1271
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ratis/diff/ca0a1271
Branch: refs/heads/master
Commit: ca0a1271d1ed73987c8910fc2cfacb1b1b18585e
Parents: 48d6a2a
Author: Tsz Wo Nicholas Sze <sz...@apache.org>
Authored: Fri Oct 19 06:55:08 2018 +0800
Committer: Tsz Wo Nicholas Sze <sz...@apache.org>
Committed: Fri Oct 19 06:55:08 2018 +0800
----------------------------------------------------------------------
.../java/org/apache/ratis/util/LifeCycle.java | 8 ++++++
.../apache/ratis/server/impl/LogAppender.java | 2 +-
.../ratis/server/impl/RaftServerImpl.java | 9 ++++---
.../java/org/apache/ratis/MiniRaftCluster.java | 28 +++++++++++---------
4 files changed, 29 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/ca0a1271/ratis-common/src/main/java/org/apache/ratis/util/LifeCycle.java
----------------------------------------------------------------------
diff --git a/ratis-common/src/main/java/org/apache/ratis/util/LifeCycle.java b/ratis-common/src/main/java/org/apache/ratis/util/LifeCycle.java
index f8f3648..824e409 100644
--- a/ratis-common/src/main/java/org/apache/ratis/util/LifeCycle.java
+++ b/ratis-common/src/main/java/org/apache/ratis/util/LifeCycle.java
@@ -131,6 +131,14 @@ public class LifeCycle {
State.validate(name, from, to);
}
+ /** Transition from the current state to the given state if the current state is not equal to the given state. */
+ public void transitionIfNotEqual(final State to) {
+ final State from = current.getAndSet(to);
+ if (from != to) {
+ State.validate(name, from, to);
+ }
+ }
+
/**
* If the current state is equal to the specified from state,
* then transition to the give to state; otherwise, make no change.
http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/ca0a1271/ratis-server/src/main/java/org/apache/ratis/server/impl/LogAppender.java
----------------------------------------------------------------------
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/LogAppender.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/LogAppender.java
index f26a48c..529bd7d 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/LogAppender.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/LogAppender.java
@@ -107,7 +107,7 @@ public class LogAppender {
lifeCycle.transition(EXCEPTION);
} finally {
if (!lifeCycle.compareAndTransition(CLOSING, CLOSED)) {
- lifeCycle.transition(EXCEPTION);
+ lifeCycle.transitionIfNotEqual(EXCEPTION);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/ca0a1271/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
----------------------------------------------------------------------
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
index c1e3303..115ea22 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
@@ -868,8 +868,8 @@ public class RaftServerImpl implements RaftServerProtocol, RaftServerAsynchronou
final List<CompletableFuture<Long>> futures;
final long currentTerm;
- long nextIndex = state.getLog().getNextIndex();
- long followerCommit = state.getLog().getLastCommittedIndex();
+ final long nextIndex = state.getLog().getNextIndex();
+ final long followerCommit = state.getLog().getLastCommittedIndex();
synchronized (this) {
final boolean recognized = state.recognizeLeader(leaderId, leaderTerm);
currentTerm = state.getCurrentTerm();
@@ -913,7 +913,7 @@ public class RaftServerImpl implements RaftServerProtocol, RaftServerAsynchronou
commitInfos.forEach(commitInfoCache::update);
}
- if (entries.length > 0) {
+ if (!isHeartbeat) {
CodeInjectionForTesting.execute(RaftLog.LOG_SYNC, getId(), null);
}
return JavaUtils.allOf(futures).thenApply(v -> {
@@ -925,8 +925,9 @@ public class RaftServerImpl implements RaftServerProtocol, RaftServerAsynchronou
updateLastRpcTime(false);
}
state.updateStatemachine(leaderCommit, currentTerm);
+ final long n = isHeartbeat? state.getLog().getNextIndex(): entries[entries.length - 1].getIndex() + 1;
reply = ServerProtoUtils.toAppendEntriesReplyProto(leaderId, getId(), groupId, currentTerm,
- state.getLog().getLastCommittedIndex(), state.getLog().getNextIndex(), SUCCESS, callId);
+ state.getLog().getLastCommittedIndex(), n, SUCCESS, callId);
}
logAppendEntries(isHeartbeat, () ->
getId() + ": succeeded to handle AppendEntries. Reply: " + ServerProtoUtils.toString(reply));
http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/ca0a1271/ratis-server/src/test/java/org/apache/ratis/MiniRaftCluster.java
----------------------------------------------------------------------
diff --git a/ratis-server/src/test/java/org/apache/ratis/MiniRaftCluster.java b/ratis-server/src/test/java/org/apache/ratis/MiniRaftCluster.java
index 921a7ce..2d28896 100644
--- a/ratis-server/src/test/java/org/apache/ratis/MiniRaftCluster.java
+++ b/ratis-server/src/test/java/org/apache/ratis/MiniRaftCluster.java
@@ -263,20 +263,22 @@ public abstract class MiniRaftCluster implements Closeable {
return STATEMACHINE_REGISTRY_DEFAULT;
}
- final RuntimeException exception;
- try {
- return gid -> ReflectionUtils.newInstance(smClass);
- } catch(RuntimeException e) {
- exception = e;
- }
+ return gid -> {
+ final RuntimeException exception;
+ try {
+ return ReflectionUtils.newInstance(smClass);
+ } catch(RuntimeException e) {
+ exception = e;
+ }
- try {
- final Class<?>[] argClasses = {RaftProperties.class};
- return gid -> ReflectionUtils.newInstance(smClass, argClasses, properties);
- } catch(RuntimeException e) {
- exception.addSuppressed(e);
- }
- throw exception;
+ try {
+ final Class<?>[] argClasses = {RaftProperties.class};
+ return ReflectionUtils.newInstance(smClass, argClasses, properties);
+ } catch(RuntimeException e) {
+ exception.addSuppressed(e);
+ }
+ throw exception;
+ };
}
public static List<RaftPeer> toRaftPeers(