You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by be...@apache.org on 2021/02/01 19:09:53 UTC
[couchdb] branch 3.x updated: Set a finite default for
max_attachment_size (#3347)
This is an automated email from the ASF dual-hosted git repository.
bessbd pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/3.x by this push:
new 0837b51 Set a finite default for max_attachment_size (#3347)
0837b51 is described below
commit 0837b5162708d1c4482e404cc7488f70f2d1e301
Author: Bessenyei Balázs Donát <be...@users.noreply.github.com>
AuthorDate: Mon Feb 1 20:09:39 2021 +0100
Set a finite default for max_attachment_size (#3347)
The current default for max_attachment_size is infinity.
This commit changes that to 1 gibibyte.
---
rel/overlay/etc/default.ini | 2 +-
src/couch/src/couch_att.erl | 27 ++++++++++++++++++++++++---
src/couch/test/eunit/couch_doc_tests.erl | 1 +
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 3abe757..2cacf77 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -47,7 +47,7 @@ changes_doc_ids_optimization_threshold = 100
max_document_size = 8000000 ; bytes
;
; Maximum attachment size.
-; max_attachment_size = infinity
+; max_attachment_size = 1073741824 ; 1 gibibyte
;
; Do not update the least recently used DB cache on reads, only writes
;update_lru_on_read = false
diff --git a/src/couch/src/couch_att.erl b/src/couch/src/couch_att.erl
index 8a3d6b1..12ac487 100644
--- a/src/couch/src/couch_att.erl
+++ b/src/couch/src/couch_att.erl
@@ -178,6 +178,8 @@
-type att() :: #att{} | attachment() | disk_att().
+-define(GB, (1024*1024*1024)).
+
new() ->
%% We construct a record by default for compatability. This will be
%% upgraded on demand. A subtle effect this has on all attachments
@@ -732,13 +734,25 @@ upgrade_encoding(true) -> gzip;
upgrade_encoding(false) -> identity;
upgrade_encoding(Encoding) -> Encoding.
-
max_attachment_size() ->
- case config:get("couchdb", "max_attachment_size", "infinity") of
+ max_attachment_size(config:get("couchdb", "max_attachment_size", ?GB)).
+
+max_attachment_size(MaxAttSizeConfig) ->
+ case MaxAttSizeConfig of
"infinity" ->
infinity;
+ MaxAttSize when is_list(MaxAttSize) ->
+ try list_to_integer(MaxAttSize) of
+ Result -> Result
+ catch _:_ ->
+ couch_log:error("invalid config value for max attachment size: ~p ", [MaxAttSize]),
+ throw(internal_server_error)
+ end;
+ MaxAttSize when is_integer(MaxAttSize) ->
+ MaxAttSize;
MaxAttSize ->
- list_to_integer(MaxAttSize)
+ couch_log:error("invalid config value for max attachment size: ~p ", [MaxAttSize]),
+ throw(internal_server_error)
end.
@@ -949,4 +963,11 @@ test_transform() ->
?assertEqual(1, fetch(counter, Transformed)).
+max_attachment_size_test_() ->
+ {"Max attachment size tests", [
+ ?_assertEqual(infinity, max_attachment_size("infinity")),
+ ?_assertEqual(5, max_attachment_size(5)),
+ ?_assertEqual(5, max_attachment_size("5"))
+ ]}.
+
-endif.
diff --git a/src/couch/test/eunit/couch_doc_tests.erl b/src/couch/test/eunit/couch_doc_tests.erl
index cf41df6..fc63d3f 100644
--- a/src/couch/test/eunit/couch_doc_tests.erl
+++ b/src/couch/test/eunit/couch_doc_tests.erl
@@ -139,6 +139,7 @@ mock_config() ->
meck:expect(config, get,
fun("couchdb", "max_document_id_length", "infinity") -> "1024";
("couchdb", "max_attachment_size", "infinity") -> "infinity";
+ ("couchdb", "max_attachment_size", 1073741824) -> 1073741824;
("mem3", "shards_db", "_dbs") -> "_dbs";
(Key, Val, Default) -> meck:passthrough([Key, Val, Default])
end