Permalink
Browse files

Resolve the process crashes when doing key or object folds

Fixes: bz1255

To resolve the process crashes when doing key or object folds, the
Innostore connection port is also saved in the process dictionary
for reuse in asynchronous workers. Without this it is useless to
save the keystore information because using it with a different
port results in a bad argument error when the port_control
function is called.

Remove deps traversal since there are no deps for innostore
  • Loading branch information...
1 parent 1a99817 commit 1e4ce84d6e0507058c6dbe324047e153e123da18 Kelly McLaughlin committed Oct 19, 2011
Showing with 21 additions and 14 deletions.
  1. +1 −4 Makefile
  2. +20 −10 src/riak_kv_innostore_backend.erl
View
@@ -40,10 +40,7 @@ buildtar = mkdir distdir && \
git clone . distdir/$(REPO)-clone && \
cd distdir/$(REPO)-clone && \
git checkout $(INNOSTORE_TAG) && \
- $(call archive,$(RELEASE_NAME),..) && \
- mkdir ../$(RELEASE_NAME)/deps && \
- make deps; \
- for dep in deps/*; do cd $${dep} && $(call archive,$${dep},../../../$(RELEASE_NAME)); cd ../..; done
+ $(call archive,$(RELEASE_NAME),..) && cd ..
distdir:
$(if $(INNOSTORE_TAG), $(call buildtar), $(error "You can't generate a release tarball from a non-tagged revision. Run 'git checkout <tag>', then 'make dist'"))
@@ -160,13 +160,12 @@ fold_buckets(FoldBucketsFun, Acc, Opts, #state{partition_str=Partition,
true ->
BucketFolder =
fun() ->
- case innostore:connect() of
+ case get_port() of
{ok, Port1} ->
FoldResults =
lists:foldl(FilterFun,
Acc,
innostore:list_keystores(Port1)),
- innostore:disconnect(Port1),
FoldResults;
{error, Reason} ->
{error, Reason}
@@ -245,6 +244,21 @@ callback(_Ref, _Msg, State) ->
%% Internal functions
%% ===================================================================
+%% @private
+get_port() ->
+ case erlang:get(inno_port) of
+ undefined ->
+ case innostore:connect() of
+ {ok, Port} ->
+ erlang:put(inno_port, Port),
+ {ok, Port};
+ Error ->
+ Error
+ end;
+ Port ->
+ {ok, Port}
+ end.
+
%% @private
keystore(Bucket, Partition, Port) ->
KeyStoreId = <<Bucket/binary, Partition/binary>>,
@@ -268,7 +282,7 @@ fold_buckets_fun(FoldBucketsFun) ->
%% Return a function to synchronously fold over keys on this backend
async_key_folder(undefined, FoldFun, Acc, Partition) ->
fun() ->
- case innostore:connect() of
+ case get_port() of
{ok, Port} ->
Buckets = list_buckets(Partition, Port),
%% Fold over all keys in all buckets
@@ -277,7 +291,6 @@ async_key_folder(undefined, FoldFun, Acc, Partition) ->
FoldFun,
Partition,
Port),
- innostore:disconnect(Port),
FoldResults;
{error, Reason} ->
{error, Reason}
@@ -286,12 +299,11 @@ async_key_folder(undefined, FoldFun, Acc, Partition) ->
async_key_folder(Bucket, FoldFun, Acc, Partition) ->
FoldKeysFun = fold_keys_fun(FoldFun, Bucket),
fun() ->
- case innostore:connect() of
+ case get_port() of
{ok, Port} ->
KeyStore = keystore(Bucket, Partition, Port),
FoldResults =
innostore:fold_keys(FoldKeysFun, Acc, KeyStore),
- innostore:disconnect(Port),
FoldResults;
{error, Reason} ->
{error, Reason}
@@ -338,7 +350,7 @@ sync_object_fold(Bucket, FoldFun, Acc, Partition, Port) ->
%% Return a function to synchronously fold over objects on this backend
async_object_folder(undefined, FoldFun, Acc, Partition) ->
fun() ->
- case innostore:connect() of
+ case get_port() of
{ok, Port} ->
Buckets = list_buckets(Partition, Port),
%% Fold over all objects in all buckets
@@ -347,7 +359,6 @@ async_object_folder(undefined, FoldFun, Acc, Partition) ->
FoldFun,
Partition,
Port),
- innostore:disconnect(Port),
FoldResults;
{error, Reason} ->
{error, Reason}
@@ -356,11 +367,10 @@ async_object_folder(undefined, FoldFun, Acc, Partition) ->
async_object_folder(Bucket, FoldFun, Acc, Partition) ->
FoldObjectsFun = fold_objects_fun(FoldFun, Bucket),
fun() ->
- case innostore:connect() of
+ case get_port() of
{ok, Port} ->
KeyStore = keystore(Bucket, Partition, Port),
FoldResults = innostore:fold(FoldObjectsFun, Acc, KeyStore),
- innostore:disconnect(Port),
FoldResults;
{error, Reason} ->
{error, Reason}

0 comments on commit 1e4ce84

Please sign in to comment.