LebronAl commented on a change in pull request #1112:
URL: https://github.com/apache/incubator-iotdb/pull/1112#discussion_r417291302
##########
File path:
cluster/src/main/java/org/apache/iotdb/cluster/server/member/RaftMember.java
##########
@@ -384,7 +385,89 @@ public void appendEntry(AppendEntryRequest request,
AsyncMethodCallback resultHa
@Override
public void appendEntries(AppendEntriesRequest request, AsyncMethodCallback
resultHandler) {
- //TODO-Cluster#354: implement
+ logger.debug("{} received an AppendEntriesRequest", name);
+
+ // the term checked here is that of the leader, not that of the log
+ if (!checkRequestTerm(request, resultHandler)) {
+ return;
+ }
+
+ try {
+ long response = 0;
+ List<Log> logs = new ArrayList<>();
+ for (ByteBuffer buffer : request.getEntries()) {
+ Log log = LogParser.getINSTANCE().parse(buffer);
+ logs.add(log);
+ }
+
+ response = appendEntries(logs);
+ resultHandler.onComplete(response);
+ logger.debug("{} AppendEntriesRequest of log size {} completed", name,
+ request.getEntries().size());
+ } catch (UnknownLogTypeException e) {
+ resultHandler.onError(e);
+ }
+ }
+
+ /**
+ * Find the local previous log of "log". If such log is found, discard all
local logs behind it
+ * and append "log" to it. Otherwise report a log mismatch.
+ *
+ * @param logs
+ * @return Response.RESPONSE_AGREE when the log is successfully appended or
Response
+ * .RESPONSE_LOG_MISMATCH if the previous log of "log" is not found.
+ */
+ private long appendEntries(List<Log> logs) {
Review comment:
In my view, `maybeAppend ` will make catchUp more fault-tolerant.When
catching up in batch, even if the index of the first log sent is smaller than
follower's commitIndex, some previous logs can be removed. Otherwise, if the
index of the first Log is smaller than follower's commitindex, such a batch of
logs cannot be appended.
----------------------------------------------------------------
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:
[email protected]