mumrah commented on code in PR #14594:
URL: https://github.com/apache/kafka/pull/14594#discussion_r1380240564


##########
core/src/main/scala/kafka/cluster/Partition.scala:
##########
@@ -359,10 +359,14 @@ class Partition(val topicPartition: TopicPartition,
   // a false positive under min isr check, it has to check the 
leaderReplicaIdOpt again. Though it can still be affected
   // by ABA problems when leader->follower->leader, but it should be good 
enough for a metric.
   def isUnderMinIsr: Boolean = {
-    leaderLogIfLocal.exists { partitionState.isr.size < 
_.config.minInSyncReplicas } && isLeader
+    leaderLogIfLocal.exists { partitionState.isr.size < effectiveMinIsr(_) } 
&& isLeader
   }
 
-  def isAtMinIsr: Boolean = leaderLogIfLocal.exists { partitionState.isr.size 
== _.config.minInSyncReplicas }
+  private def effectiveMinIsr(leaderLog: UnifiedLog): Int = {

Review Comment:
   Can we add a short doc string for this method?



##########
core/src/main/scala/kafka/cluster/Partition.scala:
##########
@@ -1106,6 +1112,10 @@ class Partition(val topicPartition: TopicPartition,
    * @return true if the HW was incremented, and false otherwise.
    */
   private def maybeIncrementLeaderHW(leaderLog: UnifiedLog, currentTimeMs: 
Long = time.milliseconds): Boolean = {
+    if (isUnderMinIsr) {
+      trace(s"Skip checking whether HWM can advance because partition is under 
min ISR(ISR=${partitionState.isr}")

Review Comment:
   Should we word this more like "Not increasing HWM..." so it's explicit that 
the HWM is not increasing?



##########
core/src/main/scala/kafka/cluster/Partition.scala:
##########
@@ -359,10 +361,14 @@ class Partition(val topicPartition: TopicPartition,
   // a false positive under min isr check, it has to check the 
leaderReplicaIdOpt again. Though it can still be affected
   // by ABA problems when leader->follower->leader, but it should be good 
enough for a metric.
   def isUnderMinIsr: Boolean = {
-    leaderLogIfLocal.exists { partitionState.isr.size < 
_.config.minInSyncReplicas } && isLeader
+    leaderLogIfLocal.exists{partitionState.isr.size < effectiveMinIsr(_) } && 
isLeader
   }
 
-  def isAtMinIsr: Boolean = leaderLogIfLocal.exists { partitionState.isr.size 
== _.config.minInSyncReplicas }
+  private def effectiveMinIsr(leaderLog: UnifiedLog): Int = {
+      leaderLog.config.minInSyncReplicas.min(remoteReplicasMap.size + 1)

Review Comment:
   Yea, it makes sense to constrain the min ISR like this, I was just wondering 
if we actually saw this problem in practice. Either way, I'm fine with fixing 
this here.



##########
core/src/main/scala/kafka/cluster/Partition.scala:
##########
@@ -359,10 +359,14 @@ class Partition(val topicPartition: TopicPartition,
   // a false positive under min isr check, it has to check the 
leaderReplicaIdOpt again. Though it can still be affected
   // by ABA problems when leader->follower->leader, but it should be good 
enough for a metric.
   def isUnderMinIsr: Boolean = {
-    leaderLogIfLocal.exists { partitionState.isr.size < 
_.config.minInSyncReplicas } && isLeader
+    leaderLogIfLocal.exists { partitionState.isr.size < effectiveMinIsr(_) } 
&& isLeader
   }
 
-  def isAtMinIsr: Boolean = leaderLogIfLocal.exists { partitionState.isr.size 
== _.config.minInSyncReplicas }
+  private def effectiveMinIsr(leaderLog: UnifiedLog): Int = {
+      leaderLog.config.minInSyncReplicas.min(remoteReplicasMap.size + 1)
+  }
+
+  def isAtMinIsr: Boolean = leaderLogIfLocal.exists { partitionState.isr.size 
== effectiveMinIsr(_) }

Review Comment:
   Can we add a short doc string for this that mentions the constraint on min 
ISR?



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to