KAFKA-14505; [6/N] Avoid recheduling callback in request thread#15176
KAFKA-14505; [6/N] Avoid recheduling callback in request thread#15176dajac merged 2 commits intoapache:trunkfrom
Conversation
| baseSequence: Int, | ||
| requestLocal: RequestLocal, | ||
| callback: (Errors, RequestLocal, VerificationGuard) => Unit | ||
| callback: Either[Errors, VerificationGuard] => Unit |
There was a problem hiding this comment.
I had to change the callback because KafkaRequestHandler.wrapAsyncCallback only support wrapping unary functions.
|
@artemlivshits @jolshan Could you please take a look at this one when you get a chance? Let me know what you think. |
| preAppendErrors.getOrElse(topicPartition, Errors.NONE), | ||
| newRequestLocal, | ||
| verificationGuards.getOrElse(topicPartition, VerificationGuard.SENTINEL)) | ||
| def generalizedCallback(results: Map[TopicPartition, Either[Errors, VerificationGuard]]): Unit = { |
There was a problem hiding this comment.
I think we could do the translation from preAppendErrors, newRequestLocal, verificationGuards here, then we'd avoid propagating the changes all the way to replication layer.
There was a problem hiding this comment.
Yeah, I was debating about this. The reasoning for not doing it here is that @jolshan may also use maybeStartTransactionVerificationForPartitions from the core path in conjunction with wrapAsyncCallback so she will also need to have a unary callback. @jolshan Is my understanding correct? Otherwise, we could limit the change to this method.
There was a problem hiding this comment.
Please take a look at my refactor PR. I have some this to some extent.
I'd prefer not to overhaul it again (as I did after the previous group coordinator change)
Hopefully it makes this work easier too.
| newRequestLocal, | ||
| verificationGuards.getOrElse(topicPartition, VerificationGuard.SENTINEL)) | ||
| def generalizedCallback(results: Map[TopicPartition, Either[Errors, VerificationGuard]]): Unit = { | ||
| callback(results.getOrElse(topicPartition, Right(VerificationGuard.SENTINEL))) |
There was a problem hiding this comment.
This logic is just a translation from the current implementation (so it's not introducing anything new), but is it expected that we don't get the results for the requested topicPartition? Should we log a warning, so that we know that we're hitting some unexpected code path?
There was a problem hiding this comment.
It should not happen but who knows. Let me log an error and fail the callback if it would ever happen.
| producerEpoch: Short, | ||
| requestLocal: RequestLocal, | ||
| callback: (Map[TopicPartition, Errors], RequestLocal, Map[TopicPartition, VerificationGuard]) => Unit | ||
| callback: mutable.Map[TopicPartition, Either[Errors, VerificationGuard]] => Unit |
There was a problem hiding this comment.
My understanding, that once we refactor these changes, this function could be either called from GC code path (that may not care about requestLocal) or from the core data path, that needs requestLocal, because the callback may be called immediately in this thread context.
There was a problem hiding this comment.
This is correct. The requestLocal is not required within this function though. The caller if it uses wrapAsyncCallback will get the correct one to use.
| postVerificationCallback | ||
| // Wrap the callback to be handled on an arbitrary request handler thread | ||
| // when transaction verification is complete. | ||
| KafkaRequestHandler.wrapAsyncCallback(postVerificationCallback, requestLocal) |
There was a problem hiding this comment.
It's interesting to note (I don't think we need to change anything) is that now we'll have a production code path (and not just unit test) where we can call wrapped callback on the same request thread and we'll go through the optimized code path where we call the callback directly.
There was a problem hiding this comment.
Why are we calling this here? I thought we wanted to avoid this wrap here and only do it for produce requests.
There was a problem hiding this comment.
We still need this in the old coordinator.
There was a problem hiding this comment.
Oh sorry. I guess I was just confused I didn't see it in the replica manager flow. (for produce)
|
Thanks @jolshan. I have addressed your comments. |
…he#15176) This patch removes the extra hop via the request thread when the new group coordinator verifies a transaction. Prior to it, the ReplicaManager would automatically re-schedule the callback to a request thread. However, the new group coordinator does not need this as it already schedules the write into its own thread. With this patch, the decision to re-schedule on a request thread or not is left to the caller. Reviewers: Artem Livshits <alivshits@confluent.io>, Justine Olshan <jolshan@confluent.io>
…he#15176) This patch removes the extra hop via the request thread when the new group coordinator verifies a transaction. Prior to it, the ReplicaManager would automatically re-schedule the callback to a request thread. However, the new group coordinator does not need this as it already schedules the write into its own thread. With this patch, the decision to re-schedule on a request thread or not is left to the caller. Reviewers: Artem Livshits <alivshits@confluent.io>, Justine Olshan <jolshan@confluent.io>
…he#15176) This patch removes the extra hop via the request thread when the new group coordinator verifies a transaction. Prior to it, the ReplicaManager would automatically re-schedule the callback to a request thread. However, the new group coordinator does not need this as it already schedules the write into its own thread. With this patch, the decision to re-schedule on a request thread or not is left to the caller. Reviewers: Artem Livshits <alivshits@confluent.io>, Justine Olshan <jolshan@confluent.io>
This patch removes the extra hop via the request thread when the new group coordinator verifies a transaction. Prior to it, the ReplicaManager would automatically re-schedule the callback to a request thread. However, the new group coordinator does not need this as it already schedules the write into its own thread. With this patch, the decision to re-schedule on a request thread or not is left to the caller.
Committer Checklist (excluded from commit message)