You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Antony Blakey <an...@gmail.com> on 2009/03/26 23:41:58 UTC

Re: Restricting user interactions to a single document - PATCH

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?


Re: Restricting user interactions to a single document - PATCH

Posted by Antony Blakey <an...@gmail.com>.
On 27/03/2009, at 9:37 AM, Antony Blakey wrote:

> It seems the m/l is eating the patch attachment. Here is a gist: http://gist.github.com/86434

And now at: http://github.com/AntonyBlakey/couchdb/commit/3e831884367a49d723a9035f8fed1a0f0ed498ba

Antony Blakey
-------------
CTO, Linkuistics Pty Ltd
Ph: 0438 840 787

Some defeats are instalments to victory.
  -- Jacob Riis



Re: Restricting user interactions to a single document - PATCH

Posted by Antony Blakey <an...@gmail.com>.
It seems the m/l is eating the patch attachment. Here is a gist: http://gist.github.com/86434

Antony Blakey
--------------------------
CTO, Linkuistics Pty Ltd
Ph: 0438 840 787

Isn't it enough to see that a garden is beautiful without having to  
believe that there are fairies at the bottom of it too?
   -- Douglas Adams