Skip to content

KAFKA-19530 RemoteLogManager should record lag stats when remote storage is offline #20218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,9 @@ public void copyLogSegmentsToRemote(UnifiedLog log) throws InterruptedException
segmentIdsBeingCopied.add(segmentId);
try {
copyLogSegment(log, candidateLogSegment.logSegment, segmentId, candidateLogSegment.nextSegmentOffset);
} catch (Exception e) {
recordLagStats(log);
throw e;
} finally {
segmentIdsBeingCopied.remove(segmentId);
}
Expand Down Expand Up @@ -1088,6 +1091,10 @@ private void copyLogSegment(UnifiedLog log, LogSegment segment, RemoteLogSegment
logger.info("Copied {} to remote storage with segment-id: {}",
logFileName, copySegmentFinishedRlsm.remoteLogSegmentId());

recordLagStats(log);
}

private void recordLagStats(UnifiedLog log) {
long bytesLag = log.onlyLocalLogSegmentsSize() - log.activeSegment().size();
long segmentsLag = log.onlyLocalLogSegmentsCount() - 1;
recordLagStats(bytesLag, segmentsLag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ void testFailedCopyShouldDeleteTheDanglingSegment() throws Exception {
long lastStableOffset = 150L;
long logEndOffset = 150L;

when(mockLog.onlyLocalLogSegmentsSize()).thenReturn(12L);
when(mockLog.onlyLocalLogSegmentsCount()).thenReturn(2L);
when(mockLog.topicPartition()).thenReturn(leaderTopicIdPartition.topicPartition());

// leader epoch preparation
Expand All @@ -708,6 +710,7 @@ void testFailedCopyShouldDeleteTheDanglingSegment() throws Exception {

when(oldSegment.baseOffset()).thenReturn(oldSegmentStartOffset);
when(activeSegment.baseOffset()).thenReturn(nextSegmentStartOffset);
when(activeSegment.size()).thenReturn(2);
verify(oldSegment, times(0)).readNextOffset();
verify(activeSegment, times(0)).readNextOffset();

Expand Down Expand Up @@ -764,6 +767,8 @@ void testFailedCopyShouldDeleteTheDanglingSegment() throws Exception {
assertEquals(1, brokerTopicStats.allTopicsStats().remoteCopyRequestRate().count());
assertEquals(0, brokerTopicStats.allTopicsStats().remoteCopyBytesRate().count());
assertEquals(1, brokerTopicStats.allTopicsStats().failedRemoteCopyRequestRate().count());
assertEquals(10, brokerTopicStats.allTopicsStats().remoteCopyLagBytesAggrMetric().value());
assertEquals(1, brokerTopicStats.allTopicsStats().remoteCopyLagSegmentsAggrMetric().value());
}

@Test
Expand Down