chia7712 commented on code in PR #23569: URL: https://github.com/apache/kafka/pull/23569#discussion_r4221709148
########## core/src/test/java/kafka/server/TierStateMachineBuildRemoteLogAuxStateTest.java: ########## @@ -0,0 +1,246 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package kafka.server; + +import kafka.server.builders.LogManagerBuilder; Review Comment: Please rebase code. `LogManagerBuilder` is removed already ########## 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: The case of “=” is what we really care about, right? If the start offset is larger than the local start offset, that is a real problem and we should not silently treat it as “no remote range” :) Not a blocker, just thinking out loud. -- 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]
