kamalcph commented on code in PR #15005:
URL: https://github.com/apache/kafka/pull/15005#discussion_r1431092107
##########
core/src/main/java/kafka/log/remote/RemoteLogManager.java:
##########
@@ -1071,15 +1085,38 @@ void cleanupExpiredRemoteLogSegments() throws
RemoteStorageException, ExecutionE
Iterator<Integer> epochsToClean = remoteLeaderEpochs.stream()
.filter(remoteEpoch -> remoteEpoch <
earliestEpochEntry.epoch)
.iterator();
+
+ List<RemoteLogSegmentMetadata> listOfSegmentsToBeCleaned = new
ArrayList<>();
+
while (epochsToClean.hasNext()) {
int epoch = epochsToClean.next();
Iterator<RemoteLogSegmentMetadata> segmentsToBeCleaned =
remoteLogMetadataManager.listRemoteLogSegments(topicIdPartition, epoch);
while (segmentsToBeCleaned.hasNext()) {
- if (isCancelled() || !isLeader()) {
- return;
+ if (!isCancelled() && isLeader()) {
+ 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) {
+ if (!isCancelled() && isLeader()) {
// 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());
+ if
(remoteLogRetentionHandler.deleteLogSegmentsDueToLeaderEpochCacheTruncation(earliestEpochEntry,
segmentMetadata)) {
+ sizeOfDeletableSegmentsBytes -=
segmentMetadata.segmentSizeInBytes();
+ segmentsLeftToDelete--;
+
brokerTopicMetrics.recordRemoteDeleteLagBytes(partition,
sizeOfDeletableSegmentsBytes);
+
brokerTopicMetrics.recordRemoteDeleteLagSegments(partition,
segmentsLeftToDelete);
+ }
+ } else {
Review Comment:
When the replica becomes follower, we are closing/removing those metrics. If
the concern is about concurrency, then I would suggest to mark the `rlmTask` as
follower first before removing those metrics.
In RemoteLogManager:
1. followerPartitions.forEach(topicIdPartition ->
doHandleLeaderOrFollowerPartitions(topicIdPartition,
RLMTask::convertToFollower));
2. Then, call
followerPartitions.forEach(this::removeRemoteTopicPartitionMetrics);
--
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]