Attached is my first attempt at a minimal patch to re-enable fail-on-
conflict semantics for bulk_docs. My goal was to have the smallest
possible diff that can be maintained whilst tracking HEAD, rather than
the cleanest or best way to achieve the functionality. It's had
minimal testing - basically the following rake task using Couchrest
works differently depending on whether you put the fail_on_conflct =>
true into the second _bulk_docs:
require 'rubygems'
require 'couchrest'
desc "Test bulk docs conflicts"
task :bulk_docs do |t|
CouchRest.delete("http://localhost:5984/test") rescue nil
db = CouchRest.database!("http://localhost:5984/test")
d1 = { '_id' => '1', :version => 1 }
d2 = { '_id' => '2', :version => 1 }
r1 = db.save_doc(d1)
r2 = db.save_doc(d2)
d1[:version] = 2
d1['_rev'] = r1['rev']
d2[:version] = 2
d2['_rev'] = r2['rev']
br = db.bulk_save([d1, d2])
STDOUT.puts br.to_json
STDOUT.flush
d1[:version] = 3
d1['_rev'] = br[0]['rev']
d2[:version] = 3
br = CouchRest.post("http://localhost:5984/test/_bulk_docs",
{ :fail_on_conflict => true, :docs => [d1, d2]}) rescue {}
STDOUT.puts br.to_json
STDOUT.puts db.get('1').to_json
STDOUT.puts db.get('2').to_json
STDOUT.flush
end
On 27/03/2009, at 3:30 AM, Tim Parkin wrote:
Antony Blakey wrote:
I have a patch that adds/restores fail-on-conflict bulk update
behaviour
(ie. your rollback requirement, but with no intermediate state). It's
10-15 lines depending on formatting, i.e. fairly trivial, so it
should
be easy to keep it on HEAD. I trigger it explicitly by adding
fail-on-conflict: true to the top level json in the bulk request,
which
means that existing tests pass because the default semantics are
unpatched.
I'd be very interested - could I have a play with it?
Antony Blakey
-------------
CTO, Linkuistics Pty Ltd
Ph: 0438 840 787
The intuitive mind is a sacred gift and the rational mind is a
faithful servant. We have created a society that honours the servant
and has forgotten the gift.
-- Albert Einstein