jaydoane commented on code in PR #4627: URL: https://github.com/apache/couchdb/pull/4627#discussion_r1600715531
########## src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl: ########## @@ -0,0 +1,493 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(couch_quickjs_scanner_plugin). +-behaviour(couch_scanner_plugin). + +-export([ + start/2, + resume/2, + complete/1, + checkpoint/1, + db/2, + ddoc/3, + shards/2, + db_opened/2, + doc_id/3, + doc/3, + db_closing/2 +]). + +-include_lib("couch_scanner/include/couch_scanner_plugin.hrl"). + +-record(st, { + sid, + ddocs = #{}, + docs = [], + docs_size = 0, + qjs_proc, + sm_proc, + ddoc_cnt = 0, + doc_cnt = 0, + doc_step = 0, + max_ddocs = 100, + max_shards = 4, + max_docs = 1000, + max_step = 1000, + % These match defaults in couch_mrview_updater + max_batch_items = 100, + max_batch_size = 16777216 +}). + +% DDoc fields + +-define(FILTERS, <<"filters">>). +-define(VIEWS, <<"views">>). +-define(MAP, <<"map">>). +-define(REDUCE, <<"reduce">>). +-define(LIB, <<"lib">>). +-define(VDU, <<"validate_doc_update">>). + +% Behavior callbacks + +start(SId, #{}) -> + case couch_server:with_spidermonkey() of + true -> + ?WARN("starting.", [], #{sid => SId}), + {ok, init_config(#st{sid = SId})}; + false -> + ?WARN("not starting. Spidermonkey not enabled", [], #{}), + skip + end. + +resume(SId, #{}) -> + case couch_server:with_spidermonkey() of + true -> + ?WARN("resuming", [], #{sid => SId}), + {ok, init_config(#st{sid = SId})}; + false -> + ?WARN("not resuming. Spidermonkey not enabled", [], #{}), + skip + end. + +complete(#st{sid = SId}) -> + ?WARN("completed", [], #{sid => SId}), + {ok, #{}}. + +checkpoint(#st{sid = SId}) -> + ?INFO(#{sid => SId}), + {ok, #{<<"sid">> => SId}}. + +db(#st{sid = SId} = St, DbName) -> + St1 = reset_per_db_state(St), + ?INFO(#{sid => SId, db => DbName}), + {ok, St1}. + +ddoc(#st{ddoc_cnt = C, max_ddocs = M} = St, _, _) when C > M -> + {stop, St}; Review Comment: Do you think there's any benefit to emitting a warning when processing is halted anywhere due to exceeding a limit? ########## src/couch_quickjs/rebar.config.script: ########## @@ -0,0 +1,95 @@ +% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- +% ex: ts=4 sw=4 ft=erlang et +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +% Windows is "special" so we treat it "specially" Review Comment: lol -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
