Can a CouchDB document update handler get an update conflict?

人走茶凉 提交于 2019-12-18 11:56:03

问题


How likely is a revision conflict when using an update handler? Should I concern myself with conflict-handling code when writing a robust update function?

As described in Document Update Handlers, CouchDB 0.10 and later allows on-demand server-side document modification.

Update handlers can process non-JSON formats; but the other major features are these:

  • An HTTP front-end to arbitrarily complex document modification code
  • Similar code needn't be written for all possible clients—a DRY architecture
  • Execution is faster and less likely to hit a revision conflict

I am unclear about the third point. Executing locally, the update handler will run much faster and with lower latency. But in situations with high contention, that does not guarantee a successful update. Or does the update handler guarantee a successful update?


回答1:


Update conflicts are still possible when using update handlers.

Due to the reduced "round-trip time," the chance of an update conflict is lower but not zero. A conflict will feel normal: a 409 response code with this JSON:

{"error":"conflict","reason":"Document update conflict."}

I successfully triggered a conflict using the document update handler example, and running curl twice in short succession in the shell.

curl -v -X PUT \
http://localhost:5984/db/_design/app/_update/accumulate/my_doc?amount=10 \
& curl -X PUT \
  http://localhost:5984/db/_design/app/_update/accumulate/my_doc?amount=1

One of the curl responses (randomly) was a 201 and the other a 409.

Document update handlers do not fundamentally change CouchDB

Updates are subject to conflicts, as well as validation failures (401 Unauthorized, 403 Forbidden, etc.)



来源:https://stackoverflow.com/questions/2983220/can-a-couchdb-document-update-handler-get-an-update-conflict

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!