You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ji...@apache.org on 2020/10/20 12:49:45 UTC

[couchdb] branch prototype/fdb-layer updated: convert erlfdb_error 2101 to transaction_too_large (#3215)

This is an automated email from the ASF dual-hosted git repository.

jiangphcn pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/prototype/fdb-layer by this push:
     new 7bdb432  convert erlfdb_error 2101 to transaction_too_large (#3215)
7bdb432 is described below

commit 7bdb432849f477d0c4451aaf9d41b35ab076e9f3
Author: Peng Hui Jiang <ji...@cn.ibm.com>
AuthorDate: Tue Oct 20 20:49:29 2020 +0800

    convert erlfdb_error 2101 to transaction_too_large (#3215)
---
 src/chttpd/src/chttpd.erl           |  5 +++++
 test/elixir/test/bulk_docs_test.exs | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index 1a9b19b..1198dbb 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -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, transaction_too_large);
 catch_error(HttpReq, Tag, Error) ->
     Stack = erlang:get_stacktrace(),
     % TODO improve logging and metrics collection for client disconnects
@@ -1009,6 +1011,9 @@ error_info({request_entity_too_large, {bulk_get, Max}}) when is_integer(Max) ->
     {413, <<"max_bulk_get_count_exceeded">>, integer_to_binary(Max)};
 error_info({request_entity_too_large, DocID}) ->
     {413, <<"document_too_large">>, DocID};
+error_info(transaction_too_large) ->
+    {413, <<"transaction_too_large">>,
+        <<"The request transaction is larger than 10MB" >>};
 error_info({error, security_migration_updates_disabled}) ->
     {503, <<"security_migration">>, <<"Updates to security docs are disabled during "
         "security migration.">>};
diff --git a/test/elixir/test/bulk_docs_test.exs b/test/elixir/test/bulk_docs_test.exs
index 1a7c110..d548eef 100644
--- a/test/elixir/test/bulk_docs_test.exs
+++ b/test/elixir/test/bulk_docs_test.exs
@@ -129,6 +129,17 @@ defmodule BulkDocsTest do
     assert Enum.at(rows, 2)["error"] == "conflict"
   end
 
+  @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)}]
+    old_size = Couch.get("/_node/node1@127.0.0.1/_config/couchdb/max_document_size").body
+    set_config_raw("couchdb", "max_document_size", "67108864") # 64M
+    resp = Couch.post("/#{ctx[:db_name]}/_bulk_docs", body: %{docs: docs})
+    set_config_raw("couchdb", "max_document_size", old_size) # set back
+    assert resp.status_code == 413
+    assert resp.body["error"] == "transaction_too_large"
+  end
+
   defp bulk_post(docs, db) do
     retry_until(fn ->
       resp = Couch.post("/#{db}/_bulk_docs", body: %{docs: docs})
@@ -151,4 +162,11 @@ defmodule BulkDocsTest do
     assert resp.body["error"] == "bad_request"
     assert resp.body["reason"] == reason
   end
+
+  defp random_string(length) do
+    raw = :crypto.strong_rand_bytes(length)
+    raw
+    |> Base.url_encode64
+    |> binary_part(0, length)
+  end
 end