-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-12369; Implement ListTransactions API
#10206
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
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
14da0b2
KAFKA-12369; Implement `ListTransactions` API
hachikuji a24b67e
Fix broken test cases
hachikuji c7908e7
Address review comments
hachikuji f6181b2
Remove extra space in comment
hachikuji f5b38d1
Let response indicate unknown state filters
hachikuji 3bddc5f
Add about string for transaction state
hachikuji 42cee99
Make unknown states array non-nullable
hachikuji bbc5308
Some additional test cases
hachikuji 13b6ae7
Merge remote-tracking branch 'upstream/trunk' into KAFKA-12369
hachikuji e210e76
Fix permission in test case
hachikuji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
clients/src/main/java/org/apache/kafka/common/requests/ListTransactionsRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.common.requests; | ||
|
|
||
| import org.apache.kafka.common.message.ListTransactionsRequestData; | ||
| import org.apache.kafka.common.message.ListTransactionsResponseData; | ||
| import org.apache.kafka.common.protocol.ApiKeys; | ||
| import org.apache.kafka.common.protocol.ByteBufferAccessor; | ||
| import org.apache.kafka.common.protocol.Errors; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
|
|
||
| public class ListTransactionsRequest extends AbstractRequest { | ||
| public static class Builder extends AbstractRequest.Builder<ListTransactionsRequest> { | ||
| public final ListTransactionsRequestData data; | ||
|
|
||
| public Builder(ListTransactionsRequestData data) { | ||
| super(ApiKeys.LIST_TRANSACTIONS); | ||
| this.data = data; | ||
| } | ||
|
|
||
| @Override | ||
| public ListTransactionsRequest build(short version) { | ||
| return new ListTransactionsRequest(data, version); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return data.toString(); | ||
| } | ||
| } | ||
|
|
||
| private final ListTransactionsRequestData data; | ||
|
|
||
| private ListTransactionsRequest(ListTransactionsRequestData data, short version) { | ||
| super(ApiKeys.LIST_TRANSACTIONS, version); | ||
| this.data = data; | ||
| } | ||
|
|
||
| public ListTransactionsRequestData data() { | ||
| return data; | ||
| } | ||
|
|
||
| @Override | ||
| public ListTransactionsResponse getErrorResponse(int throttleTimeMs, Throwable e) { | ||
| Errors error = Errors.forException(e); | ||
| ListTransactionsResponseData response = new ListTransactionsResponseData() | ||
| .setErrorCode(error.code()) | ||
| .setThrottleTimeMs(throttleTimeMs); | ||
| return new ListTransactionsResponse(response); | ||
| } | ||
|
|
||
| public static ListTransactionsRequest parse(ByteBuffer buffer, short version) { | ||
| return new ListTransactionsRequest(new ListTransactionsRequestData( | ||
| new ByteBufferAccessor(buffer), version), version); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(boolean verbose) { | ||
| return data.toString(); | ||
| } | ||
|
|
||
| } | ||
62 changes: 62 additions & 0 deletions
62
clients/src/main/java/org/apache/kafka/common/requests/ListTransactionsResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.common.requests; | ||
|
|
||
| import org.apache.kafka.common.message.ListTransactionsResponseData; | ||
| import org.apache.kafka.common.protocol.ApiKeys; | ||
| import org.apache.kafka.common.protocol.ByteBufferAccessor; | ||
| import org.apache.kafka.common.protocol.Errors; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class ListTransactionsResponse extends AbstractResponse { | ||
| private final ListTransactionsResponseData data; | ||
|
|
||
| public ListTransactionsResponse(ListTransactionsResponseData data) { | ||
| super(ApiKeys.LIST_TRANSACTIONS); | ||
| this.data = data; | ||
| } | ||
|
|
||
| public ListTransactionsResponseData data() { | ||
| return data; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<Errors, Integer> errorCounts() { | ||
| Map<Errors, Integer> errorCounts = new HashMap<>(); | ||
| updateErrorCounts(errorCounts, Errors.forCode(data.errorCode())); | ||
| return errorCounts; | ||
| } | ||
|
|
||
| public static ListTransactionsResponse parse(ByteBuffer buffer, short version) { | ||
| return new ListTransactionsResponse(new ListTransactionsResponseData( | ||
| new ByteBufferAccessor(buffer), version)); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return data.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public int throttleTimeMs() { | ||
| return data.throttleTimeMs(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
clients/src/main/resources/common/message/ListTransactionsRequest.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| // (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| { | ||
| "apiKey": 66, | ||
| "type": "request", | ||
| "listeners": ["zkBroker", "broker"], | ||
| "name": "ListTransactionsRequest", | ||
| "validVersions": "0", | ||
| "flexibleVersions": "0+", | ||
| "fields": [ | ||
| { "name": "StateFilters", "type": "[]string", "versions": "0+", | ||
| "about": "The transaction states to filter by: if empty, all transactions are returned; if non-empty, then only transactions matching one of the filtered states will be returned" | ||
| }, | ||
| { "name": "ProducerIdFilters", "type": "[]int64", "versions": "0+", | ||
| "about": "The producerIds to filter by: if empty, all transactions will be returned; if non-empty, only transactions which match one of the filtered producerIds will be returned" | ||
| } | ||
| ] | ||
| } |
35 changes: 35 additions & 0 deletions
35
clients/src/main/resources/common/message/ListTransactionsResponse.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| // (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| { | ||
| "apiKey": 66, | ||
| "type": "response", | ||
| "name": "ListTransactionsResponse", | ||
| "validVersions": "0", | ||
| "flexibleVersions": "0+", | ||
| "fields": [ | ||
| { "name": "ThrottleTimeMs", "type": "int32", "versions": "0+", | ||
| "about": "The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota." }, | ||
| { "name": "ErrorCode", "type": "int16", "versions": "0+" }, | ||
| { "name": "UnknownStateFilters", "type": "[]string", "versions": "0+", | ||
| "about": "Set of state filters provided in the request which were unknown to the transaction coordinator" }, | ||
| { "name": "TransactionStates", "type": "[]TransactionState", "versions": "0+", "fields": [ | ||
| { "name": "TransactionalId", "type": "string", "versions": "0+", "entityType": "transactionalId" }, | ||
| { "name": "ProducerId", "type": "int64", "versions": "0+", "entityType": "producerId" }, | ||
| { "name": "TransactionState", "type": "string", "versions": "0+", | ||
| "about": "The current transaction state of the producer" } | ||
| ]} | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.