Avoiding Race Conditions and Document Versioning
Our project is considering migrating from CouchDB to CouchBase. The initial benchmarks and prototype perform really well. One of the features in CouchDB we really liked was the embedded document versioning. Each document had the _rev field. If you attempted to update an existing document and the _rev field was not a proper increment the database would fail and send the client an error. We relied on this heavily to avoid race conditions.
A typical service request is handled somewhat like this:
1. Client sends request to service.
2. Service retrieves CouchDB document
3. Service updates necessary fields to reflect client requests
4. Service updates the document on CouchDB
If the document was updated in the middle of this service operation the _rev would be incremented by the other update operation, preventing the document from being clobbered by this other service request by sending the client an error saying that the _rev field was different.
Is there a similar feature in CouchBase 2.0 that we can leverage to obtain a similar functionality?
Thanks, I guess I just hadn't read enough into the feature set and manual. I was reading the migration guide about the _id and _rev fields being removed and that the feature was completely removed for validation by the server. I guess a better phrase would be "moved." I appreciate this and I will incorporate it into my migration proposal, thanks.
Yes you have similar think in Couchbase 2.0, using the CAS (Check And Set/Save) operations.
You can find information here:
- Check and Set (CAS) http://www.couchbase.com/docs/couchbase-devguide-2.0/cb-cas.html
Let me know if you need more information
Tug
@tgrall