summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2016-03-15 14:36:29 +0100
committerLinus Nordberg <linus@nordu.net>2016-04-25 13:14:12 +0200
commit83206ee4bcdf925826120701041b9497fd3c131c (patch)
treef17c980ee26a6cbbd8e86550044ff8995b43add4 /src
parente7ea07adcbf6f4d07412c3b2c698144c2c8a71b8 (diff)
Remove old permdb code
Diffstat (limited to 'src')
-rw-r--r--src/permdb.erl92
1 files changed, 3 insertions, 89 deletions
diff --git a/src/permdb.erl b/src/permdb.erl
index 29e321f..16ba28a 100644
--- a/src/permdb.erl
+++ b/src/permdb.erl
@@ -12,17 +12,7 @@
-export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2,
code_change/3]).
--define(KEYSIZE, 32).
--define(BITSPERLEVEL, 2).
--define(ENTRIESPERNODE, 4).
--define(BYTESPERENTRY, 8).
--define(BITSPERENTRY, (?BYTESPERENTRY*8-1)).
--define(MAGICSIZE, 2).
--define(NODEMAGIC, <<16#8a, 16#44>>).
--define(DATAMAGIC, <<16#cb, 16#0e>>).
--define(NODESIZE, (?MAGICSIZE+(?ENTRIESPERNODE*?BYTESPERENTRY))).
-
--record(state, {cachename, name, port, datafile, indexfile, requests, requestcounter}).
+-record(state, {cachename, name, port, requests, requestcounter}).
getvalue_port_command(Port, Key) ->
Port ! {self(), {command, <<0:8, Key/binary>>}}.
@@ -33,71 +23,6 @@ addvalue_port_command(Port, Key, Value) ->
commit_port_command(Port) ->
Port ! {self(), {command, <<2:8>>}}.
-getdatakey(State, Offset) ->
- {ok, DataBinary} = file:pread(State#state.datafile, Offset, ?MAGICSIZE+?KEYSIZE+?BYTESPERENTRY),
- Datamagic = ?DATAMAGIC,
- <<Datamagic:2/binary, Key:?KEYSIZE/binary, Length:?BYTESPERENTRY/integer-unit:8>> = DataBinary,
- {Key, Length}.
-
-getdata(State, Offset, Length) ->
- {ok, DataBinary} = file:pread(State#state.datafile, Offset+?MAGICSIZE+?KEYSIZE+?BYTESPERENTRY, Length),
- DataBinary.
-
-getnode(State, Offset) ->
- case ets:lookup(State#state.cachename, Offset) of
- [] ->
- {ok, NodeBinary} = file:pread(State#state.indexfile, Offset, ?NODESIZE),
- Nodemagic = ?NODEMAGIC,
- <<Nodemagic:2/binary, Node/binary>> = NodeBinary,
- ets:insert(State#state.cachename, {Offset, Node}),
- Node;
- [{_, Node}] ->
- Node
- end.
-
-getroot(State) ->
- case ets:lookup(State#state.cachename, root) of
- [] ->
- {ok, _Position} = file:position(State#state.indexfile, {eof, -?NODESIZE}),
- {ok, RootNodeBinary} = file:read(State#state.indexfile, ?NODESIZE),
- Nodemagic = ?NODEMAGIC,
- <<Nodemagic:2/binary, Node/binary>> = RootNodeBinary,
- ets:insert(State#state.cachename, {root, Node}),
- Node;
- [{root, Node}] ->
- Node
- end.
-
-getendentry(State, Key) ->
- Root = getroot(State),
- %io:format("Root: ~p~n", [Root]),
- getendentry(State, Key, Root).
-
-getendentry(State, <<KeyHead:?BITSPERLEVEL, KeyRest/bitstring>>, Node) ->
- case binary_part(Node, KeyHead*?BYTESPERENTRY, ?BYTESPERENTRY) of
- <<0:?BYTESPERENTRY/integer-unit:8>> ->
- none;
- <<0:1, Entry:?BITSPERENTRY>> ->
- NewNode = getnode(State, Entry),
- getendentry(State, KeyRest, NewNode);
- <<1:1, Entry:?BITSPERENTRY>> ->
- Entry
- end.
-
-getvalue_file(State, Key) ->
- case getendentry(State, Key) of
- none ->
- none;
- Entry ->
- case getdatakey(State, Entry) of
- {Key, Length} ->
- getdata(State, Entry, Length);
- _ ->
- none
- end
- end.
-
-
getvalue(Name, Key) ->
gen_server:call(Name, {getvalue, Key}, 600000).
@@ -115,13 +40,9 @@ init([Name, Filename]) ->
process_flag(trap_exit, true),
Port = open_port({spawn_executable, code:priv_dir(plop) ++ "/permdbport"},
[{packet, 4}, {args, [Filename]}, binary]),
- 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()}}.
@@ -183,15 +104,8 @@ handle_call(stop, _From, State) ->
handle_call({getvalue, Key}, From, State) ->
lager:debug("getvalue ~p ~p: ~p", [State#state.name, State#state.requestcounter, Key]),
- Method = port,
- case Method of
- port ->
- getvalue_port_command(State#state.port, Key),
- {noreply, add_request(State, From, getvalue)};
- file ->
- Value = getvalue_file(State, Key),
- {reply, Value, State}
- end;
+ getvalue_port_command(State#state.port, Key),
+ {noreply, add_request(State, From, getvalue)};
handle_call({addvalue, Key, Value}, From, State) ->
lager:debug("addvalue ~p ~p: ~p ~p", [State#state.name, State#state.requestcounter, Key, Value]),