Hi All,I just discovered Jedis today (it seems great!) and am already trying to put it to a non-standard use.I want to use Redis to coordinate among mappers in a Hadoop job. Hadoop creates "Mapper" classes on each machine in the cluster and then has those classes repeatedly call the "map" method to process each line of data. So I'm trying to create a connection pool when the Mapper initializes and then have each call of the map method get a connection from the pool and return it when it's done.This is giving me an error:2012-11-24 20:53:25,087 FATAL org.apache.hadoop.mapred.Child: Error running child : java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool$Config at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at org.apache.hadoop.conf.Configuration.getClassByNameOrNull(Configuration.java:1510) at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1475) at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1569) at org.apache.hadoop.mapreduce.task.JobContextImpl.getMapperClass(JobContextImpl.java:191) at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:605) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:325) at org.apache.hadoop.mapred.Child$4.run(Child.java:268) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:396) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1332) at org.apache.hadoop.mapred.Child.main(Child.java:262) Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool$Config at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 13 moreHere's the basic code I'm trying to run:static class Accretor
extends TableMapper<ImmutableBytesWritable, Writable> {
private JedisPool jPool = null;
@Override
protected void setup(Context context)
throws IOException, InterruptedException {
JedisPoolConfig j = new JedisPoolConfig();
jPool = new JedisPool(j, "ec2-23-20-255-48.compute-1.amazonaws.com");
System.out.println("Opened jedis connection");
}
@Override
public void map(ImmutableBytesWritable row, Result r, Context context)
throws IOException {
// basic setup -- get conf, create logging table, start timer
Jedis jedis = jPool.getResource();
jPool.returnResource(jedis);
}
I have Jedis included via Maven:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
And I tried including the Maven artifact for commons-pool just in case:
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.4</version>
</dependency>
I'm using Shade to bundle a "fat jar" for Hadoop that should include all the dependencies. When I run the same basic code but on my local machine, it works fine. So I'm guessing it has something to do with the dependency packaging...
Any ideas?
Thanks!
-George
Hi!You found a solution?I have hadoop single node and the same problem.I think it's because, map run in a separate thread (look code below).import java.io.IOException;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoop.mapreduce.Mapper;import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import org.apache.hadoop.util.GenericOptionsParser;import redis.clients.jedis.Jedis;import redis.clients.jedis.JedisPool;import redis.clients.jedis.JedisPoolConfig;public class RedisTest {protected static Jedis getJedis() {JedisPoolConfig config = new JedisPoolConfig();JedisPool pool = new JedisPool(config, "localhost");return pool.getResource();}static class RedisMapper extends Mapper<IntWritable, IntWritable, IntWritable, IntWritable> {protected Jedis jedis;public void map(IntWritable key, IntWritable value, Context context)throws IOException, InterruptedException {if (jedis == null) getJedis();}}public static void main(String[] args) throws Exception {// if this uncomment, error will not be// getJedis();// System.exit(1);Configuration conf = new Configuration();String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();if (otherArgs.length < 2) {System.err.println("Usage params: <input_dir> <output_dir>");System.exit(2);}Job job = new Job(conf, "Test Jedis");job.setJarByClass(RedisTest.class);job.setMapperClass(RedisMapper.class);job.setOutputKeyClass(IntWritable.class);job.setOutputValueClass(IntWritable.class);FileInputFormat.addInputPath(job, new Path(otherArgs[0]));FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));System.exit(job.waitForCompletion(true) ? 0 : 1);}}
суббота, 24 ноября 2012 г., 23:21:21 UTC+2 пользователь George London написал:
--
You received this message because you are subscribed to a topic in the Google Groups "Jedis" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jedis_redis/ziPNqJTtBes/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to jedis_redis...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Thi is great information and it is useful for hadoop learners.123trainings provides<a href="http://123trainings.com/it-hadoop-bigdata-online-training.html">hadoop online training</a>