dybyte commented on code in PR #23569:
URL: https://github.com/apache/kafka/pull/23569#discussion_r4261672079


##########
storage/src/main/java/org/apache/kafka/server/log/remote/storage/RemoteLogManager.java:
##########
@@ -498,10 +498,36 @@ public void onLeadershipChange(Set<TopicPartitionLog> 
partitionsBecomeLeader,
             // background thread and might emit metrics. So, removing the 
metrics after marking this node as follower.
             followerPartitions.forEach((tp, __) -> 
removeRemoteTopicPartitionMetrics(tp));
 
+            filterPartitions(partitionsBecomeLeader)
+                    .forEach(partition -> 
warnIfLeaderEpochCacheMissesRemoteRange(partition.unifiedLog().get()));
             leaderPartitions.forEach(this::doHandleLeaderPartition);
         }
     }
 
+    private void warnIfLeaderEpochCacheMissesRemoteRange(UnifiedLog log) {
+        if (isLeaderEpochCacheMissingRemoteEntries(log)) {
+            LOGGER.warn("The leader epoch cache of {} does not cover the 
remote log range [{}, {}), its earliest entry is {}. " +
+                            "Remote log segments of the missing epochs cannot 
be read through this replica and may be " +
+                            "deleted as unreferenced.",
+                    log.topicPartition(), log.logStartOffset(), 
log.localLogStartOffset(),
+                    log.leaderEpochCache().earliestEntry().orElse(null));
+        }
+    }
+
+    /**
+     * Returns true if the log has a remote range [logStartOffset, 
localLogStartOffset) whose leader epochs are
+     * missing from the leader epoch cache, which happens when the remote log 
aux state was lost (KAFKA-17249).
+     */
+    // Visible for testing
+    static boolean isLeaderEpochCacheMissingRemoteEntries(UnifiedLog log) {
+        long logStartOffset = log.logStartOffset();
+        if (logStartOffset >= log.localLogStartOffset()) {

Review Comment:
   Good question. `>` can actually happen in a normal flow. While remote 
storage is disabled for a topic, `maybeIncrementLogStartOffset` doesn't move 
`localLogStartOffset`, so retention or DeleteRecords leaves `logStartOffset > 
localLogStartOffset`. If remote storage is then enabled on that topic, 
`ConfigHandler` calls `onLeadershipChange` and this check runs in exactly that 
state. There is no remote data yet at that point, so "no remote range" is the 
right answer, and flagging it would log a false warning during a normal 
operation like enabling tiered storage on an existing topic.
   
   The stale `localLogStartOffset` itself is a separate bug, since it makes 
ListOffsets return wrong values for EARLIEST_LOCAL and EARLIEST_PENDING_UPLOAD. 
I filed KAFKA-21272 for it. It doesn't overlap with this PR.



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