Copilot commented on code in PR #3222:
URL: https://github.com/apache/fluss/pull/3222#discussion_r3206090749


##########
fluss-server/src/main/java/org/apache/fluss/server/log/LogTablet.java:
##########
@@ -1181,17 +1209,27 @@ private List<LogSegment> deletableSegments(long 
endOffset) {
         // readers is in progress.
         List<LogSegment> deletableSegments = new ArrayList<>();
         List<LogSegment> logSegments = localLog.getSegments().values();
-        // ignore the segments configured to be retained
-        for (int i = 0; i < logSegments.size() - tieredLogLocalSegments; i++) {
-            if (logSegments.get(i + 1).getBaseOffset() <= endOffset) {
-                deletableSegments.add(logSegments.get(i));
-            } else {
+        int tierProtectedStartIndex = logSegments.size() - 
tieredLogLocalSegments;
+        long now = clock.milliseconds();
+
+        for (int i = 0; i < logSegments.size() - 1; i++) {
+            if (logSegments.get(i + 1).getBaseOffset() > endOffset) {
                 break;
             }
+            if (i < tierProtectedStartIndex || isSegmentExpired(now, 
logSegments.get(i))) {
+                deletableSegments.add(logSegments.get(i));
+            }

Review Comment:
   `isSegmentExpired(...)` calls `LogSegment.maxTimestampSoFar()`, which can 
materialize the time index and scan the segment (`LogSegment` notes this may 
involve time index materialization). Since this loop runs under `lock`, segment 
expiration checks can introduce disk I/O while holding the LogTablet lock and 
may block concurrent appends/reads. Consider avoiding potentially heavy 
timestamp lookups under the LogTablet lock (e.g., snapshot candidate segments 
under lock and evaluate timestamps outside, or expose/use a cached 
max-timestamp value that doesn’t trigger index materialization).



-- 
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