From 26c1f04ccae5fd176b9f6071fe6be4b1604a05ef Mon Sep 17 00:00:00 2001 From: 133tosakarin <97331129+133tosakarin@users.noreply.github.com> Date: Sun, 10 Nov 2024 10:17:29 +0800 Subject: [PATCH] RATIS-2177. Purge should delete segmentLog from small to large according to logIndex (#1174) --- .../server/raftlog/segmented/SegmentedRaftLogWorker.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java index a44be6ee55..98b20bade3 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java @@ -482,9 +482,10 @@ private PurgeLog(TruncationSegments segments) { void execute() throws IOException { if (segments.getToDelete() != null) { try(UncheckedAutoCloseable ignored = raftLogMetrics.startPurgeTimer()) { - for (SegmentFileInfo fileInfo : segments.getToDelete()) { - final Path deleted = FileUtils.deleteFile(fileInfo.getFile(storage)); - LOG.info("{}: Purged RaftLog segment: info={}, path={}", name, fileInfo, deleted); + SegmentFileInfo[] toDeletes = segments.getToDelete(); + for (int i = toDeletes.length - 1; i >= 0; i--) { + final Path deleted = FileUtils.deleteFile(toDeletes[i].getFile(storage)); + LOG.info("{}: Purged RaftLog segment: info={}, path={}", name, toDeletes[i], deleted); } } }