Skip to content

Commit

Permalink
refactor: move TailCache truncate to AppendProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
areyouok committed Nov 15, 2024
1 parent 2efdb8c commit eb19314
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.github.dtprj.dongting.raft.impl.RaftStatusImpl;
import com.github.dtprj.dongting.raft.impl.RaftTask;
import com.github.dtprj.dongting.raft.impl.RaftUtil;
import com.github.dtprj.dongting.raft.impl.TailCache;
import com.github.dtprj.dongting.raft.server.LogItem;
import com.github.dtprj.dongting.raft.server.RaftGroup;
import com.github.dtprj.dongting.raft.server.RaftInput;
Expand Down Expand Up @@ -413,6 +414,9 @@ private FrameCallResult resumeWhenFindReplicatePosFinish(Pair<Integer, Long> pos
private FrameCallResult truncateAndAppend(long matchIndex, int matchTerm) {
gc.getRaftStatus().setTruncating(true);
long truncateIndex = matchIndex + 1;

TailCache tailCache = reqInfo.getRaftGroup().getGroupComponents().getRaftStatus().getTailCache();
tailCache.truncate(truncateIndex);
return Fiber.call(gc.getRaftLog().truncateTail(truncateIndex), v -> afterTruncate(matchIndex, matchTerm));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.github.dtprj.dongting.raft.impl.FileUtil;
import com.github.dtprj.dongting.raft.impl.RaftStatusImpl;
import com.github.dtprj.dongting.raft.impl.RaftUtil;
import com.github.dtprj.dongting.raft.impl.TailCache;
import com.github.dtprj.dongting.raft.server.LogItem;
import com.github.dtprj.dongting.raft.server.RaftGroupConfigEx;
import com.github.dtprj.dongting.raft.sm.RaftCodecFactory;
Expand Down Expand Up @@ -136,8 +135,6 @@ public FiberFrame<Void> truncateTail(long index) {
return new FiberFrame<>() {
@Override
public FrameCallResult execute(Void input) {
TailCache tailCache = raftStatus.getTailCache();
tailCache.truncate(index);
return Fiber.call(idxFiles.loadLogPos(index), this::afterPosLoad);
}

Expand Down

0 comments on commit eb19314

Please sign in to comment.