KAFKA-9307: Make transaction metadata loading resilient to previous errors - #7840
Conversation
junrao
left a comment
There was a problem hiding this comment.
@dhruvilshah3 : Thanks for the PR. LGTM. Just a few minor comments below. @hachikuji , do you want to take a look at the PR too?
| throw new IllegalStateException(errorMsg) | ||
| } | ||
| if (currentTxnMetadataCacheEntry.isDefined) | ||
| info(s"Unloaded $currentTxnMetadataCacheEntry for $txnTopicPartition as part of loading metadata at epoch $coordinatorEpoch") |
There was a problem hiding this comment.
It seems that we need to log currentTxnMetadataCacheEntry.get ?
| private[transaction] case class TxnMetadataCacheEntry(coordinatorEpoch: Int, | ||
| metadataPerTransactionalId: Pool[String, TransactionMetadata]) { | ||
| override def toString: String = { | ||
| s"TxnMetadataCacheEntry(coordinatorEpoch=$coordinatorEpoch, cacheSize=${metadataPerTransactionalId.size})" |
There was a problem hiding this comment.
cacheSize => transactionalEntries?
| case None => | ||
| info(s"Trying to remove cached transaction metadata for $topicPartition on follower transition but there is no entries remaining; " + | ||
| s"it is likely that another process for removing the cached entries has just executed earlier before") | ||
| info(s"No cached metadata found for $topicPartition during become-follower transition") |
There was a problem hiding this comment.
It's useful to mention the cached metadata is for transactions.
| // The operations performed during immigration must be resilient to any previous errors we saw or partial state we | ||
| // left off during the unloading phase. Ensure we remove all associated state for this partition before we continue | ||
| // loading it. | ||
| completeEmigration(txnTopicPartitionId) |
There was a problem hiding this comment.
@junrao I added this in after discussing with @hachikuji. Let me know what you think.
junrao
left a comment
There was a problem hiding this comment.
@dhruvilshah3 : Thanks for the updated PR. The patch itself seems fine. However, I am not it completely fixes the issue in the jira since validateTransactionTopicPartitionCountIsStable() is called when loading txns and the same ZK exception could be hit then.
|
|
||
| // first call must be to remove transaction markers, and then we start loading transactions | ||
| inOrderVerifier.verify(transactionMarkerChannelManager).removeMarkersForTxnTopicPartition(txnTopicPartitionId) | ||
| inOrderVerifier.verify(transactionManager).loadTransactionsForTxnTopicPartition(ArgumentMatchers.eq(txnTopicPartitionId), |
There was a problem hiding this comment.
Hmm, is there any value in this test? We are just verifying ordering of 2 methods in the code.
|
@junrao the idea is that if the leader's session has expired then transaction metadata loading would fail. However, after this point, we would expect the broker to again be made the leader in the future after it has re-established its session, and metadata loading would then succeed. Let me know if this makes sense. |
|
@dhruvilshah3 : That's in general true. However, there is a small window from the time a leader's ZK session is expired to the time when a new leader is elected. In that window, client requests will still be routed to the current leader. If the leader accepts/rejects a txn request based on inaccurate txn cache, it could have other implications. |
hachikuji
left a comment
There was a problem hiding this comment.
Thanks, left a few small comments.
| completeEmigration(txnTopicPartitionId) | ||
| } | ||
|
|
||
| private def completeEmigration(txnTopicPartitionId: Int): Unit = { |
There was a problem hiding this comment.
nit: this function doesn't seem to add much value
| throw new IllegalStateException(errorMsg) | ||
| } | ||
| if (currentTxnMetadataCacheEntry.isDefined) | ||
| info(s"Unloaded transaction metadata ${currentTxnMetadataCacheEntry.get} from $txnTopicPartition as part of " + |
There was a problem hiding this comment.
Considering whether it is worth making this a warn.. I think it is still an unexpected state in the system.
| fatal(errorMsg) | ||
| throw new IllegalStateException(errorMsg) | ||
| } | ||
| if (currentTxnMetadataCacheEntry.isDefined) |
There was a problem hiding this comment.
nit: we can make this a foreach
| } | ||
| } | ||
|
|
||
| info(s"Completed loading transaciton metadata from $topicPartition at epoch $coordinatorEpoch") |
There was a problem hiding this comment.
nit: "at epoch" -> "for coordinator epoch"?
Also, typo: transaciton
- Remove ZK lookup when unloading metadata
junrao
left a comment
There was a problem hiding this comment.
@dhruvilshah3 : Thanks for the PR. The approach looks good. Just one comment below.
| assertEquals(0, transactionManager.loadingPartitions.size) | ||
| assertEquals(0, transactionManager.leavingPartitions.size) | ||
|
|
||
| // simulate a failed emigration; immigrate partition at epoch 1 |
There was a problem hiding this comment.
Hmm, where is the logic for failing an emigration?
There was a problem hiding this comment.
I'll reword the comment. The test is now just checking if the partition can be reimmigrated even though we didn't get to execute the emigration.
|
Retest this please |
|
retest this please |
2 similar comments
|
retest this please |
|
retest this please |
|
Retest this please |
|
Can someone confirm which minor branches this fix will be back-ported to? |
|
@addisonhuddy I will merge back to 2.2 at least. |
…rrors (#7840) Allow transaction metadata to be reloaded, even if it already exists as of a previous epoch. This helps with cases where a previous become-follower transition failed to unload corresponding metadata. Reviewers: Jun Rao <junrao@gmail.com>, Jason Gustafson <jason@confluent.io>
…rrors (#7840) Allow transaction metadata to be reloaded, even if it already exists as of a previous epoch. This helps with cases where a previous become-follower transition failed to unload corresponding metadata. Reviewers: Jun Rao <junrao@gmail.com>, Jason Gustafson <jason@confluent.io>
…rrors (#7840) Allow transaction metadata to be reloaded, even if it already exists as of a previous epoch. This helps with cases where a previous become-follower transition failed to unload corresponding metadata. Reviewers: Jun Rao <junrao@gmail.com>, Jason Gustafson <jason@confluent.io>
…rrors (apache#7840) Allow transaction metadata to be reloaded, even if it already exists as of a previous epoch. This helps with cases where a previous become-follower transition failed to unload corresponding metadata. Reviewers: Jun Rao <junrao@gmail.com>, Jason Gustafson <jason@confluent.io>
…rrors (apache#7840) Allow transaction metadata to be reloaded, even if it already exists as of a previous epoch. This helps with cases where a previous become-follower transition failed to unload corresponding metadata. Reviewers: Jun Rao <junrao@gmail.com>, Jason Gustafson <jason@confluent.io>
Allow transaction metadata to be reloaded, even if it already exists as of a previous epoch. This helps with cases where a previous become-follower transition failed to unload corresponding metadata.