Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry filter_docs sequentially if the patch exceeds couchjs stack #3249

Merged
merged 2 commits into from Nov 6, 2020

Conversation

rnewson
Copy link
Member

@rnewson rnewson commented Nov 5, 2020

Overview

A document with lots of conflicts can blow up couchjs if the user
calls _changes with a javascript filter and with style=all_docs as
this option causes up to fetch all the conflicts.

All leaf revisions of the document are then passed in a single call to
ddoc_prompt, which can fail if there's a lot of them.

In that event, we simply try them sequentially and assemble the
response from each call.

Testing recommendations

Covered by unit test, but manual test as follows;

You need to create a highly conflicted document and lower couchjs's memory allowance for a practical test. Here's how I did it;

  1. edit dev/run;
-    qs_javascript = toposixpath("%s %s" % (couchjs, mainjs))
+    qs_javascript = toposixpath("%s -S 1048576 %s" % (couchjs, mainjs))
  1. create a filter;
curl 'foo:bar@localhost:15984/db1/_design/foo' -XPUT -d '{"filters":{"pass":"function(doc,req) { log(JSON.stringify(doc)); return true; }"}}'
  1. create a highly conflicted doc;
for I in {1..2000}; do curl 'foo:bar@localhost:15984/db1/bigdoc?new_edits=false' -XPUT -d "{\"_rev\":\"1-conflict$I\", \"foo\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}" ; done
  1. then run it through filter_docs;
curl 'foo:bar@localhost:15984/db1/_changes?filter=foo/pass&style=all_docs'

Without the patch, this will fail with an {exit_status, 1} error from couchjs. With it, it succeeds.

Related Issues or Pull Requests

#3248

Checklist

  • Code is written and works correctly
  • Changes are covered by tests
  • Any new configurable parameters are documented in rel/overlay/etc/default.ini
  • A PR for documentation changes has been made in https://github.com/apache/couchdb-documentation

A document with lots of conflicts can blow up couchjs if the user
calls _changes with a javascript filter and with `style=all_docs` as
this option causes up to fetch all the conflicts.

All leaf revisions of the document are then passed in a single call to
ddoc_prompt, which can fail if there's a lot of them.

In that event, we simply try them sequentially and assemble the
response from each call.

Should be backported to 3.x
Copy link
Member

@davisp davisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@rnewson rnewson merged commit 3c8490e into 3.x Nov 6, 2020
@rnewson rnewson deleted the changes_filter_all_docs_oom_3.x branch November 6, 2020 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants