summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_util.erl
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2008-04-01 20:32:15 +0000
committerDamien F. Katz <damien@apache.org>2008-04-01 20:32:15 +0000
commit042de2f5aeea9fb5be6768df934d61ba26985d5c (patch)
tree9471eb95045593332cf0df9ce5abefb190921781 /src/couchdb/couch_util.erl
parent504c93c4534f07affc2c933bd4d5d7f6075ea013 (diff)
Fix for runaway process in the view code and the so far untested storage compaction code.
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@643556 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_util.erl')
-rw-r--r--src/couchdb/couch_util.erl20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl
index 42845fe0..f85cc834 100644
--- a/src/couchdb/couch_util.erl
+++ b/src/couchdb/couch_util.erl
@@ -14,7 +14,7 @@
-behaviour(gen_server).
-export([start_link/0,start_link/1]).
--export([parse_ini/1]).
+-export([parse_ini/1,should_flush/0, should_flush/1]).
-export([new_uuid/0, rand32/0, implode/2, collate/2, collate/3]).
-export([abs_pathname/1,abs_pathname/2, trim/1, ascii_lower/1, test/0]).
-export([encodeBase64/1, decodeBase64/1]).
@@ -22,6 +22,8 @@
-export([init/1, terminate/2, handle_call/3]).
-export([handle_cast/2,code_change/3,handle_info/2]).
+% arbitrarily chosen amount of memory to use before flushing to disk
+-define(FLUSH_MAX_MEM, 10000000).
start_link() ->
start_link("").
@@ -246,6 +248,22 @@ collate(A, B, Options) when is_list(A), is_list(B) ->
[2] -> 0
end.
+should_flush() ->
+ should_flush(?FLUSH_MAX_MEM).
+
+should_flush(MemThreshHold) ->
+ case process_info(self(), memory) of
+ {memory, Mem} when Mem > 2*MemThreshHold ->
+ garbage_collect(),
+ case process_info(self(), memory) of
+ {memory, Mem} when Mem > MemThreshHold ->
+ true;
+ _ ->
+ false
+ end;
+ _ ->
+ false
+ end.