You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@tajo.apache.org by combineads <gi...@git.apache.org> on 2016/08/02 03:04:23 UTC

[GitHub] tajo pull request #1043: TAJO-1487: Kafka Scanner for kafka strage.

GitHub user combineads opened a pull request:

    https://github.com/apache/tajo/pull/1043

    TAJO-1487: Kafka Scanner for kafka strage.

    Have to implement Scanner interface for Kafka storage.
    The scan by split into many fragments. Scanner and Fragment are 1 to 1 mapping.
    For this, need to feature like this,
    Create Fragment class
    Implement 'Tuple next()' method in Scanner.
    etc..
    The issue is related to TAJO-1480, TAJO-1502. So first, must be commit TAJO-1480 and TAJO-1502.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/combineads/tajo TAJO-1487

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/tajo/pull/1043.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 #1043
    
----
commit 29d7e43aac83ff97fd5a9efbca8be8d5179f1209
Author: Byunghwa Yun <co...@combineads.co.kr>
Date:   2016-08-02T03:01:21Z

    TAJO-1487: Kafka Scanner for kafka strage.

----


---
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] tajo issue #1043: TAJO-1487: Kafka Scanner for kafka strage.

Posted by jinossy <gi...@git.apache.org>.
Github user jinossy commented on the issue:

    https://github.com/apache/tajo/pull/1043
  
    +1 LGTM!!


---
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] tajo issue #1043: TAJO-1487: Kafka Scanner for kafka strage.

Posted by combineads <gi...@git.apache.org>.
Github user combineads commented on the issue:

    https://github.com/apache/tajo/pull/1043
  
    @jinossy Done rebase.
    Thanks for your reviews.


---
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] tajo issue #1043: TAJO-1487: Kafka Scanner for kafka strage.

Posted by jinossy <gi...@git.apache.org>.
Github user jinossy commented on the issue:

    https://github.com/apache/tajo/pull/1043
  
    rebase please


---
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] tajo pull request #1043: TAJO-1487: Kafka Scanner for kafka strage.

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/tajo/pull/1043


---
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] tajo pull request #1043: TAJO-1487: Kafka Scanner for kafka strage.

Posted by jinossy <gi...@git.apache.org>.
Github user jinossy commented on a diff in the pull request:

    https://github.com/apache/tajo/pull/1043#discussion_r75110466
  
    --- Diff: tajo-storage/tajo-storage-kafka/src/main/java/org/apache/tajo/storage/kafka/KafkaFragment.java ---
    @@ -0,0 +1,199 @@
    +/**
    + * 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.tajo.storage.kafka;
    +
    +import org.apache.tajo.storage.fragment.BuiltinFragmentKinds;
    +import org.apache.tajo.storage.fragment.Fragment;
    +import org.apache.tajo.storage.kafka.KafkaFragment.KafkaFragmentKey;
    +
    +import java.net.URI;
    +
    +import com.google.common.base.Objects;
    +
    +/**
    + * Fragment for Kafka
    + */
    +public class KafkaFragment extends Fragment<KafkaFragmentKey> {
    +  private String topicName;
    +  private boolean last;
    +
    +  public KafkaFragment(URI uri, String tableName, String topicName, long startOffset, long lastOffset,
    +      int partitionId, String leaderHost) {
    +    super(BuiltinFragmentKinds.KAFKA, uri, tableName, new KafkaFragmentKey(partitionId, startOffset),
    +        new KafkaFragmentKey(partitionId, lastOffset), lastOffset - startOffset, new String[] { leaderHost });
    +
    +    this.topicName = topicName;
    +    this.last = false;
    +  }
    +
    +  public KafkaFragment(URI uri, String tableName, String topicName, long startOffset, long lastOffset,
    +      int partitionId, String leaderHost, boolean last) {
    +    this(uri, tableName, topicName, startOffset, lastOffset, partitionId, leaderHost);
    +    this.last = last;
    +  }
    +
    +  @Override
    +  public boolean isEmpty() {
    +    return startKey.isEmpty() || endKey.isEmpty();
    +  }
    +
    +  public Object clone() throws CloneNotSupportedException {
    +    KafkaFragment frag = (KafkaFragment) super.clone();
    +    frag.topicName = topicName;
    +    frag.last = last;
    +    return frag;
    +  }
    +
    +  @Override
    +  public boolean equals(Object o) {
    +    if (o instanceof KafkaFragment) {
    +      KafkaFragment t = (KafkaFragment) o;
    +      if (inputSourceId.equals(t.inputSourceId) && topicName.equals(t.topicName)
    +        && getStartKey().equals(t.getStartKey()) && getEndKey().equals(t.getEndKey())) {
    +        return true;
    +      }
    +    }
    +    return false;
    +  }
    +
    +  @Override
    +  public int hashCode() {
    +    return Objects.hashCode(inputSourceId, topicName, getStartKey(), getEndKey());
    +  }
    +
    +  @Override
    +  public String toString() {
    +    StringBuilder builder = new StringBuilder();
    +    builder.append("\"fragment\": {\"topicName\":");
    +    builder.append(topicName);
    +    builder.append(", \"uri\":");
    +    builder.append(uri);
    +    builder.append(", \"inputSourceId\":");
    +    builder.append(inputSourceId);
    +    builder.append(", \"startKey\":");
    +    builder.append(startKey);
    +    builder.append(", \"endKey\":");
    +    builder.append(endKey);
    +    builder.append(", \"length\":");
    +    builder.append(length);
    +    builder.append("}");
    +    return builder.toString();
    +  }
    +
    +  public boolean isLast() {
    +    return last;
    +  }
    +
    +  public void setLast(boolean last) {
    +    this.last = last;
    +  }
    +
    +  public String getTopicName() {
    +    return this.topicName;
    +  }
    +
    +  public void setStartKey(int partitionId, long startOffset) {
    +    this.startKey = new KafkaFragmentKey(partitionId, startOffset);
    +  }
    +
    +  public void setEndKey(int partitionId, long lastOffset) {
    +    this.endKey = new KafkaFragmentKey(partitionId, lastOffset);
    +  }
    +
    +  public static class KafkaFragmentKey implements Comparable<KafkaFragmentKey> {
    +    private final Integer partitionId;
    --- End diff --
    
    partitionId and offset should be primitive


---
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] tajo pull request #1043: TAJO-1487: Kafka Scanner for kafka strage.

Posted by jinossy <gi...@git.apache.org>.
Github user jinossy commented on a diff in the pull request:

    https://github.com/apache/tajo/pull/1043#discussion_r75111322
  
    --- Diff: tajo-storage/tajo-storage-kafka/src/main/java/org/apache/tajo/storage/kafka/KafkaScanner.java ---
    @@ -0,0 +1,274 @@
    +/**
    + * 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.tajo.storage.kafka;
    +
    +import org.apache.commons.logging.Log;
    +import org.apache.commons.logging.LogFactory;
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.kafka.clients.consumer.ConsumerRecord;
    +import org.apache.kafka.clients.consumer.ConsumerRecords;
    +import org.apache.tajo.catalog.Column;
    +import org.apache.tajo.catalog.Schema;
    +import org.apache.tajo.catalog.TableMeta;
    +import org.apache.tajo.catalog.statistics.TableStats;
    +import org.apache.tajo.exception.TajoRuntimeException;
    +import org.apache.tajo.exception.UnsupportedException;
    +import org.apache.tajo.plan.expr.EvalNode;
    +import org.apache.tajo.plan.logical.LogicalNode;
    +import org.apache.tajo.storage.EmptyTuple;
    +import org.apache.tajo.storage.Scanner;
    +import org.apache.tajo.storage.Tuple;
    +import org.apache.tajo.storage.VTuple;
    +import org.apache.tajo.storage.fragment.Fragment;
    +import org.apache.tajo.storage.kafka.KafkaFragment.KafkaFragmentKey;
    +import org.apache.tajo.storage.text.DelimitedTextFile;
    +import org.apache.tajo.storage.text.TextLineDeserializer;
    +import org.apache.tajo.storage.text.TextLineParsingError;
    +
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.concurrent.atomic.AtomicBoolean;
    +
    +import io.netty.buffer.ByteBuf;
    +import io.netty.buffer.Unpooled;
    +
    +public class KafkaScanner implements Scanner {
    +  private static final Log LOG = LogFactory.getLog(KafkaScanner.class);
    +  protected boolean inited = false;
    +
    +  private int numRows = 0;
    +  private int readRecordIndex = -1;
    +  private int fragmentSize;
    +
    +  private long pollTimeout;
    +
    +  private KafkaFragmentKey startKey;
    +  private KafkaFragmentKey endKey;
    +  private long currentOffset;
    +
    +  private SimpleConsumerManager simpleConsumerManager;
    +
    +  private List<ConsumerRecord<byte[], byte[]>> records = null;
    +
    +  private Schema schema;
    +  private TableMeta meta;
    +  private TableStats tableStats;
    +  private KafkaFragment fragment;
    +  private Column[] targets;
    +  private TextLineDeserializer deserializer;
    +  private AtomicBoolean finished = new AtomicBoolean(false);
    --- End diff --
    
    There is no race condition in scanner.


---
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.
---