szetszwo commented on code in PR #1174:
URL: https://github.com/apache/ratis/pull/1174#discussion_r1835562409


##########
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java:
##########
@@ -694,7 +695,9 @@ void execute() throws IOException {
 
       if (segments.getToDelete() != null && segments.getToDelete().length > 0) 
{
         long minStart = segments.getToDelete()[0].getStartIndex();
-        for (SegmentFileInfo del : segments.getToDelete()) {
+        SegmentFileInfo[] toDelete = segments.getToDelete();
+        for (int i = toDelete.length - 1; i >= 0; i--) {
+          final SegmentFileInfo del = toDelete[i];

Review Comment:
   Log is a list of entries with consecutive indices.
   - Truncate is an operation to delete the log from higher end -- higher 
indices should be deleted first.
   - Purge is an operation to delete the log from the lower end -- lower index 
should be deleted first.
   
   Suppose we have the following log files (RATIS-2186).
   log-88363996241_88364000257, 
   log-88364000258_88364004199, 
   log-88364004200_88364008231, 
   log-88364008232_88364012246, 
   log-88364012247_88364016452, 
   log-88364016453_88364020483. 
   
   Truncate(88364012246) should delete the last two files 
log-88364012247_88364016452 and log-88364016453_88364020483.   We should delete 
the higher index first in order to avoid holes.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to