2013-07-23 43 views
0

我是新的Riak,所以请原谅我的错误理解。无法使用地图减少与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数据库:

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 \'”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.logconsole.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 

我相信我在这里失去了一些东西。可能是配置问题?这是一个非常简单的查询。一旦这个工作正常,我显然希望向更复杂的查询前进。

回答

1

您的mapreduce作业指定a Riak Search query as input,如果您的群集中没有Riak Search enabled,则这将失败。在the Java client documentation中有一些示例可以显示如何指定不同类型的输入。尽管如此,Riak MapReduce并没有被设计成一个实时查询工具,所以我不确定它是否是您正在尝试完成的正确工具。与直接键值查找相比,由于大量节点/分区需要参与每个请求,因此它会为系统增加更多的负载。这会导致更高的延迟时间,这也意味着它无法扩展以及直接访问密钥。

当Riak和其他键值存储,数据访问模式和查询模式的数据建模需要与数据结构一起考虑时,与使用关系模型相比,这是非常不同的。一些博客文章,并在相关了Riak对数据建模演示都可以在这里: