-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-15784: Ensure atomicity of in memory update and write when transactionally committing offsets #14774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KAFKA-15784: Ensure atomicity of in memory update and write when transactionally committing offsets #14774
Changes from 23 commits
e894d84
2a52318
865078b
a20f238
9bac9a9
b4a920b
05c0d28
7bc6d06
a471f04
7c01682
965ec39
8ecbe4d
99e8577
a83b136
56a44ba
e6a14ca
de5dfad
66fff82
046425c
2c1f6a9
3f6c044
3a3160d
4f757e2
ac80ae0
13dd654
7cad567
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,9 +29,11 @@ import org.apache.kafka.common.message.LeaveGroupRequestData.MemberIdentity | |
| import org.apache.kafka.common.metrics.Metrics | ||
| import org.apache.kafka.common.metrics.stats.Meter | ||
| import org.apache.kafka.common.protocol.{ApiKeys, Errors} | ||
| import org.apache.kafka.common.record.RecordBatch | ||
| import org.apache.kafka.common.requests._ | ||
| import org.apache.kafka.common.utils.Time | ||
| import org.apache.kafka.server.record.BrokerCompressionType | ||
| import org.apache.kafka.storage.internals.log.VerificationGuard | ||
|
|
||
| import scala.collection.{Map, Seq, Set, immutable, mutable} | ||
| import scala.math.max | ||
|
|
@@ -909,8 +911,35 @@ private[group] class GroupCoordinator( | |
| val group = groupManager.getGroup(groupId).getOrElse { | ||
| groupManager.addGroup(new GroupMetadata(groupId, Empty, time)) | ||
| } | ||
| doTxnCommitOffsets(group, transactionalId, memberId, groupInstanceId, generationId, producerId, producerEpoch, | ||
| offsetMetadata, requestLocal, responseCallback) | ||
|
|
||
| val offsetTopicPartition = new TopicPartition(Topic.GROUP_METADATA_TOPIC_NAME, partitionFor(group.groupId)) | ||
|
|
||
| def postVerificationCallback( | ||
| error: Errors, | ||
| newRequestLocal: RequestLocal, | ||
| verificationGuard: VerificationGuard | ||
| ): Unit = { | ||
| if (error != Errors.NONE) { | ||
| val finalError = error match { | ||
| case Errors.NOT_ENOUGH_REPLICAS => Errors.COORDINATOR_NOT_AVAILABLE | ||
| case e => e | ||
| } | ||
| responseCallback(offsetMetadata.map { case (k, _) => k -> finalError }) | ||
| } else { | ||
| doTxnCommitOffsets(group, memberId, groupInstanceId, generationId, producerId, producerEpoch, | ||
| offsetTopicPartition, offsetMetadata, newRequestLocal, responseCallback, Some(verificationGuard)) | ||
| } | ||
| } | ||
|
|
||
| groupManager.replicaManager.maybeStartTransactionVerificationForPartition( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The access to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i was just about to push my change before I saw this comment. I will address this comment tomorrow. |
||
| topicPartition = offsetTopicPartition, | ||
| transactionalId, | ||
| producerId, | ||
| producerEpoch, | ||
| RecordBatch.NO_SEQUENCE, | ||
| requestLocal, | ||
| postVerificationCallback | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -952,15 +981,16 @@ private[group] class GroupCoordinator( | |
| } | ||
|
|
||
| private def doTxnCommitOffsets(group: GroupMetadata, | ||
| transactionalId: String, | ||
| memberId: String, | ||
| groupInstanceId: Option[String], | ||
| generationId: Int, | ||
| producerId: Long, | ||
| producerEpoch: Short, | ||
| offsetTopicPartition: TopicPartition, | ||
| offsetMetadata: immutable.Map[TopicIdPartition, OffsetAndMetadata], | ||
| requestLocal: RequestLocal, | ||
| responseCallback: immutable.Map[TopicIdPartition, Errors] => Unit): Unit = { | ||
| responseCallback: immutable.Map[TopicIdPartition, Errors] => Unit, | ||
| verificationGuard: Option[VerificationGuard]): Unit = { | ||
| group.inLock { | ||
| val validationErrorOpt = validateOffsetCommit( | ||
| group, | ||
|
|
@@ -973,8 +1003,8 @@ private[group] class GroupCoordinator( | |
| if (validationErrorOpt.isDefined) { | ||
| responseCallback(offsetMetadata.map { case (k, _) => k -> validationErrorOpt.get }) | ||
| } else { | ||
| groupManager.storeOffsets(group, memberId, offsetMetadata, responseCallback, transactionalId, producerId, | ||
| producerEpoch, requestLocal) | ||
| groupManager.storeOffsets(group, memberId, offsetTopicPartition, offsetMetadata, responseCallback, producerId, | ||
| producerEpoch, requestLocal, verificationGuard) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1033,19 +1063,21 @@ private[group] class GroupCoordinator( | |
| isTransactional = false | ||
| ) | ||
|
|
||
| val offsetTopicPartition = new TopicPartition(Topic.GROUP_METADATA_TOPIC_NAME, partitionFor(group.groupId)) | ||
|
|
||
| if (validationErrorOpt.isDefined) { | ||
| responseCallback(offsetMetadata.map { case (k, _) => k -> validationErrorOpt.get }) | ||
| } else { | ||
| group.currentState match { | ||
| case Empty => | ||
| groupManager.storeOffsets(group, memberId, offsetMetadata, responseCallback) | ||
| groupManager.storeOffsets(group, memberId, offsetTopicPartition, offsetMetadata, responseCallback, verificationGuard = None) | ||
|
|
||
| case Stable | PreparingRebalance => | ||
| // During PreparingRebalance phase, we still allow a commit request since we rely | ||
| // on heartbeat response to eventually notify the rebalance in progress signal to the consumer | ||
| val member = group.get(memberId) | ||
| completeAndScheduleNextHeartbeatExpiration(group, member) | ||
| groupManager.storeOffsets(group, memberId, offsetMetadata, responseCallback, requestLocal = requestLocal) | ||
| groupManager.storeOffsets(group, memberId, offsetTopicPartition, offsetMetadata, responseCallback, requestLocal = requestLocal, verificationGuard = None) | ||
|
|
||
| case CompletingRebalance => | ||
| // We should not receive a commit request if the group has not completed rebalance; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.