Skip to content

KAFKA-9307: Make transaction metadata loading resilient to previous errors - #7840

Merged
hachikuji merged 6 commits into
apache:trunkfrom
dhruvilshah3:kafka-9307
Dec 23, 2019
Merged

KAFKA-9307: Make transaction metadata loading resilient to previous errors#7840
hachikuji merged 6 commits into
apache:trunkfrom
dhruvilshah3:kafka-9307

Conversation

@dhruvilshah3

@dhruvilshah3 dhruvilshah3 commented Dec 17, 2019

Copy link
Copy Markdown
Contributor

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.

@junrao junrao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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})"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junrao I added this in after discussing with @hachikuji. Let me know what you think.

@junrao junrao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is there any value in this test? We are just verifying ordering of 2 methods in the code.

@dhruvilshah3

Copy link
Copy Markdown
Contributor Author

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

@junrao

junrao commented Dec 19, 2019

Copy link
Copy Markdown
Contributor

@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 hachikuji left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, left a few small comments.

completeEmigration(txnTopicPartitionId)
}

private def completeEmigration(txnTopicPartitionId: Int): Unit = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we can make this a foreach

}
}

info(s"Completed loading transaciton metadata from $topicPartition at epoch $coordinatorEpoch")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "at epoch" -> "for coordinator epoch"?

Also, typo: transaciton

- Remove ZK lookup when unloading metadata

@hachikuji hachikuji left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@junrao junrao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, where is the logic for failing an emigration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dhruvilshah3

Copy link
Copy Markdown
Contributor Author

Retest this please

@hachikuji

Copy link
Copy Markdown
Contributor

retest this please

2 similar comments
@hachikuji

Copy link
Copy Markdown
Contributor

retest this please

@hachikuji

Copy link
Copy Markdown
Contributor

retest this please

@dhruvilshah3

Copy link
Copy Markdown
Contributor Author

Retest this please

@addisonhuddy

Copy link
Copy Markdown
Member

Can someone confirm which minor branches this fix will be back-ported to?

@hachikuji
hachikuji merged commit 0f0eb49 into apache:trunk Dec 23, 2019
@hachikuji

Copy link
Copy Markdown
Contributor

@addisonhuddy I will merge back to 2.2 at least.

@dhruvilshah3
dhruvilshah3 deleted the kafka-9307 branch December 23, 2019 23:21
hachikuji pushed a commit that referenced this pull request Dec 23, 2019
…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>
hachikuji pushed a commit that referenced this pull request Dec 23, 2019
…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>
hachikuji pushed a commit that referenced this pull request Dec 23, 2019
…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>
dhruvilshah3 added a commit to confluentinc/kafka that referenced this pull request Dec 27, 2019
…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>
qq619618919 pushed a commit to qq619618919/kafka that referenced this pull request May 12, 2020
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants