Skip to content

Commit f0a0046

Browse files
committed
Skip validation for ddocs in the scanner
Previously, if users had invalid ddocs in the cluster, for instance something like `_design/`, the scanner would crash when tranforming them into `#doc{}` records. That happened because the `couch_doc` function would automatically revalidate them: check max doc length ID, attachments format, revision format, doc ID format, etc. Which altogether silly, since they are already saved in our cluster. So, to avoid wasting resources revalidating existing documents, and crashing the scanner process, use a much simpler function to transform the ddocs: make a new `#doc{}` record with the ID and body by throwing away all the "special" doc fields we don't care about (`_rev`, `_conflicts`, ...).
1 parent f8e6c25 commit f0a0046

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/couch_scanner/src/couch_scanner_plugin.erl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ scan_ddocs_fold({meta, _}, #st{} = Acc) ->
329329
{ok, Acc};
330330
scan_ddocs_fold({row, RowProps}, #st{} = Acc) ->
331331
DDoc = couch_util:get_value(doc, RowProps),
332-
scan_ddoc(couch_doc:from_json_obj(DDoc), Acc);
332+
scan_ddoc(ejson_to_doc(DDoc), Acc);
333333
scan_ddocs_fold(complete, #st{} = Acc) ->
334334
{ok, Acc};
335335
scan_ddocs_fold({error, Error}, _Acc) ->
@@ -633,6 +633,13 @@ fold_ddocs(Fun, #st{dbname = DbName} = Acc) ->
633633
Acc
634634
end.
635635

636+
% Simple ejson to #doc{} function to avoid all the extra validation in from_json_obj/1.
637+
% We just got these docs from the cluster, they are already saved on disk.
638+
ejson_to_doc({[_ | _] = Props}) ->
639+
{value, {_, DocId}, Props1} = lists:keytake(<<"_id">>, 1, Props),
640+
Props2 = [{K, V} || {K, V} <- Props1, binary:first(K) =/= $_],
641+
#doc{id = DocId, body = {Props2}}.
642+
636643
% Skip patterns
637644

638645
% Build the skip patterns from a config section

0 commit comments

Comments
 (0)