jt2594838 commented on a change in pull request #1112:
URL: https://github.com/apache/incubator-iotdb/pull/1112#discussion_r417237965
##########
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:
I guess LebronAl is talking about the chance that the logs are disjoint
with the local last log, but as `appendEntries` is only used in catch-up, I
think the possibility of that case is relatively low.
Still, it would be better to check the index of the first coming log and the
last local log, which I previously hoped to be done inside the LogManager. As
you can see, other users may not bother to do the checks (the may not know the
checks actually), so any necessary checks are better to be done within
underlined classes.
----------------------------------------------------------------
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]