summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2012-06-19 12:26:23 +0100
committerSimon MacMullen <simon@rabbitmq.com>2012-06-19 12:26:23 +0100
commit0d28244d560968c85db138934ebb113eb296ba82 (patch)
treeba7030d370de0679c426aced8c843ff71ba7ef7f
parente30874df1b9b05b0948bc2cb6785a8003d353661 (diff)
downloadrabbitmq-server-0d28244d560968c85db138934ebb113eb296ba82.tar.gz
Backport 6ceaf986f26d (Merge of bug24994; rotating logs consumes memory according to the size of the logfile)
-rw-r--r--src/rabbit_file.erl32
1 files changed, 10 insertions, 22 deletions
diff --git a/src/rabbit_file.erl b/src/rabbit_file.erl
index 59df14f3..5937a335 100644
--- a/src/rabbit_file.erl
+++ b/src/rabbit_file.erl
@@ -102,9 +102,12 @@ read_file_info(File) ->
with_fhc_handle(fun () -> prim_file:read_file_info(File) end).
with_fhc_handle(Fun) ->
- ok = file_handle_cache:obtain(),
+ with_fhc_handle(1, Fun).
+
+with_fhc_handle(N, Fun) ->
+ [ ok = file_handle_cache:obtain() || _ <- lists:seq(1, N)],
try Fun()
- after ok = file_handle_cache:release()
+ after [ ok = file_handle_cache:release() || _ <- lists:seq(1, N)]
end.
read_term_file(File) ->
@@ -165,27 +168,12 @@ make_binary(List) ->
{error, Reason}
end.
-
append_file(File, Suffix) ->
- case read_file_info(File) of
- {ok, FInfo} -> append_file(File, FInfo#file_info.size, Suffix);
- {error, enoent} -> append_file(File, 0, Suffix);
- Error -> Error
- end.
-
-append_file(_, _, "") ->
- ok;
-append_file(File, 0, Suffix) ->
- with_fhc_handle(fun () ->
- case prim_file:open([File, Suffix], [append]) of
- {ok, Fd} -> prim_file:close(Fd);
- Error -> Error
- end
- end);
-append_file(File, _, Suffix) ->
- case with_fhc_handle(fun () -> prim_file:read_file(File) end) of
- {ok, Data} -> write_file([File, Suffix], Data, [append]);
- Error -> Error
+ case with_fhc_handle(2, fun () ->
+ file:copy(File, {[File, Suffix], [append]})
+ end) of
+ {ok, _BytesCopied} -> ok;
+ Error -> Error
end.
ensure_parent_dirs_exist(Filename) ->