2018-12-13 14:47:20 -05:00
---
2019-08-21 00:48:59 -04:00
id: other-hadoop
2019-04-19 18:52:26 -04:00
title: "Working with different versions of Apache Hadoop"
2018-12-13 14:47:20 -05:00
---
2018-11-13 12:38:37 -05:00
<!--
~ 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.
-->
2015-05-05 17:07:32 -04:00
2019-04-19 18:52:26 -04:00
Apache Druid (incubating) can interact with Hadoop in two ways:
2016-02-26 01:30:01 -05:00
2019-08-21 00:48:59 -04:00
1. [Use HDFS for deep storage ](../development/extensions-core/hdfs.md ) using the druid-hdfs-storage extension.
2. [Batch-load data from Hadoop ](../ingestion/hadoop.md ) using Map/Reduce jobs.
2016-02-26 01:30:01 -05:00
2016-07-18 08:47:58 -04:00
These are not necessarily linked together; you can load data with Hadoop jobs into a non-HDFS deep storage (like S3),
and you can use HDFS for deep storage even if you're loading data from streams rather than using Hadoop jobs.
2016-02-26 01:30:01 -05:00
2016-07-18 08:47:58 -04:00
For best results, use these tips when configuring Druid to interact with your favorite Hadoop distribution.
2015-05-05 17:07:32 -04:00
2016-07-18 08:47:58 -04:00
## Tip #1: Place Hadoop XMLs on Druid classpath
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
Place your Hadoop configuration XMLs (core-site.xml, hdfs-site.xml, yarn-site.xml, mapred-site.xml) on the classpath
2019-02-28 21:10:39 -05:00
of your Druid processes. You can do this by copying them into `conf/druid/_common/core-site.xml` ,
2016-07-18 08:47:58 -04:00
`conf/druid/_common/hdfs-site.xml` , and so on. This allows Druid to find your Hadoop cluster and properly submit jobs.
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
## Tip #2: Classloader modification on Hadoop (Map/Reduce jobs only)
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
Druid uses a number of libraries that are also likely present on your Hadoop cluster, and if these libraries conflict,
your Map/Reduce jobs can fail. This problem can be avoided by enabling classloader isolation using the Hadoop job
property `mapreduce.job.classloader = true` . This instructs Hadoop to use a separate classloader for Druid dependencies
and for Hadoop's own dependencies.
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
If your version of Hadoop does not support this functionality, you can also try setting the property
`mapreduce.job.user.classpath.first = true` . This instructs Hadoop to prefer loading Druid's version of a library when
there is a conflict.
2015-07-07 23:51:44 -04:00
2016-07-29 13:19:54 -04:00
Generally, you should only set one of these parameters, not both.
2016-07-18 08:47:58 -04:00
These properties can be set in either one of the following ways:
2016-02-26 01:30:01 -05:00
2019-08-21 00:48:59 -04:00
- Using the task definition, e.g. add `"mapreduce.job.classloader": "true"` to the `jobProperties` of the `tuningConfig` of your indexing task (see the [Hadoop batch ingestion documentation ](../ingestion/hadoop.md )).
2019-01-30 22:41:07 -05:00
- Using system properties, e.g. on the MiddleManager set `druid.indexer.runner.javaOpts=... -Dhadoop.mapreduce.job.classloader=true` .
2015-07-07 23:51:44 -04:00
2016-11-18 19:16:50 -05:00
### Overriding specific classes
When `mapreduce.job.classloader = true` , it is also possible to specifically define which classes should be loaded from the hadoop system classpath and which should be loaded from job-supplied JARs.
This is controlled by defining class inclusion/exclusion patterns in the `mapreduce.job.classloader.system.classes` property in the `jobProperties` of `tuningConfig` .
For example, some community members have reported version incompatibility errors with the Validator class:
```
Error: java.lang.ClassNotFoundException: javax.validation.Validator
```
The following `jobProperties` excludes `javax.validation.` classes from being loaded from the system classpath, while including those from `java.,javax.,org.apache.commons.logging.,org.apache.log4j.,org.apache.hadoop.` .
```
"jobProperties": {
"mapreduce.job.classloader": "true",
"mapreduce.job.classloader.system.classes": "-javax.validation.,java.,javax.,org.apache.commons.logging.,org.apache.log4j.,org.apache.hadoop."
}
```
[mapred-default.xml ](https://hadoop.apache.org/docs/current/hadoop-mapreduce-client/hadoop-mapreduce-client-core/mapred-default.xml ) documentation contains more information about this property.
2016-07-18 08:47:58 -04:00
## Tip #3: Use specific versions of Hadoop libraries
Druid loads Hadoop client libraries from two different locations. Each set of libraries is loaded in an isolated
classloader.
1. HDFS deep storage uses jars from `extensions/druid-hdfs-storage/` to read and write Druid data on HDFS.
2. Batch ingestion uses jars from `hadoop-dependencies/` to submit Map/Reduce jobs (location customizable via the
2018-09-04 15:54:41 -04:00
`druid.extensions.hadoopDependenciesDir` runtime property; see [Configuration ](../configuration/index.html#extensions )).
2016-07-18 08:47:58 -04:00
2018-04-30 23:49:14 -04:00
`hadoop-client:2.8.3` is the default version of the Hadoop client bundled with Druid for both purposes. This works with
2016-07-18 08:47:58 -04:00
many Hadoop distributions (the version does not necessarily need to match), but if you run into issues, you can instead
have Druid load libraries that exactly match your distribution. To do this, either copy the jars from your Hadoop
cluster, or use the `pull-deps` tool to download the jars from a Maven repository.
### Preferred: Load using Druid's standard mechanism
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
If you have issues with HDFS deep storage, you can switch your Hadoop client libraries by recompiling the
druid-hdfs-storage extension using an alternate version of the Hadoop client libraries. You can do this by editing
the main Druid pom.xml and rebuilding the distribution by running `mvn package` .
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
If you have issues with Map/Reduce jobs, you can switch your Hadoop client libraries without rebuilding Druid. You can
do this by adding a new set of libraries to the `hadoop-dependencies/` directory (or another directory specified by
druid.extensions.hadoopDependenciesDir) and then using `hadoopDependencyCoordinates` in the
2019-08-21 00:48:59 -04:00
[Hadoop Index Task ](../ingestion/hadoop.md ) to specify the Hadoop dependencies you want Druid to load.
2016-07-18 08:47:58 -04:00
Example:
Suppose you specify `druid.extensions.hadoopDependenciesDir=/usr/local/druid_tarball/hadoop-dependencies` , and you have downloaded
`hadoop-client` 2.3.0 and 2.4.0, either by copying them from your Hadoop cluster or by using `pull-deps` to download
the jars from a Maven repository. Then underneath `hadoop-dependencies` , your jars should look like this:
2015-07-07 23:51:44 -04:00
```
2016-01-06 00:27:52 -05:00
hadoop-dependencies/
2015-07-07 23:51:44 -04:00
└── hadoop-client
├── 2.3.0
│ ├── activation-1.1.jar
│ ├── avro-1.7.4.jar
│ ├── commons-beanutils-1.7.0.jar
│ ├── commons-beanutils-core-1.8.0.jar
│ ├── commons-cli-1.2.jar
│ ├── commons-codec-1.4.jar
..... lots of jars
└── 2.4.0
├── activation-1.1.jar
├── avro-1.7.4.jar
├── commons-beanutils-1.7.0.jar
├── commons-beanutils-core-1.8.0.jar
├── commons-cli-1.2.jar
├── commons-codec-1.4.jar
..... lots of jars
```
2016-07-18 08:47:58 -04:00
As you can see, under `hadoop-client` , there are two sub-directories, each denotes a version of `hadoop-client` .
2016-02-26 01:30:01 -05:00
2019-08-21 00:48:59 -04:00
Next, use `hadoopDependencyCoordinates` in [Hadoop Index Task ](../ingestion/hadoop.md ) to specify the Hadoop dependencies you want Druid to load.
2016-02-26 01:30:01 -05:00
2016-07-18 08:47:58 -04:00
For example, in your Hadoop Index Task spec file, you can write:
2016-02-26 01:30:01 -05:00
`"hadoopDependencyCoordinates": ["org.apache.hadoop:hadoop-client:2.4.0"]`
2016-07-18 08:47:58 -04:00
This instructs Druid to load hadoop-client 2.4.0 when processing the task. What happens behind the scene is that Druid first looks for a folder
called `hadoop-client` underneath `druid.extensions.hadoopDependenciesDir` , then looks for a folder called `2.4.0`
underneath `hadoop-client` , and upon successfully locating these folders, hadoop-client 2.4.0 is loaded.
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
### Alternative: Append your Hadoop jars to the Druid classpath
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
You can also load Hadoop client libraries in Druid's main classloader, rather than an isolated classloader. This
mechanism is relatively easy to reason about, but it also means that you have to ensure that all dependency jars on the
classpath are compatible. That is, Druid makes no provisions while using this method to maintain class loader isolation
so you must make sure that the jars on your classpath are mutually compatible.
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
1. Set `druid.indexer.task.defaultHadoopCoordinates=[]` . By setting this to an empty list, Druid will not load any other Hadoop dependencies except the ones specified in the classpath.
2. Append your Hadoop jars to Druid's classpath. Druid will load them into the system.
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
## Notes on specific Hadoop distributions
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
If the tips above do not solve any issues you are having with HDFS deep storage or Hadoop batch indexing, you may
have luck with one of the following suggestions contributed by the Druid community.
2015-07-07 23:51:44 -04:00
2016-07-18 08:47:58 -04:00
### CDH
2015-07-07 23:51:44 -04:00
2016-04-12 13:51:51 -04:00
Members of the community have reported dependency conflicts between the version of Jackson used in CDH and Druid when running a Mapreduce job like:
2016-07-18 08:47:58 -04:00
2016-04-12 13:51:51 -04:00
```
java.lang.VerifyError: class com.fasterxml.jackson.datatype.guava.deser.HostAndPortDeserializer overrides final method deserialize.(Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;)Ljava/lang/Object;
```
2016-07-18 08:47:58 -04:00
**Preferred workaround**
2015-07-02 20:46:08 -04:00
2016-07-18 08:47:58 -04:00
First, try the tip under "Classloader modification on Hadoop" above. More recent versions of CDH have been reported to
work with the classloader isolation option (`mapreduce.job.classloader = true`).
2016-04-13 17:20:33 -04:00
2016-07-18 08:47:58 -04:00
**Alternate workaround - 1**
2016-04-13 17:20:33 -04:00
2016-07-18 08:47:58 -04:00
You can try editing Druid's pom.xml dependencies to match the version of Jackson in your Hadoop version and recompile Druid.
2016-04-13 17:20:33 -04:00
2019-08-21 00:48:59 -04:00
For more about building Druid, please see [Building Druid ](../development/build.md ).
2015-07-02 20:46:08 -04:00
2016-07-18 08:47:58 -04:00
**Alternate workaround - 2**
2016-04-13 17:20:33 -04:00
2019-01-30 22:41:07 -05:00
Another workaround solution is to build a custom fat jar of Druid using [sbt ](http://www.scala-sbt.org/ ), which manually excludes all the conflicting Jackson dependencies, and then put this fat jar in the classpath of the command that starts Overlord indexing service. To do this, please follow the following steps.
2015-07-18 21:02:06 -04:00
(1) Download and install sbt.
(2) Make a new directory named 'druid_build'.
2019-08-21 00:48:59 -04:00
(3) Cd to 'druid_build' and create the build.sbt file with the content [here ](./use_sbt_to_build_fat_jar.md ).
2015-07-18 21:02:06 -04:00
You can always add more building targets or remove the ones you don't need.
2015-07-07 23:51:44 -04:00
(4) In the same directory create a new directory named 'project'.
2015-07-18 21:02:06 -04:00
(5) Put the druid source code into 'druid_build/project'.
(6) Create a file 'druid_build/project/assembly.sbt' with content as follows.
```
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.13.0")
```
(7) In the 'druid_build' directory, run 'sbt assembly'.
(8) In the 'druid_build/target/scala-2.10' folder, you will find the fat jar you just build.
2015-07-07 23:51:44 -04:00
(9) Make sure the jars you've uploaded has been completely removed. The HDFS directory is by default '/tmp/druid-indexing/classpath'.
2015-07-18 21:02:06 -04:00
(10) Include the fat jar in the classpath when you start the indexing service. Make sure you've removed 'lib/*' from your classpath because now the fat jar includes all you need.
2015-05-05 17:07:32 -04:00
2016-07-18 08:47:58 -04:00
**Alternate workaround - 3**
2016-04-13 17:20:33 -04:00
If sbt is not your choice, you can also use `maven-shade-plugin` to make a fat jar: relocation all jackson packages will resolve it too. In this way, druid will not be affected by jackson library embedded in hadoop. Please follow the steps below:
(1) Add all extensions you needed to `services/pom.xml` like
```xml
< dependency >
2018-08-30 12:56:26 -04:00
< groupId > org.apache.druid.extensions< / groupId >
2016-04-13 17:20:33 -04:00
< artifactId > druid-avro-extensions< / artifactId >
< version > ${project.parent.version}< / version >
< / dependency >
< dependency >
2018-11-06 00:33:42 -05:00
< groupId > org.apache.druid.extensions< / groupId >
2016-04-13 17:20:33 -04:00
< artifactId > druid-parquet-extensions< / artifactId >
< version > ${project.parent.version}< / version >
< / dependency >
< dependency >
2018-08-30 12:56:26 -04:00
< groupId > org.apache.druid.extensions< / groupId >
2016-04-13 17:20:33 -04:00
< artifactId > druid-hdfs-storage< / artifactId >
< version > ${project.parent.version}< / version >
< / dependency >
< dependency >
2018-08-30 12:56:26 -04:00
< groupId > org.apache.druid.extensions< / groupId >
2016-04-13 17:20:33 -04:00
< artifactId > mysql-metadata-storage< / artifactId >
< version > ${project.parent.version}< / version >
< / dependency >
```
(2) Shade jackson packages and assemble a fat jar.
```xml
< plugin >
< groupId > org.apache.maven.plugins< / groupId >
< artifactId > maven-shade-plugin< / artifactId >
< executions >
< execution >
< phase > package< / phase >
< goals >
< goal > shade< / goal >
< / goals >
< configuration >
< outputFile >
${project.build.directory}/${project.artifactId}-${project.version}-selfcontained.jar
< / outputFile >
< relocations >
< relocation >
< pattern > com.fasterxml.jackson< / pattern >
< shadedPattern > shade.com.fasterxml.jackson< / shadedPattern >
< / relocation >
< / relocations >
< artifactSet >
< includes >
< include > *:*< / include >
< / includes >
< / artifactSet >
< filters >
< filter >
< artifact > *:*< / artifact >
< excludes >
< exclude > META-INF/*.SF< / exclude >
< exclude > META-INF/*.DSA< / exclude >
< exclude > META-INF/*.RSA< / exclude >
< / excludes >
< / filter >
< / filters >
< transformers >
< transformer implementation = "org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" / >
< / transformers >
< / configuration >
< / execution >
< / executions >
< / plugin >
```
Copy out `services/target/xxxxx-selfcontained.jar` after `mvn install` in project root for further usage.
(3) run hadoop indexer (post an indexing task is not possible now) as below. `lib` is not needed anymore. As hadoop indexer is a standalone tool, you don't have to replace the jars of your running services:
```bash
java -Xmx32m \
-Dfile.encoding=UTF-8 -Duser.timezone=UTC \
-classpath config/hadoop:config/overlord:config/_common:$SELF_CONTAINED_JAR:$HADOOP_DISTRIBUTION/etc/hadoop \
-Djava.security.krb5.conf=$KRB5 \
2018-08-30 12:56:26 -04:00
org.apache.druid.cli.Main index hadoop \
2016-04-13 17:20:33 -04:00
$config_path
```