Skip to content

Commit

Permalink
Address final PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
buddhisthead committed Dec 20, 2013
1 parent 6b9737a commit b645b94
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
23 changes: 0 additions & 23 deletions include/riak_core_bg_manager.hrl
Expand Up @@ -16,29 +16,6 @@
%% specific language governing permissions and limitations
%% under the License.
%%
%% NOTES:
%% The background manager allows tokens and locks to be "acquired" by
%% competing processes in a way that limits the total load on the cluster.
%%
%% The model is different than your typical semaphore. Here, we are
%% interested in coordinating background jobs that start, run, and die.
%%
%%
%% The term "given" is a general version of "held", "acquired", or
%% "allocated" for both locks and tokens. Held doesn't make sense for
%% tokens since they aren't held. So, "given" applies to both locks
%% and tokens, but you can think "held" for locks if that's more fun.
%%
%% Resources are defined by their "names", which is the same as "type"
%% or "kind". A lock name might be the atom 'aae_hashtree_lock' or the
%% tuple '{my_ultimate_lock, 42}'.
%%
%% Usage:
%% 1. register your lock/token and set it's max concurrency/rate.
%% 2. "get" a lock/token by it's resource type/name
%% 3. do stuff
%% 4. let your process die, which gives back a lock.
%% -------------------------------------------------------------------
-type bg_lock() :: any().
-type bg_token() :: any().
-type bg_resource() :: bg_token() | bg_lock().
Expand Down
23 changes: 23 additions & 0 deletions src/riak_core_bg_manager.erl
Expand Up @@ -17,6 +17,29 @@
%% under the License.
%%
%% @doc
%% The background manager allows tokens and locks to be "acquired" by
%% competing processes in a way that limits the total load on the cluster.
%%
%% The model is different than your typical semaphore. Here, we are
%% interested in coordinating background jobs that start, run, and die.
%%
%% The term "given" is a general version of "held", "acquired", or
%% "allocated" for both locks and tokens. Held doesn't make sense for
%% tokens since they aren't held. So, "given" applies to both locks
%% and tokens, but you can think "held" for locks if that's more fun.
%%
%% Resources are defined by their "names", which is the same as "type"
%% or "kind". A lock name might be the atom 'aae_hashtree_lock' or the
%% tuple '{my_ultimate_lock, 42}'.
%%
%% Usage:
%% 1. register your lock/token and set it's max concurrency/rate.
%% 2. "get" a lock/token by it's resource type/name
%% 3. do stuff
%% 4. let your process die, which gives back a lock.
%%
%% @private
%% Internal Notes:
%% We use two ETS tables to store critical data. In the event this process crashes,
%% the tables will be given back to the table manager and we can reclaim them when
%% we restart. Thus, limits and states are maintained across restarts of the
Expand Down
32 changes: 22 additions & 10 deletions test/bg_manager_eqc.erl
@@ -1,14 +1,26 @@
%%% @author Jordan West <>
%%% @copyright (C) 2013, Jordan West
%%% @doc
%%%
%%% @end
%%% Created : 13 Nov 2013 by Jordan West <>
%% -------------------------------------------------------------------
%%
%% Copyright (c) 2013 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%

-module(bg_manager_eqc).

%%-ifdef(TEST).
%% -ifdef(EQC).
-ifdef(TEST).
-ifdef(EQC).

-include("riak_core_bg_manager.hrl").
-include_lib("eqc/include/eqc.hrl").
Expand Down Expand Up @@ -871,5 +883,5 @@ prop_bgmgr_parallel() ->
Res == ok))
end))).

%% -endif.
%% -endif.
-endif.
-endif.

0 comments on commit b645b94

Please sign in to comment.