Skip to content

Commit

Permalink
port of mv-cache-object-warming from develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew V committed Jul 30, 2015
1 parent 376cec5 commit 96e172f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion c_src/build_deps.sh
Expand Up @@ -8,7 +8,7 @@ if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
fi
unset POSIX_SHELL # clear it so if we invoke other scripts, they run as ksh as well

LEVELDB_VSN="2.0.7"
LEVELDB_VSN="2.0.8"

SNAPPY_VSN="1.0.4"

Expand Down
9 changes: 9 additions & 0 deletions c_src/eleveldb.cc
Expand Up @@ -134,6 +134,7 @@ ERL_NIF_TERM ATOM_DELETE_THRESHOLD;
ERL_NIF_TERM ATOM_TIERED_SLOW_LEVEL;
ERL_NIF_TERM ATOM_TIERED_FAST_PREFIX;
ERL_NIF_TERM ATOM_TIERED_SLOW_PREFIX;
ERL_NIF_TERM ATOM_CACHE_OBJECT_WARMING;
} // namespace eleveldb


Expand Down Expand Up @@ -449,6 +450,13 @@ ERL_NIF_TERM parse_open_option(ErlNifEnv* env, ERL_NIF_TERM item, leveldb::Optio
if (0<ret_val && ret_val<256)
opts.tiered_slow_prefix = buffer;
}
else if (option[0] == eleveldb::ATOM_CACHE_OBJECT_WARMING)
{
if (option[1] == eleveldb::ATOM_TRUE)
opts.cache_object_warming = true;
else
opts.cache_object_warming = false;
}

}

Expand Down Expand Up @@ -1259,6 +1267,7 @@ try
ATOM(eleveldb::ATOM_TIERED_SLOW_LEVEL, "tiered_slow_level");
ATOM(eleveldb::ATOM_TIERED_FAST_PREFIX, "tiered_fast_prefix");
ATOM(eleveldb::ATOM_TIERED_SLOW_PREFIX, "tiered_slow_prefix");
ATOM(eleveldb::ATOM_CACHE_OBJECT_WARMING, "cache_object_warming");
#undef ATOM


Expand Down
12 changes: 12 additions & 0 deletions priv/eleveldb.schema
Expand Up @@ -228,3 +228,15 @@
{datatype, directory},
hidden
]}.

%% @doc This parameter enables/disables logic that saves a list
%% of cached objects (currently only open .sst file names) at
%% database close. The list is used on the next open to pre-populate
%% the cache. This typically eliminates heavy latencies associated
%% with .sst files opening for early user requests.
{mapping, "leveldb.cache_object_warming", "eleveldb.cache_object_warming", [
{default, on},
{datatype, flag},
hidden
]}.

8 changes: 8 additions & 0 deletions priv/eleveldb_multi.schema
Expand Up @@ -155,3 +155,11 @@
{datatype, directory},
hidden
]}.

%% @see leveldb.cache_object_warming
{mapping, "multi_backend.$name.leveldb.cache_object_warming", "riak_kv.multi_backend", [
{default, on},
{datatype, flag},
hidden
]}.

2 changes: 1 addition & 1 deletion rebar.config
Expand Up @@ -9,7 +9,7 @@
{erl_opts, [warnings_as_errors, debug_info]}.

{deps, [
{cuttlefish, ".*", {git, "git://github.com/basho/cuttlefish.git", {branch, "2.0"}}}
{cuttlefish, ".*", {git, "git://github.com/basho/cuttlefish.git", {tag, "2.0.1"}}}
]}.

{port_env, [
Expand Down
25 changes: 22 additions & 3 deletions src/eleveldb.erl
Expand Up @@ -25,6 +25,7 @@
close/1,
get/3,
put/4,
async_put/5,
delete/3,
write/3,
fold/4,
Expand Down Expand Up @@ -101,7 +102,8 @@ init() ->
{delete_threshold, pos_integer()} |
{tiered_slow_level, pos_integer()} |
{tiered_fast_prefix, string()} |
{tiered_slow_prefix, string()}].
{tiered_slow_prefix, string()} |
{cache_object_warming, boolean()}].

-type read_options() :: [{verify_checksums, boolean()} |
{fill_cache, boolean()} |
Expand Down Expand Up @@ -161,6 +163,12 @@ write(Ref, Updates, Opts) ->
async_write(CallerRef, Ref, Updates, Opts),
?WAIT_FOR_REPLY(CallerRef).

-spec async_put(db_ref(), reference(), binary(), binary(), write_options()) -> ok.
async_put(Ref, Context, Key, Value, Opts) ->
Updates = [{put, Key, Value}],
async_write(Context, Ref, Updates, Opts),
ok.

-spec async_write(reference(), db_ref(), write_actions(), write_options()) -> ok.
async_write(_CallerRef, _Ref, _Updates, _Opts) ->
erlang:nif_error({error, not_loaded}).
Expand Down Expand Up @@ -293,7 +301,8 @@ option_types(open) ->
{delete_threshold, integer},
{tiered_slow_level, integer},
{tiered_fast_prefix, any},
{tiered_slow_prefix, any}];
{tiered_slow_prefix, any},
{cache_object_warming, bool}];

option_types(read) ->
[{verify_checksums, bool},
Expand Down Expand Up @@ -480,13 +489,23 @@ values() ->
eqc_gen:non_empty(list(binary())).

ops(Keys, Values) ->
{oneof([put, delete]), oneof(Keys), oneof(Values)}.
{oneof([put, async_put, delete]), oneof(Keys), oneof(Values)}.

apply_kv_ops([], _Ref, Acc0) ->
Acc0;
apply_kv_ops([{put, K, V} | Rest], Ref, Acc0) ->
ok = eleveldb:put(Ref, K, V, []),
apply_kv_ops(Rest, Ref, orddict:store(K, V, Acc0));
apply_kv_ops([{async_put, K, V} | Rest], Ref, Acc0) ->
MyRef = make_ref(),
Context = {my_context, MyRef},
ok = eleveldb:async_put(Ref, Context, K, V, []),
receive
{Context, ok} ->
apply_kv_ops(Rest, Ref, orddict:store(K, V, Acc0));
Msg ->
error({unexpected_msg, Msg})
end;
apply_kv_ops([{delete, K, _} | Rest], Ref, Acc0) ->
ok = eleveldb:delete(Ref, K, []),
apply_kv_ops(Rest, Ref, orddict:store(K, deleted, Acc0)).
Expand Down

0 comments on commit 96e172f

Please sign in to comment.