You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by John Bartak <jo...@autodesk.com> on 2009/01/10 02:04:37 UTC

Error when running two requests to same view simultaneously

I've setup some tests that generate multiple identical requests to the same view at the same time.  One of the requests for a view occasionally fails while the other one succeeds.

The get request the gets sent to the server is:
[info] [<0.16662.0>] 192.168.200.1 - - 'GET' /fileinttests_20090109_163919_286_1161293461/_view/MultiFieldQuery_type_OwnerId_Name/view?key=%5b%22repository.repositoryfile%22%2c%22ownerid%22%2c%22filename%22%5d&include_docs=true 200

The view code is very simple:
function(doc){
  if (doc.type && doc.OwnerId && doc.Name) {
      emit([(doc.type.toLowerCase) ? doc.type.toLowerCase(): doc.type,(doc.OwnerId.toLowerCase) ? doc.OwnerId.toLowerCase(): doc.OwnerId,(doc.Name.toLowerCase) ? doc.Name.toLowerCase(): doc.Name],null);
   }
}

I'm wondering if I'm doing something wrong or if this is expected behavior or if there is a bug in CouchDB?

This is with CouchDB version: 0.9.0a712213

 I get the following error:

[error] [<0.17007.0>] {error_report,
    <0.22.0>,
    {<0.17007.0>,
     crash_report,
     [[{pid,<0.17007.0>},
       {registered_name,[]},
       {error_info,
           {function_clause,
               [{couch_doc,to_json_obj,[{not_found,missing},[]]},
                {couch_httpd_view,view_row_obj,3},
                {couch_httpd_view,'-make_view_fold_fun/5-fun-2-',9},
                {couch_view,fold_fun,4},
                {couch_btree,stream_kv_node2,7},
                {couch_btree,fold,5},
                {couch_view,fold,5},
                {couch_httpd_view,output_map_view,5}]}},
       {initial_call,
           {mochiweb_socket_server,
               acceptor_loop,
               [{<0.57.0>,#Port<0.128>,#Fun<mochiweb_http.1.62821608>}]}},
       {ancestors,[couch_httpd,<0.52.0>,couch_server_sup,<0.1.0>]},
       {messages,[]},
       {links,[#Port<0.4336>,<0.57.0>,#Port<0.4331>]},
       {dictionary,
           [{mochiweb_request_qs,
                [{"key",
                  "[\"autodesk.social.services.files.repository.repositoryfile\",\"ownerid\",\"filename\"]"},
                 {"include_docs","true"}]},
            {couch_drv_port,#Port<0.4336>}]},
       {trap_exit,false},
       {status,running},
       {heap_size,4181},
       {stack_size,21},
       {reductions,366135}],
      []]}}
[error] [<0.57.0>] {error_report,
    <0.22.0>,
    {<0.57.0>,
     std_error,
     {mochiweb_socket_server,
         235,
         {child_error,
             {function_clause,
                 [{couch_doc,to_json_obj,[{not_found,missing},[]]},
                  {couch_httpd_view,view_row_obj,3},
                  {couch_httpd_view,'-make_view_fold_fun/5-fun-2-',9},
                  {couch_view,fold_fun,4},
                  {couch_btree,stream_kv_node2,7},
                  {couch_btree,fold,5},
                  {couch_view,fold,5},
                  {couch_httpd_view,output_map_view,5}]}}}}}

=ERROR REPORT==== 9-Jan-2009::16:39:23 ===
{mochiweb_socket_server,
    235,
    {child_error,
        {function_clause,
            [{couch_doc,to_json_obj,[{not_found,missing},[]]},
             {couch_httpd_view,view_row_obj,3},
             {couch_httpd_view,'-make_view_fold_fun/5-fun-2-',9},
             {couch_view,fold_fun,4},
             {couch_btree,stream_kv_node2,7},
             {couch_btree,fold,5},
             {couch_view,fold,5},
             {couch_httpd_view,output_map_view,5}]}}}


Re: Error when running two requests to same view simultaneously

Posted by Damien Katz <da...@apache.org>.
This is a regression, but it's not related to delay commit change. The  
second commit phase conflict checking is broken. CouchDB verifies  
update isn't a conflict twice, once before writing any attachments  
(checked in parallel) and then again then again inside the updater  
(checked serially). The second phase wasn't working, but the first  
phase almost always catches it.

I've gone ahead and checked in the fix for the bug, and am now working  
on ensuring this second phase conflict detection is always tested in  
the suite.

Thanks for reporting this John, sorry for the problem.

-Damien


On Jan 12, 2009, at 4:04 PM, John Bartak wrote:

> Unfortunately, it won't be easy for me to produce a small test case  
> exposing the problem.  I've built up a pretty big .Net library  
> around CouchDB so I just can't ship you my test code.  I'll see if I  
> can find time to put something together later this week.
>
> -----Original Message-----
> From: Paul Davis [mailto:paul.joseph.davis@gmail.com]
> Sent: Monday, January 12, 2009 12:51 PM
> To: user@couchdb.apache.org
> Subject: Re: Error when running two requests to same view  
> simultaneously
>
> On Mon, Jan 12, 2009 at 3:43 PM, John Bartak  
> <jo...@autodesk.com> wrote:
>> Adding the "X-Couch-Full-Commit" header seems to make it more  
>> likely to get 412's.  But I'm still getting lots of cases where I  
>> don't see a 412.
>
> Hmm. I haven't at all looked at this new code, but inconsistent
> behavior is unexpected at best. Given my understanding of it works, I
> would expect all or none raise 412's. Would it be possible for you to
> boil this into a small test case that we can play with? Or maybe
> someone else can chime in with an explanation. I for one am totally
> lost.
>
> Paul
>
> Also, I don't see any documents in the database with a "_conflict"
> attribute on them.
>>
>> If I can't rely on getting 412's back if somebody else updated the  
>> revision of the document, I'll have to figure out some other trick  
>> to determine if the current thread updated the document.  Perhaps  
>> updating an attribute on the document with a GUID that only the  
>> current thread knows about.
>>
>> -----Original Message-----
>> From: Paul Davis [mailto:paul.joseph.davis@gmail.com]
>> Sent: Monday, January 12, 2009 11:19 AM
>> To: user@couchdb.apache.org
>> Subject: Re: Error when running two requests to same view  
>> simultaneously
>>
>> On Mon, Jan 12, 2009 at 2:10 PM, John Bartak <john.bartak@autodesk.com 
>> > wrote:
>>> It appears that the latest code (0.9.0a733848) does fix the crash  
>>> of the server.  I now get back a result string that has an error  
>>> value of missing instead of the document:
>>>
>>> {"total_rows":2,"offset":0,"rows":[
>>> {"id":"09e2fb54e77545c0aec61578fe041965","key": 
>>> ["repository 
>>> .repositoryfile 
>>> ","ownerid","filename"],"value":null,"error":"missing"},
>>> {"id":"8cc55e26dfb047b09f222d7967f2a047","key": 
>>> ["repository.repositoryfile",  
>>> "ownerid","filename"],"value":null,"doc": 
>>> {"_id 
>>> ":"8cc55e26dfb047b09f222d7967f2a047 
>>> ","_rev":"2138313893","OwnerId":"ownerId","Name":"filename"}}
>>> ]}
>>>
>>> I'll have to update my code to handle that, but that's no big deal.
>>>
>>> Unfortunately, I don't get back 412's when two threads attempt to  
>>> update the same revision of a document simultaneously.  This  
>>> happens for both the bulk_docs api and the standard PUT api:
>>>
>>> [info] [<0.3374.0>] 192.168.200.1 - - 'GET' / 
>>> fileinttests_20090112_105825_501_1818439740 
>>> /473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
>>> [info] [<0.3371.0>] 192.168.200.1 - - 'GET' / 
>>> fileinttests_20090112_105825_501_1818439740 
>>> /473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
>>> [info] [<0.3371.0>] 192.168.200.1 - - 'PUT' / 
>>> fileinttests_20090112_105825_501_1818439740 
>>> /473dccb50cb54a57abe19e7687c491ce 201
>>> [info] [<0.3374.0>] 192.168.200.1 - - 'PUT' / 
>>> fileinttests_20090112_105825_501_1818439740 
>>> /473dccb50cb54a57abe19e7687c491ce 201
>>>
>>> In the two threads that I have running, I first get the document I  
>>> want to revise and I then update the revision.
>>>
>>
>> I have a sneaking suspicion that this is from the code that damien
>> commited a few days ago.  Try adding a head like [1] to each of your
>> requests to check the status of each. Also, in your example, to  
>> double
>> check that this is expected behavior, you should look at that  
>> document
>> and verify it has a _conflict attribute. Remember that we're working
>> with eventual consistency here. This type of thing is expected and
>> it's your app's responsibility to figure things out.
>>
>> [1] X-Couch-Full-Commit: true
>>
>> HTH,
>> Paul Davis
>>
>>>
>>>
>>> -----Original Message-----
>>> From: Chris Anderson [mailto:jchris@gmail.com]
>>> Sent: Saturday, January 10, 2009 9:54 AM
>>> To: user@couchdb.apache.org
>>> Subject: Re: Error when running two requests to same view  
>>> simultaneously
>>>
>>> On Sat, Jan 10, 2009 at 8:48 AM, Michael McDaniel <couchdb@autosys.us 
>>> > wrote:
>>>> The short answer is that there is no function   
>>>> couch_doc:to_json_doc/2
>>>> that accepts the arguments ( {not_found, missing}, [] ) gracefully
>>>>
>>>>>           {function_clause,
>>>>>               [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>>>>>               ...
>>>>
>>>
>>> The problem seems to have been in the error handling in the
>>> include_docs code. Do you mind updating to the latest trunk and
>>> attempting to recreate the error? It should be fixed.
>>>
>>>
>>> --
>>> Chris Anderson
>>> http://jchris.mfdz.com
>>>
>>


RE: Error when running two requests to same view simultaneously

Posted by John Bartak <jo...@autodesk.com>.
Unfortunately, it won't be easy for me to produce a small test case exposing the problem.  I've built up a pretty big .Net library around CouchDB so I just can't ship you my test code.  I'll see if I can find time to put something together later this week.

-----Original Message-----
From: Paul Davis [mailto:paul.joseph.davis@gmail.com]
Sent: Monday, January 12, 2009 12:51 PM
To: user@couchdb.apache.org
Subject: Re: Error when running two requests to same view simultaneously

On Mon, Jan 12, 2009 at 3:43 PM, John Bartak <jo...@autodesk.com> wrote:
> Adding the "X-Couch-Full-Commit" header seems to make it more likely to get 412's.  But I'm still getting lots of cases where I don't see a 412.

Hmm. I haven't at all looked at this new code, but inconsistent
behavior is unexpected at best. Given my understanding of it works, I
would expect all or none raise 412's. Would it be possible for you to
boil this into a small test case that we can play with? Or maybe
someone else can chime in with an explanation. I for one am totally
lost.

Paul

Also, I don't see any documents in the database with a "_conflict"
attribute on them.
>
> If I can't rely on getting 412's back if somebody else updated the revision of the document, I'll have to figure out some other trick to determine if the current thread updated the document.  Perhaps updating an attribute on the document with a GUID that only the current thread knows about.
>
> -----Original Message-----
> From: Paul Davis [mailto:paul.joseph.davis@gmail.com]
> Sent: Monday, January 12, 2009 11:19 AM
> To: user@couchdb.apache.org
> Subject: Re: Error when running two requests to same view simultaneously
>
> On Mon, Jan 12, 2009 at 2:10 PM, John Bartak <jo...@autodesk.com> wrote:
>> It appears that the latest code (0.9.0a733848) does fix the crash of the server.  I now get back a result string that has an error value of missing instead of the document:
>>
>> {"total_rows":2,"offset":0,"rows":[
>> {"id":"09e2fb54e77545c0aec61578fe041965","key":["repository.repositoryfile","ownerid","filename"],"value":null,"error":"missing"},
>> {"id":"8cc55e26dfb047b09f222d7967f2a047","key":["repository.repositoryfile", "ownerid","filename"],"value":null,"doc":{"_id":"8cc55e26dfb047b09f222d7967f2a047","_rev":"2138313893","OwnerId":"ownerId","Name":"filename"}}
>> ]}
>>
>> I'll have to update my code to handle that, but that's no big deal.
>>
>> Unfortunately, I don't get back 412's when two threads attempt to update the same revision of a document simultaneously.  This happens for both the bulk_docs api and the standard PUT api:
>>
>> [info] [<0.3374.0>] 192.168.200.1 - - 'GET' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
>> [info] [<0.3371.0>] 192.168.200.1 - - 'GET' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
>> [info] [<0.3371.0>] 192.168.200.1 - - 'PUT' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce 201
>> [info] [<0.3374.0>] 192.168.200.1 - - 'PUT' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce 201
>>
>> In the two threads that I have running, I first get the document I want to revise and I then update the revision.
>>
>
> I have a sneaking suspicion that this is from the code that damien
> commited a few days ago.  Try adding a head like [1] to each of your
> requests to check the status of each. Also, in your example, to double
> check that this is expected behavior, you should look at that document
> and verify it has a _conflict attribute. Remember that we're working
> with eventual consistency here. This type of thing is expected and
> it's your app's responsibility to figure things out.
>
> [1] X-Couch-Full-Commit: true
>
> HTH,
> Paul Davis
>
>>
>>
>> -----Original Message-----
>> From: Chris Anderson [mailto:jchris@gmail.com]
>> Sent: Saturday, January 10, 2009 9:54 AM
>> To: user@couchdb.apache.org
>> Subject: Re: Error when running two requests to same view simultaneously
>>
>> On Sat, Jan 10, 2009 at 8:48 AM, Michael McDaniel <co...@autosys.us> wrote:
>>>  The short answer is that there is no function  couch_doc:to_json_doc/2
>>>  that accepts the arguments ( {not_found, missing}, [] ) gracefully
>>>
>>>>            {function_clause,
>>>>                [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>>>>                ...
>>>
>>
>> The problem seems to have been in the error handling in the
>> include_docs code. Do you mind updating to the latest trunk and
>> attempting to recreate the error? It should be fixed.
>>
>>
>> --
>> Chris Anderson
>> http://jchris.mfdz.com
>>
>

Re: Error when running two requests to same view simultaneously

Posted by Paul Davis <pa...@gmail.com>.
On Mon, Jan 12, 2009 at 3:43 PM, John Bartak <jo...@autodesk.com> wrote:
> Adding the "X-Couch-Full-Commit" header seems to make it more likely to get 412's.  But I'm still getting lots of cases where I don't see a 412.

Hmm. I haven't at all looked at this new code, but inconsistent
behavior is unexpected at best. Given my understanding of it works, I
would expect all or none raise 412's. Would it be possible for you to
boil this into a small test case that we can play with? Or maybe
someone else can chime in with an explanation. I for one am totally
lost.

Paul

Also, I don't see any documents in the database with a "_conflict"
attribute on them.
>
> If I can't rely on getting 412's back if somebody else updated the revision of the document, I'll have to figure out some other trick to determine if the current thread updated the document.  Perhaps updating an attribute on the document with a GUID that only the current thread knows about.
>
> -----Original Message-----
> From: Paul Davis [mailto:paul.joseph.davis@gmail.com]
> Sent: Monday, January 12, 2009 11:19 AM
> To: user@couchdb.apache.org
> Subject: Re: Error when running two requests to same view simultaneously
>
> On Mon, Jan 12, 2009 at 2:10 PM, John Bartak <jo...@autodesk.com> wrote:
>> It appears that the latest code (0.9.0a733848) does fix the crash of the server.  I now get back a result string that has an error value of missing instead of the document:
>>
>> {"total_rows":2,"offset":0,"rows":[
>> {"id":"09e2fb54e77545c0aec61578fe041965","key":["repository.repositoryfile","ownerid","filename"],"value":null,"error":"missing"},
>> {"id":"8cc55e26dfb047b09f222d7967f2a047","key":["repository.repositoryfile", "ownerid","filename"],"value":null,"doc":{"_id":"8cc55e26dfb047b09f222d7967f2a047","_rev":"2138313893","OwnerId":"ownerId","Name":"filename"}}
>> ]}
>>
>> I'll have to update my code to handle that, but that's no big deal.
>>
>> Unfortunately, I don't get back 412's when two threads attempt to update the same revision of a document simultaneously.  This happens for both the bulk_docs api and the standard PUT api:
>>
>> [info] [<0.3374.0>] 192.168.200.1 - - 'GET' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
>> [info] [<0.3371.0>] 192.168.200.1 - - 'GET' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
>> [info] [<0.3371.0>] 192.168.200.1 - - 'PUT' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce 201
>> [info] [<0.3374.0>] 192.168.200.1 - - 'PUT' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce 201
>>
>> In the two threads that I have running, I first get the document I want to revise and I then update the revision.
>>
>
> I have a sneaking suspicion that this is from the code that damien
> commited a few days ago.  Try adding a head like [1] to each of your
> requests to check the status of each. Also, in your example, to double
> check that this is expected behavior, you should look at that document
> and verify it has a _conflict attribute. Remember that we're working
> with eventual consistency here. This type of thing is expected and
> it's your app's responsibility to figure things out.
>
> [1] X-Couch-Full-Commit: true
>
> HTH,
> Paul Davis
>
>>
>>
>> -----Original Message-----
>> From: Chris Anderson [mailto:jchris@gmail.com]
>> Sent: Saturday, January 10, 2009 9:54 AM
>> To: user@couchdb.apache.org
>> Subject: Re: Error when running two requests to same view simultaneously
>>
>> On Sat, Jan 10, 2009 at 8:48 AM, Michael McDaniel <co...@autosys.us> wrote:
>>>  The short answer is that there is no function  couch_doc:to_json_doc/2
>>>  that accepts the arguments ( {not_found, missing}, [] ) gracefully
>>>
>>>>            {function_clause,
>>>>                [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>>>>                ...
>>>
>>
>> The problem seems to have been in the error handling in the
>> include_docs code. Do you mind updating to the latest trunk and
>> attempting to recreate the error? It should be fixed.
>>
>>
>> --
>> Chris Anderson
>> http://jchris.mfdz.com
>>
>

RE: Error when running two requests to same view simultaneously

Posted by John Bartak <jo...@autodesk.com>.
Adding the "X-Couch-Full-Commit" header seems to make it more likely to get 412's.  But I'm still getting lots of cases where I don't see a 412.  Also, I don't see any documents in the database with a "_conflict" attribute on them.

If I can't rely on getting 412's back if somebody else updated the revision of the document, I'll have to figure out some other trick to determine if the current thread updated the document.  Perhaps updating an attribute on the document with a GUID that only the current thread knows about.

-----Original Message-----
From: Paul Davis [mailto:paul.joseph.davis@gmail.com]
Sent: Monday, January 12, 2009 11:19 AM
To: user@couchdb.apache.org
Subject: Re: Error when running two requests to same view simultaneously

On Mon, Jan 12, 2009 at 2:10 PM, John Bartak <jo...@autodesk.com> wrote:
> It appears that the latest code (0.9.0a733848) does fix the crash of the server.  I now get back a result string that has an error value of missing instead of the document:
>
> {"total_rows":2,"offset":0,"rows":[
> {"id":"09e2fb54e77545c0aec61578fe041965","key":["repository.repositoryfile","ownerid","filename"],"value":null,"error":"missing"},
> {"id":"8cc55e26dfb047b09f222d7967f2a047","key":["repository.repositoryfile", "ownerid","filename"],"value":null,"doc":{"_id":"8cc55e26dfb047b09f222d7967f2a047","_rev":"2138313893","OwnerId":"ownerId","Name":"filename"}}
> ]}
>
> I'll have to update my code to handle that, but that's no big deal.
>
> Unfortunately, I don't get back 412's when two threads attempt to update the same revision of a document simultaneously.  This happens for both the bulk_docs api and the standard PUT api:
>
> [info] [<0.3374.0>] 192.168.200.1 - - 'GET' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
> [info] [<0.3371.0>] 192.168.200.1 - - 'GET' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
> [info] [<0.3371.0>] 192.168.200.1 - - 'PUT' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce 201
> [info] [<0.3374.0>] 192.168.200.1 - - 'PUT' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce 201
>
> In the two threads that I have running, I first get the document I want to revise and I then update the revision.
>

I have a sneaking suspicion that this is from the code that damien
commited a few days ago.  Try adding a head like [1] to each of your
requests to check the status of each. Also, in your example, to double
check that this is expected behavior, you should look at that document
and verify it has a _conflict attribute. Remember that we're working
with eventual consistency here. This type of thing is expected and
it's your app's responsibility to figure things out.

[1] X-Couch-Full-Commit: true

HTH,
Paul Davis

>
>
> -----Original Message-----
> From: Chris Anderson [mailto:jchris@gmail.com]
> Sent: Saturday, January 10, 2009 9:54 AM
> To: user@couchdb.apache.org
> Subject: Re: Error when running two requests to same view simultaneously
>
> On Sat, Jan 10, 2009 at 8:48 AM, Michael McDaniel <co...@autosys.us> wrote:
>>  The short answer is that there is no function  couch_doc:to_json_doc/2
>>  that accepts the arguments ( {not_found, missing}, [] ) gracefully
>>
>>>            {function_clause,
>>>                [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>>>                ...
>>
>
> The problem seems to have been in the error handling in the
> include_docs code. Do you mind updating to the latest trunk and
> attempting to recreate the error? It should be fixed.
>
>
> --
> Chris Anderson
> http://jchris.mfdz.com
>

Re: Error when running two requests to same view simultaneously

Posted by Paul Davis <pa...@gmail.com>.
On Mon, Jan 12, 2009 at 2:10 PM, John Bartak <jo...@autodesk.com> wrote:
> It appears that the latest code (0.9.0a733848) does fix the crash of the server.  I now get back a result string that has an error value of missing instead of the document:
>
> {"total_rows":2,"offset":0,"rows":[
> {"id":"09e2fb54e77545c0aec61578fe041965","key":["repository.repositoryfile","ownerid","filename"],"value":null,"error":"missing"},
> {"id":"8cc55e26dfb047b09f222d7967f2a047","key":["repository.repositoryfile", "ownerid","filename"],"value":null,"doc":{"_id":"8cc55e26dfb047b09f222d7967f2a047","_rev":"2138313893","OwnerId":"ownerId","Name":"filename"}}
> ]}
>
> I'll have to update my code to handle that, but that's no big deal.
>
> Unfortunately, I don't get back 412's when two threads attempt to update the same revision of a document simultaneously.  This happens for both the bulk_docs api and the standard PUT api:
>
> [info] [<0.3374.0>] 192.168.200.1 - - 'GET' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
> [info] [<0.3371.0>] 192.168.200.1 - - 'GET' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
> [info] [<0.3371.0>] 192.168.200.1 - - 'PUT' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce 201
> [info] [<0.3374.0>] 192.168.200.1 - - 'PUT' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce 201
>
> In the two threads that I have running, I first get the document I want to revise and I then update the revision.
>

I have a sneaking suspicion that this is from the code that damien
commited a few days ago.  Try adding a head like [1] to each of your
requests to check the status of each. Also, in your example, to double
check that this is expected behavior, you should look at that document
and verify it has a _conflict attribute. Remember that we're working
with eventual consistency here. This type of thing is expected and
it's your app's responsibility to figure things out.

[1] X-Couch-Full-Commit: true

HTH,
Paul Davis

>
>
> -----Original Message-----
> From: Chris Anderson [mailto:jchris@gmail.com]
> Sent: Saturday, January 10, 2009 9:54 AM
> To: user@couchdb.apache.org
> Subject: Re: Error when running two requests to same view simultaneously
>
> On Sat, Jan 10, 2009 at 8:48 AM, Michael McDaniel <co...@autosys.us> wrote:
>>  The short answer is that there is no function  couch_doc:to_json_doc/2
>>  that accepts the arguments ( {not_found, missing}, [] ) gracefully
>>
>>>            {function_clause,
>>>                [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>>>                ...
>>
>
> The problem seems to have been in the error handling in the
> include_docs code. Do you mind updating to the latest trunk and
> attempting to recreate the error? It should be fixed.
>
>
> --
> Chris Anderson
> http://jchris.mfdz.com
>

RE: Error when running two requests to same view simultaneously

Posted by John Bartak <jo...@autodesk.com>.
It appears that the latest code (0.9.0a733848) does fix the crash of the server.  I now get back a result string that has an error value of missing instead of the document:

{"total_rows":2,"offset":0,"rows":[
{"id":"09e2fb54e77545c0aec61578fe041965","key":["repository.repositoryfile","ownerid","filename"],"value":null,"error":"missing"},
{"id":"8cc55e26dfb047b09f222d7967f2a047","key":["repository.repositoryfile", "ownerid","filename"],"value":null,"doc":{"_id":"8cc55e26dfb047b09f222d7967f2a047","_rev":"2138313893","OwnerId":"ownerId","Name":"filename"}}
]}

I'll have to update my code to handle that, but that's no big deal.

Unfortunately, I don't get back 412's when two threads attempt to update the same revision of a document simultaneously.  This happens for both the bulk_docs api and the standard PUT api:

[info] [<0.3374.0>] 192.168.200.1 - - 'GET' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
[info] [<0.3371.0>] 192.168.200.1 - - 'GET' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce?rev=4134090793 200
[info] [<0.3371.0>] 192.168.200.1 - - 'PUT' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce 201
[info] [<0.3374.0>] 192.168.200.1 - - 'PUT' /fileinttests_20090112_105825_501_1818439740/473dccb50cb54a57abe19e7687c491ce 201

In the two threads that I have running, I first get the document I want to revise and I then update the revision.



-----Original Message-----
From: Chris Anderson [mailto:jchris@gmail.com]
Sent: Saturday, January 10, 2009 9:54 AM
To: user@couchdb.apache.org
Subject: Re: Error when running two requests to same view simultaneously

On Sat, Jan 10, 2009 at 8:48 AM, Michael McDaniel <co...@autosys.us> wrote:
>  The short answer is that there is no function  couch_doc:to_json_doc/2
>  that accepts the arguments ( {not_found, missing}, [] ) gracefully
>
>>            {function_clause,
>>                [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>>                ...
>

The problem seems to have been in the error handling in the
include_docs code. Do you mind updating to the latest trunk and
attempting to recreate the error? It should be fixed.


--
Chris Anderson
http://jchris.mfdz.com

Re: Error when running two requests to same view simultaneously

Posted by Chris Anderson <jc...@gmail.com>.
On Sat, Jan 10, 2009 at 8:48 AM, Michael McDaniel <co...@autosys.us> wrote:
>  The short answer is that there is no function  couch_doc:to_json_doc/2
>  that accepts the arguments ( {not_found, missing}, [] ) gracefully
>
>>            {function_clause,
>>                [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>>                ...
>

The problem seems to have been in the error handling in the
include_docs code. Do you mind updating to the latest trunk and
attempting to recreate the error? It should be fixed.


-- 
Chris Anderson
http://jchris.mfdz.com

Re: Error when running two requests to same view simultaneously

Posted by Michael McDaniel <co...@autosys.us>.
 The short answer is that there is no function  couch_doc:to_json_doc/2 
 that accepts the arguments ( {not_found, missing}, [] ) gracefully

>            {function_clause,
>                [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>                ...


 Some possibilities are
 a) couch_doc:to_json_doc/2 should accept that arg and return ???
 b) previous fun should never pass that arg to couch_doc:to_json_doc
    (possibly bug in previous arg(s)
 c) ?


 I have not backtracked any further than that.


~Michael



On Fri, Jan 09, 2009 at 05:04:37PM -0800, John Bartak wrote:
> I've setup some tests that generate multiple identical requests to the same view at the same time.  One of the requests for a view occasionally fails while the other one succeeds.
> 
> The get request the gets sent to the server is:
> [info] [<0.16662.0>] 192.168.200.1 - - 'GET' /fileinttests_20090109_163919_286_1161293461/_view/MultiFieldQuery_type_OwnerId_Name/view?key=%5b%22repository.repositoryfile%22%2c%22ownerid%22%2c%22filename%22%5d&include_docs=true 200
> 
> The view code is very simple:
> function(doc){
>   if (doc.type && doc.OwnerId && doc.Name) {
>       emit([(doc.type.toLowerCase) ? doc.type.toLowerCase(): doc.type,(doc.OwnerId.toLowerCase) ? doc.OwnerId.toLowerCase(): doc.OwnerId,(doc.Name.toLowerCase) ? doc.Name.toLowerCase(): doc.Name],null);
>    }
> }
> 
> I'm wondering if I'm doing something wrong or if this is expected behavior or if there is a bug in CouchDB?
> 
> This is with CouchDB version: 0.9.0a712213
> 
>  I get the following error:
> 
> [error] [<0.17007.0>] {error_report,
>     <0.22.0>,
>     {<0.17007.0>,
>      crash_report,
>      [[{pid,<0.17007.0>},
>        {registered_name,[]},
>        {error_info,
>            {function_clause,
>                [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>                 {couch_httpd_view,view_row_obj,3},
>                 {couch_httpd_view,'-make_view_fold_fun/5-fun-2-',9},
>                 {couch_view,fold_fun,4},
>                 {couch_btree,stream_kv_node2,7},
>                 {couch_btree,fold,5},
>                 {couch_view,fold,5},
>                 {couch_httpd_view,output_map_view,5}]}},
>        {initial_call,
>            {mochiweb_socket_server,
>                acceptor_loop,
>                [{<0.57.0>,#Port<0.128>,#Fun<mochiweb_http.1.62821608>}]}},
>        {ancestors,[couch_httpd,<0.52.0>,couch_server_sup,<0.1.0>]},
>        {messages,[]},
>        {links,[#Port<0.4336>,<0.57.0>,#Port<0.4331>]},
>        {dictionary,
>            [{mochiweb_request_qs,
>                 [{"key",
>                   "[\"autodesk.social.services.files.repository.repositoryfile\",\"ownerid\",\"filename\"]"},
>                  {"include_docs","true"}]},
>             {couch_drv_port,#Port<0.4336>}]},
>        {trap_exit,false},
>        {status,running},
>        {heap_size,4181},
>        {stack_size,21},
>        {reductions,366135}],
>       []]}}
> [error] [<0.57.0>] {error_report,
>     <0.22.0>,
>     {<0.57.0>,
>      std_error,
>      {mochiweb_socket_server,
>          235,
>          {child_error,
>              {function_clause,
>                  [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>                   {couch_httpd_view,view_row_obj,3},
>                   {couch_httpd_view,'-make_view_fold_fun/5-fun-2-',9},
>                   {couch_view,fold_fun,4},
>                   {couch_btree,stream_kv_node2,7},
>                   {couch_btree,fold,5},
>                   {couch_view,fold,5},
>                   {couch_httpd_view,output_map_view,5}]}}}}}
> 
> =ERROR REPORT==== 9-Jan-2009::16:39:23 ===
> {mochiweb_socket_server,
>     235,
>     {child_error,
>         {function_clause,
>             [{couch_doc,to_json_obj,[{not_found,missing},[]]},
>              {couch_httpd_view,view_row_obj,3},
>              {couch_httpd_view,'-make_view_fold_fun/5-fun-2-',9},
>              {couch_view,fold_fun,4},
>              {couch_btree,stream_kv_node2,7},
>              {couch_btree,fold,5},
>              {couch_view,fold,5},
>              {couch_httpd_view,output_map_view,5}]}}}
> 

-- 
Michael McDaniel
Portland, Oregon, USA
http://trip.autosys.us
http://autosys.us