Skip to content

Instantly share code, notes, and snippets.

@seancribbs
Created July 16, 2012 12:22
Show Gist options
  • Save seancribbs/3122409 to your computer and use it in GitHub Desktop.
Save seancribbs/3122409 to your computer and use it in GitHub Desktop.
--- erl_src/riak_kv_test_backend.erl 2012-07-06 14:52:37.000000000 -0400
+++ /Users/sean/Development/riak/deps/riak_kv/src/riak_kv_memory_backend.erl 2012-07-11 09:59:34.000000000 -0400
@@ -1,6 +1,6 @@
%% -------------------------------------------------------------------
%%
-%% riak_kv_test_backend: storage engine using ETS tables, for use in testing.
+%% riak_memory_backend: storage engine using ETS tables
%%
%% Copyright (c) 2007-2011 Basho Technologies, Inc. All Rights Reserved.
%%
@@ -32,11 +32,11 @@
%% <ul>
%% <li>`ttl' - The time in seconds that an object should live before being expired.</li>
%% <li>`max_memory' - The amount of memory in megabytes to limit the backend to.</li>
-%% <li>`test' - When `true', exposes the internal ETS tables so that they can be efficiently cleared using {@link reset/3}.</li>
+%% <li>`test' - When true, allow public access to ETS tables so they can be cleared efficiently.</li>
%% </ul>
%%
--module(riak_kv_test_backend).
+-module(riak_kv_memory_backend).
-behavior(riak_kv_backend).
%% KV Backend API
@@ -95,12 +95,7 @@
%% current API.
-spec api_version() -> {ok, integer()}.
api_version() ->
- case lists:member({capabilities, 1}, riak_kv_backend:behaviour_info(callbacks)) of
- true -> % Using 1.1 API or later
- {ok, ?API_VERSION};
- _ -> % Using 1.0 API
- {?API_VERSION, ?CAPABILITIES}
- end.
+ {ok, ?API_VERSION}.
%% @doc Return the capabilities of the backend.
-spec capabilities(state()) -> {ok, [atom()]}.
@@ -114,13 +109,10 @@
%% @doc Start the memory backend
-spec start(integer(), config()) -> {ok, state()}.
-%% Bug in riak_kv_vnode in 1.0
-start(Partition, [{async_folds,_}=AFolds, Rest]) when is_list(Rest) ->
- start(Partition, [AFolds|Rest]);
start(Partition, Config) ->
- TTL = get_prop_or_env(ttl, Config, memory_backend),
- MemoryMB = get_prop_or_env(max_memory, Config, memory_backend),
- TableOpts = case get_prop_or_env(test, Config, memory_backend) of
+ TTL = app_helper:get_prop_or_env(ttl, Config, memory_backend),
+ MemoryMB = app_helper:get_prop_or_env(max_memory, Config, memory_backend),
+ TableOpts = case app_helper:get_prop_or_env(test, Config, memory_backend) of
true ->
[ordered_set, public, named_table];
_ ->
@@ -591,26 +583,6 @@
end,
size(Bucket) + size(Key) + size(Val).
-%% Copied from riak_core 1.2 app_helper module
-%% @private
-%% @doc Retrieve value for Key from Properties if it exists, otherwise
-%% return from the application's env.
--spec get_prop_or_env(atom(), [{atom(), term()}], atom()) -> term().
-get_prop_or_env(Key, Properties, App) ->
- get_prop_or_env(Key, Properties, App, undefined).
-
-%% @private
-%% @doc Return the value for Key in Properties if it exists, otherwise return
-%% the value from the application's env, or Default.
--spec get_prop_or_env(atom(), [{atom(), term()}], atom(), term()) -> term().
-get_prop_or_env(Key, Properties, App, Default) ->
- case proplists:get_value(Key, Properties) of
- undefined ->
- app_helper:get_env(App, Key, Default);
- Value ->
- Value
- end.
-
%% ===================================================================
%% EUnit tests
%% ===================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment