我正在使用0.9版本,我有这种非常天真的方法来更新文档,它基本上进行了比较和交换: (仅显示相关代码)
for (int i = 0; i < MAX_RETRY; i++) { GetResponse get = client.prepareGet().execute().actionGet(); // Assume document already exists try { client .prepareIndex() .setId(id) .setSource(newDoc) .setVersion(get.getVersion()) .execute() .actionGet(); // Successfully updated } catch (VersionConflictEngineException e) { continue; //retry } throw UpdateFailedException(); }该代码适用于大多数更新,但也比我期望的版本冲突更频繁地失败。 奇怪的是,似乎服务器文档在失败时是预期版本的+1。 有什么明显的东西我不见了吗?
我知道Elasticsearch有一个适当的更新功能,但我不能使用这个ATM。
I'm using version 0.9 and I have this very naive approach to update documents, which essentially does a compare and swap: (only relevant code is shown)
for (int i = 0; i < MAX_RETRY; i++) { GetResponse get = client.prepareGet().execute().actionGet(); // Assume document already exists try { client .prepareIndex() .setId(id) .setSource(newDoc) .setVersion(get.getVersion()) .execute() .actionGet(); // Successfully updated } catch (VersionConflictEngineException e) { continue; //retry } throw UpdateFailedException(); }The code works for most of the updates, but also fails more frequent than I'd expect with version conflict. Curiously, it always seems that the server document is +1 the expected version when it fails. Is there anything obvious that I'm missing?
I understand Elasticsearch has a proper update functionality but I can't use this ATM.
最满意答案
事实证明,由于存在错误,我只是非常频繁地更新文档。
Turns out I was just legitimately updating documents very frequently due to a bug.
更多推荐
发布评论