summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2011-08-10 21:06:50 +0000
committerRobert Newson <rnewson@apache.org>2011-08-10 21:06:50 +0000
commit0ac7f70c85f3be8fc65d814473b9a5a5a0aed0f7 (patch)
tree60c047443e1499aad8ee84bf9195eb0deca8f26b
parentb2db4f11376472fa801c58f98dcc2e356783e276 (diff)
COUCHDB-1245 - enforce maximum chunk size for _log call to better manage memory.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1156369 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--etc/couchdb/default.ini.tpl.in1
-rw-r--r--src/couchdb/couch_log.erl9
2 files changed, 10 insertions, 0 deletions
diff --git a/etc/couchdb/default.ini.tpl.in b/etc/couchdb/default.ini.tpl.in
index 1592e330..18a5c1c8 100644
--- a/etc/couchdb/default.ini.tpl.in
+++ b/etc/couchdb/default.ini.tpl.in
@@ -24,6 +24,7 @@ allow_jsonp = false
;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
; For more socket options, consult Erlang's module 'inet' man page.
;socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]
+log_max_chunk_size = 1000000
[ssl]
port = 6984
diff --git a/src/couchdb/couch_log.erl b/src/couchdb/couch_log.erl
index bb75f161..ab649cac 100644
--- a/src/couchdb/couch_log.erl
+++ b/src/couchdb/couch_log.erl
@@ -172,6 +172,15 @@ get_log_messages(Pid, Level, Format, Args) ->
read(Bytes, Offset) ->
LogFileName = couch_config:get("log", "file"),
LogFileSize = filelib:file_size(LogFileName),
+ MaxChunkSize = list_to_integer(
+ couch_config:get("httpd", "log_max_chunk_size", "1000000")),
+ case Bytes > MaxChunkSize of
+ true ->
+ throw({bad_request, "'bytes' cannot exceed " ++
+ integer_to_list(MaxChunkSize)});
+ false ->
+ ok
+ end,
{ok, Fd} = file:open(LogFileName, [read]),
Start = lists:max([LogFileSize - Bytes, 0]) + Offset,