Conversation
fbbacc2 to
4c103c9
Compare
bessbd
left a comment
There was a problem hiding this comment.
Thank you for this PR, @garrensmith .
The change looks good to me on a first read.
Do you think there's an easy way to add a test for this?
|
@bessbd this functionality is used throughout all the fabric2 and couch_views test. I think it's pretty well covered there. |
That I get. I'd just like to make sure we avoid accidentally (partially) reverting this. |
|
@bessbd could you give me an example? |
If I understand correctly, the essence of this PR is https://github.com/apache/couchdb/pull/3481/files#diff-eb8693c8aa6baf90841ed8bc66c04cbc525af0bb34368e3201ab4891b954190eL2157-R2157 . I'd just like to make sure that we don't inadvertently undo that change. |
src/couch_eval/src/couch_eval.erl
Outdated
| map_docs({ApiMod, Ctx}, Docs) -> | ||
| ApiMod:map_docs(Ctx, Docs). | ||
|
|
||
| -spec acquire_context(language()) -> {ok, context()} | {error, any()}. |
There was a problem hiding this comment.
The way the function is written it cannot return {error, any()}. I think the correct spec would be:
-type error(_Error) :: no_return().
....
spec acquire_context(language()) ->
{ok, context()}
| error({invalid_eval_api_mod, Language :: binary()})
| error({unknown_eval_api_language, Language :: binary()}).
There was a problem hiding this comment.
Don't forget to update -callback acquire_context().... above as well.
There was a problem hiding this comment.
Don't forget to update -callback acquire_context().... above as well.
Never mind it doesn't apply to the callback.
| }} = couch_mrview_util:ddoc_to_mrst(DbName, DDoc), | ||
|
|
||
| try Views =/= [] andalso couch_query_servers:get_os_process(Lang) of | ||
| try Views =/= [] andalso couch_eval:acquire_context(Lang) of |
There was a problem hiding this comment.
couch_eval:acquire_context/1 can raise {invalid_eval_api_mod, Language} or `{unknown_eval_api_language, Language}. Do we need to handle this on line 224?
There was a problem hiding this comment.
I don't think so. I'm happy for that error to bubble up.
src/couch_js/src/couch_js.erl
Outdated
|
|
||
|
|
||
| try_compile(Proc, FunName, FunSrc) -> | ||
| couch_query_servers:try_compile(Proc, map, FunName, FunSrc). |
There was a problem hiding this comment.
Is it always would be a map in a second argument?
There was a problem hiding this comment.
I can see that we used to call couch_query_servers:try_compile(Proc, reduce, RedName, RedSrc) here
There was a problem hiding this comment.
Looks like we either need to pass it explicitly as try_compile argument or have it as part of a context.
There was a problem hiding this comment.
Can you explain why it is ok to always call map?
|
There are very few places where we need to call Then the caller would look like: |
4c103c9 to
820e3b3
Compare
Since |
I didn't know that |
|
@bessbd right. I've deleted the function. I think that is the best approach. |
97818fc to
9765c09
Compare
| validate_ddoc(Db, DDoc) -> | ||
| try | ||
| ok = couch_index_server:validate(Db, couch_doc:with_ejson_body(DDoc)) | ||
| ok = couch_mrview:validate(Db, couch_doc:with_ejson_body(DDoc)) |
There was a problem hiding this comment.
isn't this a layering violation? the index/mrview split was intended to make the m/r view a specific kind of index
There was a problem hiding this comment.
This isn't ideal. But it will be temporary. I want to remove couch_index_server but I want to do it in a few smaller PR's rather than one large one. This first step will get the validation_ddoc using couch_eval instead of couch_index_server and the old javascript proc system.
The next one will be fixes to the replication filtering and the vdu. A final one will be where I can remove couch_index_server and the fix this.
There was a problem hiding this comment.
ok, I'm onboard with this change and will keep an eye out for the subsequent PR's. There is a lot of cleanup of dead code to do before a 4.0 release can be considered so I hope to see couch_index_server disappear in the near future.
src/couch_eval/src/couch_eval.erl
Outdated
| map_docs({ApiMod, Ctx}, Docs) -> | ||
| ApiMod:map_docs(Ctx, Docs). | ||
|
|
||
| -spec acquire_context(language()) -> {ok, context()} | {error, any()}. |
There was a problem hiding this comment.
Don't forget to update -callback acquire_context().... above as well.
Never mind it doesn't apply to the callback.
src/couch_js/src/couch_js.erl
Outdated
|
|
||
|
|
||
| release_context(Proc) -> | ||
| couch_js_query_servers:ret_os_process(Proc). |
There was a problem hiding this comment.
Should it be couch_query_servers:ret_os_process(Proc).?
src/couch_eval/src/couch_eval.erl
Outdated
| | error({invalid_eval_api_mod, Language :: binary()}) | ||
| | error({unknown_eval_api_language, Language :: binary()}). | ||
| with_context(#{language := Language}, Fun) -> | ||
| case acquire_context(Language) of |
There was a problem hiding this comment.
The case with a single pattern looks weird. In this particular case we can get away with {ok, Ctx} = acquire_context(Language). Because all errors are returned via either of:
erlang:error/1- get_api_moderlang:throw/1-couch_query_servers:get_os_process/1
src/couch_js/src/couch_js.erl
Outdated
|
|
||
|
|
||
| try_compile(Proc, FunName, FunSrc) -> | ||
| couch_query_servers:try_compile(Proc, map, FunName, FunSrc). |
There was a problem hiding this comment.
Can you explain why it is ok to always call map?
| %% Allow users to save ddocs written in unknown languages | ||
| ok | ||
| end. | ||
| Views =/= [] andalso couch_eval:with_context(#{language => Lang}, fun (Ctx) -> |
There was a problem hiding this comment.
Do we want to change the behavior and disallow users to save documents with incorrect language?
There was a problem hiding this comment.
Because currently the way it is written we wouldn't allow incorrect language.
Change the validate ddoc check to use couch_eval. Also add in some extra functions in couch_eval so that the try_compile will work.
This makes it that the only way to validate a design doc is through couch_mrview:validate_ddoc so that the correct couch_eval will be used.
ec1bf5b to
d568be8
Compare
Overview
Change the validate ddoc check to use couch_eval.
Also add in some extra functions in couch_eval so that the try_compile
will work.
Testing recommendations
All current design doc tests should pass.
Related Issues or Pull Requests
Checklist
rel/overlay/etc/default.ini