summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_file.erl
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2009-02-17 14:01:51 +0000
committerDamien F. Katz <damien@apache.org>2009-02-17 14:01:51 +0000
commit3b431fc0b30c5fb110afd06347058727724f0fb2 (patch)
tree5370bd65fdf8a586d415a03da6c5fb367d569f25 /src/couchdb/couch_file.erl
parent15976c8008473c9d8a97e0bf50f760faab12ee15 (diff)
Put file ref_counting into it's own module, to make the speed of opening an already open database faster (by not waiting on file pending operations, particularly fsync).
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@745076 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_file.erl')
-rw-r--r--src/couchdb/couch_file.erl81
1 files changed, 4 insertions, 77 deletions
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl
index b29f45d2..d1103030 100644
--- a/src/couchdb/couch_file.erl
+++ b/src/couchdb/couch_file.erl
@@ -20,7 +20,6 @@
-export([open/1, open/2, close/1, pread/3, pwrite/3, expand/2, bytes/1, sync/1]).
-export([append_term/2, pread_term/2,write_header/3, read_header/2, truncate/2]).
-export([init/1, terminate/2, handle_call/3, handle_cast/2, code_change/3, handle_info/2]).
--export([close_maybe/1,drop_ref/1,drop_ref/2,add_ref/1,add_ref/2,num_refs/1]).
%%----------------------------------------------------------------------
%% Args: Valid Options are [create] and [create,overwrite].
@@ -168,26 +167,6 @@ close(Fd) ->
Result = gen_server:cast(Fd, close),
catch unlink(Fd),
Result.
-
-close_maybe(Fd) ->
- catch unlink(Fd),
- catch gen_server:cast(Fd, close_maybe).
-
-drop_ref(Fd) ->
- drop_ref(Fd, self()).
-
-drop_ref(Fd, Pid) ->
- gen_server:cast(Fd, {drop_ref, Pid}).
-
-
-add_ref(Fd) ->
- add_ref(Fd, self()).
-
-add_ref(Fd, Pid) ->
- gen_server:call(Fd, {add_ref, Pid}).
-
-num_refs(Fd) ->
- gen_server:call(Fd, num_refs).
write_header(Fd, Prefix, Data) ->
@@ -291,7 +270,6 @@ init_status_error(ReturnPid, Ref, Error) ->
% server functions
init({Filepath, Options, ReturnPid, Ref}) ->
- process_flag(trap_exit, true),
case lists:member(create, Options) of
true ->
filelib:ensure_dir(Filepath),
@@ -357,66 +335,15 @@ handle_call({append_bin, Bin}, _From, Fd) ->
handle_call({pread_bin, Pos}, _From, Fd) ->
{ok, <<TermLen:32>>} = file:pread(Fd, Pos, 4),
{ok, Bin} = file:pread(Fd, Pos + 4, TermLen),
- {reply, {ok, Bin}, Fd};
-handle_call({add_ref, Pid},_From, Fd) ->
- case get(Pid) of
- undefined ->
- put(Pid, {erlang:monitor(process, Pid), 1});
- {MonRef, RefCnt} ->
- put(Pid, {MonRef, RefCnt + 1})
- end,
- {reply, ok, Fd};
-handle_call(num_refs, _From, Fd) ->
- {monitors, Monitors} = process_info(self(), monitors),
- {reply, length(Monitors), Fd}.
+ {reply, {ok, Bin}, Fd}.
handle_cast(close, Fd) ->
- {stop,normal,Fd};
-handle_cast(close_maybe, Fd) ->
- maybe_close_async(Fd);
-handle_cast({drop_ref, Pid}, Fd) ->
- case get(Pid) of
- {MonRef, 1} ->
- erase(Pid),
- % don't check return of demonitor. The process could haved crashed causing
- % the {'DOWN', ...} message to be sent and the process unmonitored.
- erlang:demonitor(MonRef, [flush]);
- {MonRef, Num} ->
- put(Pid, {MonRef, Num-1})
- end,
- maybe_close_async(Fd).
+ {stop,normal,Fd}.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-handle_info({'EXIT', _Pid, Reason}, Fd) ->
- {stop, Reason, Fd};
-handle_info({'DOWN', MonitorRef, _Type, Pid, _Info}, Fd) ->
- {MonitorRef, _RefCount} = erase(Pid),
- maybe_close_async(Fd).
-
-
-
-should_close(_Fd) ->
- case process_info(self(), links) of
- {links, [_]} ->
- % no linkers left (except our fd port). What about monitors?
- case process_info(self(), monitors) of
- {monitors, []} ->
- true;
- _ ->
- false
- end;
- {links, [_|_]} ->
- false
- end.
-
-maybe_close_async(Fd) ->
- case should_close(Fd) of
- true ->
- {stop,normal,Fd};
- false ->
- {noreply,Fd}
- end.
+handle_info(foo, Fd) ->
+ {stop, foo, Fd}.