gearpump-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From manuzhang <...@git.apache.org>
Subject [GitHub] incubator-gearpump pull request: fix GEARPUMP-122, refactor kafka ...
Date Fri, 27 May 2016 07:00:23 GMT
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.
---

Mime
View raw message