-
Notifications
You must be signed in to change notification settings - Fork 9
/
RaftService.java
executable file
·62 lines (56 loc) · 2.41 KB
/
RaftService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package io.lubricant.consensus.raft;
import io.lubricant.consensus.raft.command.RaftLog.Entry;
import io.lubricant.consensus.raft.transport.RaftCluster.ID;
import io.lubricant.consensus.raft.transport.rpc.Async;
/**
* RPC 接口
* */
public interface RaftService {
/**
* 复制日志+发送心跳(由 leader 调用)
* @param term leader 任期
* @param leaderId leader 在集群中的唯一标识
* @param prevLogIndex 紧接在新的之前的日志条目索引
* @param prevLogTerm prevLogIndex 对应的任期
* @param entries 日志条目(发送心跳时为空)
* @param leaderCommit leader 已经提交的日志条目索引
* @return 当 follower 中的日志包含 prevLogIndex 与 prevLogTerm 匹配的日志条目返回 true
* */
Async<RaftResponse> appendEntries(
long term, ID leaderId,
long prevLogIndex, long prevLogTerm,
Entry[] entries, long leaderCommit) throws Exception;
/**
* 预选(由 follower 调用)
* @param term candidate 任期
* @param candidateId candidate 在集群中的唯一标识
* @param lastLogIndex candidate 最后一条日志条目的索引
* @param lastLogTerm candidate 最后一条日志条目的任期
* @return 当收到赞成票时返回 true
* */
Async<RaftResponse> preVote(
long term, ID candidateId,
long lastLogIndex, long lastLogTerm) throws Exception;
/**
* 选主(由 candidate 调用)
* @param term candidate 任期
* @param candidateId candidate 在集群中的唯一标识
* @param lastLogIndex candidate 最后一条日志条目的索引
* @param lastLogTerm candidate 最后一条日志条目的任期
* @return 当收到赞成票时返回 true
* */
Async<RaftResponse> requestVote(
long term, ID candidateId,
long lastLogIndex, long lastLogTerm) throws Exception;
/**
* 同步快照(由 leader 调用)
* @param term leader 任期
* @param leaderId leader 在集群中的唯一标识
* @param lastIncludedIndex 快照将替换所有条目,直至包括该索引
* @param lastIncludedTerm lastIncludedIndex 对应的任期
* @return 当同步完成时返回 true
*/
Async<RaftResponse> installSnapshot(
long term, ID leaderId,
long lastIncludedIndex, long lastIncludedTerm) throws Exception;
}