0

I am using oficial Riak Java client v2.0.2. When I update previously written value (with 2i indexes), the secondary indexes are not preserved.

This is how I do update:

Location location = new Location(this.namespace, key);
UpdateValue updateOp = new UpdateValue.Builder(location)
        .withFetchOption(FetchValue.Option.DELETED_VCLOCK, true)
        .withUpdate(new RiakKVUpdateValue(values))
        .build();

And this is my update class:

public class RiakKVUpdateValue extends Update<Map<String, String>> {

    private final Map<String, String> value;

    public RiakKVUpdateValue(HashMap<String, ByteIterator> values) {
        this.value = StringByteIterator.getStringMap(values);
    }

    @Override
    public Map<String, String> apply(Map<String, String> original) {
        return this.value;
    }
}

I haven't found anything in the docs about updating objects with 2i indexes.

  • Am I doing someting wrong?
  • Should I do manual Read/Modify/Write?
4

1 回答 1

3

每次更新值时,您都必须获取索引并将其写回。请参阅2i 索引对象

我建议创建一个字段来保存索引并用@RiakIndex. 使用此注释注释的字段在获取时由 Java 客户端自动填充 2i 值。然后,复制其值RiakKVUpdateValue.apply()以保留它。或者,如您已经提到的,获取然后在两个单独的命令中写回。这将允许您控制要写回的元数据。不要忘记填充 VClocks。

PS 自动保留 2i 可能不是一个好主意,因为用户想要保留旧的 2i 值并不明显。我相信这就是为什么要由用户决定的原因。

于 2016-01-11T05:51:52.360 回答