【问题标题】:Failed to use map reduce with riak无法将 map reduce 与 riak 一起使用
【发布时间】:2013-07-23 16:17:14
【问题描述】:

我是 Riak 的新手,所以请原谅我的误解。

我能够添加新条目并通过键和索引执行查询。但是我必须实现更复杂的查询,所以我尝试使用MapReduce

我有一个名为 Volume 的应用程序级实体,它现在只有普通字段:

public class Volume implements Comparable<Volume>, Serializable {
    @RiakIndex(name = "id")
    @JsonProperty("id")
    private Integer id;

    @RiakIndex(name = "name")
    @RiakKey
    private String name;

    @RiakIndex(name = "created_at")
    @JsonProperty("created_at")
    private long createdAt;


    // setters, getters....
}

这是我将Volume 实例添加到 Riak DB 的方法:

IRiakClient riakClient = RiakFactory.httpClient();
Bucket bucket = riakClient.fetchBucket(bucketName).execute();
for (int i = 0; i < n; i++) {
    int id = i;
    ManagedVolume volume = new ManagedVolume();
    volume.setCreatedAt(System.currentTimeMillis());
    volume.setId(id);
    volume.setName("volume" + i);
    bucket.store(volume).execute();
}

现在我可以毫无问题地检索实例,如下所示。

Collection<String> col = backet.fetchIndex(IntIndex.named("id")).from(3).to(5).execute();

但是所有使用MapReduce 的尝试都失败了:

String str = riakClient.mapReduce(bucketName, "name: volume1")
    .addMapPhase(new NamedJSFunction("Riak.mapValuesJson")).
    execute().getResultRaw();

我尝试在不添加Riak.mapValuesJson 的情况下执行此操作,尝试修改查询以使用id 而不是name 并包装volume`` with quotes ("name: \"volume\""","name: \ 'volume\'"etc.) but nothing helps. I always get HTTP status 500 and the following error: {"error":"map_reduce_error"}`

这里是堆栈跟踪:

Exception in thread "main" com.basho.riak.client.RiakException: java.io.IOException: {"error":"map_reduce_error"}
    at com.basho.riak.client.query.MapReduce.execute(MapReduce.java:81)
    at com.infinidat.riak.TryRiak.search(TryRiak.java:288)
    at com.infinidat.riak.TryRiak.main(TryRiak.java:66)
Caused by: java.io.IOException: {"error":"map_reduce_error"}
    at com.basho.riak.client.raw.http.ConversionUtil.convert(ConversionUtil.java:589)
    at com.basho.riak.client.raw.http.HTTPClientAdapter.mapReduce(HTTPClientAdapter.java:386)
    at com.basho.riak.client.query.MapReduce.execute(MapReduce.java:79)
    ... 2 more

我在 Riak 的 error.log 中找到了以下记录,在 console.log 中找到了类似的记录。

2013-07-23 19:14:12.451 [error] <0.194.0> Supervisor riak_pipe_builder_sup had child undefined started with {riak_pipe_builder,start_link,undefined} at <0.18058.4> exit with reason {{modfun,riak_search,mapred_search,[<<"VolumeBucket">>,<<"name: 1">>]},error,badarg,[{ets,lookup,[schema_table,<<"VolumeBucket">>],[]},{riak_search_config,get_schema,1,[{file,"src/riak_search_config.erl"},{line,69}]},{riak_search_client,parse_query,3,[{file,"src/riak_search_client.erl"},{line,40}]},{riak_search,parse_query,3,[{file,"src/riak_search.erl"},{line,59}]},{riak_search,mapred_search,3,[{file,"src/riak_search.erl"},{line,46}]},{riak_kv_mrc_pipe,send_inputs,3,[{file,"src/riak_kv_mrc..."},...]},...]} in context child_terminated

我相信我在这里缺少一些东西。可能是配置问题?这是一个非常简单的查询。一旦这个工作有效,我显然想继续进行更复杂的查询。

【问题讨论】:

    标签: java riak riak-search


    【解决方案1】:

    您的 mapreduce 作业指定 a Riak Search query as input,如果您的集群中没有 Riak Search enabled,这将失败。 the Java client documentation 中提供了一些示例,展示了如何指定不同类型的输入。

    话虽如此,Riak MapReduce 并非旨在成为实时查询工具,因此我不确定它是否适合您想要完成的任务。与直接键值查找相比,它显着增加了系统负载,因为大量节点/分区需要参与每个请求。这会导致更高的延迟,也意味着它往往无法像直接访问密钥那样扩展。

    在为 Riak 和其他键值存储进行数据建模时,需要预先考虑数据访问模式和查询模式以及数据结构,这与使用关系模型相比有很大不同。一些与 Riak 中的数据建模相关的博客文章和演示文稿可在此处获得:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      相关资源
      最近更新 更多