summaryrefslogtreecommitdiff
path: root/src/permdb.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/permdb.erl')
-rw-r--r--src/permdb.erl15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/permdb.erl b/src/permdb.erl
index 393e6df..6157a60 100644
--- a/src/permdb.erl
+++ b/src/permdb.erl
@@ -22,7 +22,7 @@
-define(DATAMAGIC, <<16#cb, 16#0e>>).
-define(NODESIZE, (?MAGICSIZE+(?ENTRIESPERNODE*?BYTESPERENTRY))).
--record(state, {cachename, port, datafile, indexfile, requests}).
+-record(state, {cachename, name, port, datafile, indexfile, requests, requestcounter}).
getvalue_port_command(Port, Key) ->
Port ! {self(), {command, <<0:8, Key/binary>>}}.
@@ -118,9 +118,11 @@ init([Name, Filename]) ->
DataFile = none,%%openfile(Filename),
IndexFile = none,%%openfile(Filename ++ ".idx"),
{ok, #state{cachename = Cachename,
+ name = Name,
port = Port,
datafile = DataFile,
indexfile = IndexFile,
+ requestcounter = 0,
requests = queue:new()}}.
init_module() ->
@@ -139,7 +141,7 @@ handle_cast(_Request, State) ->
handle_info({Port, {data, Data}}, State) when is_port(Port) ->
lager:debug("response: ~p", [Data]),
{{value, {From, Action}}, Requests} = queue:out(State#state.requests),
- lager:debug("response: ~p", [Action]),
+ lager:debug("response ~p ~p: ~p", [State#state.name, State#state.requestcounter, Action]),
gen_server:reply(From, case Action of
getvalue ->
case Data of
@@ -172,14 +174,15 @@ terminate(_Reason, State) ->
add_request(State, From, Action) ->
State#state{
- requests = queue:in({From, Action}, State#state.requests)
+ requests = queue:in({From, Action}, State#state.requests),
+ requestcounter = State#state.requestcounter + 1
}.
handle_call(stop, _From, State) ->
{stop, normal, stopped, State};
handle_call({getvalue, Key}, From, State) ->
- lager:debug("getvalue: ~p", [Key]),
+ lager:debug("getvalue ~p ~p: ~p", [State#state.name, State#state.requestcounter, Key]),
Method = port,
case Method of
port ->
@@ -191,11 +194,11 @@ handle_call({getvalue, Key}, From, State) ->
end;
handle_call({addvalue, Key, Value}, From, State) ->
- lager:debug("addvalue: ~p ~p", [Key, Value]),
+ lager:debug("addvalue ~p ~p: ~p ~p", [State#state.name, State#state.requestcounter, Key, Value]),
addvalue_port_command(State#state.port, Key, Value),
{noreply, add_request(State, From, addvalue)};
handle_call({commit}, From, State) ->
- lager:debug("commit", []),
+ lager:debug("commit ~p ~p", [State#state.name, State#state.requestcounter]),
commit_port_command(State#state.port),
{noreply, add_request(State, From, commit)}.