AlexanderKaraberov opened a new pull request #1382: Fix for a function_clause crash in couch_native_process URL: https://github.com/apache/couchdb/pull/1382 ## Overview When CouchDB has a native query server enabled and we call an Erlang `map` function for the first time (therefore there is no view index) `couch_mrview_updater:start_update` calls `run(State, [<<"map_doc">> , Doc])` from the `couch_native_process` and after this view index is built and data is read from it and everything is fine. Unfortunately when the same Erlang map function is used for changes feed with `_view` filter `couch_native_process` crashes with: ``` {"error":"error","reason":"{{function_clause,\n [{couch_native_process,ddoc,\n [{evstate, .... ``` Changes feed with `_view` filter allows to use existing map function as the filter and it doesn’t query the view index files by default. Also `seq_indexed` option doesn't work correctly in the mrview (more details in [this thread](https://github.com/apache/couchdb/issues/1142#issuecomment-378228093)) therefore `fast_view` filter (which allows to use a dedicated `seq` and `keyseq` indexes) was disabled in CouchDB 2. As a consequence changes feed with `_view` will use neither `map_doc` nor index but will try to do `run(#evstate{ddocs=DDocs}=State, [<<"ddoc">>` instead and will crash with the mentioned error. This crash is caused by a missing implementation of `ddoc` function for `<<"views">>` FunPath case, because for the request like `/_changes?style=all_docs&filter=_view&view=test/repl` the `FunPath` will be: `[<<"views">>,<<"repl">>,<<"map">>]`. For JS map functions this does work because in this case `couch_query_server` delegates map to an external `couch_js` process. This fix effectively provides that missing case and it is based on the `FilterFun` case but matches return values of the `erlang:put()` function (which is called from the native `Emit` function) and it also matches `ok` and `false` return values for the cases when docs were not emitted and view just returns either `ok` or a `false` atom. ## Testing recommendations I've attached a simple shell script which makes curl requests to populate a test db with docs and a design doc containing Erlang `map` function and a JS one. In order to test just run changes feed for both JS map: ``` curl -u admin:admin1 'http://127.0.0.1:5983/db1/_changes?style=all_docs&filter=_view&view=testjs/repl' ``` and Erlang one `filter=_view&view=test/repl` and compare the output including the "last_seq" which should be the same.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
