benoitc / couchbeam

Apache CouchDB client in Erlang
Other
242 stars 113 forks source link

Correctly execute couchbeam_view:fetch/3 #86

Closed 0xAX closed 11 years ago

0xAX commented 11 years ago

Hello @benoitc,

Sorry if it wrong place for this issues, actually i don't know is it couchbeam issues, couchdb issue or it's my hand.

In fact i tried to fetch some data from CouchDB with CouchBeam. I'm using CouchDB-1.2.0 and CouchBeam d66706641a36b68507e38c844e1714f8d96d4e2a.

I have following view:

{
   "_id": "_design/task",
   "_rev": "5-c8cf44664bd02d170e3fb5bdfef1f35c",
   "language": "erlang",
   "views": {
       "by_task_creation": {
           "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"created\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Created -> Emit(Created, null)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n",
           "reduce": "fun(_Keys, Values, false) -> 0;\n   (_Keys, Values, true)  -> 0 end.\n"
       },
       "by_task_selector": {
           "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"selector\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Selector -> Emit(Selector, TaskId)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n"
       }
   }
}

Than i successfully connect to the database, and try to fetch data and reduce with:

couchbeam_view:fetch(DB, {<<"_design/task">>, <<"by_task_creation">>}, [{reduce, true}]).

But got error there:

Reason: {case_clause,{error,[],function_clause}}

I tried to request it with curl:

http://localhost:5984/xray/_design/task/_view/by_task_creation/?reduce=true

And it works, it returns:

{"rows":[]}

Maybe reduce crashes from the fact that there are no rows in the database?...

Thank you.

benoitc commented 11 years ago

can you provide the full trace?

0xAX commented 11 years ago

Log from /var/log/couchdb/couch.log:

[Thu, 27 Jun 2013 13:44:31 GMT] [info] [<0.195.0>] 127.0.0.1 - - GET / 200
[Thu, 27 Jun 2013 13:44:44 GMT] [error] [emulator] Error in process <0.266.0> with exit value: {{nocatch,{'EXIT',{{badmatch,[]},[{couch_query_servers,new_process,3,[{file,"couch_query_servers.erl"},{line,472}]},{couch_query_servers,lang_proc,3,[{file,"couch_query_servers.erl"},{line,462}]},{couch_query_servers,handle_call... 

[Thu, 27 Jun 2013 13:44:44 GMT] [error] [<0.258.0>] ** Generic server <0.258.0> terminating 
** Last message in was {'EXIT',<0.263.0>,
                        {{nocatch,
                          {'EXIT',
                           {{badmatch,[]},
                            [{couch_query_servers,new_process,3,
                              [{file,"couch_query_servers.erl"},{line,472}]},
                             {couch_query_servers,lang_proc,3,
                              [{file,"couch_query_servers.erl"},{line,462}]},
                             {couch_query_servers,handle_call,3,
                              [{file,"couch_query_servers.erl"},{line,334}]},
                             {gen_server,handle_msg,5,
                              [{file,"gen_server.erl"},{line,588}]},
                             {proc_lib,init_p_do_apply,3,
                              [{file,"proc_lib.erl"},{line,227}]}]}}},
                         [{couch_query_servers,get_os_process,1,
                           [{file,"couch_query_servers.erl"},{line,578}]},
                          {couch_query_servers,start_doc_map,3,
                           [{file,"couch_query_servers.erl"},{line,53}]},
                          {couch_view_updater,add_query_server,1,
                           [{file,"couch_view_updater.erl"},{line,102}]},
                          {couch_view_updater,'-update/3-fun-0-',3,
                           [{file,"couch_view_updater.erl"},{line,53}]}]}}
** When Server state == {group_state,undefined,<<"xray">>,
                         {"/var/lib/couchdb/1.2.0",<<"xray">>,
                          {group,
                           <<108,94,176,19,82,97,218,194,32,155,210,91,181,126,
                             18,123>>,
                           nil,<<"_design/task">>,<<"erlang">>,[],
                           [{view,0,0,0,[],
                             <<"fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"created\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Created -> Emit(Created, null)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n">>,
                             nil,
                             [{<<"by_task_creation">>,
                               <<"fun(_Keys, Values, false) -> length(Values);\n   (_Keys, Values, true)  -> lists:sum(Values) end.\n">>}],
                             []},
                            {view,1,0,0,
                             [<<"by_task_selector">>],
                             <<"fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"selector\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Selector -> Emit(Selector, TaskId)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n">>,
                             nil,[],[]}],
                           {[]},
                           nil,0,0,nil,nil}},
                         {group,
                          <<108,94,176,19,82,97,218,194,32,155,210,91,181,126,
                            18,123>>,
                          <0.260.0>,<<"_design/task">>,<<"erlang">>,[],
                          [{view,0,0,0,[],
                            <<"fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"created\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Created -> Emit(Created, null)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n">>,
                            {btree,<0.260.0>,nil,
                             #Fun<couch_btree.3.133731799>,
                             #Fun<couch_btree.4.133731799>,
                             #Fun<couch_view.less_json_ids.2>,
                             #Fun<couch_view_group.10.75991388>,snappy},
                            [{<<"by_task_creation">>,
                              <<"fun(_Keys, Values, false) -> length(Values);\n   (_Keys, Values, true)  -> lists:sum(Values) end.\n">>}],
                            []},
                           {view,1,0,0,
                            [<<"by_task_selector">>],
                            <<"fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"selector\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Selector -> Emit(Selector, TaskId)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n">>,
                            {btree,<0.260.0>,nil,
                             #Fun<couch_btree.3.133731799>,
                             #Fun<couch_btree.4.133731799>,
                             #Fun<couch_view.less_json_ids.2>,
                             #Fun<couch_view_group.10.75991388>,snappy},
                            [],[]}],
                          {[]},
                          {btree,<0.260.0>,nil,#Fun<couch_btree.3.133731799>,
                           #Fun<couch_btree.4.133731799>,
                           #Fun<couch_btree.5.133731799>,nil,snappy},
                          0,0,nil,nil},
                         <0.263.0>,nil,false,
                         [{{<0.218.0>,#Ref<0.0.0.1788>},2}],
                         <0.262.0>,false}
** Reason for termination == 
** {'EXIT',{{badmatch,[]},
            [{couch_query_servers,new_process,3,
                                  [{file,"couch_query_servers.erl"},
                                   {line,472}]},
             {couch_query_servers,lang_proc,3,
                                  [{file,"couch_query_servers.erl"},
                                   {line,462}]},
             {couch_query_servers,handle_call,3,
                                  [{file,"couch_query_servers.erl"},
                                   {line,334}]},
             {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,588}]},
             {proc_lib,init_p_do_apply,3,
                       [{file,"proc_lib.erl"},{line,227}]}]}}

[Thu, 27 Jun 2013 13:44:44 GMT] [error] [<0.258.0>] {error_report,<0.31.0>,
                     {<0.258.0>,crash_report,
                      [[{initial_call,{couch_view_group,init,['Argument__1']}},
                        {pid,<0.258.0>},
                        {registered_name,[]},
                        {error_info,
                         {exit,
                          {'EXIT',
                           {{badmatch,[]},
                            [{couch_query_servers,new_process,3,
                              [{file,"couch_query_servers.erl"},{line,472}]},
                             {couch_query_servers,lang_proc,3,
                              [{file,"couch_query_servers.erl"},{line,462}]},
                             {couch_query_servers,handle_call,3,
                              [{file,"couch_query_servers.erl"},{line,334}]},
                             {gen_server,handle_msg,5,
                              [{file,"gen_server.erl"},{line,588}]},
                             {proc_lib,init_p_do_apply,3,
                              [{file,"proc_lib.erl"},{line,227}]}]}},
                          [{gen_server,terminate,6,
                            [{file,"gen_server.erl"},{line,747}]},
                           {proc_lib,init_p_do_apply,3,
                            [{file,"proc_lib.erl"},{line,227}]}]}},
                        {ancestors,[<0.257.0>]},
                        {messages,[]},
                        {links,[<0.260.0>,<0.128.0>]},
                        {dictionary,[]},
                        {trap_exit,true},
                        {status,running},
                        {heap_size,1597},
                        {stack_size,24},
                        {reductions,546}],
                       []]}}
[Thu, 27 Jun 2013 13:44:44 GMT] [error] [<0.218.0>] Uncaught server error: {'EXIT',
                                            {{badmatch,[]},
                                             [{couch_query_servers,
                                               new_process,3,
                                               [{file,
                                                 "couch_query_servers.erl"},
                                                {line,472}]},
                                              {couch_query_servers,lang_proc,
                                               3,
                                               [{file,
                                                 "couch_query_servers.erl"},
                                                {line,462}]},
                                              {couch_query_servers,
                                               handle_call,3,
                                               [{file,
                                                 "couch_query_servers.erl"},
                                                {line,334}]},
                                              {gen_server,handle_msg,5,
                                               [{file,"gen_server.erl"},
                                                {line,588}]},
                                              {proc_lib,init_p_do_apply,3,
                                               [{file,"proc_lib.erl"},
                                                {line,227}]}]}}
[Thu, 27 Jun 2013 13:44:44 GMT] [error] [<0.260.0>] ** Generic server <0.260.0> terminating 
** Last message in was {'EXIT',<0.258.0>,
                           {'EXIT',
                               {{badmatch,[]},
                                [{couch_query_servers,new_process,3,
                                     [{file,"couch_query_servers.erl"},
                                      {line,472}]},
                                 {couch_query_servers,lang_proc,3,
                                     [{file,"couch_query_servers.erl"},
                                      {line,462}]},
                                 {couch_query_servers,handle_call,3,
                                     [{file,"couch_query_servers.erl"},
                                      {line,334}]},
                                 {gen_server,handle_msg,5,
                                     [{file,"gen_server.erl"},{line,588}]},
                                 {proc_lib,init_p_do_apply,3,
                                     [{file,"proc_lib.erl"},{line,227}]}]}}}
** When Server state == {file,{file_descriptor,prim_file,{#Port<0.2665>,25}},
                              51}
** Reason for termination == 
** {'EXIT',{{badmatch,[]},
            [{couch_query_servers,new_process,3,
                                  [{file,"couch_query_servers.erl"},
                                   {line,472}]},
             {couch_query_servers,lang_proc,3,
                                  [{file,"couch_query_servers.erl"},
                                   {line,462}]},
             {couch_query_servers,handle_call,3,
                                  [{file,"couch_query_servers.erl"},
                                   {line,334}]},
             {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,588}]},
             {proc_lib,init_p_do_apply,3,
                       [{file,"proc_lib.erl"},{line,227}]}]}}

[Thu, 27 Jun 2013 13:44:44 GMT] [error] [<0.260.0>] {error_report,<0.31.0>,
                     {<0.260.0>,crash_report,
                      [[{initial_call,{couch_file,init,['Argument__1']}},
                        {pid,<0.260.0>},
                        {registered_name,[]},
                        {error_info,
                         {exit,
                          {'EXIT',
                           {{badmatch,[]},
                            [{couch_query_servers,new_process,3,
                              [{file,"couch_query_servers.erl"},{line,472}]},
                             {couch_query_servers,lang_proc,3,
                              [{file,"couch_query_servers.erl"},{line,462}]},
                             {couch_query_servers,handle_call,3,
                              [{file,"couch_query_servers.erl"},{line,334}]},
                             {gen_server,handle_msg,5,
                              [{file,"gen_server.erl"},{line,588}]},
                             {proc_lib,init_p_do_apply,3,
                              [{file,"proc_lib.erl"},{line,227}]}]}},
                          [{gen_server,terminate,6,
                            [{file,"gen_server.erl"},{line,747}]},
                           {proc_lib,init_p_do_apply,3,
                            [{file,"proc_lib.erl"},{line,227}]}]}},
                        {ancestors,[<0.258.0>,<0.257.0>]},
                        {messages,[{'EXIT',<0.262.0>,shutdown}]},
                        {links,[]},
                        {dictionary,[]},
                        {trap_exit,true},
                        {status,running},
                        {heap_size,1597},
                        {stack_size,24},
                        {reductions,1530}],
                       []]}}
[Thu, 27 Jun 2013 13:44:44 GMT] [info] [<0.218.0>] 127.0.0.1 - - GET /xray/_design/task/_view/by_task_creation?reduce=true 500
[Thu, 27 Jun 2013 14:06:19 GMT] [info] [<0.197.0>] 127.0.0.1 - - POST /basic 404
benoitc commented 11 years ago

I don't see the function_clause error, I guess this one is happening in couchbeam then. I'm on it.

benoitc commented 11 years ago

should be fixed in 21c44d50f893f4e18f1a33bc89c260e40c4ff85f let me know.

0xAX commented 11 years ago

Today I alredy can't check it, but tomorrow morning i'll let you know, many thanks

0xAX commented 11 years ago

@benoitc i tried many different versions of couchbeam from different repositories and this https://github.com/travelping/couchbeam/tree/tp-integration not crash for my example.

benoitc commented 11 years ago

Is the current master working for you? What is your current error?

benoitc commented 11 years ago

note that tests are passing:

https://github.com/benoitc/couchbeam/blob/master/t/005-view.t#L106

0xAX commented 11 years ago

@benoitc i think i had the same error with current master, In monday i will have my working machine and i'll test with current master yet another time and let you know about results.

benoitc commented 11 years ago

I just show that in your code you have reduce=false but tested reduce=true in your code, does it gave the same result? What is the full trace in the application using couchbeam?

0xAX commented 11 years ago

sorry, i missunderstood, i have error with {reduce, true} and if i remove it all works

benoitc commented 11 years ago

@0xAX I will add a test over the we, and will see what happen. Thanks for the feedback :)

0xAX commented 11 years ago

Hello @benoitc i tested it, and now it works with master. Thank you.

benoitc commented 11 years ago

@0xAX thanks for the feedback, closing the issue now :)