You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gearpump.apache.org by manuzhang <gi...@git.apache.org> on 2016/05/27 05:54:55 UTC
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
GitHub user manuzhang opened a pull request:
https://github.com/apache/incubator-gearpump/pull/25
fix GEARPUMP-122, refactor kafka connector API
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/manuzhang/incubator-gearpump kafka
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-gearpump/pull/25.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #25
----
commit 2018cae129181f92c00fab601770b1ace0e266a4
Author: manuzhang <ow...@gmail.com>
Date: 2016-05-23T08:57:02Z
fix GEARPUMP-122, refactor kafka connector API
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka connector ...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-gearpump/pull/25
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by manuzhang <gi...@git.apache.org>.
Github user manuzhang commented on the pull request:
https://github.com/apache/incubator-gearpump/pull/25#issuecomment-222076186
may I update doc as follow-up ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by huafengw <gi...@git.apache.org>.
Github user huafengw commented on a diff in the pull request:
https://github.com/apache/incubator-gearpump/pull/25#discussion_r64864167
--- Diff: external/kafka/src/main/scala/org/apache/gearpump/streaming/kafka/lib/source/AbstractKafkaSource.scala ---
@@ -0,0 +1,173 @@
+/*
+ * 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.gearpump.streaming.kafka.lib.source
+
+import java.util.Properties
+
+import com.twitter.bijection.Injection
+import kafka.common.TopicAndPartition
+import org.apache.gearpump.streaming.kafka.KafkaSource
+import org.apache.gearpump.streaming.kafka.lib.source.consumer.FetchThread.FetchThreadFactory
+import org.apache.gearpump.streaming.kafka.lib.util.KafkaClient
+import KafkaClient.KafkaClientFactory
+import org.apache.gearpump.streaming.kafka.lib.source.consumer.{KafkaMessage, FetchThread}
+import org.apache.gearpump.streaming.kafka.lib.source.grouper.PartitionGrouper
+import org.apache.gearpump.streaming.kafka.lib.util.KafkaClient
+import org.apache.gearpump.streaming.kafka.util.KafkaConfig
+import org.apache.gearpump.streaming.kafka.util.KafkaConfig.KafkaConfigFactory
+import org.apache.gearpump.streaming.task.TaskContext
+import org.apache.gearpump.streaming.transaction.api._
+import org.apache.gearpump.util.LogUtil
+import org.apache.gearpump.{Message, TimeStamp}
+import org.slf4j.Logger
+
+object AbstractKafkaSource {
+ private val LOG: Logger = LogUtil.getLogger(classOf[KafkaSource])
+}
+
+/**
+ * Contains implementation for Kafka source connectors, users should use
+ * [[org.apache.gearpump.streaming.kafka.KafkaSource]].
+ *
+ * This is a TimeReplayableSource which is able to replay messages given a start time.
+ * Each kafka message is tagged with a timestamp by
+ * [[org.apache.gearpump.streaming.transaction.api.MessageDecoder]] and the (timestamp, offset)
+ * mapping is stored to a [[org.apache.gearpump.streaming.transaction.api.CheckpointStore]].
+ * On recovery, we could retrieve the previously stored offset from the
+ * [[org.apache.gearpump.streaming.transaction.api.CheckpointStore]] by timestamp and start to read
+ * from there.
+ *
+ * kafka message is wrapped into gearpump [[org.apache.gearpump.Message]] and further filtered by a
+ * [[org.apache.gearpump.streaming.transaction.api.TimeStampFilter]]
+ * such that obsolete messages are dropped.
+ */
+abstract class AbstractKafkaSource(
+ topic: String,
+ props: Properties,
+ kafkaConfigFactory: KafkaConfigFactory,
+ kafkaClientFactory: KafkaClientFactory,
+ fetchThreadFactory: FetchThreadFactory)
+ extends TimeReplayableSource {
+ import org.apache.gearpump.streaming.kafka.lib.source.AbstractKafkaSource._
+
+ def this(topic: String, properties: Properties) = {
+ this(topic, properties, new KafkaConfigFactory, KafkaClient.factory, FetchThread.factory)
+ }
+
+ private lazy val config: KafkaConfig = kafkaConfigFactory.getKafkaConfig(props)
+ private lazy val kafkaClient: KafkaClient = kafkaClientFactory.getKafkaClient(config)
+ private lazy val fetchThread: FetchThread = fetchThreadFactory.getFetchThread(config, kafkaClient)
+ private lazy val messageDecoder = config.getConfiguredInstance(
+ KafkaConfig.MESSAGE_DECODER_CLASS_CONFIG, classOf[MessageDecoder])
+ private lazy val timestampFilter = config.getConfiguredInstance(
+ KafkaConfig.TIMESTAMP_FILTER_CLASS_CONFIG, classOf[TimeStampFilter])
+
+ private var startTime: Long = 0L
+ private var checkpointStoreFactory: Option[CheckpointStoreFactory] = None
+ private var checkpointStores: Map[TopicAndPartition, CheckpointStore] =
+ Map.empty[TopicAndPartition, CheckpointStore]
+
+ override def checkpoint(checkpointStoreFactory: CheckpointStoreFactory): Unit = {
+ this.checkpointStoreFactory = Some(checkpointStoreFactory)
+ }
+
+ override def open(context: TaskContext, startTime: TimeStamp): Unit = {
+ import context.{parallelism, taskId}
+
+ LOG.info("KafkaSource opened at start time {}", startTime)
--- End diff --
I think adding the topic list that are consumed to the log is better.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by huafengw <gi...@git.apache.org>.
Github user huafengw commented on a diff in the pull request:
https://github.com/apache/incubator-gearpump/pull/25#discussion_r64866016
--- Diff: external/kafka/src/main/java/org/apache/gearpump/streaming/kafka/KafkaSource.java ---
@@ -0,0 +1,54 @@
+/*
+ * 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.gearpump.streaming.kafka;
+
+import kafka.common.TopicAndPartition;
+import org.apache.gearpump.streaming.kafka.lib.source.AbstractKafkaSource;
+import org.apache.gearpump.streaming.kafka.lib.util.KafkaClient;
+import org.apache.gearpump.streaming.kafka.lib.source.consumer.FetchThread;
+import org.apache.gearpump.streaming.kafka.util.KafkaConfig;
+import org.apache.gearpump.streaming.transaction.api.CheckpointStore;
+import org.apache.gearpump.streaming.transaction.api.TimeReplayableSource;
+
+import java.util.Properties;
+
+/**
+ * USER API for kafka source connector.
+ * Please refer to {@link AbstractKafkaSource} for detailed descriptions and implementations.
+ */
+public class KafkaSource extends AbstractKafkaSource implements TimeReplayableSource {
+
+ public KafkaSource(String topic, Properties properties) {
+ super(topic, properties);
+ }
+
+ // constructor for tests
+ KafkaSource(String topic, Properties properties,
+ KafkaConfig.KafkaConfigFactory configFactory,
+ KafkaClient.KafkaClientFactory clientFactory,
+ FetchThread.FetchThreadFactory threadFactory) {
+ super(topic, properties, configFactory, clientFactory, threadFactory);
+ }
+
+ /**
+ * for tests only
+ */
+ void addPartitionAndStore(TopicAndPartition tp, CheckpointStore store) {
--- End diff --
```protected```?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by codecov-io <gi...@git.apache.org>.
Github user codecov-io commented on the pull request:
https://github.com/apache/incubator-gearpump/pull/25#issuecomment-222076849
## [Current coverage][cc-pull] is **63.75%**
> Merging [#25][cc-pull] into [master][cc-base-branch] will increase coverage by **1.97%**
1. 5 files (not in diff) in `...rpump/streaming/task` were modified. [more](https://codecov.io/gh/apache/incubator-gearpump/commit/25b36316754f18caa74d22ec2aa13de0f5e39fc8/changes?src=pr#73747265616D696E672F7372632F6D61696E2F7363616C612F6F72672F6170616368652F6765617270756D702F73747265616D696E672F7461736B)
1. 2 files (not in diff) in `...streaming/state/impl` were modified. [more](https://codecov.io/gh/apache/incubator-gearpump/commit/25b36316754f18caa74d22ec2aa13de0f5e39fc8/changes?src=pr#73747265616D696E672F7372632F6D61696E2F7363616C612F6F72672F6170616368652F6765617270756D702F73747265616D696E672F73746174652F696D706C)
1. 1 files (not in diff) in `...e/gearpump/streaming` were modified. [more](https://codecov.io/gh/apache/incubator-gearpump/commit/25b36316754f18caa74d22ec2aa13de0f5e39fc8/changes?src=pr#73747265616D696E672F7372632F6D61696E2F7363616C612F6F72672F6170616368652F6765617270756D702F73747265616D696E67)
- Misses `-1`
- Hits `+1`
1. 2 files (not in diff) in `...streaming/hadoop/lib` were modified. [more](https://codecov.io/gh/apache/incubator-gearpump/commit/25b36316754f18caa74d22ec2aa13de0f5e39fc8/changes?src=pr#65787465726E616C2F6861646F6F7066732F7372632F6D61696E2F7363616C612F6F72672F6170616368652F6765617270756D702F73747265616D696E672F6861646F6F702F6C6962)
1. 1 files (not in diff) in `...ump/streaming/hadoop` were modified. [more](https://codecov.io/gh/apache/incubator-gearpump/commit/25b36316754f18caa74d22ec2aa13de0f5e39fc8/changes?src=pr#65787465726E616C2F6861646F6F7066732F7372632F6D61696E2F7363616C612F6F72672F6170616368652F6765617270756D702F73747265616D696E672F6861646F6F70)
1. 2 files (not in diff) in `...rpump/cluster/master` were modified. [more](https://codecov.io/gh/apache/incubator-gearpump/commit/25b36316754f18caa74d22ec2aa13de0f5e39fc8/changes?src=pr#6461656D6F6E2F7372632F6D61696E2F7363616C612F6F72672F6170616368652F6765617270756D702F636C75737465722F6D6173746572)
- Misses `+75`
- Hits `-75`
1. 1 files (not in diff) in `...che/gearpump/cluster` were modified. [more](https://codecov.io/gh/apache/incubator-gearpump/commit/25b36316754f18caa74d22ec2aa13de0f5e39fc8/changes?src=pr#6461656D6F6E2F7372632F6D61696E2F7363616C612F6F72672F6170616368652F6765617270756D702F636C7573746572)
- Misses `+1`
- Hits `-1`
1. 1 files (not in diff) in `.../org/apache/gearpump` were modified. [more](https://codecov.io/gh/apache/incubator-gearpump/commit/25b36316754f18caa74d22ec2aa13de0f5e39fc8/changes?src=pr#6461656D6F6E2F7372632F6D61696E2F7363616C612F6F72672F6170616368652F6765617270756D70)
- Misses `+8`
- Hits `-8`
1. 7 files (not in diff) in `...apache/gearpump/util` were modified. [more](https://codecov.io/gh/apache/incubator-gearpump/commit/25b36316754f18caa74d22ec2aa13de0f5e39fc8/changes?src=pr#636F72652F7372632F6D61696E2F7363616C612F6F72672F6170616368652F6765617270756D702F7574696C)
- Misses `-49`
- Hits `+44`
1. 2 files (not in diff) in `...rpump/cluster/client` were modified. [more](https://codecov.io/gh/apache/incubator-gearpump/commit/25b36316754f18caa74d22ec2aa13de0f5e39fc8/changes?src=pr#636F72652F7372632F6D61696E2F7363616C612F6F72672F6170616368652F6765617270756D702F636C75737465722F636C69656E74)
- Misses `-43`
- Hits `+43`
```diff
@@ master #25 diff @@
==========================================
Files 180 177 -3
Lines 5955 5898 -57
Methods 5676 5626 -50
Messages 0 0
Branches 279 272 -7
==========================================
+ Hits 3679 3760 +81
+ Misses 2276 2138 -138
Partials 0 0
```
[][cc-pull]
> Powered by [Codecov](https://codecov.io?src=pr). Last updated by [c80c069...25b3631][cc-compare]
[cc-base-branch]: https://codecov.io/gh/apache/incubator-gearpump/branch/master?src=pr
[cc-compare]: https://codecov.io/gh/apache/incubator-gearpump/compare/c80c069637f57ff9691373e1194027a8613f174d...25b36316754f18caa74d22ec2aa13de0f5e39fc8
[cc-pull]: https://codecov.io/gh/apache/incubator-gearpump/pull/25?src=pr
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by manuzhang <gi...@git.apache.org>.
Github user manuzhang commented on the pull request:
https://github.com/apache/incubator-gearpump/pull/25#issuecomment-222407072
I've verified related integration tests pass
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by manuzhang <gi...@git.apache.org>.
Github user manuzhang commented on a diff in the pull request:
https://github.com/apache/incubator-gearpump/pull/25#discussion_r64864436
--- Diff: external/kafka/src/main/scala/org/apache/gearpump/streaming/kafka/lib/source/AbstractKafkaSource.scala ---
@@ -0,0 +1,173 @@
+/*
+ * 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.gearpump.streaming.kafka.lib.source
+
+import java.util.Properties
+
+import com.twitter.bijection.Injection
+import kafka.common.TopicAndPartition
+import org.apache.gearpump.streaming.kafka.KafkaSource
+import org.apache.gearpump.streaming.kafka.lib.source.consumer.FetchThread.FetchThreadFactory
+import org.apache.gearpump.streaming.kafka.lib.util.KafkaClient
+import KafkaClient.KafkaClientFactory
+import org.apache.gearpump.streaming.kafka.lib.source.consumer.{KafkaMessage, FetchThread}
+import org.apache.gearpump.streaming.kafka.lib.source.grouper.PartitionGrouper
+import org.apache.gearpump.streaming.kafka.lib.util.KafkaClient
+import org.apache.gearpump.streaming.kafka.util.KafkaConfig
+import org.apache.gearpump.streaming.kafka.util.KafkaConfig.KafkaConfigFactory
+import org.apache.gearpump.streaming.task.TaskContext
+import org.apache.gearpump.streaming.transaction.api._
+import org.apache.gearpump.util.LogUtil
+import org.apache.gearpump.{Message, TimeStamp}
+import org.slf4j.Logger
+
+object AbstractKafkaSource {
+ private val LOG: Logger = LogUtil.getLogger(classOf[KafkaSource])
+}
+
+/**
+ * Contains implementation for Kafka source connectors, users should use
+ * [[org.apache.gearpump.streaming.kafka.KafkaSource]].
+ *
+ * This is a TimeReplayableSource which is able to replay messages given a start time.
+ * Each kafka message is tagged with a timestamp by
+ * [[org.apache.gearpump.streaming.transaction.api.MessageDecoder]] and the (timestamp, offset)
+ * mapping is stored to a [[org.apache.gearpump.streaming.transaction.api.CheckpointStore]].
+ * On recovery, we could retrieve the previously stored offset from the
+ * [[org.apache.gearpump.streaming.transaction.api.CheckpointStore]] by timestamp and start to read
+ * from there.
+ *
+ * kafka message is wrapped into gearpump [[org.apache.gearpump.Message]] and further filtered by a
+ * [[org.apache.gearpump.streaming.transaction.api.TimeStampFilter]]
+ * such that obsolete messages are dropped.
+ */
+abstract class AbstractKafkaSource(
+ topic: String,
+ props: Properties,
+ kafkaConfigFactory: KafkaConfigFactory,
+ kafkaClientFactory: KafkaClientFactory,
+ fetchThreadFactory: FetchThreadFactory)
+ extends TimeReplayableSource {
+ import org.apache.gearpump.streaming.kafka.lib.source.AbstractKafkaSource._
+
+ def this(topic: String, properties: Properties) = {
+ this(topic, properties, new KafkaConfigFactory, KafkaClient.factory, FetchThread.factory)
+ }
+
+ private lazy val config: KafkaConfig = kafkaConfigFactory.getKafkaConfig(props)
+ private lazy val kafkaClient: KafkaClient = kafkaClientFactory.getKafkaClient(config)
+ private lazy val fetchThread: FetchThread = fetchThreadFactory.getFetchThread(config, kafkaClient)
+ private lazy val messageDecoder = config.getConfiguredInstance(
+ KafkaConfig.MESSAGE_DECODER_CLASS_CONFIG, classOf[MessageDecoder])
+ private lazy val timestampFilter = config.getConfiguredInstance(
+ KafkaConfig.TIMESTAMP_FILTER_CLASS_CONFIG, classOf[TimeStampFilter])
+
+ private var startTime: Long = 0L
+ private var checkpointStoreFactory: Option[CheckpointStoreFactory] = None
+ private var checkpointStores: Map[TopicAndPartition, CheckpointStore] =
+ Map.empty[TopicAndPartition, CheckpointStore]
+
+ override def checkpoint(checkpointStoreFactory: CheckpointStoreFactory): Unit = {
+ this.checkpointStoreFactory = Some(checkpointStoreFactory)
+ }
+
+ override def open(context: TaskContext, startTime: TimeStamp): Unit = {
+ import context.{parallelism, taskId}
+
+ LOG.info("KafkaSource opened at start time {}", startTime)
--- End diff --
We already log assigned partitions below. Will that be sufficient ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by huafengw <gi...@git.apache.org>.
Github user huafengw commented on the pull request:
https://github.com/apache/incubator-gearpump/pull/25#issuecomment-222075106
Documentation update?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by huafengw <gi...@git.apache.org>.
Github user huafengw commented on a diff in the pull request:
https://github.com/apache/incubator-gearpump/pull/25#discussion_r64864833
--- Diff: external/kafka/src/main/scala/org/apache/gearpump/streaming/kafka/lib/source/AbstractKafkaSource.scala ---
@@ -0,0 +1,173 @@
+/*
+ * 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.gearpump.streaming.kafka.lib.source
+
+import java.util.Properties
+
+import com.twitter.bijection.Injection
+import kafka.common.TopicAndPartition
+import org.apache.gearpump.streaming.kafka.KafkaSource
+import org.apache.gearpump.streaming.kafka.lib.source.consumer.FetchThread.FetchThreadFactory
+import org.apache.gearpump.streaming.kafka.lib.util.KafkaClient
+import KafkaClient.KafkaClientFactory
+import org.apache.gearpump.streaming.kafka.lib.source.consumer.{KafkaMessage, FetchThread}
+import org.apache.gearpump.streaming.kafka.lib.source.grouper.PartitionGrouper
+import org.apache.gearpump.streaming.kafka.lib.util.KafkaClient
+import org.apache.gearpump.streaming.kafka.util.KafkaConfig
+import org.apache.gearpump.streaming.kafka.util.KafkaConfig.KafkaConfigFactory
+import org.apache.gearpump.streaming.task.TaskContext
+import org.apache.gearpump.streaming.transaction.api._
+import org.apache.gearpump.util.LogUtil
+import org.apache.gearpump.{Message, TimeStamp}
+import org.slf4j.Logger
+
+object AbstractKafkaSource {
+ private val LOG: Logger = LogUtil.getLogger(classOf[KafkaSource])
+}
+
+/**
+ * Contains implementation for Kafka source connectors, users should use
+ * [[org.apache.gearpump.streaming.kafka.KafkaSource]].
+ *
+ * This is a TimeReplayableSource which is able to replay messages given a start time.
+ * Each kafka message is tagged with a timestamp by
+ * [[org.apache.gearpump.streaming.transaction.api.MessageDecoder]] and the (timestamp, offset)
+ * mapping is stored to a [[org.apache.gearpump.streaming.transaction.api.CheckpointStore]].
+ * On recovery, we could retrieve the previously stored offset from the
+ * [[org.apache.gearpump.streaming.transaction.api.CheckpointStore]] by timestamp and start to read
+ * from there.
+ *
+ * kafka message is wrapped into gearpump [[org.apache.gearpump.Message]] and further filtered by a
+ * [[org.apache.gearpump.streaming.transaction.api.TimeStampFilter]]
+ * such that obsolete messages are dropped.
+ */
+abstract class AbstractKafkaSource(
+ topic: String,
+ props: Properties,
+ kafkaConfigFactory: KafkaConfigFactory,
+ kafkaClientFactory: KafkaClientFactory,
+ fetchThreadFactory: FetchThreadFactory)
+ extends TimeReplayableSource {
+ import org.apache.gearpump.streaming.kafka.lib.source.AbstractKafkaSource._
+
+ def this(topic: String, properties: Properties) = {
+ this(topic, properties, new KafkaConfigFactory, KafkaClient.factory, FetchThread.factory)
+ }
+
+ private lazy val config: KafkaConfig = kafkaConfigFactory.getKafkaConfig(props)
+ private lazy val kafkaClient: KafkaClient = kafkaClientFactory.getKafkaClient(config)
+ private lazy val fetchThread: FetchThread = fetchThreadFactory.getFetchThread(config, kafkaClient)
+ private lazy val messageDecoder = config.getConfiguredInstance(
+ KafkaConfig.MESSAGE_DECODER_CLASS_CONFIG, classOf[MessageDecoder])
+ private lazy val timestampFilter = config.getConfiguredInstance(
+ KafkaConfig.TIMESTAMP_FILTER_CLASS_CONFIG, classOf[TimeStampFilter])
+
+ private var startTime: Long = 0L
+ private var checkpointStoreFactory: Option[CheckpointStoreFactory] = None
+ private var checkpointStores: Map[TopicAndPartition, CheckpointStore] =
+ Map.empty[TopicAndPartition, CheckpointStore]
+
+ override def checkpoint(checkpointStoreFactory: CheckpointStoreFactory): Unit = {
+ this.checkpointStoreFactory = Some(checkpointStoreFactory)
+ }
+
+ override def open(context: TaskContext, startTime: TimeStamp): Unit = {
+ import context.{parallelism, taskId}
+
+ LOG.info("KafkaSource opened at start time {}", startTime)
--- End diff --
all right, I missed that part.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by huafengw <gi...@git.apache.org>.
Github user huafengw commented on the pull request:
https://github.com/apache/incubator-gearpump/pull/25#issuecomment-222614486
UT failed
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by manuzhang <gi...@git.apache.org>.
Github user manuzhang commented on the pull request:
https://github.com/apache/incubator-gearpump/pull/25#issuecomment-222085353
please do not merge. I need to verify whether integration test passes
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by manuzhang <gi...@git.apache.org>.
Github user manuzhang commented on a diff in the pull request:
https://github.com/apache/incubator-gearpump/pull/25#discussion_r64865818
--- Diff: examples/streaming/kafka/src/main/scala/org/apache/gearpump/streaming/examples/kafka/KafkaReadWrite.scala ---
@@ -60,14 +64,19 @@ object KafkaReadWrite extends AkkaApp with ArgumentsParser {
val sinkTopic = config.getString("sinkTopic")
val appConfig = UserConfig.empty
- val offsetStorageFactory = new KafkaStorageFactory(zookeeperConnect, brokerList)
- val source = new KafkaSource(sourceTopic, zookeeperConnect, offsetStorageFactory)
+ val props = new Properties
+ props.put(KafkaConfig.ZOOKEEPER_CONNECT_CONFIG, zookeeperConnect)
+ props.put(KafkaConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList)
+ props.put(KafkaConfig.CHECKPOINT_STORE_NAME_PREFIX_CONFIG, appName)
+ val source = new KafkaSource(sourceTopic, props)
+ val checkpointStoreFactory = new KafkaStoreFactory(props)
+ source.checkpoint(checkpointStoreFactory)
--- End diff --
then kafka offsets will not be checkpointed
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by huafengw <gi...@git.apache.org>.
Github user huafengw commented on the pull request:
https://github.com/apache/incubator-gearpump/pull/25#issuecomment-222634297
+1
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Posted by huafengw <gi...@git.apache.org>.
Github user huafengw commented on a diff in the pull request:
https://github.com/apache/incubator-gearpump/pull/25#discussion_r64865492
--- Diff: examples/streaming/kafka/src/main/scala/org/apache/gearpump/streaming/examples/kafka/KafkaReadWrite.scala ---
@@ -60,14 +64,19 @@ object KafkaReadWrite extends AkkaApp with ArgumentsParser {
val sinkTopic = config.getString("sinkTopic")
val appConfig = UserConfig.empty
- val offsetStorageFactory = new KafkaStorageFactory(zookeeperConnect, brokerList)
- val source = new KafkaSource(sourceTopic, zookeeperConnect, offsetStorageFactory)
+ val props = new Properties
+ props.put(KafkaConfig.ZOOKEEPER_CONNECT_CONFIG, zookeeperConnect)
+ props.put(KafkaConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList)
+ props.put(KafkaConfig.CHECKPOINT_STORE_NAME_PREFIX_CONFIG, appName)
+ val source = new KafkaSource(sourceTopic, props)
+ val checkpointStoreFactory = new KafkaStoreFactory(props)
+ source.checkpoint(checkpointStoreFactory)
--- End diff --
What if user doesn't call ```checkpoint```?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---