-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finatra-kafka-streams: Be able to compile Finatra kafka Stream to com…
…pile for both 2.2 and 2.5 Problem ------- Some code in current Finatra Kafka Stream has internal dependency on Kafka 2.2, which blocks 2.5 upgrade. Solution -------- After some experiments, we think the best way to upgrade to Kafka 2.5 is: 1. Make the code change in finatra kafka-streams to move those Kafka 2.2 direct dependency in to separate folder. 2. In build.sbt, we added filter to control which version to include. 3. In this phab, it is still building finatra kafka with 2.2 by default, but allowing us to easily switch to build with 2.5. Result -------- No public API change. It should have no impact for current Kafka 2.2 customers. Differential Revision: https://phabricator.twitter.biz/D545900
- Loading branch information
Ming Liu
authored and
jenkins
committed
Sep 24, 2020
1 parent
1c1b55c
commit 3c78c34
Showing
34 changed files
with
342 additions
and
138 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
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
1 change: 1 addition & 0 deletions
1
kafka-streams/kafka-streams-static-partitioning/src/main/java/BUILD
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
6 changes: 4 additions & 2 deletions
6
...itioningKafkaClientSupplierSupplier.scala → ...itioningKafkaClientSupplierSupplier.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
3 changes: 2 additions & 1 deletion
3
...ing/internal/ClientStateAndHostInfo.scala → ...2.2/internal/ClientStateAndHostInfo.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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package com.twitter.finatra.kafkastreams.partitioning.internal | ||
|
||
import com.twitter.finatra.streams.queryable.thrift.domain.ServiceShardId | ||
import com.twitter.finatra.kafkastreams.partitioning.StaticPartitioning | ||
import org.apache.kafka.streams.processor.internals.assignment.ClientState | ||
import org.apache.kafka.streams.state.HostInfo | ||
|
||
case class ClientStateAndHostInfo[ID](id: ID, clientState: ClientState, hostInfo: HostInfo) { | ||
|
||
val serviceShardId: ServiceShardId = { | ||
StaticPartitioningStreamAssignor.parseShardId(hostInfo.host()) | ||
StaticPartitioning.parseShardId(hostInfo.host()) | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
...-partitioning/src/main/scala-kafka2.5/StaticPartitioningKafkaClientSupplierSupplier.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,26 @@ | ||
package com.twitter.finatra.kafkastreams.partitioning.internal | ||
|
||
import java.util | ||
import com.twitter.finatra.kafkastreams.partitioning.StaticPartitioning | ||
import org.apache.kafka.clients.consumer._ | ||
import org.apache.kafka.common.utils.Utils | ||
import org.apache.kafka.streams.processor.internals.DefaultKafkaClientSupplier | ||
|
||
class StaticPartitioningKafkaClientSupplierSupplier( | ||
numApplicationInstances: Int, | ||
serverConfig: String) | ||
extends DefaultKafkaClientSupplier { | ||
|
||
override def getConsumer(config: util.Map[String, AnyRef]): Consumer[Array[Byte], Array[Byte]] = { | ||
val applicationServerHost = Utils.getHost(serverConfig) | ||
|
||
val serviceShardId = StaticPartitioning.parseShardId(applicationServerHost) | ||
|
||
config.put( | ||
"group.instance.id", | ||
serviceShardId.id.toString | ||
) | ||
|
||
super.getConsumer(config) | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
kafka-streams/kafka-streams-static-partitioning/src/main/scala/BUILD
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
43 changes: 43 additions & 0 deletions
43
kafka-streams/kafka-streams/src/main/scala-kafka2.2/CompatibleUtils.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,43 @@ | ||
package com.twitter.finatra.kafkastreams.internal.utils | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
import org.apache.kafka.streams.Topology | ||
import org.apache.kafka.streams.processor.{ProcessorContext, StateStore} | ||
import org.apache.kafka.streams.processor.internals.InternalTopologyBuilder | ||
import org.apache.kafka.streams.processor.internals.StreamThread | ||
import org.apache.kafka.streams.state.internals.WrappedStateStore | ||
|
||
private[kafkastreams] object CompatibleUtils { | ||
|
||
private val internalTopologyBuilderField = | ||
ReflectionUtils.getFinalField(classOf[Topology], "internalTopologyBuilder") | ||
|
||
def isStateless(topology: Topology): Boolean = { | ||
val internalTopologyBuilder = getInternalTopologyBuilder(topology) | ||
|
||
internalTopologyBuilder.getStateStores.isEmpty | ||
} | ||
|
||
private def getInternalTopologyBuilder(topology: Topology): InternalTopologyBuilder = { | ||
internalTopologyBuilderField | ||
.get(topology) | ||
.asInstanceOf[InternalTopologyBuilder] | ||
} | ||
|
||
def getUnwrappedStateStore[K, V](name: String, processorContext: ProcessorContext): StateStore = { | ||
val unwrappedStateStore = processorContext | ||
.getStateStore(name).asInstanceOf[WrappedStateStore[_]] | ||
.wrapped() | ||
|
||
unwrappedStateStore | ||
} | ||
|
||
def resetStreamThreadId() = { | ||
val streamThreadClass = classOf[StreamThread] | ||
val streamThreadIdSequenceField = streamThreadClass | ||
.getDeclaredField("STREAM_THREAD_ID_SEQUENCE") | ||
streamThreadIdSequenceField.setAccessible(true) | ||
val streamThreadIdSequence = streamThreadIdSequenceField.get(null).asInstanceOf[AtomicInteger] | ||
streamThreadIdSequence.set(1) | ||
} | ||
} |
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
16 changes: 14 additions & 2 deletions
16
...ernal/utils/TopologyReflectionUtils.scala → ...main/scala-kafka2.5/CompatibleUtils.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 |
---|---|---|
@@ -1,22 +1,34 @@ | ||
package com.twitter.finatra.kafkastreams.internal.utils | ||
|
||
import org.apache.kafka.streams.Topology | ||
import org.apache.kafka.streams.processor.{ProcessorContext, StateStore} | ||
import org.apache.kafka.streams.processor.internals.InternalTopologyBuilder | ||
import org.apache.kafka.streams.state.internals.WrappedStateStore | ||
|
||
private[kafkastreams] object TopologyReflectionUtils { | ||
private[kafkastreams] object CompatibleUtils { | ||
|
||
private val internalTopologyBuilderField = | ||
ReflectionUtils.getFinalField(classOf[Topology], "internalTopologyBuilder") | ||
|
||
def isStateless(topology: Topology): Boolean = { | ||
val internalTopologyBuilder = getInternalTopologyBuilder(topology) | ||
|
||
internalTopologyBuilder.getStateStores.isEmpty | ||
internalTopologyBuilder.stateStores.isEmpty | ||
} | ||
|
||
private def getInternalTopologyBuilder(topology: Topology): InternalTopologyBuilder = { | ||
internalTopologyBuilderField | ||
.get(topology) | ||
.asInstanceOf[InternalTopologyBuilder] | ||
} | ||
|
||
def getUnwrappedStateStore[K, V](name: String, processorContext: ProcessorContext): StateStore = { | ||
val unwrappedStateStore = processorContext | ||
.getStateStore(name).asInstanceOf[WrappedStateStore[_, K, V]] | ||
.wrapped().asInstanceOf[StateStore] | ||
|
||
unwrappedStateStore | ||
} | ||
|
||
def resetStreamThreadId() = {} | ||
} |
10 changes: 10 additions & 0 deletions
10
kafka-streams/kafka-streams/src/main/scala-kafka2.5/RocksDBStoreFactory.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,10 @@ | ||
package org.apache.kafka.streams.state.internals | ||
|
||
/** | ||
* Factory to allow us to call the package private RocksDBStore constructor | ||
*/ | ||
object RocksDBStoreFactory { | ||
def create(name: String, metricScope: String): RocksDBStore = { | ||
new RocksDBStore(name, metricScope) | ||
} | ||
} |
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.