Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-1012; Consumer offset management in Kafka; patched by Tejas Pat…
…il and Joel Koshy; feedback and reviews from Neha Narkhede, Jun Rao, Guozhang Wang, Sriram Subramanian, Joe Stein, Chris Riccomini
- Loading branch information
Showing
82 changed files
with
3,609 additions
and
1,644 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
79 changes: 79 additions & 0 deletions
79
core/src/main/scala/kafka/api/ConsumerMetadataRequest.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,79 @@ | ||
/** | ||
* 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.api | ||
|
||
import java.nio.ByteBuffer | ||
import kafka.network.{BoundedByteBufferSend, RequestChannel} | ||
import kafka.network.RequestChannel.Response | ||
import kafka.common.ErrorMapping | ||
|
||
object ConsumerMetadataRequest { | ||
val CurrentVersion = 0.shortValue | ||
val DefaultClientId = "" | ||
|
||
def readFrom(buffer: ByteBuffer) = { | ||
// envelope | ||
val versionId = buffer.getShort | ||
val correlationId = buffer.getInt | ||
val clientId = ApiUtils.readShortString(buffer) | ||
|
||
// request | ||
val group = ApiUtils.readShortString(buffer) | ||
ConsumerMetadataRequest(group, versionId, correlationId, clientId) | ||
} | ||
|
||
} | ||
|
||
case class ConsumerMetadataRequest(group: String, | ||
versionId: Short = ConsumerMetadataRequest.CurrentVersion, | ||
override val correlationId: Int = 0, | ||
clientId: String = ConsumerMetadataRequest.DefaultClientId) | ||
extends RequestOrResponse(Some(RequestKeys.ConsumerMetadataKey), correlationId) { | ||
|
||
def sizeInBytes = | ||
2 + /* versionId */ | ||
4 + /* correlationId */ | ||
ApiUtils.shortStringLength(clientId) + | ||
ApiUtils.shortStringLength(group) | ||
|
||
def writeTo(buffer: ByteBuffer) { | ||
// envelope | ||
buffer.putShort(versionId) | ||
buffer.putInt(correlationId) | ||
ApiUtils.writeShortString(buffer, clientId) | ||
|
||
// consumer metadata request | ||
ApiUtils.writeShortString(buffer, group) | ||
} | ||
|
||
override def handleError(e: Throwable, requestChannel: RequestChannel, request: RequestChannel.Request): Unit = { | ||
// return ConsumerCoordinatorNotAvailable for all uncaught errors | ||
val errorResponse = ConsumerMetadataResponse(None, ErrorMapping.ConsumerCoordinatorNotAvailableCode) | ||
requestChannel.sendResponse(new Response(request, new BoundedByteBufferSend(errorResponse))) | ||
} | ||
|
||
def describe(details: Boolean) = { | ||
val consumerMetadataRequest = new StringBuilder | ||
consumerMetadataRequest.append("Name: " + this.getClass.getSimpleName) | ||
consumerMetadataRequest.append("; Version: " + versionId) | ||
consumerMetadataRequest.append("; CorrelationId: " + correlationId) | ||
consumerMetadataRequest.append("; ClientId: " + clientId) | ||
consumerMetadataRequest.append("; Group: " + group) | ||
consumerMetadataRequest.toString() | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
core/src/main/scala/kafka/api/ConsumerMetadataResponse.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,57 @@ | ||
/** | ||
* 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.api | ||
|
||
import java.nio.ByteBuffer | ||
import kafka.cluster.Broker | ||
import kafka.common.ErrorMapping | ||
|
||
object ConsumerMetadataResponse { | ||
val CurrentVersion = 0 | ||
|
||
def readFrom(buffer: ByteBuffer) = { | ||
val correlationId = buffer.getInt | ||
val errorCode = buffer.getShort | ||
val coordinatorOpt = if (errorCode == ErrorMapping.NoError) | ||
Some(Broker.readFrom(buffer)) | ||
else | ||
None | ||
|
||
ConsumerMetadataResponse(coordinatorOpt, errorCode, correlationId) | ||
} | ||
|
||
} | ||
|
||
case class ConsumerMetadataResponse (coordinator: Option[Broker], errorCode: Short, override val correlationId: Int = 0) | ||
extends RequestOrResponse(correlationId = correlationId) { | ||
|
||
def sizeInBytes = | ||
4 + /* correlationId */ | ||
2 + /* error code */ | ||
coordinator.map(_.sizeInBytes).getOrElse(0) | ||
|
||
def writeTo(buffer: ByteBuffer) { | ||
buffer.putInt(correlationId) | ||
buffer.putShort(errorCode) | ||
if (errorCode == ErrorMapping.NoError) { | ||
coordinator.get.writeTo(buffer) | ||
} | ||
} | ||
|
||
def describe(details: Boolean) = toString | ||
} |
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.