kamalcph commented on code in PR #15005:
URL: https://github.com/apache/kafka/pull/15005#discussion_r1428764470


##########
core/src/main/java/kafka/log/remote/RemoteLogManager.java:
##########
@@ -1073,13 +1087,29 @@ void cleanupExpiredRemoteLogSegments() throws 
RemoteStorageException, ExecutionE
                         .iterator();
                 while (epochsToClean.hasNext()) {
                     int epoch = epochsToClean.next();
+                    List<RemoteLogSegmentMetadata> listOfSegmentsToBeCleaned = 
new ArrayList<>();
                     Iterator<RemoteLogSegmentMetadata> segmentsToBeCleaned = 
remoteLogMetadataManager.listRemoteLogSegments(topicIdPartition, epoch);
                     while (segmentsToBeCleaned.hasNext()) {
                         if (isCancelled() || !isLeader()) {
                             return;
                         }
-                        // No need to update the log-start-offset even though 
the segment is deleted as these epochs/offsets are earlier to that value.
-                        
remoteLogRetentionHandler.deleteLogSegmentsDueToLeaderEpochCacheTruncation(earliestEpochEntry,
 segmentsToBeCleaned.next());
+
+                        RemoteLogSegmentMetadata nextSegmentMetadata = 
segmentsToBeCleaned.next();
+                        sizeOfDeletableSegmentsBytes += 
nextSegmentMetadata.segmentSizeInBytes();
+                        listOfSegmentsToBeCleaned.add(nextSegmentMetadata);
+
+                        segmentsLeftToDelete += 
listOfSegmentsToBeCleaned.size();
+                        
brokerTopicMetrics.recordRemoteDeleteLagBytes(partition, 
sizeOfDeletableSegmentsBytes);
+                        
brokerTopicMetrics.recordRemoteDeleteLagSegments(partition, 
segmentsLeftToDelete);
+                        for (RemoteLogSegmentMetadata segmentMetadata : 
listOfSegmentsToBeCleaned) {

Review Comment:
   `listOfSegmentsToBeCleaned` gets processed multiple times. This section 
needs an update. 
   
   My understanding with `RemoteDeleteLagBytes` and `RemoteDeleteLagSegments` 
metrics is that some of the remote log segments are eligible for deletion but 
they *couldn't* be deleted now due to degradation in the secondary storage. 
   
   Here, we are calculating the `lag` for each segment and deleting the same. 
If the secondary storage throws RemoteStorageException, then the `lag` 
calculated becomes invalid.



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