Skip to content

Commit

Permalink
leader is elected
Browse files Browse the repository at this point in the history
  • Loading branch information
simbo1905 committed Sep 24, 2024
1 parent 8dfd296 commit 19ad646
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions trex2-lib/src/main/java/com/github/trex_paxos/TrexNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,16 @@ case Accept(_, _, _, NoOperation _) -> {
}
case PrepareResponse prepareResponse -> {
if (RECOVER == role) {
if (prepareResponse.catchupResponse().isPresent()) {
// FIXME we should handle this
}
if (prepareResponse.highestUncommitted().isPresent()) {
//noinspection OptionalGetWithoutIsPresent
if (prepareResponse.highestUncommitted().isPresent() && prepareResponse.highestCommittedIndex().isPresent()) {
final long highestCommittedOther = prepareResponse.highestCommittedIndex().get();
final long highestCommitted = progress.highestCommitted();
if (highestCommitted < highestCommittedOther) {
// we are behind so now try to catch up
saveCatchup(prepareResponse.catchupResponse().get());
// this may be evidence of a new leader so back down
backdown();
prepareResponse.catchupResponse().ifPresent(catchupResponse -> {
saveCatchup(catchupResponse);
// this is evidence of a new leader so back down
backdown();
});
}
} else if (prepareResponse.vote().to() == nodeIdentifier) {
final byte from = prepareResponse.from();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public Progress loadProgress(byte nodeIdentifier) {

@Override
public Optional<Accept> loadAccept(long logIndex) {
return logIndex >= fakeJournal.size() ? Optional.empty() : Optional.ofNullable(fakeJournal.get((int) logIndex));
return Optional.ofNullable(fakeJournal.get(logIndex));
}
}

Expand Down

0 comments on commit 19ad646

Please sign in to comment.