-
Notifications
You must be signed in to change notification settings - Fork 1k
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
convert erlfdb_error 2101 to transaction_too_large #3215
Conversation
d0404f0
to
ad48e5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good to me, +1! (non-binding)
I wonder if it's easy to add a test case for this.
src/chttpd/src/chttpd.erl
Outdated
@@ -362,6 +362,8 @@ catch_error(HttpReq, error, decryption_failed) -> | |||
send_error(HttpReq, decryption_failed); | |||
catch_error(HttpReq, error, not_ciphertext) -> | |||
send_error(HttpReq, not_ciphertext); | |||
catch_error(HttpReq, error, {erlfdb_error,2101}) -> | |||
send_error(HttpReq, {request_transcation_too_large, 2101}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
send_error(HttpReq, {request_transcation_too_large, 2101}); | |
send_error(HttpReq, {request_transaction_too_large, 2101}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably just use the transaction_too_large
atom instead of the tuple {request_transaction_too_large, 2101}
since the tag explains the error pretty well.
And we'd want to stay somewhat consistent with https://apple.github.io/foundationdb/api-error-codes.html
transaction_too_large | 2101 | Transaction exceeds byte limit
src/chttpd/src/chttpd.erl
Outdated
@@ -362,6 +362,8 @@ catch_error(HttpReq, error, decryption_failed) -> | |||
send_error(HttpReq, decryption_failed); | |||
catch_error(HttpReq, error, not_ciphertext) -> | |||
send_error(HttpReq, not_ciphertext); | |||
catch_error(HttpReq, error, {erlfdb_error,2101}) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's leave a space after ,
and 2101
src/chttpd/src/chttpd.erl
Outdated
error_info({request_transcation_too_large, Code}) -> | ||
CodeBin = integer_to_binary(Code), | ||
{413, <<"request_transcation_too_large">>, | ||
<<"The request transcation is too large. (", CodeBin/binary, ")" >>}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users might confuse 2101
with the transaction size limit. Since we know the limit as 10MB we can just include in the message perhaps something like {413, <<"transaction_too_large">>, <<"The request transaction is larger than 10MB">>}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great improvement!
Made a few suggestions about simplifying the error names.
Good idea by @bessbd to add tests. Maybe in fabric2_update_docs_tests or if you can find a better place. Just make sure to generate random data so compression doesn't undo your large data generation.
Then it should be good to go.
As an extra aside to this PR, and mainly for discussion, it is interesting that max doc size doesn't take effect here. We should double check why does max_document_size
limit of 8MB from default.ini not work? Is it because the check there is approximate (json "size") or, there is a bug somewhere with _bulk_docs. What if we lowered the max doc size limit to 4MB would we start getting a max doc size error then...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
f33459d
to
cccdcdf
Compare
cccdcdf
to
d4557f2
Compare
LGTM. Thank you for the test case, @jiangphcn |
src/chttpd/src/chttpd.erl
Outdated
@@ -362,6 +362,8 @@ catch_error(HttpReq, error, decryption_failed) -> | |||
send_error(HttpReq, decryption_failed); | |||
catch_error(HttpReq, error, not_ciphertext) -> | |||
send_error(HttpReq, not_ciphertext); | |||
catch_error(HttpReq, error, {erlfdb_error, 2101}) -> | |||
send_error(HttpReq, transcation_too_large); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just realized there's a typo here (and on line 1014):
send_error(HttpReq, transcation_too_large); | |
send_error(HttpReq, transaction_too_large); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, and fixed in 4f7caf7
d4557f2
to
4f7caf7
Compare
test "bulk docs raises transaction_too_large error for transaction larger than 10MB", ctx do | ||
docs = [%{_id: "0", a: random_string(16_000_000)}] | ||
resp = Couch.post("/#{ctx[:db_name]}/_bulk_docs", body: %{docs: docs}) | ||
assert resp.status_code == 413 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's match on the error message ("transaction_too_large") since we're testing for it.
Wondering if with 16MB we would hit transaction_too_large or the document size limit of 8MB. If we don't hit 8MB we may have another bug to fix about why that doesn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are different settings on CouchDB and Cloudant for Transaction Engine for max_document_size
.
max_document_size = 8000000 ; bytes (CouchDB)
max_document_size = 67108864 ; 64 MB (Cloudant for Transaction Engine)
So by default, we will get document_too_large
in CouchDB while we will get transaction_too_large
if we pass 16MB document.
I added codes to adjust max_document_size
in this test to support 64MB documents to get transaction_too_large
in any cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find!
TxE is technically Cloudant's problem and shouldn't have any relevance for CouchDB. Though looking at the code there, is that the /dev/run instance may have 65Mb however the instance used in production has 1Mb.
Also maybe in a separate commit, we could probably switch to using the code default (in Erlang) to be 8Mb instead of keeping in the default.ini. Then default.ini can be a commented out line with the default value in it like we usually do it.
a0ba69a
to
7e97a04
Compare
test/elixir/test/bulk_docs_test.exs
Outdated
@tag :with_db | ||
test "bulk docs raises transaction_too_large error for transaction larger than 10MB", ctx do | ||
docs = [%{_id: "0", a: random_string(16_000_000)}] | ||
set_config_raw("couchdb", "max_document_size", "67108864") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this automatically reset if the test ends (either ok or fails)? We wouldn't want to alter the max doc size for other tests here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the setting on [couchdb][max_document_size]
will not be reverted after one test or test suite ends. I added codes to revert them. I believe that currently we are fine with this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 After double-checking that the config changes are reverted after the test finishes
9f3fb54
to
e275669
Compare
e275669
to
640c173
Compare
@jiangphcn One more thing is we'd have to merge this to main since we use main as the 4.x branch |
Good reminder, @nickva. I will do soon. |
Yeah, we should be careful, |
Overview
If transaction exceeds byte limit using the
_bulk_docs
endpoint, the{u'reason': u'2101', u'ref': 3853288219, u'error': u'erlfdb_error'}
with 500 error code was returned. This is user-friendly. Using this PR is to provide meaningful error message to users.Testing recommendations
The test python code:
Original response:
New response:
make elixir tests=test/elixir/test/bulk_docs_test.exs
make exunit tests=src/couchdb/test/elixir/test/bulk_docs_test.exs
Related Issues or Pull Requests
Checklist
rel/overlay/etc/default.ini