summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2014-10-27 01:28:32 +0100
committerMagnus Ahltorp <map@kth.se>2014-10-27 01:28:32 +0100
commitfb3b9591cc81158824db13818cf6320d5f4a0f7b (patch)
tree3a662f20aab49b983e6d7aa9cdc10eb059c7b206 /src
parent80ea2ac6af8f993888444a4f75bbcc976ddd3973 (diff)
Fix mistake in ebc9d5ba (Optimize fetchnewentries)
Diffstat (limited to 'src')
-rw-r--r--src/index.erl13
-rw-r--r--src/storage.erl8
2 files changed, 14 insertions, 7 deletions
diff --git a/src/index.erl b/src/index.erl
index c1e0352..96195e3 100644
--- a/src/index.erl
+++ b/src/index.erl
@@ -12,7 +12,7 @@
%% TODO: Checksums
-module(index).
--export([get/2, getrange/3, add/3, addlast/2]).
+-export([get/2, getrange/3, add/3, addlast/2, indexsize/1]).
-define(ENTRYSIZE, 32).
-define(ENTRYSIZEINFILE, (?ENTRYSIZE*2+1)).
@@ -77,18 +77,19 @@ decodedata(<<_:?ENTRYSIZE/binary-unit:16, _>>, _Acc) ->
util:exit_with_error(badformat, readindex,
"Index line not ending with linefeed").
--spec size(string()) -> integer().
-size(Basepath) ->
+-spec indexsize(string()) -> integer().
+indexsize(Basepath) ->
case file:open(Basepath, [read, binary]) of
{ok, File} ->
{ok, Filesize} = file:position(File, eof),
- Filesize mod ?ENTRYSIZEINFILE;
+ lager:debug("file ~p size ~p", [Basepath, Filesize]),
+ Filesize div ?ENTRYSIZEINFILE;
{error, Error} ->
util:exit_with_error(Error, readfile,
"Error opening file for reading")
end.
--spec get(string(), integer()) -> binary().
+-spec get(string(), integer()) -> binary() | noentry.
get(Basepath, Index) ->
case getrange(Basepath, Index, Index) of
noentry ->
@@ -99,6 +100,7 @@ get(Basepath, Index) ->
-spec getrange(string(), integer(), integer()) -> [binary()].
getrange(Basepath, Start, End) when Start =< End ->
+ lager:debug("path ~p start ~p end ~p", [Basepath, Start, End]),
case file:open(Basepath, [read, binary]) of
{ok, File} ->
{ok, Filesize} = file:position(File, eof),
@@ -109,6 +111,7 @@ getrange(Basepath, Start, End) when Start =< End ->
{ok, EntryText} =
file:read(File, ?ENTRYSIZEINFILE * (End - Start + 1)),
Entry = decodedata(EntryText),
+ lager:debug("entries ~p", [length(Entry)]),
file:close(File),
Entry;
true ->
diff --git a/src/storage.erl b/src/storage.erl
index df6641a..8136308 100644
--- a/src/storage.erl
+++ b/src/storage.erl
@@ -43,8 +43,12 @@ request(get, "ct/storage/fetchnewentries", _Input) ->
{entries, Entries}]}).
fetchnewhashes(Index) ->
- Size = index:size(newentries_path()),
- index:getrange(newentries_path(), Index, Size - 1).
+ case index:indexsize(newentries_path()) of
+ 0 ->
+ [];
+ Size ->
+ index:getrange(newentries_path(), Index, Size - 1)
+ end.
%% Private functions.
html(Text, Input) ->