forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-5059: Implement Transactional Coordinator
Author: Damian Guy <[email protected]> Author: Guozhang Wang <[email protected]> Author: Apurva Mehta <[email protected]> Reviewers: Guozhang Wang, Jason Gustafson, Apurva Mehta, Jun Rao Closes apache#2849 from dguy/exactly-once-tc
- Loading branch information
1 parent
8d8ab2e
commit f69d941
Showing
58 changed files
with
4,452 additions
and
442 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
25 changes: 25 additions & 0 deletions
25
clients/src/main/java/org/apache/kafka/common/errors/ConcurrentTransactionsException.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,25 @@ | ||
/* | ||
* 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.errors; | ||
|
||
public class ConcurrentTransactionsException extends ApiException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public ConcurrentTransactionsException(final String message) { | ||
super(message); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -31,3 +31,4 @@ public InvalidTxnTimeoutException(String message) { | |
super(message); | ||
} | ||
} | ||
|
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
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
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
69 changes: 69 additions & 0 deletions
69
core/src/main/scala/kafka/common/InterBrokerSendThread.scala
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,69 @@ | ||
/* | ||
* 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 kafka.common | ||
|
||
import kafka.utils.ShutdownableThread | ||
import org.apache.kafka.clients.{ClientResponse, NetworkClient, RequestCompletionHandler} | ||
import org.apache.kafka.common.Node | ||
import org.apache.kafka.common.requests.AbstractRequest | ||
import org.apache.kafka.common.utils.Time | ||
|
||
|
||
/** | ||
* Class for inter-broker send thread that utilize a non-blocking network client. | ||
*/ | ||
class InterBrokerSendThread(name: String, | ||
networkClient: NetworkClient, | ||
requestGenerator: () => Iterable[RequestAndCompletionHandler], | ||
time: Time) | ||
extends ShutdownableThread(name, isInterruptible = false) { | ||
|
||
override def doWork() { | ||
val now = time.milliseconds() | ||
var pollTimeout = Long.MaxValue | ||
|
||
val requestsToSend: Iterable[RequestAndCompletionHandler] = requestGenerator() | ||
|
||
for (request: RequestAndCompletionHandler <- requestsToSend) { | ||
val destination = Integer.toString(request.destination.id()) | ||
val completionHandler = request.handler | ||
// TODO: Need to check inter broker protocol and error if new request is not supported | ||
val clientRequest = networkClient.newClientRequest(destination, | ||
request.request, | ||
now, | ||
true, | ||
completionHandler) | ||
|
||
if (networkClient.ready(request.destination, now)) { | ||
networkClient.send(clientRequest, now) | ||
} else { | ||
val disConnectedResponse: ClientResponse = new ClientResponse(clientRequest.makeHeader(request.request.desiredOrLatestVersion()), | ||
completionHandler, destination, | ||
now /* createdTimeMs */, now /* receivedTimeMs */, true /* disconnected */, null /* versionMismatch */, null /* responseBody */) | ||
|
||
// poll timeout would be the minimum of connection delay if there are any dest yet to be reached; | ||
// otherwise it is infinity | ||
pollTimeout = Math.min(pollTimeout, networkClient.connectionDelay(request.destination, now)) | ||
|
||
completionHandler.onComplete(disConnectedResponse) | ||
} | ||
} | ||
networkClient.poll(pollTimeout, now) | ||
} | ||
} | ||
|
||
case class RequestAndCompletionHandler(destination: Node, request: AbstractRequest.Builder[_ <: AbstractRequest], handler: RequestCompletionHandler) |
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.