artemlivshits commented on code in PR #13787:
URL: https://github.com/apache/kafka/pull/13787#discussion_r1361539171


##########
core/src/main/scala/kafka/cluster/Partition.scala:
##########
@@ -1279,7 +1283,7 @@ class Partition(val topicPartition: TopicPartition,
   }
 
   def appendRecordsToLeader(records: MemoryRecords, origin: AppendOrigin, 
requiredAcks: Int,
-                            requestLocal: RequestLocal): LogAppendInfo = {
+                            requestLocal: RequestLocal, verificationGuard: 
Object = null): LogAppendInfo = {

Review Comment:
   We don't use object content, we just use object identity (i.e. its address), 
so passing anything is perfectly fine - 2 different objects would have 2 
different addresses.  `null` works because we know that it is not equal to any 
real object identity.
   
   The scenario that we're solving is this: we need to check some condition 
under lock, then we need to release the lock and do a bunch of work (that 
includes sending RPCs and etc.), then once the work is done, we need to make 
sure that the condition still holds.  So to implement the solution, we create 
an object and remember a reference to it.  If the condition is changed, the 
reference is set to `null`.  So when we come back, we check if the reference is 
still set to the object that we remember, if it's not then we've got raced and 
the condition isn't valid anymore.  Naively, it may seem that we can use just a 
Boolean flag, and set it to `true` when we start validation, and if the 
condition is changed, we set the flag to `false`.  This approach, however, is 
prone to ABA problem.
   
   There are some details here: 
https://github.com/apache/kafka/pull/13787#discussion_r1213675427



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