kamalcph commented on code in PR #21158:
URL: https://github.com/apache/kafka/pull/21158#discussion_r2626448149
##########
storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java:
##########
@@ -3632,6 +3632,63 @@ public void testTierLagResetsToZeroOnBecomingFollower() {
assertEquals(0,
brokerTopicStats.topicStats(leaderTopicIdPartition.topic()).remoteCopyLagSegments());
}
+ @Test
+ public void testCopyLagMetricsAfterLeaderChange() {
+ LogSegment activeSegment = mock(LogSegment.class);
+
when(mockLog.topicPartition()).thenReturn(leaderTopicIdPartition.topicPartition());
+ when(mockLog.activeSegment()).thenReturn(activeSegment);
+ when(mockLog.onlyLocalLogSegmentsSize()).thenReturn(50L);
+ when(activeSegment.size()).thenReturn(100);
+ when(mockLog.onlyLocalLogSegmentsCount()).thenReturn(1L);
+
+ remoteLogManager.onLeadershipChange(
+ Set.of(mockPartition(leaderTopicIdPartition)), Set.of(),
topicIds);
+ RemoteLogManager.RLMCopyTask rlmTask = (RemoteLogManager.RLMCopyTask)
remoteLogManager.rlmCopyTask(leaderTopicIdPartition);
+ assertNotNull(rlmTask);
+
+ rlmTask.recordLagStats(mockLog);
+ assertEquals(0,
brokerTopicStats.topicStats(leaderTopicIdPartition.topic()).remoteCopyLagBytes());
+ assertEquals(0,
brokerTopicStats.topicStats(leaderTopicIdPartition.topic()).remoteCopyLagSegments());
+ }
+
+ @Test
+ public void testCopyLagMetricsWithOnlyActiveSegment() {
+ LogSegment activeSegment = mock(LogSegment.class);
+
when(mockLog.topicPartition()).thenReturn(leaderTopicIdPartition.topicPartition());
+ when(mockLog.activeSegment()).thenReturn(activeSegment);
+ when(mockLog.onlyLocalLogSegmentsSize()).thenReturn(100L);
+ when(activeSegment.size()).thenReturn(100);
+ when(mockLog.onlyLocalLogSegmentsCount()).thenReturn(0L);
Review Comment:
when activeSegment size is 100, then the onlyLocalLogSegmentsCount should be
1.
Also, mock the `highestOffsetInRemoteStorage` as 125L and activeSegment
baseOffset as 100L, last-stable-offset / log-end-offset as 150, then the lag
should not report negative values.
--
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]