Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #278] Fix the bug because of enqueueing an unchecked commit task #279

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,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 @@ -895,13 +895,14 @@ private PushEntryResponse buildResponse(PushEntryRequest request, int code) {
private void handleDoAppend(long writeIndex, PushEntryRequest request,
CompletableFuture<PushEntryResponse> future) {
try {
logger.info("[HandleDoAppend] writerIndex = {}, entry index = {} pos = {}", writeIndex, request.getEntry().getIndex(), request.getEntry().getPos());
TheR1sing3un marked this conversation as resolved.
Show resolved Hide resolved
PreConditions.check(writeIndex == request.getEntry().getIndex(), DLedgerResponseCode.INCONSISTENT_STATE);
DLedgerEntry entry = dLedgerStore.appendAsFollower(request.getEntry(), request.getTerm(), request.getLeaderId());
PreConditions.check(entry.getIndex() == writeIndex, DLedgerResponseCode.INCONSISTENT_STATE);
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 @@ -90,9 +90,11 @@ 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;
logger.info("enqueue a commit task with commit index = {}", committedIndex);
TheR1sing3un marked this conversation as resolved.
Show resolved Hide resolved
return enqueueTask(task);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,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 @@ -574,7 +574,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 >= ledgerBeginIndex, DLedgerResponseCode.INDEX_LESS_THAN_LOCAL_BEGIN, "%d should be gt %d, ledgerBeginIndex may be revised", index, ledgerBeginIndex);
PreConditions.check(index <= ledgerEndIndex, DLedgerResponseCode.INDEX_OUT_OF_RANGE, "%d should between %d-%d", index, ledgerBeginIndex, ledgerEndIndex);
Expand Down