Skip to content

Commit

Permalink
Merge pull request apache#2220 from gianm/appenderator-kafka
Browse files Browse the repository at this point in the history
Appenderators, DataSource metadata, KafkaIndexTask
  • Loading branch information
himanshug committed Mar 14, 2016
2 parents 2861e85 + f22fb2c commit d51a0a0
Show file tree
Hide file tree
Showing 68 changed files with 7,750 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ Void insertOrUpdate(
final byte[] value
) throws Exception;


byte[] lookup(
final String tableName,
final String keyColumn,
final String valueColumn,
final String key
);

void createDataSourceTable();

void createPendingSegmentsTable();

void createSegmentTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MetadataStorageTablesConfig
{
public static MetadataStorageTablesConfig fromBase(String base)
{
return new MetadataStorageTablesConfig(base, null, null, null, null, null, null, null, null);
return new MetadataStorageTablesConfig(base, null, null, null, null, null, null, null, null, null);
}

public static final String TASK_ENTRY_TYPE = "task";
Expand All @@ -45,6 +45,9 @@ public static MetadataStorageTablesConfig fromBase(String base)
@JsonProperty("base")
private final String base;

@JsonProperty("dataSource")
private final String dataSourceTable;

@JsonProperty("pendingSegments")
private final String pendingSegmentsTable;

Expand Down Expand Up @@ -72,6 +75,7 @@ public static MetadataStorageTablesConfig fromBase(String base)
@JsonCreator
public MetadataStorageTablesConfig(
@JsonProperty("base") String base,
@JsonProperty("dataSource") String dataSourceTable,
@JsonProperty("pendingSegments") String pendingSegmentsTable,
@JsonProperty("segments") String segmentsTable,
@JsonProperty("rules") String rulesTable,
Expand All @@ -83,6 +87,7 @@ public MetadataStorageTablesConfig(
)
{
this.base = (base == null) ? DEFAULT_BASE : base;
this.dataSourceTable = makeTableName(dataSourceTable, "dataSource");
this.pendingSegmentsTable = makeTableName(pendingSegmentsTable, "pendingSegments");
this.segmentsTable = makeTableName(segmentsTable, "segments");
this.rulesTable = makeTableName(rulesTable, "rules");
Expand Down Expand Up @@ -115,6 +120,11 @@ public String getBase()
return base;
}

public String getDataSourceTable()
{
return dataSourceTable;
}

public String getPendingSegmentsTable()
{
return pendingSegmentsTable;
Expand Down
2 changes: 2 additions & 0 deletions distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
<argument>-c</argument>
<argument>io.druid.extensions:druid-kafka-extraction-namespace</argument>
<argument>-c</argument>
<argument>io.druid.extensions:druid-kafka-indexing-service</argument>
<argument>-c</argument>
<argument>io.druid.extensions:mysql-metadata-storage</argument>
<argument>-c</argument>
<argument>io.druid.extensions:druid-namespace-lookup</argument>
Expand Down
91 changes: 91 additions & 0 deletions extensions-core/kafka-indexing-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to Metamarkets Group Inc. (Metamarkets) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. Metamarkets 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.druid.extensions</groupId>
<artifactId>druid-kafka-indexing-service</artifactId>
<name>druid-kafka-indexing-service</name>
<description>druid-kafka-indexing-service</description>

<parent>
<groupId>io.druid</groupId>
<artifactId>druid</artifactId>
<version>0.9.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>io.druid</groupId>
<artifactId>druid-api</artifactId>
</dependency>
<dependency>
<groupId>io.druid</groupId>
<artifactId>druid-indexing-service</artifactId>
<version>0.9.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>0.9.0.0</version>
</dependency>

<!-- Tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>0.9.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.druid</groupId>
<artifactId>druid-server</artifactId>
<version>0.9.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.druid</groupId>
<artifactId>druid-indexing-service</artifactId>
<version>0.9.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets 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 io.druid.indexing.kafka;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
import com.metamx.common.IAE;
import io.druid.indexing.overlord.DataSourceMetadata;

import java.util.Map;
import java.util.Objects;

public class KafkaDataSourceMetadata implements DataSourceMetadata
{
private final KafkaPartitions kafkaPartitions;

@JsonCreator
public KafkaDataSourceMetadata(
@JsonProperty("partitions") KafkaPartitions kafkaPartitions
)
{
this.kafkaPartitions = kafkaPartitions;
}

@JsonProperty("partitions")
public KafkaPartitions getKafkaPartitions()
{
return kafkaPartitions;
}

@Override
public boolean isValidStart()
{
return true;
}

@Override
public boolean matches(DataSourceMetadata other)
{
if (getClass() != other.getClass()) {
return false;
}

return plus(other).equals(other.plus(this));
}

@Override
public DataSourceMetadata plus(DataSourceMetadata other)
{
if (!(other instanceof KafkaDataSourceMetadata)) {
throw new IAE(
"Expected instance of %s, got %s",
KafkaDataSourceMetadata.class.getCanonicalName(),
other.getClass().getCanonicalName()
);
}

final KafkaDataSourceMetadata that = (KafkaDataSourceMetadata) other;

if (that.getKafkaPartitions().getTopic().equals(kafkaPartitions.getTopic())) {
// Same topic, merge offsets.
final Map<Integer, Long> newMap = Maps.newHashMap();

for (Map.Entry<Integer, Long> entry : kafkaPartitions.getPartitionOffsetMap().entrySet()) {
newMap.put(entry.getKey(), entry.getValue());
}

for (Map.Entry<Integer, Long> entry : that.getKafkaPartitions().getPartitionOffsetMap().entrySet()) {
newMap.put(entry.getKey(), entry.getValue());
}

return new KafkaDataSourceMetadata(new KafkaPartitions(kafkaPartitions.getTopic(), newMap));
} else {
// Different topic, prefer "other".
return other;
}
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
KafkaDataSourceMetadata that = (KafkaDataSourceMetadata) o;
return Objects.equals(kafkaPartitions, that.kafkaPartitions);
}

@Override
public int hashCode()
{
return Objects.hash(kafkaPartitions);
}

@Override
public String toString()
{
return "KafkaDataSourceMetadata{" +
"kafkaPartitions=" + kafkaPartitions +
'}';
}
}
Loading

0 comments on commit d51a0a0

Please sign in to comment.