Skip to content

KAFKA-19073: add transactional ID pattern filter to ListTransactions #19355

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

Merged
merged 13 commits into from
May 1, 2025

Conversation

CalvinConfluent
Copy link
Contributor

@CalvinConfluent CalvinConfluent commented Apr 2, 2025

@github-actions github-actions bot added triage PRs from the community core Kafka Broker tools clients labels Apr 2, 2025
@CalvinConfluent CalvinConfluent changed the title KAFKA-19073: add transactional ID prefix filter to ListTransactions KAFKA-19073: add transactional ID pattern filter to ListTransactions Apr 4, 2025
Copy link

A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the triage label
should be removed to prevent this automation from happening again.

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@CalvinConfluent thanks for this patch!

Copy link
Collaborator

@m1a2st m1a2st left a comment

Choose a reason for hiding this comment

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

Thanks @CalvinConfluent for this patch, a little comments

@github-actions github-actions bot removed needs-attention triage PRs from the community labels Apr 16, 2025
@github-actions github-actions bot added the build Gradle build or GitHub Actions label Apr 23, 2025
@CalvinConfluent
Copy link
Contributor Author

@chia7712 @m1a2st The KIP-1152 has been accepted! Can you help take another look? Thanks!

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@CalvinConfluent thanks for this patch. one small comment is left. PTAL

@@ -75,6 +75,9 @@ public ListTransactionsRequest.Builder buildBatchedRequest(
.map(TransactionState::toString)
.collect(Collectors.toList()));
request.setDurationFilter(options.filteredDuration());
if (!options.filteredTransactionalIdPattern().isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

filteredTransactionalIdPattern is nullable, so should we add null check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the filteredTransactionalIdPattern in the ListTransactionsOptions, the default value is "" and we only update it if the user sets the --transactional-id-pattern. It should be valid.

Copy link
Member

Choose a reason for hiding this comment

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

or could you please add null check to ListTransactionsOptions#filterOnTransactionalIdPattern if we don't want to user to set it to null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, updated.

@@ -30,6 +32,9 @@
},
{ "name": "DurationFilter", "type": "int64", "versions": "1+", "default": -1,
"about": "Duration (in millis) to filter by: if < 0, all transactions will be returned; otherwise, only transactions running longer than this duration will be returned."
},
{ "name": "TransactionalIdPattern", "type": "string", "versions": "2+", "nullableVersions": "2+", "default": "null",
Copy link
Member

@jolshan jolshan Apr 29, 2025

Choose a reason for hiding this comment

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

I'm a little confused by why we convert null to "" on the client side if we allow null and it's the same result as "" (but we do the extra step of filtering for "" on the server side)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think it is because the other regex fields allow null. So we want to get they aligned, like SubscribedTopicRegex in ConsumerGroupHeartbeatRequest. As for converting to an empty string, I find it is convenient to handle in code.

Copy link
Member

Choose a reason for hiding this comment

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

Any reason why we can't just accept null on the client side? We convert to "" now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the client side not to convert null in ListTransactionsOptions#filterOnTransactionalIdPattern. Also adding necessary null handlings.

@CalvinConfluent CalvinConfluent requested a review from jolshan April 29, 2025 23:07
@@ -2472,7 +2472,17 @@ class KafkaApis(val requestChannel: RequestChannel,
val filteredProducerIds = listTransactionsRequest.data.producerIdFilters.asScala.map(Long.unbox).toSet
val filteredStates = listTransactionsRequest.data.stateFilters.asScala.toSet
val durationFilter = listTransactionsRequest.data.durationFilter()
val response = txnCoordinator.handleListTransactions(filteredProducerIds, filteredStates, durationFilter)
val transactionalIdPatternFilter = if (listTransactionsRequest.data.transactionalIdPattern == null) {
""
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this as well? We have a null check in TransactionStateManager

Copy link
Member

Choose a reason for hiding this comment

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

        val pattern = if (filterTransactionalIdPattern.nonEmpty) {
          try {
            Pattern.compile(filterTransactionalIdPattern)
          }
          catch {
            case e: PatternSyntaxException =>
              throw new InvalidRegularExpression(String.format("Transaction ID pattern `%s` is not a valid regular expression: %s.", filterTransactionalIdPattern, e.getMessage))
          }
        } else null

It seems TransactionStateManager does not check the null for filterTransactionalIdPattern

Copy link
Member

Choose a reason for hiding this comment

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

I see. I was looking at the lines directly above where we do check for null. It's a bit confusing which things check for null vs empty 😓

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main reason to convert null to an empty string is to avoid null handling in the downstream. But yeah, looks like there is only one place to check null. Updated to use null in the code path.

Copy link
Member

@jolshan jolshan left a comment

Choose a reason for hiding this comment

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

Thanks Calvin!

Copy link
Member

@brandboat brandboat left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@CalvinConfluent
Copy link
Contributor Author

@chia7712 Any other comments? Thanks!

@chia7712 chia7712 merged commit 0c1fbf3 into apache:trunk May 1, 2025
21 checks passed
shmily7829 pushed a commit to shmily7829/kafka that referenced this pull request May 7, 2025
…pache#19355)

Propose adding a new filter TransactionalIdPattern. This transaction ID pattern filter works as AND with the other transaction filters. Also, it is empowered with Re2j.

KIP: https://cwiki.apache.org/confluence/x/4gm9F

Reviewers: Justine Olshan <[email protected]>, Ken Huang
<[email protected]>, Kuan-Po Tseng <[email protected]>, Chia-Ping
Tsai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Gradle build or GitHub Actions ci-approved clients core Kafka Broker tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants