-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch implements the `ListTransactions` API as documented in KIP-664: https://cwiki.apache.org/confluence/display/KAFKA/KIP-664%3A+Provide+tooling+to+detect+and+abort+hanging+transactions. Reviewers: Tom Bentley <tbentley@redhat.com>, Chia-Ping Tsai <chia7712@gmail.com>
- Loading branch information
Jason Gustafson
authored
Mar 2, 2021
1 parent
a848e0c
commit 3708a7c
Showing
20 changed files
with
587 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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.