Sitemap
Roger Hoover

Roger Hoover

Engineer at Confluent

Camus Gotchas

3 min readNov 27, 2013

--

LinkedIn has been making significant contributions to the Open Source community, including Apache Kafka, Voldemort, Apache Samza, and more. Recently, they’ve open-sourced their ETL job, called Camus, which batch imports data from Kafka into Hadoop. It has some great features like automatic topic discovery, Avro schema management, date partitioning, and fault tolerance.

I’m very grateful for this project. It has saved me a lot of effort. However, there are still some rough edges. These are the things I’ve run into so far that might save you some grief. I’m using Kafka 0.8.0-beta1 and Avro for serialization.

Schema Registry

The SchemaRegistry.register() API should be globally idempotent. If the same schema is added to the registry more than once from any JVM process, it should return the same schema id. This requirement is not stated anywhere but the default message encoder assumes that it can safely auto-register any schema that it hasn’t seen before. The current MemorySchemaRegistry implementation (intended as a toy demo) is not idempotent, which can trip you up when you’re trying to get started.

A simple solution is to use Avro Fingerprints but that requires that schema ids be able to hold 64-bit values. Unfortunately, the default message encoding assumes integer (32-bit) schema ids (more on this below).

Message Encoding/Decoding

The default messaging encoding for Kafka and Avro assumes that schema ids are integer (32-bit) values. If your schema ids are bigger than 32 bits, you’ll need to write your own encoder and decoder and there isn’t a great way to share the 90+% of the code that you’ll want to leverage from the default implementation.

Partitioner API

What if you want to override the default path conventions for HDFS? No worries, Camus allows you to plugin your own Partitioner. Problem solved, right?

Get Roger Hoover’s stories in your inbox

Join Medium for free to get updates from this writer.

Not so fast! If you need to use data from the message to construct the HDFS path, it requires a few awkward steps.

  • First, in your message decoder, extract the data you need from the message and put it into a MapWritable on the CamusWrapper. The framework will add this to an ETLKey that will get passed to your partitioner.
  • Strangely, the ETLKey is only passed to one of the methods of your partitioner and not the one where you construct the HDFS path. To get around this, you have to extract the data in the encodePartition() method, encode it as a string, and decode it in the generatePartitionedPath() method. Not just any string encoding will do. The encoding must conform to some documented and some additional undocumented assumptions.

Kafka 0.8.x

Use this branch with Kafka 0.8.x.

Build Dependencies

If you want your own project to depend on Camus, you can probably include it’s source in your project using git submodules or you can publish it to your own Maven repository. We setup an internal Archiva instance and published camus artifacts to it. However, the camus build has two dependent jars bundled into it so you’ll need to publish those to your Archiva instance as well.

mvn deploy:deploy-file -DpomFile=lib/avro-repo-bundle-1.7.4-SNAPSHOT-withdeps.xml -Dfile=lib/avro-repo-bundle-1.7.4-SNAPSHOT-withdeps.jar -DrepositoryId="your-repo.snapshots" -Durl="http://your-achiva-host:8070/archiva/repository/snapshots/"mvn deploy:deploy-file -DpomFile=lib/kafka-0.8-SNAPSHOT.xml -Dfile=lib/kafka-0.8-SNAPSHOT.jar -DrepositoryId="your-repo.snapshots" -Durl="http://your-achiva-host:8070/archiva/repository/snapshots/"

Configuration

There are a lot of properties you can configure and most of them are not documented. You’ll have to look at the source code.

Embedding The Producer

When you embed the KafkaAvroMessageEncoder class in your application as a producer to the Camus, you may run into some dependency issues. In particular, let’s say you have a RESTful API that takes messages over HTTP and enqueues them to Kafka. If you build an uber war file that includes all the Camus dependencies, it will include hadoop-core. By default, Jetty will scan all dependent jars in the war file and read any WEB-INF/web.xml files that it finds.

$ jar tf repository/org/apache/hadoop/hadoop-core/1.0.3/hadoop-core-1.0.3.jar | grep web.xml
webapps/datanode/WEB-INF/web.xml
webapps/hdfs/WEB-INF/web.xml
webapps/history/WEB-INF/web.xml
webapps/job/WEB-INF/web.xml
webapps/task/WEB-INF/web.xml

If you decompile the classes that get loaded by the web apps in hadoop-core, you’ll see they are referring to an old version of Jersey (when it was still com.sun.jersey instead of org.glassfish.jersey).

javap ./org/apache/hadoop/hdfs/web/resources/UserProvider.class | grep jersey
public com.sun.jersey.spi.inject.Injectable getInjectable(com.sun.jersey.core.spi.component.ComponentContext, java.lang.annotation.Annotation, java.lang.Object);

This will cause a ClassNotFoundException for com.sun.jersey.spi.inject.InjectableProvider unless you tell Jetty not to include any WEB-INF dirs from included jars by setting the WebInfIncludeJarPattern so it won’t match anything (e.g. “none”).

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name=”contextPath”>/</Set>
<Set name=”war”>/path/to/war</Set>
<Call name="setAttribute">
<Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
<Arg>none</Arg>
</Call>
</Configure>

--

--