Skip to content

Commit

Permalink
fix(core): fix commit without check
Browse files Browse the repository at this point in the history
1. fix commit without check

Closes openmessaging#278
  • Loading branch information
TheR1sing3un committed Mar 10, 2023
1 parent b227855 commit fc7648a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private void checkResponseFuturesElapsed(final long endIndex) {

private void updateCommittedIndex(final long term, final long committedIndex) {
dLedgerStore.updateCommittedIndex(term, committedIndex);
this.fsmCaller.ifPresent(caller -> caller.onCommitted(committedIndex));
this.fsmCaller.ifPresent(caller -> caller.onCommitted(dLedgerStore.getCommittedIndex()));
}

/**
Expand Down Expand Up @@ -874,7 +874,7 @@ private void handleDoAppend(long writeIndex, PushEntryRequest request,
future.complete(buildResponse(request, DLedgerResponseCode.SUCCESS.getCode()));
updateCommittedIndex(request.getTerm(), request.getCommitIndex());
} catch (Throwable t) {
logger.error("[HandleDoWrite] writeIndex={}", writeIndex, t);
logger.error("[HandleDoAppend] writeIndex={}", writeIndex, t);
future.complete(buildResponse(request, DLedgerResponseCode.INCONSISTENT_STATE.getCode()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public StateMachine getStateMachine() {
}

public boolean onCommitted(final long committedIndex) {
if (committedIndex <= this.lastAppliedIndex.get()) return false;
final ApplyTask task = new ApplyTask();
task.type = TaskType.COMMITTED;
task.committedIndex = committedIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public DLedgerEntry get(Long index) {
}
}

public Pair<Long, Integer> getEntryPosAndSize(Long index) {
private Pair<Long, Integer> getEntryPosAndSize(Long index) {
indexCheck(index);
SelectMmapBufferResult indexSbr = null;
try {
Expand All @@ -625,7 +625,7 @@ public Pair<Long, Integer> getEntryPosAndSize(Long index) {
}
}

public void indexCheck(Long index) {
private void indexCheck(Long index) {
PreConditions.check(index >= 0, DLedgerResponseCode.INDEX_OUT_OF_RANGE, "%d should gt 0", index);
PreConditions.check(index > ledgerBeforeBeginIndex, DLedgerResponseCode.INDEX_LESS_THAN_LOCAL_BEGIN, "%d should be gt %d, beforeBeginIndex may be revised", index, ledgerBeforeBeginIndex);
PreConditions.check(index <= ledgerEndIndex, DLedgerResponseCode.INDEX_OUT_OF_RANGE, "%d should between (%d-%d]", index, ledgerBeforeBeginIndex, ledgerEndIndex);
Expand Down

0 comments on commit fc7648a

Please sign in to comment.