Permalink
Browse files

Add bitcask:get_offset/2 to find out where a key is on disk

  • Loading branch information...
Vagabond committed Aug 24, 2012
1 parent 4c6d6df commit 4329b7cc466681d131014549d160e6dd983dfc0e
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/bitcask.erl
View
@@ -27,6 +27,7 @@
close/1,
close_write_file/1,
get/2,
+ get_offset/2,
put/3,
delete/2,
sync/1,
@@ -216,6 +217,17 @@ get(Ref, Key, TryNum) ->
end
end.
+%% @doc Get the offset of a key on-disk
+-spec get_offset(reference(), Key::binary()) -> integer() | not_found.
+get_offset(Ref, Key) ->
+ State = get_state(Ref),
+ case bitcask_nifs:keydir_get(State#bc_state.keydir, Key) of
+ not_found ->
+ not_found;
+ E when is_record(E, bitcask_entry) ->
+ E#bitcask_entry.offset
+ end.
+
%% @doc Store a key and value in a bitcase datastore.
-spec put(reference(), Key::binary(), Value::binary()) -> ok.
put(Ref, Key, Value) ->

0 comments on commit 4329b7c

Please sign in to comment.