在Hadoop DistributedCache上存储TreeSet

时间:2013-04-21 22:23:31

标签: java serialization hadoop mapreduce distributed-cache

我正在尝试在TreeSet上存储DistributedCache以供Hadoop map-reduce作业使用。到目前为止,我有以下内容将HDFS中的文件添加到DistributedCache

Configuration conf = new Configuration();
DistributedCache.addCacheFile(new URI("/my/cache/path"), conf);
Job job = new Job(conf, "my job");
// Proceed with remainder of Hadoop map-reduce job set-up and running

如何有效地将TreeSet(我已在此类中构建)添加到我添加到DistributedCache的此文件中?我应该使用Java的本机序列化以某种方式将其序列化到文件中吗?

请注意,TreeSet在启动map-reduce作业的主类中构建一次。 TreeSet永远不会被修改,我只希望每个映射器都具有对这个TreeSet的只读访问权限,而不必反复重建它。

1 个答案:

答案 0 :(得分:1)

序列化TreeSet似乎就是这种方法。在这种情况下,您不需要创建HashMap。只需从文件中反序列化TreeSet,然后使用这些方法根据密钥进行搜索。我喜欢这种方法。