diff options
author | Linus Nordberg <linus@nordberg.se> | 2014-10-29 16:35:44 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2014-10-29 16:56:48 +0100 |
commit | 92f681e1cbb444317d2603994c60c02feeab32be (patch) | |
tree | ef62cdfece8c1f063cb27cf299094e1f4d7eed1a /src/index.erl | |
parent | b15f4636337c45b487651e8d442afed0d4141725 (diff) | |
parent | cc2aaa2807bb13f4683c2d74a414d39d5b29a372 (diff) |
Merge remote-tracking branch 'refs/remotes/map/external-merge3' into merging-external-merge
Conflicts:
src/db.erl
src/frontend.erl
src/index.erl
src/plop.erl
src/storage.erl
src/ts.erl
Diffstat (limited to 'src/index.erl')
-rw-r--r-- | src/index.erl | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/index.erl b/src/index.erl index bbc9a10..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,7 +77,19 @@ decodedata(<<_:?ENTRYSIZE/binary-unit:16, _>>, _Acc) -> util:exit_with_error(badformat, readindex, "Index line not ending with linefeed"). --spec get(string(), integer()) -> binary(). +-spec indexsize(string()) -> integer(). +indexsize(Basepath) -> + case file:open(Basepath, [read, binary]) of + {ok, File} -> + {ok, Filesize} = file:position(File, eof), + 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() | noentry. get(Basepath, Index) -> case getrange(Basepath, Index, Index) of noentry -> @@ -88,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), @@ -98,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 -> |