Permalink
Browse files

Apply dialyzer fixes from riak_kv version.

  • Loading branch information...
1 parent 799d00b commit 334c8d805dbf770774e9ab5a4c5d79ab4d639bd8 @seancribbs seancribbs committed Apr 12, 2012
Showing with 25 additions and 32 deletions.
  1. BIN erl_src/riak_kv_test_backend.beam
  2. +25 −32 erl_src/riak_kv_test_backend.erl
Binary file not shown.
@@ -159,14 +159,20 @@ stop(#state{data_ref=DataRef,
{ok, not_found, state()} |
{error, term(), state()}.
get(Bucket, Key, State=#state{data_ref=DataRef,
+ index_ref=IndexRef,
+ used_memory=UsedMemory,
ttl=TTL}) ->
case ets:lookup(DataRef, {Bucket, Key}) of
[] -> {error, not_found, State};
- [{{Bucket, Key}, {{ts, Timestamp}, Val}}] ->
+ [{{Bucket, Key}, {{ts, Timestamp}, Val}}=Object] ->
case exceeds_ttl(Timestamp, TTL) of
true ->
- delete(Bucket, Key, undefined, State),
- {error, not_found, State};
+ %% Because we do not have the IndexSpecs, we must
+ %% delete the object directly and all index
+ %% entries blindly using match_delete.
+ ets:delete(DataRef, {Bucket, Key}),
+ ets:match_delete(IndexRef, ?DELETE_PTN(Bucket, Key)),
+ {error, not_found, State#state{used_memory=UsedMemory - object_size(Object)}};
false ->
{ok, Val, State}
end;
@@ -177,13 +183,9 @@ get(Bucket, Key, State=#state{data_ref=DataRef,
end.
%% @doc Insert an object into the memory backend.
-%% NOTE: The memory backend does not currently
-%% support secondary indexing and the _IndexSpecs
-%% parameter is ignored.
-type index_spec() :: {add, Index, SecondaryKey} | {remove, Index, SecondaryKey}.
-spec put(riak_object:bucket(), riak_object:key(), [index_spec()], binary(), state()) ->
- {ok, state()} |
- {error, term(), state()}.
+ {ok, state()}.
put(Bucket, PrimaryKey, IndexSpecs, Val, State=#state{data_ref=DataRef,
index_ref=IndexRef,
max_memory=MaxMemory,
@@ -197,32 +199,23 @@ put(Bucket, PrimaryKey, IndexSpecs, Val, State=#state{data_ref=DataRef,
_ ->
Val1 = {{ts, Now}, Val}
end,
- case do_put(Bucket, PrimaryKey, Val1, IndexSpecs, DataRef, IndexRef) of
- {ok, Size} ->
- %% If the memory is capped update timestamp table
- %% and check if the memory usage is over the cap.
- case MaxMemory of
- undefined ->
- UsedMemory1 = UsedMemory;
- _ ->
- time_entry(Bucket, PrimaryKey, Now, TimeRef),
- Freed = trim_data_table(MaxMemory,
- UsedMemory + Size,
- DataRef,
- TimeRef,
- IndexRef,
- 0),
- UsedMemory1 = UsedMemory + Size - Freed
- end,
- {ok, State#state{used_memory=UsedMemory1}};
- {error, Reason} ->
- {error, Reason, State}
- end.
+ {ok, Size} = do_put(Bucket, PrimaryKey, Val1, IndexSpecs, DataRef, IndexRef),
+ case MaxMemory of
+ undefined ->
+ UsedMemory1 = UsedMemory;
+ _ ->
+ time_entry(Bucket, PrimaryKey, Now, TimeRef),
+ Freed = trim_data_table(MaxMemory,
+ UsedMemory + Size,
+ DataRef,
+ TimeRef,
+ IndexRef,
+ 0),
+ UsedMemory1 = UsedMemory + Size - Freed
+ end,
+ {ok, State#state{used_memory=UsedMemory1}}.
%% @doc Delete an object from the memory backend
-%% NOTE: The memory backend does not currently
-%% support secondary indexing and the _IndexSpecs
-%% parameter is ignored.
-spec delete(riak_object:bucket(), riak_object:key(), [index_spec()], state()) ->
{ok, state()}.
delete(Bucket, Key, IndexSpecs, State=#state{data_ref=DataRef,

0 comments on commit 334c8d8

Please sign in to comment.