From 9df7c69b7930ec685444aa2382b086a91a878760 Mon Sep 17 00:00:00 2001 From: Joseph Blomstedt Date: Thu, 19 Feb 2015 13:27:03 -0800 Subject: [PATCH 1/3] async_put (immutable work-in-progress) --- src/eleveldb.erl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/eleveldb.erl b/src/eleveldb.erl index 0e75563e..d0803e42 100644 --- a/src/eleveldb.erl +++ b/src/eleveldb.erl @@ -25,6 +25,7 @@ close/1, get/3, put/4, + async_put/5, delete/3, write/3, fold/4, @@ -161,6 +162,11 @@ write(Ref, Updates, Opts) -> async_write(CallerRef, Ref, Updates, Opts), ?WAIT_FOR_REPLY(CallerRef). +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}). From 26a1ac6224287476e28e0635c0b8919e998e019b Mon Sep 17 00:00:00 2001 From: Fred Dushin Date: Thu, 26 Mar 2015 23:13:10 -0400 Subject: [PATCH 2/3] Fixed dialyzer spec for asyc_put --- src/eleveldb.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/eleveldb.erl b/src/eleveldb.erl index d0803e42..8046e158 100644 --- a/src/eleveldb.erl +++ b/src/eleveldb.erl @@ -162,6 +162,7 @@ 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), From d946c610ebd1aff5780293cc985eef611b8cd747 Mon Sep 17 00:00:00 2001 From: Jon Meredith Date: Sun, 29 Mar 2015 19:20:39 -0600 Subject: [PATCH 3/3] Extended EQC test for async_put. --- src/eleveldb.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/eleveldb.erl b/src/eleveldb.erl index 8046e158..fa32975b 100644 --- a/src/eleveldb.erl +++ b/src/eleveldb.erl @@ -484,13 +484,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)).