You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by "szetszwo (via GitHub)" <gi...@apache.org> on 2023/09/15 16:51:45 UTC

[GitHub] [ratis] szetszwo commented on a diff in pull request #919: RATIS-1887. Gap between segement log

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


##########
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java:
##########
@@ -657,6 +657,21 @@ private class TruncateLog extends Task {
     void execute() throws IOException {
       freeSegmentedRaftLogOutputStream();
 
+      if (segments.getToDelete() != null && segments.getToDelete().length > 0) {
+        long minStart = segments.getToDelete()[0].getStartIndex();
+        for (SegmentFileInfo del : segments.getToDelete()) {

Review Comment:
   Let's sort the array so that the latest log will be deleted first.
   ```java
        TruncationSegments(SegmentFileInfo toTruncate,
                           List<SegmentFileInfo> toDelete) {
   -      this.toDelete = toDelete == null ? null :
   -          toDelete.toArray(new SegmentFileInfo[toDelete.size()]);
   +      this.toDelete = SegmentFileInfo.toSortedArray(toDelete);
          this.toTruncate = toTruncate;
        }
   ```
   ```java
     static final class SegmentFileInfo {
       static final SegmentFileInfo[] EMPTY_ARRAY = {};
       static final Comparator<SegmentFileInfo> REVERSED_ORDER = Comparator.comparingLong(SegmentFileInfo::getStartIndex)
           .thenComparingLong(SegmentFileInfo::getEndIndex)
           .reversed();
   
       static SegmentFileInfo[] toSortedArray(List<SegmentFileInfo> list) {
         if (list == null) {
           return EMPTY_ARRAY;
         }
         final SegmentFileInfo[] array = list.toArray(EMPTY_ARRAY);
         Arrays.sort(array, REVERSED_ORDER);
         return array;
       }
   ```
   



-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org