Skip to content

Commit 72c920c

Browse files
RATIS-2237 Add getFollowerMatchIndices interface for DivisionInfo
Signed-off-by: OneSizeFitQuorum <[email protected]>
1 parent bdde3ae commit 72c920c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

ratis-server-api/src/main/java/org/apache/ratis/server/DivisionInfo.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,10 @@ default boolean isAlive() {
8080
* otherwise, return null.
8181
*/
8282
long[] getFollowerNextIndices();
83+
84+
/**
85+
* @return an array of match indices of the followers if this server division is the leader;
86+
* otherwise, return null.
87+
*/
88+
long[] getFollowerMatchIndices();
8389
}

ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,10 @@ long[] getFollowerNextIndices() {
12141214
return getLogAppenders().mapToLong(s -> s.getFollower().getNextIndex()).toArray();
12151215
}
12161216

1217+
long[] getFollowerMatchIndices() {
1218+
return getLogAppenders().mapToLong(s -> s.getFollower().getMatchIndex()).toArray();
1219+
}
1220+
12171221
static Map<RaftPeerId, RaftPeer> newMap(Collection<RaftPeer> peers, String str) {
12181222
Objects.requireNonNull(peers, () -> str + " == null");
12191223
final Map<RaftPeerId, RaftPeer> map = new HashMap<>();

ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ public long[] getFollowerNextIndices() {
206206
.map(LeaderStateImpl::getFollowerNextIndices)
207207
.orElse(null);
208208
}
209+
210+
@Override
211+
public long[] getFollowerMatchIndices() {
212+
return role.getLeaderState()
213+
.filter(leader -> isLeader())
214+
.map(LeaderStateImpl::getFollowerMatchIndices)
215+
.orElse(null);
216+
}
209217
}
210218

211219
private final RaftServerProxy proxy;

0 commit comments

Comments
 (0)