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

fix: follower should try clean pending closure to avoid memory leak #309

Merged
merged 5 commits into from
Aug 11, 2023
Merged
Changes from 2 commits
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 @@ -226,6 +226,7 @@ public void checkResponseFuturesTimeout(final long beginIndex) {
break;
} else if (closure.isTimeOut()) {
closure.done(Status.error(DLedgerResponseCode.WAIT_QUORUM_ACK_TIMEOUT));
closureMap.remove(i);
} else {
break;
}
Expand Down Expand Up @@ -254,6 +255,7 @@ private class QuorumAckChecker extends ShutdownAbleThread {

private long lastPrintWatermarkTimeMs = System.currentTimeMillis();
private long lastCheckLeakTimeMs = System.currentTimeMillis();
private long lastCheckFollowerTimeMs = System.currentTimeMillis();

public QuorumAckChecker(Logger logger) {
super("QuorumAckChecker-" + memberState.getSelfId(), logger);
Expand All @@ -267,10 +269,7 @@ public void doWork() {
memberState.getSelfId(), memberState.getRole(), memberState.currTerm(), dLedgerStore.getLedgerBeforeBeginIndex(), dLedgerStore.getLedgerEndIndex(), memberState.getCommittedIndex(), JSON.toJSONString(peerWaterMarksByTerm), memberState.getAppliedIndex());
lastPrintWatermarkTimeMs = System.currentTimeMillis();
}
if (!memberState.isLeader()) {
waitForRunning(1);
return;
}

long currTerm = memberState.currTerm();
checkTermForPendingMap(currTerm, "QuorumAckChecker");
checkTermForWaterMark(currTerm, "QuorumAckChecker");
Expand Down Expand Up @@ -304,6 +303,30 @@ public void doWork() {
lastCheckLeakTimeMs = System.currentTimeMillis();
}

if (!memberState.isLeader()) {
if (DLedgerUtils.elapsed(lastCheckFollowerTimeMs) > 1000) {
ConcurrentMap<Long, Closure> closureMap = pendingClosure.get(currTerm);
if (closureMap != null) {
for (Map.Entry<Long, Closure> futureEntry : closureMap.entrySet()) {
if (futureEntry == null) {
continue;
}
Closure closure = futureEntry.getValue();
if (closure == null) {
continue;
}
if (closure.isTimeOut()) {
closure.done(Status.error(DLedgerResponseCode.WAIT_QUORUM_ACK_TIMEOUT));
closureMap.remove(futureEntry.getKey());
}
}
}
lastCheckFollowerTimeMs = System.currentTimeMillis();
}
waitForRunning(1);
return;
}

// clear the timeout pending closure which index > appliedIndex
checkResponseFuturesTimeout(DLedgerEntryPusher.this.memberState.getAppliedIndex() + 1);

Expand Down
Loading